| ... | @@ -740,41 +740,22 @@ fn printSourceAtAddressMacOs(debug_info: *DebugInfo, out_stream: var, address: u | ... | @@ -740,41 +740,22 @@ fn printSourceAtAddressMacOs(debug_info: *DebugInfo, out_stream: var, address: u |
| 740 | } | 740 | } |
| 741 | | 741 | |
| 742 | pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void { | 742 | pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void { |
| 743 | var symbol_name: []const u8 = ""; | 743 | const module = debug_info.lookupByAddress(address) catch |err| switch (err) { |
| 744 | var compile_unit_name: []const u8 = ""; | 744 | error.MissingDebugInfo, error.InvalidDebugInfo => { |
| 745 | var line_info: ?LineInfo = null; | 745 | return printLineInfo(out_stream, null, address, "???", "???", tty_config, printLineFromFileAnyOs); |
| 746 | | 746 | }, |
| 747 | if (debug_info.lookupByAddress(address)) |module| { | | |
| 748 | // Translate the VA into an address into this object | | |
| 749 | const relocated_address = address - module.base_address; | | |
| 750 | | | |
| 751 | if (module.dwarf.findCompileUnit(relocated_address)) |compile_unit| { | | |
| 752 | symbol_name = module.dwarf.getSymbolName(relocated_address) orelse "???"; | | |
| 753 | compile_unit_name = compile_unit.die.getAttrString(&module.dwarf, DW.AT_name) catch |err| switch (err) { | | |
| 754 | error.MissingDebugInfo, error.InvalidDebugInfo => "???", | | |
| 755 | else => return err, | | |
| 756 | }; | | |
| 757 | line_info = module.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) { | | |
| 758 | error.MissingDebugInfo, error.InvalidDebugInfo => null, | | |
| 759 | else => return err, | | |
| 760 | }; | | |
| 761 | } else |err| switch (err) { | | |
| 762 | error.MissingDebugInfo, error.InvalidDebugInfo => {}, | | |
| 763 | else => return err, | | |
| 764 | } | | |
| 765 | } else |err| switch (err) { | | |
| 766 | error.MissingDebugInfo, error.InvalidDebugInfo => {}, | | |
| 767 | else => return err, | 747 | else => return err, |
| 768 | } | 748 | }; |
| 769 | | 749 | |
| 770 | defer if (line_info) |li| li.deinit(); | 750 | const info = try module.getSymbolAtAddress(address); |
| | 751 | defer if (info.line_info) |li| li.deinit(); |
| 771 | | 752 | |
| 772 | return printLineInfo( | 753 | return printLineInfo( |
| 773 | out_stream, | 754 | out_stream, |
| 774 | line_info, | 755 | info.line_info, |
| 775 | address, | 756 | address, |
| 776 | symbol_name, | 757 | info.symbol_name, |
| 777 | compile_unit_name, | 758 | info.compile_unit_name, |
| 778 | tty_config, | 759 | tty_config, |
| 779 | printLineFromFileAnyOs, | 760 | printLineFromFileAnyOs, |
| 780 | ); | 761 | ); |
| ... | @@ -1445,6 +1426,12 @@ pub const DebugInfo = struct { | ... | @@ -1445,6 +1426,12 @@ pub const DebugInfo = struct { |
| 1445 | } | 1426 | } |
| 1446 | }; | 1427 | }; |
| 1447 | | 1428 | |
| | 1429 | const SymbolInfo = struct { |
| | 1430 | symbol_name: []const u8, |
| | 1431 | compile_unit_name: []const u8, |
| | 1432 | line_info: ?LineInfo, |
| | 1433 | }; |
| | 1434 | |
| 1448 | pub const ObjectDebugInfo = switch (builtin.os) { | 1435 | pub const ObjectDebugInfo = switch (builtin.os) { |
| 1449 | .macosx, .ios, .watchos, .tvos => struct { | 1436 | .macosx, .ios, .watchos, .tvos => struct { |
| 1450 | base_address: usize, | 1437 | base_address: usize, |
| ... | @@ -1475,6 +1462,36 @@ pub const ObjectDebugInfo = switch (builtin.os) { | ... | @@ -1475,6 +1462,36 @@ pub const ObjectDebugInfo = switch (builtin.os) { |
| 1475 | base_address: usize, | 1462 | base_address: usize, |
| 1476 | dwarf: DW.DwarfInfo, | 1463 | dwarf: DW.DwarfInfo, |
| 1477 | mapped_memory: []const u8, | 1464 | mapped_memory: []const u8, |
| | 1465 | |
| | 1466 | fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo { |
| | 1467 | // Translate the VA into an address into this object |
| | 1468 | const relocated_address = address - self.base_address; |
| | 1469 | |
| | 1470 | if (self.dwarf.findCompileUnit(relocated_address)) |compile_unit| { |
| | 1471 | return SymbolInfo{ |
| | 1472 | .symbol_name = self.dwarf.getSymbolName(relocated_address) orelse "???", |
| | 1473 | .compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) { |
| | 1474 | error.MissingDebugInfo, error.InvalidDebugInfo => "???", |
| | 1475 | else => return err, |
| | 1476 | }, |
| | 1477 | .line_info = self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) { |
| | 1478 | error.MissingDebugInfo, error.InvalidDebugInfo => null, |
| | 1479 | else => return err, |
| | 1480 | }, |
| | 1481 | }; |
| | 1482 | } else |err| switch (err) { |
| | 1483 | error.MissingDebugInfo, error.InvalidDebugInfo => { |
| | 1484 | return SymbolInfo{ |
| | 1485 | .symbol_name = "???", |
| | 1486 | .compile_unit_name = "???", |
| | 1487 | .line_info = null, |
| | 1488 | }; |
| | 1489 | }, |
| | 1490 | else => return err, |
| | 1491 | } |
| | 1492 | |
| | 1493 | unreachable; |
| | 1494 | } |
| 1478 | }, | 1495 | }, |
| 1479 | else => DW.DwarfInfo, | 1496 | else => DW.DwarfInfo, |
| 1480 | }; | 1497 | }; |