| ... | @@ -26,7 +26,7 @@ const Info = @This(); | ... | @@ -26,7 +26,7 @@ const Info = @This(); |
| 26 | const root = @import("root"); | 26 | const root = @import("root"); |
| 27 | | 27 | |
| 28 | allocator: Allocator, | 28 | allocator: Allocator, |
| 29 | address_map: std.AutoHashMap(usize, *ModuleDebugInfo), | 29 | address_map: std.AutoHashMap(usize, *Module), |
| 30 | modules: if (native_os == .windows) std.ArrayListUnmanaged(WindowsModuleInfo) else void, | 30 | modules: if (native_os == .windows) std.ArrayListUnmanaged(WindowsModuleInfo) else void, |
| 31 | | 31 | |
| 32 | pub const OpenSelfError = error{ | 32 | pub const OpenSelfError = error{ |
| ... | @@ -58,9 +58,9 @@ pub fn openSelf(allocator: Allocator) OpenSelfError!Info { | ... | @@ -58,9 +58,9 @@ pub fn openSelf(allocator: Allocator) OpenSelfError!Info { |
| 58 | } | 58 | } |
| 59 | | 59 | |
| 60 | pub fn init(allocator: Allocator) !Info { | 60 | pub fn init(allocator: Allocator) !Info { |
| 61 | var debug_info = Info{ | 61 | var debug_info: Info = .{ |
| 62 | .allocator = allocator, | 62 | .allocator = allocator, |
| 63 | .address_map = std.AutoHashMap(usize, *ModuleDebugInfo).init(allocator), | 63 | .address_map = std.AutoHashMap(usize, *Module).init(allocator), |
| 64 | .modules = if (native_os == .windows) .{} else {}, | 64 | .modules = if (native_os == .windows) .{} else {}, |
| 65 | }; | 65 | }; |
| 66 | | 66 | |
| ... | @@ -118,7 +118,7 @@ pub fn deinit(self: *Info) void { | ... | @@ -118,7 +118,7 @@ pub fn deinit(self: *Info) void { |
| 118 | } | 118 | } |
| 119 | } | 119 | } |
| 120 | | 120 | |
| 121 | pub fn getModuleForAddress(self: *Info, address: usize) !*ModuleDebugInfo { | 121 | pub fn getModuleForAddress(self: *Info, address: usize) !*Module { |
| 122 | if (comptime builtin.target.isDarwin()) { | 122 | if (comptime builtin.target.isDarwin()) { |
| 123 | return self.lookupModuleDyld(address); | 123 | return self.lookupModuleDyld(address); |
| 124 | } else if (native_os == .windows) { | 124 | } else if (native_os == .windows) { |
| ... | @@ -149,7 +149,7 @@ pub fn getModuleNameForAddress(self: *Info, address: usize) ?[]const u8 { | ... | @@ -149,7 +149,7 @@ pub fn getModuleNameForAddress(self: *Info, address: usize) ?[]const u8 { |
| 149 | } | 149 | } |
| 150 | } | 150 | } |
| 151 | | 151 | |
| 152 | fn lookupModuleDyld(self: *Info, address: usize) !*ModuleDebugInfo { | 152 | fn lookupModuleDyld(self: *Info, address: usize) !*Module { |
| 153 | const image_count = std.c._dyld_image_count(); | 153 | const image_count = std.c._dyld_image_count(); |
| 154 | | 154 | |
| 155 | var i: u32 = 0; | 155 | var i: u32 = 0; |
| ... | @@ -189,7 +189,7 @@ fn lookupModuleDyld(self: *Info, address: usize) !*ModuleDebugInfo { | ... | @@ -189,7 +189,7 @@ fn lookupModuleDyld(self: *Info, address: usize) !*ModuleDebugInfo { |
| 189 | } | 189 | } |
| 190 | } | 190 | } |
| 191 | | 191 | |
| 192 | const obj_di = try self.allocator.create(ModuleDebugInfo); | 192 | const obj_di = try self.allocator.create(Module); |
| 193 | errdefer self.allocator.destroy(obj_di); | 193 | errdefer self.allocator.destroy(obj_di); |
| 194 | | 194 | |
| 195 | const macho_path = mem.sliceTo(std.c._dyld_get_image_name(i), 0); | 195 | const macho_path = mem.sliceTo(std.c._dyld_get_image_name(i), 0); |
| ... | @@ -253,14 +253,14 @@ fn lookupModuleNameDyld(self: *Info, address: usize) ?[]const u8 { | ... | @@ -253,14 +253,14 @@ fn lookupModuleNameDyld(self: *Info, address: usize) ?[]const u8 { |
| 253 | return null; | 253 | return null; |
| 254 | } | 254 | } |
| 255 | | 255 | |
| 256 | fn lookupModuleWin32(self: *Info, address: usize) !*ModuleDebugInfo { | 256 | fn lookupModuleWin32(self: *Info, address: usize) !*Module { |
| 257 | for (self.modules.items) |*module| { | 257 | for (self.modules.items) |*module| { |
| 258 | if (address >= module.base_address and address < module.base_address + module.size) { | 258 | if (address >= module.base_address and address < module.base_address + module.size) { |
| 259 | if (self.address_map.get(module.base_address)) |obj_di| { | 259 | if (self.address_map.get(module.base_address)) |obj_di| { |
| 260 | return obj_di; | 260 | return obj_di; |
| 261 | } | 261 | } |
| 262 | | 262 | |
| 263 | const obj_di = try self.allocator.create(ModuleDebugInfo); | 263 | const obj_di = try self.allocator.create(Module); |
| 264 | errdefer self.allocator.destroy(obj_di); | 264 | errdefer self.allocator.destroy(obj_di); |
| 265 | | 265 | |
| 266 | const mapped_module = @as([*]const u8, @ptrFromInt(module.base_address))[0..module.size]; | 266 | const mapped_module = @as([*]const u8, @ptrFromInt(module.base_address))[0..module.size]; |
| ... | @@ -390,7 +390,7 @@ fn lookupModuleNameDl(self: *Info, address: usize) ?[]const u8 { | ... | @@ -390,7 +390,7 @@ fn lookupModuleNameDl(self: *Info, address: usize) ?[]const u8 { |
| 390 | return null; | 390 | return null; |
| 391 | } | 391 | } |
| 392 | | 392 | |
| 393 | fn lookupModuleDl(self: *Info, address: usize) !*ModuleDebugInfo { | 393 | fn lookupModuleDl(self: *Info, address: usize) !*Module { |
| 394 | var ctx: struct { | 394 | var ctx: struct { |
| 395 | // Input | 395 | // Input |
| 396 | address: usize, | 396 | address: usize, |
| ... | @@ -458,7 +458,7 @@ fn lookupModuleDl(self: *Info, address: usize) !*ModuleDebugInfo { | ... | @@ -458,7 +458,7 @@ fn lookupModuleDl(self: *Info, address: usize) !*ModuleDebugInfo { |
| 458 | return obj_di; | 458 | return obj_di; |
| 459 | } | 459 | } |
| 460 | | 460 | |
| 461 | const obj_di = try self.allocator.create(ModuleDebugInfo); | 461 | const obj_di = try self.allocator.create(Module); |
| 462 | errdefer self.allocator.destroy(obj_di); | 462 | errdefer self.allocator.destroy(obj_di); |
| 463 | | 463 | |
| 464 | var sections: Dwarf.SectionArray = Dwarf.null_section_array; | 464 | var sections: Dwarf.SectionArray = Dwarf.null_section_array; |
| ... | @@ -484,19 +484,19 @@ fn lookupModuleDl(self: *Info, address: usize) !*ModuleDebugInfo { | ... | @@ -484,19 +484,19 @@ fn lookupModuleDl(self: *Info, address: usize) !*ModuleDebugInfo { |
| 484 | return obj_di; | 484 | return obj_di; |
| 485 | } | 485 | } |
| 486 | | 486 | |
| 487 | fn lookupModuleHaiku(self: *Info, address: usize) !*ModuleDebugInfo { | 487 | fn lookupModuleHaiku(self: *Info, address: usize) !*Module { |
| 488 | _ = self; | 488 | _ = self; |
| 489 | _ = address; | 489 | _ = address; |
| 490 | @panic("TODO implement lookup module for Haiku"); | 490 | @panic("TODO implement lookup module for Haiku"); |
| 491 | } | 491 | } |
| 492 | | 492 | |
| 493 | fn lookupModuleWasm(self: *Info, address: usize) !*ModuleDebugInfo { | 493 | fn lookupModuleWasm(self: *Info, address: usize) !*Module { |
| 494 | _ = self; | 494 | _ = self; |
| 495 | _ = address; | 495 | _ = address; |
| 496 | @panic("TODO implement lookup module for Wasm"); | 496 | @panic("TODO implement lookup module for Wasm"); |
| 497 | } | 497 | } |
| 498 | | 498 | |
| 499 | pub const ModuleDebugInfo = switch (native_os) { | 499 | pub const Module = switch (native_os) { |
| 500 | .macos, .ios, .watchos, .tvos, .visionos => struct { | 500 | .macos, .ios, .watchos, .tvos, .visionos => struct { |
| 501 | base_address: usize, | 501 | base_address: usize, |
| 502 | vmaddr_slide: usize, | 502 | vmaddr_slide: usize, |
| ... | @@ -861,7 +861,7 @@ pub const WindowsModuleInfo = struct { | ... | @@ -861,7 +861,7 @@ pub const WindowsModuleInfo = struct { |
| 861 | /// This takes ownership of macho_file: users of this function should not close | 861 | /// This takes ownership of macho_file: users of this function should not close |
| 862 | /// it themselves, even on error. | 862 | /// it themselves, even on error. |
| 863 | /// TODO it's weird to take ownership even on error, rework this code. | 863 | /// TODO it's weird to take ownership even on error, rework this code. |
| 864 | fn readMachODebugInfo(allocator: Allocator, macho_file: File) !ModuleDebugInfo { | 864 | fn readMachODebugInfo(allocator: Allocator, macho_file: File) !Module { |
| 865 | const mapped_mem = try mapWholeFile(macho_file); | 865 | const mapped_mem = try mapWholeFile(macho_file); |
| 866 | | 866 | |
| 867 | const hdr: *const macho.mach_header_64 = @ptrCast(@alignCast(mapped_mem.ptr)); | 867 | const hdr: *const macho.mach_header_64 = @ptrCast(@alignCast(mapped_mem.ptr)); |
| ... | @@ -975,19 +975,19 @@ fn readMachODebugInfo(allocator: Allocator, macho_file: File) !ModuleDebugInfo { | ... | @@ -975,19 +975,19 @@ fn readMachODebugInfo(allocator: Allocator, macho_file: File) !ModuleDebugInfo { |
| 975 | // This sort is so that we can binary search later. | 975 | // This sort is so that we can binary search later. |
| 976 | mem.sort(MachoSymbol, symbols, {}, MachoSymbol.addressLessThan); | 976 | mem.sort(MachoSymbol, symbols, {}, MachoSymbol.addressLessThan); |
| 977 | | 977 | |
| 978 | return ModuleDebugInfo{ | 978 | return .{ |
| 979 | .base_address = undefined, | 979 | .base_address = undefined, |
| 980 | .vmaddr_slide = undefined, | 980 | .vmaddr_slide = undefined, |
| 981 | .mapped_memory = mapped_mem, | 981 | .mapped_memory = mapped_mem, |
| 982 | .ofiles = ModuleDebugInfo.OFileTable.init(allocator), | 982 | .ofiles = Module.OFileTable.init(allocator), |
| 983 | .symbols = symbols, | 983 | .symbols = symbols, |
| 984 | .strings = strings, | 984 | .strings = strings, |
| 985 | }; | 985 | }; |
| 986 | } | 986 | } |
| 987 | | 987 | |
| 988 | fn readCoffDebugInfo(allocator: Allocator, coff_obj: *coff.Coff) !ModuleDebugInfo { | 988 | fn readCoffDebugInfo(allocator: Allocator, coff_obj: *coff.Coff) !Module { |
| 989 | nosuspend { | 989 | nosuspend { |
| 990 | var di = ModuleDebugInfo{ | 990 | var di: Module = .{ |
| 991 | .base_address = undefined, | 991 | .base_address = undefined, |
| 992 | .coff_image_base = coff_obj.getImageBase(), | 992 | .coff_image_base = coff_obj.getImageBase(), |
| 993 | .coff_section_headers = undefined, | 993 | .coff_section_headers = undefined, |
| ... | @@ -1062,7 +1062,7 @@ pub fn readElfDebugInfo( | ... | @@ -1062,7 +1062,7 @@ pub fn readElfDebugInfo( |
| 1062 | expected_crc: ?u32, | 1062 | expected_crc: ?u32, |
| 1063 | parent_sections: *Dwarf.SectionArray, | 1063 | parent_sections: *Dwarf.SectionArray, |
| 1064 | parent_mapped_mem: ?[]align(mem.page_size) const u8, | 1064 | parent_mapped_mem: ?[]align(mem.page_size) const u8, |
| 1065 | ) !ModuleDebugInfo { | 1065 | ) !Module { |
| 1066 | nosuspend { | 1066 | nosuspend { |
| 1067 | const elf_file = (if (elf_filename) |filename| blk: { | 1067 | const elf_file = (if (elf_filename) |filename| blk: { |
| 1068 | break :blk fs.cwd().openFile(filename, .{}); | 1068 | break :blk fs.cwd().openFile(filename, .{}); |
| ... | @@ -1236,7 +1236,7 @@ pub fn readElfDebugInfo( | ... | @@ -1236,7 +1236,7 @@ pub fn readElfDebugInfo( |
| 1236 | | 1236 | |
| 1237 | try Dwarf.open(&di, allocator); | 1237 | try Dwarf.open(&di, allocator); |
| 1238 | | 1238 | |
| 1239 | return ModuleDebugInfo{ | 1239 | return .{ |
| 1240 | .base_address = undefined, | 1240 | .base_address = undefined, |
| 1241 | .dwarf = di, | 1241 | .dwarf = di, |
| 1242 | .mapped_memory = parent_mapped_mem orelse mapped_mem, | 1242 | .mapped_memory = parent_mapped_mem orelse mapped_mem, |