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) {
310310
311311pub 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.
313317pub 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
328331pub 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+1-6
......@@ -3,11 +3,6 @@ const os = std.os;
33const tests = @import("tests.zig");
44
55pub 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 =