From 070282a96ec23fb41041843d5753608ec5090f8b Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Wed, 17 Aug 2022 16:58:16 +0200 Subject: [PATCH] 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. --- lib/std/pdb.zig | 9 ++++++--- test/stack_traces.zig | 7 +------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index a44296c9209e81fe2d91159609cf37000846460f..00ce2cc5baab19b3704d4713bfa9d8d1793bb13b 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -310,6 +310,10 @@ pub const SymbolKind = enum(u16) { pub const TypeIndex = u32; +// TODO According to this header: +// https://github.com/microsoft/microsoft-pdb/blob/082c5290e5aff028ae84e43affa8be717aa7af73/include/cvinfo.h#L3722 +// we should define RecordPrefix as part of the ProcSym structure. +// This might be important when we start generating PDB in self-hosted with our own PE linker. pub const ProcSym = extern struct { Parent: u32, End: u32, @@ -321,8 +325,7 @@ pub const ProcSym = extern struct { CodeOffset: u32, Segment: u16, Flags: ProcSymFlags, - // following is a null terminated string - // Name: [*]u8, + Name: [1]u8, // null-terminated }; pub const ProcSymFlags = packed struct { @@ -693,7 +696,7 @@ pub const Pdb = struct { .S_LPROC32, .S_GPROC32 => { const proc_sym = @ptrCast(*align(1) ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]); if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) { - return mem.sliceTo(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym), 0); + return mem.sliceTo(@ptrCast([*:0]u8, &proc_sym.Name[0]), 0); } }, else => {}, diff --git a/test/stack_traces.zig b/test/stack_traces.zig index e514e0fd881a419893cb9dacf56928c891fa171f..06534a2f7e45c489a0ca08a85396cfe00395865f 100644 --- a/test/stack_traces.zig +++ b/test/stack_traces.zig @@ -3,11 +3,6 @@ const os = std.os; const tests = @import("tests.zig"); pub fn addCases(cases: *tests.StackTracesContext) void { - if (@import("builtin").os.tag == .windows) { - // https://github.com/ziglang/zig/issues/12422 - return; - } - cases.addCase(.{ .name = "return", .source = @@ -178,7 +173,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { cases.addCase(.{ .exclude_os = .{ .openbsd, // integer overflow - .windows, + .windows, // TODO intermittent failures }, .name = "dumpCurrentStackTrace", .source = -- 2.54.0