aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-05-01 19:02:16 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-05-01 19:02:16 -0400
commit988031c07c1959b05682f007ed3bc848a75a43d0 (patch)
tree372035990a592f73cc2a065106205c1a23494834 /lib/std/debug.zig
parent94b0d0e80242563f4ad7ad41e3c0f5193a60b70c (diff)
parent67e51311c3352ab4b2a381bd90dc386032254058 (diff)
downloadzig-988031c07c1959b05682f007ed3bc848a75a43d0.tar.gz
zig-988031c07c1959b05682f007ed3bc848a75a43d0.zip
Merge branch 'windows-evented-io' of https://github.com/FireFox317/zig into FireFox317-windows-evented-io
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig334
1 files changed, 169 insertions, 165 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 4459907576..d3497b4dc8 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -666,158 +666,160 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
/// TODO resources https://github.com/ziglang/zig/issues/4353
fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !ModuleDebugInfo {
- const coff_file = try std.fs.openFileAbsoluteW(coff_file_path.ptr, .{});
- errdefer coff_file.close();
+ noasync {
+ const coff_file = try std.fs.openFileAbsoluteW(coff_file_path.ptr, .{});
+ errdefer coff_file.close();
- const coff_obj = try allocator.create(coff.Coff);
- coff_obj.* = coff.Coff.init(allocator, coff_file);
+ const coff_obj = try allocator.create(coff.Coff);
+ coff_obj.* = coff.Coff.init(allocator, coff_file);
- var di = ModuleDebugInfo{
- .base_address = undefined,
- .coff = coff_obj,
- .pdb = undefined,
- .sect_contribs = undefined,
- .modules = undefined,
- };
+ var di = ModuleDebugInfo{
+ .base_address = undefined,
+ .coff = coff_obj,
+ .pdb = undefined,
+ .sect_contribs = undefined,
+ .modules = undefined,
+ };
- try di.coff.loadHeader();
+ try di.coff.loadHeader();
- var path_buf: [windows.MAX_PATH]u8 = undefined;
- const len = try di.coff.getPdbPath(path_buf[0..]);
- const raw_path = path_buf[0..len];
+ var path_buf: [windows.MAX_PATH]u8 = undefined;
+ const len = try di.coff.getPdbPath(path_buf[0..]);
+ const raw_path = path_buf[0..len];
- const path = try fs.path.resolve(allocator, &[_][]const u8{raw_path});
+ const path = try fs.path.resolve(allocator, &[_][]const u8{raw_path});
- try di.pdb.openFile(di.coff, path);
+ try di.pdb.openFile(di.coff, path);
- var pdb_stream = di.pdb.getStream(pdb.StreamType.Pdb) orelse return error.InvalidDebugInfo;
- const version = try pdb_stream.inStream().readIntLittle(u32);
- const signature = try pdb_stream.inStream().readIntLittle(u32);
- const age = try pdb_stream.inStream().readIntLittle(u32);
- var guid: [16]u8 = undefined;
- try pdb_stream.inStream().readNoEof(&guid);
- if (version != 20000404) // VC70, only value observed by LLVM team
- return error.UnknownPDBVersion;
- if (!mem.eql(u8, &di.coff.guid, &guid) or di.coff.age != age)
- return error.PDBMismatch;
- // We validated the executable and pdb match.
+ var pdb_stream = di.pdb.getStream(pdb.StreamType.Pdb) orelse return error.InvalidDebugInfo;
+ const version = try pdb_stream.inStream().readIntLittle(u32);
+ const signature = try pdb_stream.inStream().readIntLittle(u32);
+ const age = try pdb_stream.inStream().readIntLittle(u32);
+ var guid: [16]u8 = undefined;
+ try pdb_stream.inStream().readNoEof(&guid);
+ if (version != 20000404) // VC70, only value observed by LLVM team
+ return error.UnknownPDBVersion;
+ if (!mem.eql(u8, &di.coff.guid, &guid) or di.coff.age != age)
+ return error.PDBMismatch;
+ // We validated the executable and pdb match.
- const string_table_index = str_tab_index: {
- const name_bytes_len = try pdb_stream.inStream().readIntLittle(u32);
- const name_bytes = try allocator.alloc(u8, name_bytes_len);
- try pdb_stream.inStream().readNoEof(name_bytes);
+ const string_table_index = str_tab_index: {
+ const name_bytes_len = try pdb_stream.inStream().readIntLittle(u32);
+ const name_bytes = try allocator.alloc(u8, name_bytes_len);
+ try pdb_stream.inStream().readNoEof(name_bytes);
- const HashTableHeader = packed struct {
- Size: u32,
- Capacity: u32,
+ const HashTableHeader = packed struct {
+ Size: u32,
+ Capacity: u32,
- fn maxLoad(cap: u32) u32 {
- return cap * 2 / 3 + 1;
- }
- };
- const hash_tbl_hdr = try pdb_stream.inStream().readStruct(HashTableHeader);
- if (hash_tbl_hdr.Capacity == 0)
- return error.InvalidDebugInfo;
+ fn maxLoad(cap: u32) u32 {
+ return cap * 2 / 3 + 1;
+ }
+ };
+ const hash_tbl_hdr = try pdb_stream.inStream().readStruct(HashTableHeader);
+ if (hash_tbl_hdr.Capacity == 0)
+ return error.InvalidDebugInfo;
- if (hash_tbl_hdr.Size > HashTableHeader.maxLoad(hash_tbl_hdr.Capacity))
- return error.InvalidDebugInfo;
+ if (hash_tbl_hdr.Size > HashTableHeader.maxLoad(hash_tbl_hdr.Capacity))
+ return error.InvalidDebugInfo;
- const present = try readSparseBitVector(&pdb_stream.inStream(), allocator);
- if (present.len != hash_tbl_hdr.Size)
- return error.InvalidDebugInfo;
- const deleted = try readSparseBitVector(&pdb_stream.inStream(), allocator);
+ const present = try readSparseBitVector(&pdb_stream.inStream(), allocator);
+ if (present.len != hash_tbl_hdr.Size)
+ return error.InvalidDebugInfo;
+ const deleted = try readSparseBitVector(&pdb_stream.inStream(), allocator);
- const Bucket = struct {
- first: u32,
- second: u32,
- };
- const bucket_list = try allocator.alloc(Bucket, present.len);
- for (present) |_| {
- const name_offset = try pdb_stream.inStream().readIntLittle(u32);
- const name_index = try pdb_stream.inStream().readIntLittle(u32);
- const name = mem.spanZ(@ptrCast([*:0]u8, name_bytes.ptr + name_offset));
- if (mem.eql(u8, name, "/names")) {
- break :str_tab_index name_index;
+ const Bucket = struct {
+ first: u32,
+ second: u32,
+ };
+ const bucket_list = try allocator.alloc(Bucket, present.len);
+ for (present) |_| {
+ const name_offset = try pdb_stream.inStream().readIntLittle(u32);
+ const name_index = try pdb_stream.inStream().readIntLittle(u32);
+ const name = mem.spanZ(@ptrCast([*:0]u8, name_bytes.ptr + name_offset));
+ if (mem.eql(u8, name, "/names")) {
+ break :str_tab_index name_index;
+ }
}
- }
- return error.MissingDebugInfo;
- };
+ return error.MissingDebugInfo;
+ };
- di.pdb.string_table = di.pdb.getStreamById(string_table_index) orelse return error.MissingDebugInfo;
- di.pdb.dbi = di.pdb.getStream(pdb.StreamType.Dbi) orelse return error.MissingDebugInfo;
+ di.pdb.string_table = di.pdb.getStreamById(string_table_index) orelse return error.MissingDebugInfo;
+ di.pdb.dbi = di.pdb.getStream(pdb.StreamType.Dbi) orelse return error.MissingDebugInfo;
- const dbi = di.pdb.dbi;
+ const dbi = di.pdb.dbi;
- // Dbi Header
- const dbi_stream_header = try dbi.inStream().readStruct(pdb.DbiStreamHeader);
- if (dbi_stream_header.VersionHeader != 19990903) // V70, only value observed by LLVM team
- return error.UnknownPDBVersion;
- if (dbi_stream_header.Age != age)
- return error.UnmatchingPDB;
+ // Dbi Header
+ const dbi_stream_header = try dbi.inStream().readStruct(pdb.DbiStreamHeader);
+ if (dbi_stream_header.VersionHeader != 19990903) // V70, only value observed by LLVM team
+ return error.UnknownPDBVersion;
+ if (dbi_stream_header.Age != age)
+ return error.UnmatchingPDB;
- const mod_info_size = dbi_stream_header.ModInfoSize;
- const section_contrib_size = dbi_stream_header.SectionContributionSize;
+ const mod_info_size = dbi_stream_header.ModInfoSize;
+ const section_contrib_size = dbi_stream_header.SectionContributionSize;
- var modules = ArrayList(Module).init(allocator);
+ var modules = ArrayList(Module).init(allocator);
- // Module Info Substream
- var mod_info_offset: usize = 0;
- while (mod_info_offset != mod_info_size) {
- const mod_info = try dbi.inStream().readStruct(pdb.ModInfo);
- var this_record_len: usize = @sizeOf(pdb.ModInfo);
+ // Module Info Substream
+ var mod_info_offset: usize = 0;
+ while (mod_info_offset != mod_info_size) {
+ const mod_info = try dbi.inStream().readStruct(pdb.ModInfo);
+ var this_record_len: usize = @sizeOf(pdb.ModInfo);
- const module_name = try dbi.readNullTermString(allocator);
- this_record_len += module_name.len + 1;
+ const module_name = try dbi.readNullTermString(allocator);
+ this_record_len += module_name.len + 1;
- const obj_file_name = try dbi.readNullTermString(allocator);
- this_record_len += obj_file_name.len + 1;
+ const obj_file_name = try dbi.readNullTermString(allocator);
+ this_record_len += obj_file_name.len + 1;
- if (this_record_len % 4 != 0) {
- const round_to_next_4 = (this_record_len | 0x3) + 1;
- const march_forward_bytes = round_to_next_4 - this_record_len;
- try dbi.seekBy(@intCast(isize, march_forward_bytes));
- this_record_len += march_forward_bytes;
- }
+ if (this_record_len % 4 != 0) {
+ const round_to_next_4 = (this_record_len | 0x3) + 1;
+ const march_forward_bytes = round_to_next_4 - this_record_len;
+ try dbi.seekBy(@intCast(isize, march_forward_bytes));
+ this_record_len += march_forward_bytes;
+ }
- try modules.append(Module{
- .mod_info = mod_info,
- .module_name = module_name,
- .obj_file_name = obj_file_name,
+ try modules.append(Module{
+ .mod_info = mod_info,
+ .module_name = module_name,
+ .obj_file_name = obj_file_name,
- .populated = false,
- .symbols = undefined,
- .subsect_info = undefined,
- .checksum_offset = null,
- });
+ .populated = false,
+ .symbols = undefined,
+ .subsect_info = undefined,
+ .checksum_offset = null,
+ });
- mod_info_offset += this_record_len;
- if (mod_info_offset > mod_info_size)
- return error.InvalidDebugInfo;
- }
+ mod_info_offset += this_record_len;
+ if (mod_info_offset > mod_info_size)
+ return error.InvalidDebugInfo;
+ }
- di.modules = modules.toOwnedSlice();
+ di.modules = modules.toOwnedSlice();
- // Section Contribution Substream
- var sect_contribs = ArrayList(pdb.SectionContribEntry).init(allocator);
- var sect_cont_offset: usize = 0;
- if (section_contrib_size != 0) {
- const ver = @intToEnum(pdb.SectionContrSubstreamVersion, try dbi.inStream().readIntLittle(u32));
- if (ver != pdb.SectionContrSubstreamVersion.Ver60)
- return error.InvalidDebugInfo;
- sect_cont_offset += @sizeOf(u32);
- }
- while (sect_cont_offset != section_contrib_size) {
- const entry = try sect_contribs.addOne();
- entry.* = try dbi.inStream().readStruct(pdb.SectionContribEntry);
- sect_cont_offset += @sizeOf(pdb.SectionContribEntry);
+ // Section Contribution Substream
+ var sect_contribs = ArrayList(pdb.SectionContribEntry).init(allocator);
+ var sect_cont_offset: usize = 0;
+ if (section_contrib_size != 0) {
+ const ver = @intToEnum(pdb.SectionContrSubstreamVersion, try dbi.inStream().readIntLittle(u32));
+ if (ver != pdb.SectionContrSubstreamVersion.Ver60)
+ return error.InvalidDebugInfo;
+ sect_cont_offset += @sizeOf(u32);
+ }
+ while (sect_cont_offset != section_contrib_size) {
+ const entry = try sect_contribs.addOne();
+ entry.* = try dbi.inStream().readStruct(pdb.SectionContribEntry);
+ sect_cont_offset += @sizeOf(pdb.SectionContribEntry);
- if (sect_cont_offset > section_contrib_size)
- return error.InvalidDebugInfo;
- }
+ if (sect_cont_offset > section_contrib_size)
+ return error.InvalidDebugInfo;
+ }
- di.sect_contribs = sect_contribs.toOwnedSlice();
+ di.sect_contribs = sect_contribs.toOwnedSlice();
- return di;
+ return di;
+ }
}
fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
@@ -1410,59 +1412,61 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
}
fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo {
- // Translate the VA into an address into this object
- const relocated_address = address - self.base_address;
- assert(relocated_address >= 0x100000000);
-
- // Find the .o file where this symbol is defined
- const symbol = machoSearchSymbols(self.symbols, relocated_address) orelse
- return SymbolInfo{};
-
- // Take the symbol name from the N_FUN STAB entry, we're going to
- // use it if we fail to find the DWARF infos
- const stab_symbol = mem.spanZ(self.strings[symbol.nlist.n_strx..]);
+ noasync {
+ // Translate the VA into an address into this object
+ const relocated_address = address - self.base_address;
+ assert(relocated_address >= 0x100000000);
- if (symbol.ofile == null)
- return SymbolInfo{ .symbol_name = stab_symbol };
+ // Find the .o file where this symbol is defined
+ const symbol = machoSearchSymbols(self.symbols, relocated_address) orelse
+ return SymbolInfo{};
- const o_file_path = mem.spanZ(self.strings[symbol.ofile.?.n_strx..]);
+ // Take the symbol name from the N_FUN STAB entry, we're going to
+ // use it if we fail to find the DWARF infos
+ const stab_symbol = mem.spanZ(self.strings[symbol.nlist.n_strx..]);
- // Check if its debug infos are already in the cache
- var o_file_di = self.ofiles.getValue(o_file_path) orelse
- (self.loadOFile(o_file_path) catch |err| switch (err) {
- error.FileNotFound,
- error.MissingDebugInfo,
- error.InvalidDebugInfo,
- => {
+ if (symbol.ofile == null)
return SymbolInfo{ .symbol_name = stab_symbol };
- },
- else => return err,
- });
- // Translate again the address, this time into an address inside the
- // .o file
- const relocated_address_o = relocated_address - symbol.reloc;
+ const o_file_path = mem.spanZ(self.strings[symbol.ofile.?.n_strx..]);
- if (o_file_di.findCompileUnit(relocated_address_o)) |compile_unit| {
- return SymbolInfo{
- .symbol_name = o_file_di.getSymbolName(relocated_address_o) orelse "???",
- .compile_unit_name = compile_unit.die.getAttrString(&o_file_di, DW.AT_name) catch |err| switch (err) {
- error.MissingDebugInfo, error.InvalidDebugInfo => "???",
- else => return err,
+ // Check if its debug infos are already in the cache
+ var o_file_di = self.ofiles.getValue(o_file_path) orelse
+ (self.loadOFile(o_file_path) catch |err| switch (err) {
+ error.FileNotFound,
+ error.MissingDebugInfo,
+ error.InvalidDebugInfo,
+ => {
+ return SymbolInfo{ .symbol_name = stab_symbol };
},
- .line_info = o_file_di.getLineNumberInfo(compile_unit.*, relocated_address_o) catch |err| switch (err) {
- error.MissingDebugInfo, error.InvalidDebugInfo => null,
- else => return err,
+ else => return err,
+ });
+
+ // Translate again the address, this time into an address inside the
+ // .o file
+ const relocated_address_o = relocated_address - symbol.reloc;
+
+ if (o_file_di.findCompileUnit(relocated_address_o)) |compile_unit| {
+ return SymbolInfo{
+ .symbol_name = o_file_di.getSymbolName(relocated_address_o) orelse "???",
+ .compile_unit_name = compile_unit.die.getAttrString(&o_file_di, DW.AT_name) catch |err| switch (err) {
+ error.MissingDebugInfo, error.InvalidDebugInfo => "???",
+ else => return err,
+ },
+ .line_info = o_file_di.getLineNumberInfo(compile_unit.*, relocated_address_o) catch |err| switch (err) {
+ error.MissingDebugInfo, error.InvalidDebugInfo => null,
+ else => return err,
+ },
+ };
+ } else |err| switch (err) {
+ error.MissingDebugInfo, error.InvalidDebugInfo => {
+ return SymbolInfo{ .symbol_name = stab_symbol };
},
- };
- } else |err| switch (err) {
- error.MissingDebugInfo, error.InvalidDebugInfo => {
- return SymbolInfo{ .symbol_name = stab_symbol };
- },
- else => return err,
- }
+ else => return err,
+ }
- unreachable;
+ unreachable;
+ }
}
},
.uefi, .windows => struct {