Skip to content

Dwarf.zig parser fails to get valid source locations from DWARF 5 #23732

@SamWindell

Description

@SamWindell

Zig Version

0.14.0 - but present in master too

Steps to Reproduce and Observed Behavior

std.debug.Dwarf fails to extract source files and line numbers info from my C++ code when compiled with zig compiler and -gdwarf-5 (or just -gdwarf which defaults to 5). std.debug.Dwarf.getSynbol will have null as it's source_location field.

libbacktrace seems to find source locations fine.

If compiled with -gdwarf-4 it also works fine.

These binaries have embedded DWARF 5 info that should recreate this issue.

Stepping through with the debugger, this line returns an error:

const compile_unit_cwd = try compile_unit.die.getAttrString(d, AT.comp_dir, d.section(.debug_line_str), compile_unit.*);

A simple fix I found is to move the declaration of compile_unit_cwd to inside the if (version < 5) {} so that it only runs when it's actually needed: for version 4 or lower. I don't know the reason why this works so I'm not confident to suggest it unanimously.

Workaround for me is to use -gdwarf-4.

Expected Behavior

Source location and line number should be correctly extracted from DWARF 5.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions