Skip to content
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

Use DWARF debug format option #19633

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

chrisbodhi
Copy link

Addresses #19478

.elf, .macho, .wasm => switch (options.debug_format.?.dwarf) {
.@"32" => .{ .dwarf = .@"32" },
.@"64" => .{ .dwarf = .@"64" },
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as expected with

$ zig build-obj -gdwarf32 -O Debug -target x86_64-linux example.zig

$ /opt/homebrew/opt/binutils/bin/objdump --dwarf=info example.o | head -20

example.o:     file format elf64-x86-64

Contents of the .debug_info section:

  Compilation Unit @ offset 0:
   Length:        0x25f5a (32-bit)
   Version:       4
   Abbrev Offset: 0
   Pointer Size:  8
...

and

$ zig build-obj -gdwarf64 -O Debug -target x86_64-linux example.zig

$ /opt/homebrew/opt/binutils/bin/objdump --dwarf=info example.o | head -20

example.o:     file format elf64-x86-64

Contents of the .debug_info section:

  Compilation Unit @ offset 0:
   Length:        0x31232 (64-bit)
   Version:       4
   Abbrev Offset: 0
   Pointer Size:  8
...

But, reviewing my code, I'm unsure of what the behavior would be if debug_format were empty. I can see that a 32-bit size is used when no flag is added:

$ zig build-obj -O Debug -target x86_64-linux example.zig

$ /opt/homebrew/opt/binutils/bin/objdump --dwarf=info example.o | head -20

example.o:     file format elf64-x86-64

Contents of the .debug_info section:

  Compilation Unit @ offset 0:
   Length:        0x25f5a (32-bit)
   Version:       4
   Abbrev Offset: 0
   Pointer Size:  8
...

Is this wanted?

@geezmolycos
Copy link

I can see in past versions 32-bit format was used, and the -dwarf64 option was added to resolve a specific problem (#7962), so default to 32-bit should be good for most situations.

@geezmolycos
Copy link

Also, as a further suggestion, it might be straightforward to also support DWARF generation for windows target (COFF object) with these options. As mentioned in CodeLLDB's wiki page, LLDB's support for CodeView is incomplete, and GDB currently has no support for Codeview.

Allowing DWARF generation for windows could make it easier to integrate with mingw toolchain (which uses GDB or LLDB) and to debug zig program in Wine environment

@chrisbodhi chrisbodhi force-pushed the 19478-use-dwarf-debug-format-opt branch from 7afec96 to b1ff696 Compare April 17, 2024 13:45
@chrisbodhi
Copy link
Author

@geezmolycos I made a pass at adding DWARF support for COFF objects as you suggested, but with my limited time, wasn't able to come up with a good emulation solution for verifying my changes. I'd prefer to add a new issue for adding DWARF support for COFF objects, and get this code reviewed as is. How does that all sound to you?

@geezmolycos
Copy link

Okay, the current solution should be fine for the original problem. I know that the COFF thing might need more reviewing and testing. I will look into that and post another issue to find help or try to work with that myself. Anyways, thanks for your contribution

@chrisbodhi chrisbodhi marked this pull request as ready for review April 23, 2024 12:46
@chrisbodhi
Copy link
Author

Thanks for all of your guidance, @geezmolycos, and for writing a detailed & helpful issue -- that made it much easier to contribute. :D

@chrisbodhi
Copy link
Author

@kubkon 👋 Pinging for a review, since you've previously reviewed a different, related PR.

@chrisbodhi
Copy link
Author

@andrewrk 👋 Pinging for a review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants