authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-02-21 12:11:04+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-02-21 12:11:04+01:00
log8df4d7e4f445e8e9598b79bc495503d919c0d99a
tree5f13d61cb4676d352f863af8d7d03176f8c14e3b
parenta4d0d7f1de78a6d0b4993baeca0b8aa636ba9f33

unsure


1 files changed, 46 insertions(+), 29 deletions(-)

lib/std/debug.zig+46-29
...@@ -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}
741741
742pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void {742pub 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);
746746 },
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 };
769749
770 defer if (line_info) |li| li.deinit();750 const info = try module.getSymbolAtAddress(address);
751 defer if (info.line_info) |li| li.deinit();
771752
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};
14471428
1429const SymbolInfo = struct {
1430 symbol_name: []const u8,
1431 compile_unit_name: []const u8,
1432 line_info: ?LineInfo,
1433};
1434
1448pub const ObjectDebugInfo = switch (builtin.os) {1435pub 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};