authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-01 15:39:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-01 22:11:29-07:00
logab0253f6620f5b87f06fdbddfc8876263c2a10a2
treef991457b995340f71e85ecc89b2e4f1d01d300c7
parent1ba6b56c817777c5f504a5975591da6de68dd361

std.debug.Info: rename ModuleDebugInfo to Module


1 files changed, 20 insertions(+), 20 deletions(-)

lib/std/debug/Info.zig+20-20
......@@ -26,7 +26,7 @@ const Info = @This();
2626const root = @import("root");
2727
2828allocator: Allocator,
29address_map: std.AutoHashMap(usize, *ModuleDebugInfo),
29address_map: std.AutoHashMap(usize, *Module),
3030modules: if (native_os == .windows) std.ArrayListUnmanaged(WindowsModuleInfo) else void,
3131
3232pub const OpenSelfError = error{
......@@ -58,9 +58,9 @@ pub fn openSelf(allocator: Allocator) OpenSelfError!Info {
5858}
5959
6060pub fn init(allocator: Allocator) !Info {
61 var debug_info = Info{
61 var debug_info: Info = .{
6262 .allocator = allocator,
63 .address_map = std.AutoHashMap(usize, *ModuleDebugInfo).init(allocator),
63 .address_map = std.AutoHashMap(usize, *Module).init(allocator),
6464 .modules = if (native_os == .windows) .{} else {},
6565 };
6666
......@@ -118,7 +118,7 @@ pub fn deinit(self: *Info) void {
118118 }
119119}
120120
121pub fn getModuleForAddress(self: *Info, address: usize) !*ModuleDebugInfo {
121pub fn getModuleForAddress(self: *Info, address: usize) !*Module {
122122 if (comptime builtin.target.isDarwin()) {
123123 return self.lookupModuleDyld(address);
124124 } else if (native_os == .windows) {
......@@ -149,7 +149,7 @@ pub fn getModuleNameForAddress(self: *Info, address: usize) ?[]const u8 {
149149 }
150150}
151151
152fn lookupModuleDyld(self: *Info, address: usize) !*ModuleDebugInfo {
152fn lookupModuleDyld(self: *Info, address: usize) !*Module {
153153 const image_count = std.c._dyld_image_count();
154154
155155 var i: u32 = 0;
......@@ -189,7 +189,7 @@ fn lookupModuleDyld(self: *Info, address: usize) !*ModuleDebugInfo {
189189 }
190190 }
191191
192 const obj_di = try self.allocator.create(ModuleDebugInfo);
192 const obj_di = try self.allocator.create(Module);
193193 errdefer self.allocator.destroy(obj_di);
194194
195195 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 {
253253 return null;
254254}
255255
256fn lookupModuleWin32(self: *Info, address: usize) !*ModuleDebugInfo {
256fn lookupModuleWin32(self: *Info, address: usize) !*Module {
257257 for (self.modules.items) |*module| {
258258 if (address >= module.base_address and address < module.base_address + module.size) {
259259 if (self.address_map.get(module.base_address)) |obj_di| {
260260 return obj_di;
261261 }
262262
263 const obj_di = try self.allocator.create(ModuleDebugInfo);
263 const obj_di = try self.allocator.create(Module);
264264 errdefer self.allocator.destroy(obj_di);
265265
266266 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 {
390390 return null;
391391}
392392
393fn lookupModuleDl(self: *Info, address: usize) !*ModuleDebugInfo {
393fn lookupModuleDl(self: *Info, address: usize) !*Module {
394394 var ctx: struct {
395395 // Input
396396 address: usize,
......@@ -458,7 +458,7 @@ fn lookupModuleDl(self: *Info, address: usize) !*ModuleDebugInfo {
458458 return obj_di;
459459 }
460460
461 const obj_di = try self.allocator.create(ModuleDebugInfo);
461 const obj_di = try self.allocator.create(Module);
462462 errdefer self.allocator.destroy(obj_di);
463463
464464 var sections: Dwarf.SectionArray = Dwarf.null_section_array;
......@@ -484,19 +484,19 @@ fn lookupModuleDl(self: *Info, address: usize) !*ModuleDebugInfo {
484484 return obj_di;
485485}
486486
487fn lookupModuleHaiku(self: *Info, address: usize) !*ModuleDebugInfo {
487fn lookupModuleHaiku(self: *Info, address: usize) !*Module {
488488 _ = self;
489489 _ = address;
490490 @panic("TODO implement lookup module for Haiku");
491491}
492492
493fn lookupModuleWasm(self: *Info, address: usize) !*ModuleDebugInfo {
493fn lookupModuleWasm(self: *Info, address: usize) !*Module {
494494 _ = self;
495495 _ = address;
496496 @panic("TODO implement lookup module for Wasm");
497497}
498498
499pub const ModuleDebugInfo = switch (native_os) {
499pub const Module = switch (native_os) {
500500 .macos, .ios, .watchos, .tvos, .visionos => struct {
501501 base_address: usize,
502502 vmaddr_slide: usize,
......@@ -861,7 +861,7 @@ pub const WindowsModuleInfo = struct {
861861/// This takes ownership of macho_file: users of this function should not close
862862/// it themselves, even on error.
863863/// TODO it's weird to take ownership even on error, rework this code.
864fn readMachODebugInfo(allocator: Allocator, macho_file: File) !ModuleDebugInfo {
864fn readMachODebugInfo(allocator: Allocator, macho_file: File) !Module {
865865 const mapped_mem = try mapWholeFile(macho_file);
866866
867867 const hdr: *const macho.mach_header_64 = @ptrCast(@alignCast(mapped_mem.ptr));
......@@ -975,19 +975,19 @@ fn readMachODebugInfo(allocator: Allocator, macho_file: File) !ModuleDebugInfo {
975975 // This sort is so that we can binary search later.
976976 mem.sort(MachoSymbol, symbols, {}, MachoSymbol.addressLessThan);
977977
978 return ModuleDebugInfo{
978 return .{
979979 .base_address = undefined,
980980 .vmaddr_slide = undefined,
981981 .mapped_memory = mapped_mem,
982 .ofiles = ModuleDebugInfo.OFileTable.init(allocator),
982 .ofiles = Module.OFileTable.init(allocator),
983983 .symbols = symbols,
984984 .strings = strings,
985985 };
986986}
987987
988fn readCoffDebugInfo(allocator: Allocator, coff_obj: *coff.Coff) !ModuleDebugInfo {
988fn readCoffDebugInfo(allocator: Allocator, coff_obj: *coff.Coff) !Module {
989989 nosuspend {
990 var di = ModuleDebugInfo{
990 var di: Module = .{
991991 .base_address = undefined,
992992 .coff_image_base = coff_obj.getImageBase(),
993993 .coff_section_headers = undefined,
......@@ -1062,7 +1062,7 @@ pub fn readElfDebugInfo(
10621062 expected_crc: ?u32,
10631063 parent_sections: *Dwarf.SectionArray,
10641064 parent_mapped_mem: ?[]align(mem.page_size) const u8,
1065) !ModuleDebugInfo {
1065) !Module {
10661066 nosuspend {
10671067 const elf_file = (if (elf_filename) |filename| blk: {
10681068 break :blk fs.cwd().openFile(filename, .{});
......@@ -1236,7 +1236,7 @@ pub fn readElfDebugInfo(
12361236
12371237 try Dwarf.open(&di, allocator);
12381238
1239 return ModuleDebugInfo{
1239 return .{
12401240 .base_address = undefined,
12411241 .dwarf = di,
12421242 .mapped_memory = parent_mapped_mem orelse mapped_mem,