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...@@ -937,7 +937,7 @@ fn openMachODebugInfo(allocator: *mem.Allocator, macho_file_path: []const u8) !M
937 return error.MissingDebugInfo;937 return error.MissingDebugInfo;
938 };938 };
939 const syms = @ptrCast([*]const macho.nlist_64, @alignCast(@alignOf(macho.nlist_64), hdr_base + symtab.symoff))[0..symtab.nsyms];939 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
942 const symbols_buf = try allocator.alloc(MachoSymbol, syms.len);942 const symbols_buf = try allocator.alloc(MachoSymbol, syms.len);
943943
...@@ -1418,19 +1418,23 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {...@@ -1418,19 +1418,23 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
1418 const symbol = machoSearchSymbols(self.symbols, relocated_address) orelse1418 const symbol = machoSearchSymbols(self.symbols, relocated_address) orelse
1419 return SymbolInfo{};1419 return SymbolInfo{};
14201420
1421 // XXX: Return the symbol name1421 // 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
1422 if (symbol.ofile == null)1425 if (symbol.ofile == null)
1423 return SymbolInfo{};1426 return SymbolInfo{ .symbol_name = stab_symbol };
14241427
1425 assert(symbol.ofile.?.n_strx < self.strings.len);1428 const o_file_path = mem.spanZ(self.strings[symbol.ofile.?.n_strx..]);
1426 const o_file_path = mem.spanZ(self.strings.ptr + symbol.ofile.?.n_strx);
14271429
1428 // Check if its debug infos are already in the cache1430 // Check if its debug infos are already in the cache
1429 var o_file_di = self.ofiles.getValue(o_file_path) orelse1431 var o_file_di = self.ofiles.getValue(o_file_path) orelse
1430 (self.loadOFile(o_file_path) catch |err| switch (err) {1432 (self.loadOFile(o_file_path) catch |err| switch (err) {
1431 error.MissingDebugInfo, error.InvalidDebugInfo => {1433 error.FileNotFound,
1432 // XXX: Return the symbol name1434 error.MissingDebugInfo,
1433 return SymbolInfo{};1435 error.InvalidDebugInfo,
1436 => {
1437 return SymbolInfo{ .symbol_name = stab_symbol };
1434 },1438 },
1435 else => return err,1439 else => return err,
1436 });1440 });
...@@ -1453,7 +1457,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {...@@ -1453,7 +1457,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
1453 };1457 };
1454 } else |err| switch (err) {1458 } else |err| switch (err) {
1455 error.MissingDebugInfo, error.InvalidDebugInfo => {1459 error.MissingDebugInfo, error.InvalidDebugInfo => {
1456 return SymbolInfo{};1460 return SymbolInfo{ .symbol_name = stab_symbol };
1457 },1461 },
1458 else => return err,1462 else => return err,
1459 }1463 }