Skip to content

Commit 070282a

Browse files
kubkonandrewrk
authored andcommitted
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.
1 parent c764640 commit 070282a

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

lib/std/pdb.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ pub const SymbolKind = enum(u16) {
310310

311311
pub 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.
313317
pub const ProcSym = extern struct {
314318
Parent: u32,
315319
End: u32,
@@ -321,8 +325,7 @@ pub const ProcSym = extern struct {
321325
CodeOffset: u32,
322326
Segment: u16,
323327
Flags: ProcSymFlags,
324-
// following is a null terminated string
325-
// Name: [*]u8,
328+
Name: [1]u8, // null-terminated
326329
};
327330

328331
pub const ProcSymFlags = packed struct {
@@ -693,7 +696,7 @@ pub const Pdb = struct {
693696
.S_LPROC32, .S_GPROC32 => {
694697
const proc_sym = @ptrCast(*align(1) ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]);
695698
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);
697700
}
698701
},
699702
else => {},

test/stack_traces.zig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ const os = std.os;
33
const tests = @import("tests.zig");
44

55
pub 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-
116
cases.addCase(.{
127
.name = "return",
138
.source =
@@ -178,7 +173,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
178173
cases.addCase(.{
179174
.exclude_os = .{
180175
.openbsd, // integer overflow
181-
.windows,
176+
.windows, // TODO intermittent failures
182177
},
183178
.name = "dumpCurrentStackTrace",
184179
.source =

0 commit comments

Comments
 (0)