zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 48723113642f553db5dda1020eeb32a0e9df9cc0 (tree)
parent 157f566f2dd9c8d694270f5b7fcb8525834d7646
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu, 16 Apr 2020 11:10:53 +0200

debug: Minor QOL improvements for osx

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

Diffstat:
Mlib/std/debug.zig | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git 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, }