authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-05 22:46:30-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-07 00:48:32-07:00
log40edd11516081b455df09ce0d19b3ca686655924
treef7412e8c4da4c0cd31c065855c9db0612a958072
parent8dae629c4f89155b6945ee952ee2aeb5bfa1d271

std.debug: fix compile errors on windows and macos


2 files changed, 15 insertions(+), 12 deletions(-)

lib/std/debug/Dwarf.zig+1-1
...@@ -2352,7 +2352,7 @@ pub const ElfModule = struct {...@@ -2352,7 +2352,7 @@ pub const ElfModule = struct {
2352 }2352 }
2353};2353};
23542354
2355fn getSymbol(di: *Dwarf, allocator: Allocator, address: u64) !std.debug.Symbol {2355pub fn getSymbol(di: *Dwarf, allocator: Allocator, address: u64) !std.debug.Symbol {
2356 if (di.findCompileUnit(address)) |compile_unit| {2356 if (di.findCompileUnit(address)) |compile_unit| {
2357 return .{2357 return .{
2358 .name = di.getSymbolName(address) orelse "???",2358 .name = di.getSymbolName(address) orelse "???",
lib/std/debug/SelfInfo.zig+14-11
...@@ -602,10 +602,11 @@ pub const Module = switch (native_os) {...@@ -602,10 +602,11 @@ pub const Module = switch (native_os) {
602 sections[@intFromEnum(Dwarf.Section.Id.debug_line)] == null;602 sections[@intFromEnum(Dwarf.Section.Id.debug_line)] == null;
603 if (missing_debug_info) return error.MissingDebugInfo;603 if (missing_debug_info) return error.MissingDebugInfo;
604604
605 var di = Dwarf{605 var di: Dwarf = .{
606 .endian = .little,606 .endian = .little,
607 .sections = sections,607 .sections = sections,
608 .is_macho = true,608 .is_macho = true,
609 .compile_units_sorted = false,
609 };610 };
610611
611 try Dwarf.open(&di, allocator);612 try Dwarf.open(&di, allocator);
...@@ -622,7 +623,7 @@ pub const Module = switch (native_os) {...@@ -622,7 +623,7 @@ pub const Module = switch (native_os) {
622 return result.value_ptr;623 return result.value_ptr;
623 }624 }
624625
625 pub fn getSymbolAtAddress(self: *@This(), allocator: Allocator, address: usize) !Dwarf.SymbolInfo {626 pub fn getSymbolAtAddress(self: *@This(), allocator: Allocator, address: usize) !std.debug.Symbol {
626 nosuspend {627 nosuspend {
627 const result = try self.getOFileInfoForAddress(allocator, address);628 const result = try self.getOFileInfoForAddress(allocator, address);
628 if (result.symbol == null) return .{};629 if (result.symbol == null) return .{};
...@@ -630,19 +631,19 @@ pub const Module = switch (native_os) {...@@ -630,19 +631,19 @@ pub const Module = switch (native_os) {
630 // Take the symbol name from the N_FUN STAB entry, we're going to631 // Take the symbol name from the N_FUN STAB entry, we're going to
631 // use it if we fail to find the DWARF infos632 // use it if we fail to find the DWARF infos
632 const stab_symbol = mem.sliceTo(self.strings[result.symbol.?.strx..], 0);633 const stab_symbol = mem.sliceTo(self.strings[result.symbol.?.strx..], 0);
633 if (result.o_file_info == null) return .{ .symbol_name = stab_symbol };634 if (result.o_file_info == null) return .{ .name = stab_symbol };
634635
635 // Translate again the address, this time into an address inside the636 // Translate again the address, this time into an address inside the
636 // .o file637 // .o file
637 const relocated_address_o = result.o_file_info.?.addr_table.get(stab_symbol) orelse return .{638 const relocated_address_o = result.o_file_info.?.addr_table.get(stab_symbol) orelse return .{
638 .symbol_name = "???",639 .name = "???",
639 };640 };
640641
641 const addr_off = result.relocated_address - result.symbol.?.addr;642 const addr_off = result.relocated_address - result.symbol.?.addr;
642 const o_file_di = &result.o_file_info.?.di;643 const o_file_di = &result.o_file_info.?.di;
643 if (o_file_di.findCompileUnit(relocated_address_o)) |compile_unit| {644 if (o_file_di.findCompileUnit(relocated_address_o)) |compile_unit| {
644 return .{645 return .{
645 .symbol_name = o_file_di.getSymbolName(relocated_address_o) orelse "???",646 .name = o_file_di.getSymbolName(relocated_address_o) orelse "???",
646 .compile_unit_name = compile_unit.die.getAttrString(647 .compile_unit_name = compile_unit.die.getAttrString(
647 o_file_di,648 o_file_di,
648 std.dwarf.AT.name,649 std.dwarf.AT.name,
...@@ -651,9 +652,9 @@ pub const Module = switch (native_os) {...@@ -651,9 +652,9 @@ pub const Module = switch (native_os) {
651 ) catch |err| switch (err) {652 ) catch |err| switch (err) {
652 error.MissingDebugInfo, error.InvalidDebugInfo => "???",653 error.MissingDebugInfo, error.InvalidDebugInfo => "???",
653 },654 },
654 .line_info = o_file_di.getLineNumberInfo(655 .source_location = o_file_di.getLineNumberInfo(
655 allocator,656 allocator,
656 compile_unit.*,657 compile_unit,
657 relocated_address_o + addr_off,658 relocated_address_o + addr_off,
658 ) catch |err| switch (err) {659 ) catch |err| switch (err) {
659 error.MissingDebugInfo, error.InvalidDebugInfo => null,660 error.MissingDebugInfo, error.InvalidDebugInfo => null,
...@@ -662,7 +663,7 @@ pub const Module = switch (native_os) {...@@ -662,7 +663,7 @@ pub const Module = switch (native_os) {
662 };663 };
663 } else |err| switch (err) {664 } else |err| switch (err) {
664 error.MissingDebugInfo, error.InvalidDebugInfo => {665 error.MissingDebugInfo, error.InvalidDebugInfo => {
665 return .{ .symbol_name = stab_symbol };666 return .{ .name = stab_symbol };
666 },667 },
667 else => return err,668 else => return err,
668 }669 }
...@@ -760,9 +761,9 @@ pub const Module = switch (native_os) {...@@ -760,9 +761,9 @@ pub const Module = switch (native_os) {
760 );761 );
761762
762 return .{763 return .{
763 .symbol_name = symbol_name,764 .name = symbol_name,
764 .compile_unit_name = obj_basename,765 .compile_unit_name = obj_basename,
765 .line_info = opt_line_info,766 .source_location = opt_line_info,
766 };767 };
767 }768 }
768769
...@@ -991,10 +992,11 @@ fn readCoffDebugInfo(allocator: Allocator, coff_obj: *coff.Coff) !Module {...@@ -991,10 +992,11 @@ fn readCoffDebugInfo(allocator: Allocator, coff_obj: *coff.Coff) !Module {
991 } else null;992 } else null;
992 }993 }
993994
994 var dwarf = Dwarf{995 var dwarf: Dwarf = .{
995 .endian = native_endian,996 .endian = native_endian,
996 .sections = sections,997 .sections = sections,
997 .is_macho = false,998 .is_macho = false,
999 .compile_units_sorted = false,
998 };1000 };
9991001
1000 try Dwarf.open(&dwarf, allocator);1002 try Dwarf.open(&dwarf, allocator);
...@@ -1808,6 +1810,7 @@ fn unwindFrameMachODwarf(...@@ -1808,6 +1810,7 @@ fn unwindFrameMachODwarf(
1808 var di: Dwarf = .{1810 var di: Dwarf = .{
1809 .endian = native_endian,1811 .endian = native_endian,
1810 .is_macho = true,1812 .is_macho = true,
1813 .compile_units_sorted = false,
1811 };1814 };
1812 defer di.deinit(context.allocator);1815 defer di.deinit(context.allocator);
18131816