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