authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-04-16 11:10:53+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-16 16:21:54-04:00
log48723113642f553db5dda1020eeb32a0e9df9cc0
tree0ab1873025bbde3042d757bfad666a33c4eb6f18
parent157f566f2dd9c8d694270f5b7fcb8525834d7646

debug: Minor QOL improvements for osx

* Handle FileNotFound errors when searching for .o files * Use the STAB symbol name when everything else fails

1 files changed, 13 insertions(+), 9 deletions(-)

lib/std/debug.zig+13-9
......@@ -937,7 +937,7 @@ fn openMachODebugInfo(allocator: *mem.Allocator, macho_file_path: []const u8) !M
937937 return error.MissingDebugInfo;
938938 };
939939 const syms = @ptrCast([*]const macho.nlist_64, @alignCast(@alignOf(macho.nlist_64), hdr_base + symtab.symoff))[0..symtab.nsyms];
940 const strings = @ptrCast([*]const u8, hdr_base + symtab.stroff)[0..symtab.strsize :0];
940 const strings = @ptrCast([*]const u8, hdr_base + symtab.stroff)[0 .. symtab.strsize - 1 :0];
941941
942942 const symbols_buf = try allocator.alloc(MachoSymbol, syms.len);
943943
......@@ -1418,19 +1418,23 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
14181418 const symbol = machoSearchSymbols(self.symbols, relocated_address) orelse
14191419 return SymbolInfo{};
14201420
1421 // XXX: Return the symbol name
1421 // Take the symbol name from the N_FUN STAB entry, we're going to
1422 // use it if we fail to find the DWARF infos
1423 const stab_symbol = mem.spanZ(self.strings[symbol.nlist.n_strx..]);
1424
14221425 if (symbol.ofile == null)
1423 return SymbolInfo{};
1426 return SymbolInfo{ .symbol_name = stab_symbol };
14241427
1425 assert(symbol.ofile.?.n_strx < self.strings.len);
1426 const o_file_path = mem.spanZ(self.strings.ptr + symbol.ofile.?.n_strx);
1428 const o_file_path = mem.spanZ(self.strings[symbol.ofile.?.n_strx..]);
14271429
14281430 // Check if its debug infos are already in the cache
14291431 var o_file_di = self.ofiles.getValue(o_file_path) orelse
14301432 (self.loadOFile(o_file_path) catch |err| switch (err) {
1431 error.MissingDebugInfo, error.InvalidDebugInfo => {
1432 // XXX: Return the symbol name
1433 return SymbolInfo{};
1433 error.FileNotFound,
1434 error.MissingDebugInfo,
1435 error.InvalidDebugInfo,
1436 => {
1437 return SymbolInfo{ .symbol_name = stab_symbol };
14341438 },
14351439 else => return err,
14361440 });
......@@ -1453,7 +1457,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
14531457 };
14541458 } else |err| switch (err) {
14551459 error.MissingDebugInfo, error.InvalidDebugInfo => {
1456 return SymbolInfo{};
1460 return SymbolInfo{ .symbol_name = stab_symbol };
14571461 },
14581462 else => return err,
14591463 }