Skip to content

Commit

Permalink
libstd: fix off-by-one error in def of ProcSym in pdb
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kubkon authored and andrewrk committed Aug 17, 2022
1 parent c764640 commit 070282a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 6 additions & 3 deletions lib/std/pdb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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 => {},
Expand Down
7 changes: 1 addition & 6 deletions test/stack_traces.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 070282a

Please sign in to comment.