diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-02-21 12:11:04 +0100 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2020-02-21 12:11:04 +0100 |
| commit | 8df4d7e4f445e8e9598b79bc495503d919c0d99a (patch) | |
| tree | 5f13d61cb4676d352f863af8d7d03176f8c14e3b /lib/std/debug.zig | |
| parent | a4d0d7f1de78a6d0b4993baeca0b8aa636ba9f33 (diff) | |
| download | zig-8df4d7e4f445e8e9598b79bc495503d919c0d99a.tar.gz zig-8df4d7e4f445e8e9598b79bc495503d919c0d99a.zip | |
unsure
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 75 |
1 files changed, 46 insertions, 29 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 9b5f23001a..27c53a1f37 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -740,41 +740,22 @@ fn printSourceAtAddressMacOs(debug_info: *DebugInfo, out_stream: var, address: u } pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void { - var symbol_name: []const u8 = ""; - var compile_unit_name: []const u8 = ""; - var line_info: ?LineInfo = null; - - if (debug_info.lookupByAddress(address)) |module| { - // Translate the VA into an address into this object - const relocated_address = address - module.base_address; - - if (module.dwarf.findCompileUnit(relocated_address)) |compile_unit| { - symbol_name = module.dwarf.getSymbolName(relocated_address) orelse "???"; - compile_unit_name = compile_unit.die.getAttrString(&module.dwarf, DW.AT_name) catch |err| switch (err) { - error.MissingDebugInfo, error.InvalidDebugInfo => "???", - else => return err, - }; - line_info = module.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) { - error.MissingDebugInfo, error.InvalidDebugInfo => null, - else => return err, - }; - } else |err| switch (err) { - error.MissingDebugInfo, error.InvalidDebugInfo => {}, - else => return err, - } - } else |err| switch (err) { - error.MissingDebugInfo, error.InvalidDebugInfo => {}, + const module = debug_info.lookupByAddress(address) catch |err| switch (err) { + error.MissingDebugInfo, error.InvalidDebugInfo => { + return printLineInfo(out_stream, null, address, "???", "???", tty_config, printLineFromFileAnyOs); + }, else => return err, - } + }; - defer if (line_info) |li| li.deinit(); + const info = try module.getSymbolAtAddress(address); + defer if (info.line_info) |li| li.deinit(); return printLineInfo( out_stream, - line_info, + info.line_info, address, - symbol_name, - compile_unit_name, + info.symbol_name, + info.compile_unit_name, tty_config, printLineFromFileAnyOs, ); @@ -1445,6 +1426,12 @@ pub const DebugInfo = struct { } }; +const SymbolInfo = struct { + symbol_name: []const u8, + compile_unit_name: []const u8, + line_info: ?LineInfo, +}; + pub const ObjectDebugInfo = switch (builtin.os) { .macosx, .ios, .watchos, .tvos => struct { base_address: usize, @@ -1475,6 +1462,36 @@ pub const ObjectDebugInfo = switch (builtin.os) { base_address: usize, dwarf: DW.DwarfInfo, mapped_memory: []const u8, + + fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo { + // Translate the VA into an address into this object + const relocated_address = address - self.base_address; + + if (self.dwarf.findCompileUnit(relocated_address)) |compile_unit| { + return SymbolInfo{ + .symbol_name = self.dwarf.getSymbolName(relocated_address) orelse "???", + .compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) { + error.MissingDebugInfo, error.InvalidDebugInfo => "???", + else => return err, + }, + .line_info = self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) { + error.MissingDebugInfo, error.InvalidDebugInfo => null, + else => return err, + }, + }; + } else |err| switch (err) { + error.MissingDebugInfo, error.InvalidDebugInfo => { + return SymbolInfo{ + .symbol_name = "???", + .compile_unit_name = "???", + .line_info = null, + }; + }, + else => return err, + } + + unreachable; + } }, else => DW.DwarfInfo, }; |
