authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-08-17 16:58:16+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-17 16:36:02-04:00
log070282a96ec23fb41041843d5753608ec5090f8b
tree13b62bf7381e603a55c13110b271ace2334bcbd6
parentc764640e92c9e4d32b89650ac774bebf1498be92

libstd: fix off-by-one error in def of ProcSym in pdb

Make sure `ProcSym` includes a single element byte-array which delimits the start of the symbol's name as part of its definition. This makes the code more elegant in that accessing the name is equivalent to taking the address of this one element array.

2 files changed, 7 insertions(+), 9 deletions(-)

lib/std/pdb.zig+6-3
...@@ -310,6 +310,10 @@ pub const SymbolKind = enum(u16) {...@@ -310,6 +310,10 @@ pub const SymbolKind = enum(u16) {
310310
311pub const TypeIndex = u32;311pub const TypeIndex = u32;
312312
313// TODO According to this header:
314// https://github.com/microsoft/microsoft-pdb/blob/082c5290e5aff028ae84e43affa8be717aa7af73/include/cvinfo.h#L3722
315// we should define RecordPrefix as part of the ProcSym structure.
316// This might be important when we start generating PDB in self-hosted with our own PE linker.
313pub const ProcSym = extern struct {317pub const ProcSym = extern struct {
314 Parent: u32,318 Parent: u32,
315 End: u32,319 End: u32,
...@@ -321,8 +325,7 @@ pub const ProcSym = extern struct {...@@ -321,8 +325,7 @@ pub const ProcSym = extern struct {
321 CodeOffset: u32,325 CodeOffset: u32,
322 Segment: u16,326 Segment: u16,
323 Flags: ProcSymFlags,327 Flags: ProcSymFlags,
324 // following is a null terminated string328 Name: [1]u8, // null-terminated
325 // Name: [*]u8,
326};329};
327330
328pub const ProcSymFlags = packed struct {331pub const ProcSymFlags = packed struct {
...@@ -693,7 +696,7 @@ pub const Pdb = struct {...@@ -693,7 +696,7 @@ pub const Pdb = struct {
693 .S_LPROC32, .S_GPROC32 => {696 .S_LPROC32, .S_GPROC32 => {
694 const proc_sym = @ptrCast(*align(1) ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]);697 const proc_sym = @ptrCast(*align(1) ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]);
695 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {698 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {
696 return mem.sliceTo(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym), 0);699 return mem.sliceTo(@ptrCast([*:0]u8, &proc_sym.Name[0]), 0);
697 }700 }
698 },701 },
699 else => {},702 else => {},
test/stack_traces.zig+1-6
...@@ -3,11 +3,6 @@ const os = std.os;...@@ -3,11 +3,6 @@ const os = std.os;
3const tests = @import("tests.zig");3const tests = @import("tests.zig");
44
5pub fn addCases(cases: *tests.StackTracesContext) void {5pub fn addCases(cases: *tests.StackTracesContext) void {
6 if (@import("builtin").os.tag == .windows) {
7 // https://github.com/ziglang/zig/issues/12422
8 return;
9 }
10
11 cases.addCase(.{6 cases.addCase(.{
12 .name = "return",7 .name = "return",
13 .source = 8 .source =
...@@ -178,7 +173,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -178,7 +173,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
178 cases.addCase(.{173 cases.addCase(.{
179 .exclude_os = .{174 .exclude_os = .{
180 .openbsd, // integer overflow175 .openbsd, // integer overflow
181 .windows,176 .windows, // TODO intermittent failures
182 },177 },
183 .name = "dumpCurrentStackTrace",178 .name = "dumpCurrentStackTrace",
184 .source = 179 .source =