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();...@@ -26,7 +26,7 @@ const Info = @This();
26const root = @import("root");26const root = @import("root");
2727
28allocator: Allocator,28allocator: Allocator,
29address_map: std.AutoHashMap(usize, *ModuleDebugInfo),29address_map: std.AutoHashMap(usize, *Module),
30modules: if (native_os == .windows) std.ArrayListUnmanaged(WindowsModuleInfo) else void,30modules: if (native_os == .windows) std.ArrayListUnmanaged(WindowsModuleInfo) else void,
3131
32pub const OpenSelfError = error{32pub 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}
5959
60pub fn init(allocator: Allocator) !Info {60pub 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 };
6666
...@@ -118,7 +118,7 @@ pub fn deinit(self: *Info) void {...@@ -118,7 +118,7 @@ pub fn deinit(self: *Info) void {
118 }118 }
119}119}
120120
121pub fn getModuleForAddress(self: *Info, address: usize) !*ModuleDebugInfo {121pub 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}
151151
152fn lookupModuleDyld(self: *Info, address: usize) !*ModuleDebugInfo {152fn lookupModuleDyld(self: *Info, address: usize) !*Module {
153 const image_count = std.c._dyld_image_count();153 const image_count = std.c._dyld_image_count();
154154
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 }
191191
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);
194194
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}
255255
256fn lookupModuleWin32(self: *Info, address: usize) !*ModuleDebugInfo {256fn 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 }
262262
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);
265265
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}
392392
393fn lookupModuleDl(self: *Info, address: usize) !*ModuleDebugInfo {393fn lookupModuleDl(self: *Info, address: usize) !*Module {
394 var ctx: struct {394 var ctx: struct {
395 // Input395 // 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 }
460460
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);
463463
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}
486486
487fn lookupModuleHaiku(self: *Info, address: usize) !*ModuleDebugInfo {487fn 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}
492492
493fn lookupModuleWasm(self: *Info, address: usize) !*ModuleDebugInfo {493fn 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}
498498
499pub const ModuleDebugInfo = switch (native_os) {499pub 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 close861/// 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.
864fn readMachODebugInfo(allocator: Allocator, macho_file: File) !ModuleDebugInfo {864fn readMachODebugInfo(allocator: Allocator, macho_file: File) !Module {
865 const mapped_mem = try mapWholeFile(macho_file);865 const mapped_mem = try mapWholeFile(macho_file);
866866
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);
977977
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}
987987
988fn readCoffDebugInfo(allocator: Allocator, coff_obj: *coff.Coff) !ModuleDebugInfo {988fn 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(
12361236
1237 try Dwarf.open(&di, allocator);1237 try Dwarf.open(&di, allocator);
12381238
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,