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.
This commit is contained in:
Jakub Konka 2022-08-17 16:58:16 +02:00 committed by Andrew Kelley
parent c764640e92
commit 070282a96e
2 changed files with 7 additions and 9 deletions

View File

@ -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 => {},

View File

@ -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 =