Skip to content

printer: Use std dwarf implementation - #1115

Merged
mattnite merged 8 commits into
mainfrom
printer_std_dwarf
Nov 13, 2026
Merged

mattnite merged 8 commits into
mainfrom
printer_std_dwarf

Conversation

@tact1m4n3

@tact1m4n3 tact1m4n3 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Tested on an esp32c3 stack trace, it gives the same results as before

Comment thread tools/printer/src/root.zig Outdated
const maybe_src_loc = di.getLineNumberInfo(gpa, text_arena.allocator(), elf.endian, compile_unit, address) catch null;

try output_location_info(terminal, address, maybe_name, maybe_src_loc);
if (maybe_src_loc) |src_loc| try output_source_line(io, terminal, src_loc);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe outside the scope of this PR and up for debate, but why not just make this shaped more like output_location_info, let it take an optional maybe_src_loc, and handle the logic there?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is more like a style preference. Inspired from TIGERSTYLE:

Centralize control flow. When splitting a large function, try to keep all switch/if statements in the "parent" function, and move non-branchy logic fragments to helper functions. Divide responsibility. All control flow should be handled by one function, the rest shouldn't care about control flow at all. In other words, "push ifs up and fors down".

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah that makes sense, the inconsistency is what stuck out to me. output_location_info still needs the maybe you I guess you can't do it there. That's fine by me. Ship it!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't know this was tiger style, but since we're in a nitty mood, this is definitely how I like to do things.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@Grazfather I did some more refactoring to clear the control flow a bit. We probably don't want to print only question marks in the annotation (in case both symbol name and source loc is null) :) I wonder if there is a situation where you get a symbol name but no source location 🤔 For now I refactored so we only print if we have all the info.

Comment thread .github/workflows/ci.yml
run: zig build test
working-directory: tools/esp-image

test-printer:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we get a build for the test printer and the example so that we at least smoke test here? Also is there anything from the removed tests that we could keep around?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good idea :) All the previous tests were for the dwarf parser.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Interesting.. the windows build is failing. What do you suggest? Should we wait on this PR until std.debug.Info is truly cross platform? The problem is that std.debug.ElfFile isn't yet updated to use std.Io.File.MemoryMap

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm let's just test on the other ones and cut a ticket to check back in later. Lame, but AFAIK no one is using this yet, when that happens we can always revert.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've made a PR to make it truly cross platform (by applying the changes on 0.17.1 I can compile to windows): https://codeberg.org/ziglang/zig/pulls/37592

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work! I'll cut a ticket to turn on windows when we get to 0.18

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I removed windows from CI

@mattnite
mattnite merged commit ea71ec4 into main Nov 13, 2026
36 checks passed
@mattnite
mattnite deleted the printer_std_dwarf branch November 13, 2026 20:38
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.

3 participants