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
740740}
741741
742742pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void {
743 var symbol_name: []const u8 = "";
744 var compile_unit_name: []const u8 = "";
745 var line_info: ?LineInfo = null;
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 => {},
743 const module = debug_info.lookupByAddress(address) catch |err| switch (err) {
744 error.MissingDebugInfo, error.InvalidDebugInfo => {
745 return printLineInfo(out_stream, null, address, "???", "???", tty_config, printLineFromFileAnyOs);
746 },
767747 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
772753 return printLineInfo(
773754 out_stream,
774 line_info,
755 info.line_info,
775756 address,
776 symbol_name,
777 compile_unit_name,
757 info.symbol_name,
758 info.compile_unit_name,
778759 tty_config,
779760 printLineFromFileAnyOs,
780761 );
......@@ -1445,6 +1426,12 @@ pub const DebugInfo = struct {
14451426 }
14461427};
14471428
1429const SymbolInfo = struct {
1430 symbol_name: []const u8,
1431 compile_unit_name: []const u8,
1432 line_info: ?LineInfo,
1433};
1434
14481435pub const ObjectDebugInfo = switch (builtin.os) {
14491436 .macosx, .ios, .watchos, .tvos => struct {
14501437 base_address: usize,
......@@ -1475,6 +1462,36 @@ pub const ObjectDebugInfo = switch (builtin.os) {
14751462 base_address: usize,
14761463 dwarf: DW.DwarfInfo,
14771464 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 }
14781495 },
14791496 else => DW.DwarfInfo,
14801497};