-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add COFF (Windows) support to std/debug (stack traces) #721
Comments
Depends on #516 (which will be resolved with llvm 6) |
Currently does: - read COFF executable file - locate and load corresponding .pdb file - expose .pdb content as streams (PDB format)
Working in the test.zigtest "crash" {
@panic("boom");
} output
So this is getting a valid list of addresses from
(Indeed if you decode the last field before
I'll try auditing the Msf stream code and make sure that it is correctly reading the bytes. |
Weird, I actually get an error from llvm-pdbutil:
|
Oh, I probably am supposed to run that on the pdb file :-) |
So the next step is getting zig's code to match this output. Zig is not correctly finding the offset for module 2. |
I studied the MSF code and it looks fine. There are 2 problems right now, where I am stuck:
I haven't tried to solve the second problem yet, but here's where I'm at with the first problem. This is debug output interspersed with my commentary:
These are printing the offsets that we read. The first value is the file offset. I pasted the output from the middle of parsing modules. Here we are at the end of finding the module name.
Found the 0 byte. So next we read the ModInfo struct.
This ends up being bogus data. We read another ModInfo, but the offset is whack:
The part where we read a null terminated string found the end of a module name. I added a hack to seek the stream back to the beginning of the ModInfo based on this data, which is why it says
This ends up being the correct module (see below)
At this point everything parses fine until the end of the module info stream. So here's the interesting part: the correct offset was I read the source code for llvm-pdbutil and it looks like it has the same logic as I have here in this branch - read the struct, read 2 null terminated strings. I don't see any code in there for alignment or padding. |
I added this logic and it does work, but I'm confused since I don't see the equivalent in llvm-pdbutil or in the documentation: const march_forward_bytes = dbi.getFilePos() % 4;
if (march_forward_bytes != 0) {
try dbi.seekForward(march_forward_bytes);
mod_info_offset += march_forward_bytes;
} Anyway if we run with this for now, we're down to this question:
|
Mystery solved: uint32_t DbiModuleDescriptor::getRecordLength() const {
uint32_t M = ModuleName.str().size() + 1;
uint32_t O = ObjFileName.str().size() + 1;
uint32_t Size = sizeof(ModuleInfoHeader) + M + O;
Size = alignTo(Size, 4);
return Size;
} So the length is 4 bytes aligned. As for the other mystery, I think I solved that one too. The |
|
Glad you have zturner helping. I unfortunately do not have time to spend on this at the moment, and can only follow your progress. :( |
No worries, thanks for getting me started! |
Now, based on address, zig can find object name and function name. Next up, figure out how the CodeView line information in C13 format works. At this point the documentation does not exist and I'm left reading llvm source code. |
This is starting to come together:
|
Regarding the |
It's all figured out now! Just need to re-arrange the code and pretty print it |
Right now if you try to print a stack trace on windows, it prints "Stack trace not available for COFF"
These are super useful, especially now that we have error return tracing.
The text was updated successfully, but these errors were encountered: