| ... | ... | @@ -22,12 +22,26 @@ pub fn deinit(si: *SelfInfo, io: Io) void { |
| 22 | 22 | si.modules.deinit(gpa); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | | pub fn getSymbol(si: *SelfInfo, io: Io, address: usize) Error!std.debug.Symbol { |
| 25 | pub const SymbolIterator = struct { |
| 26 | curr: ?Error!std.debug.Symbol, |
| 27 | |
| 28 | pub fn deinit(self: *SymbolIterator, _: Io) void { |
| 29 | self.* = undefined; |
| 30 | } |
| 31 | |
| 32 | pub fn next(self: *SymbolIterator) ?Error!std.debug.Symbol { |
| 33 | const result = self.curr; |
| 34 | self.curr = null; |
| 35 | return result; |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | pub fn getSymbols(si: *SelfInfo, io: Io, address: usize) SymbolIterator { |
| 26 | 40 | const gpa = std.debug.getDebugInfoAllocator(); |
| 27 | | const module = try si.findModule(gpa, io, address); |
| 41 | const module = si.findModule(gpa, io, address) catch |err| return .{ .curr = err }; |
| 28 | 42 | defer si.mutex.unlock(io); |
| 29 | 43 | |
| 30 | | const file = try module.getFile(gpa, io); |
| 44 | const file = module.getFile(gpa, io) catch |err| return .{ .curr = err }; |
| 31 | 45 | |
| 32 | 46 | // This is not necessarily the same as the vmaddr_slide that dyld would report. This is |
| 33 | 47 | // because the segments in the file on disk might differ from the ones in memory. Normally |
| ... | ... | @@ -43,25 +57,26 @@ pub fn getSymbol(si: *SelfInfo, io: Io, address: usize) Error!std.debug.Symbol { |
| 43 | 57 | |
| 44 | 58 | const ofile_dwarf, const ofile_vaddr = file.getDwarfForAddress(gpa, io, vaddr) catch { |
| 45 | 59 | // Return at least the symbol name if available. |
| 46 | | return .{ |
| 47 | | .name = try file.lookupSymbolName(vaddr), |
| 60 | return .{ .curr = .{ |
| 61 | .name = file.lookupSymbolName(vaddr) catch |err| return .{ .curr = err }, |
| 48 | 62 | .compile_unit_name = null, |
| 49 | 63 | .source_location = null, |
| 50 | | }; |
| 64 | } }; |
| 51 | 65 | }; |
| 52 | 66 | |
| 53 | 67 | const compile_unit = ofile_dwarf.findCompileUnit(native_endian, ofile_vaddr) catch { |
| 54 | 68 | // Return at least the symbol name if available. |
| 55 | | return .{ |
| 56 | | .name = try file.lookupSymbolName(vaddr), |
| 69 | return .{ .curr = .{ |
| 70 | .name = file.lookupSymbolName(vaddr) catch |err| return .{ .curr = err }, |
| 57 | 71 | .compile_unit_name = null, |
| 58 | 72 | .source_location = null, |
| 59 | | }; |
| 73 | } }; |
| 60 | 74 | }; |
| 61 | 75 | |
| 62 | | return .{ |
| 76 | return .{ .curr = .{ |
| 63 | 77 | .name = ofile_dwarf.getSymbolName(ofile_vaddr) orelse |
| 64 | | try file.lookupSymbolName(vaddr), |
| 78 | file.lookupSymbolName(vaddr) catch |err| |
| 79 | return .{ .curr = err }, |
| 65 | 80 | .compile_unit_name = compile_unit.die.getAttrString( |
| 66 | 81 | ofile_dwarf, |
| 67 | 82 | native_endian, |
| ... | ... | @@ -77,7 +92,7 @@ pub fn getSymbol(si: *SelfInfo, io: Io, address: usize) Error!std.debug.Symbol { |
| 77 | 92 | compile_unit, |
| 78 | 93 | ofile_vaddr, |
| 79 | 94 | ) catch null, |
| 80 | | }; |
| 95 | } }; |
| 81 | 96 | } |
| 82 | 97 | pub fn getModuleName(si: *SelfInfo, io: Io, address: usize) Error![]const u8 { |
| 83 | 98 | _ = si; |