Skip to content

std.debug.Dwarf enhancements #25418

@mlugg

Description

@mlugg

This is just a list of enhancements which should be applied to std.debug.Dwarf. This issue can be closed when all of these are investigated and/or resolved.

The implementation of std.debug.Dwarf is extremely old (it looks to have evolved organically from the very first implementation of debug info in the standard library!), so I strongly suspect that the best solution to these issues would be a sweeping refactor or even a rewrite.

  • Detect and print inline callers in stack traces (detect inline calls in std.debug.Dwarf and print their frames in stack traces #19407). When printing stack traces, we should not only resolve the source location of the return address, but also print frames corresponding to any inline callees at this point. This will also require some enhancements to the std.debug.SelfInfo API so that this information can be communicated to stack trace printing logic.

  • Audit the "scanning" functions. It's very weird that open scans functions, then compile units, when compile units are required information for functions; this implies we're doing redundant work. I'm also not sure if it even makes sense to be doing this stuff separately; probably we should scan all DIEs at once, collecting whatever information we need (perhaps the user could pass in options saying what to collect vs ignore).

  • Remove or rename open. This name is very bad, because the function doesn't "open" anything nowadays (I think it's named this because it opened a file in the past). I don't think there's actually any need for it to exist at all (it's only two lines anyway!), but if there is, then it should be named something more appropriate.

  • Decrease memory consumption of the line number tables. 1792258 introduced a cache for line number information for performance reasons, but it takes up several megabytes even for simple binaries, which in (e.g.) freestanding contexts may be undesirable. We should try to find a middle ground where lookups are relatively fast without consuming too much memory.

  • Remove std.debug.Dwarf.Section. The owned field here is redundant. The idea behind it is that callers set it to true if they needed to, for instance, decompress the section from a file rather than directly memory-mapping it; but this use case, where you make multiple allocations (up to one per DWARF section) and will free them all as a batch, is exactly what arena allocators are for! I believe that this field is unused as of b64535e, so removing it should be pretty straightforward. At that point, Section itself need not exist, because it's just a slice of the bytes as God intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions