aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-04-16 11:10:53 +0200
committerAndrew Kelley <andrew@ziglang.org>2020-04-16 16:21:54 -0400
commit48723113642f553db5dda1020eeb32a0e9df9cc0 (patch)
tree0ab1873025bbde3042d757bfad666a33c4eb6f18 /lib/std/debug.zig
parent157f566f2dd9c8d694270f5b7fcb8525834d7646 (diff)
downloadzig-48723113642f553db5dda1020eeb32a0e9df9cc0.tar.gz
zig-48723113642f553db5dda1020eeb32a0e9df9cc0.zip
debug: Minor QOL improvements for osx
* Handle FileNotFound errors when searching for .o files * Use the STAB symbol name when everything else fails
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 5a8f556517..4459907576 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -937,7 +937,7 @@ fn openMachODebugInfo(allocator: *mem.Allocator, macho_file_path: []const u8) !M
return error.MissingDebugInfo;
};
const syms = @ptrCast([*]const macho.nlist_64, @alignCast(@alignOf(macho.nlist_64), hdr_base + symtab.symoff))[0..symtab.nsyms];
- const strings = @ptrCast([*]const u8, hdr_base + symtab.stroff)[0..symtab.strsize :0];
+ const strings = @ptrCast([*]const u8, hdr_base + symtab.stroff)[0 .. symtab.strsize - 1 :0];
const symbols_buf = try allocator.alloc(MachoSymbol, syms.len);
@@ -1418,19 +1418,23 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
const symbol = machoSearchSymbols(self.symbols, relocated_address) orelse
return SymbolInfo{};
- // XXX: Return the symbol name
+ // Take the symbol name from the N_FUN STAB entry, we're going to
+ // use it if we fail to find the DWARF infos
+ const stab_symbol = mem.spanZ(self.strings[symbol.nlist.n_strx..]);
+
if (symbol.ofile == null)
- return SymbolInfo{};
+ return SymbolInfo{ .symbol_name = stab_symbol };
- assert(symbol.ofile.?.n_strx < self.strings.len);
- const o_file_path = mem.spanZ(self.strings.ptr + symbol.ofile.?.n_strx);
+ const o_file_path = mem.spanZ(self.strings[symbol.ofile.?.n_strx..]);
// Check if its debug infos are already in the cache
var o_file_di = self.ofiles.getValue(o_file_path) orelse
(self.loadOFile(o_file_path) catch |err| switch (err) {
- error.MissingDebugInfo, error.InvalidDebugInfo => {
- // XXX: Return the symbol name
- return SymbolInfo{};
+ error.FileNotFound,
+ error.MissingDebugInfo,
+ error.InvalidDebugInfo,
+ => {
+ return SymbolInfo{ .symbol_name = stab_symbol };
},
else => return err,
});
@@ -1453,7 +1457,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
};
} else |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => {
- return SymbolInfo{};
+ return SymbolInfo{ .symbol_name = stab_symbol };
},
else => return err,
}