-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bring windows segfault handler on par with linux #4319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/std/debug.zig
Outdated
else => return windows.EXCEPTION_CONTINUE_SEARCH, | ||
} | ||
} | ||
|
||
// zig won't let me use an anon enum here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that? What error does it give?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D:\zig>zig run ill.zig -target x86_64-windows-gnu
.\lib\zig\std\debug.zig:2311:85: error: expected type 'std.debug.enum:2320:80', found 'std.debug.enum:2320:80'
windows.EXCEPTION_DATATYPE_MISALIGNMENT => handleSegfaultWindowsExtra(info, .fmt, "Unaligned Memory Access"),
^
.\lib\zig\std\debug.zig:2320:80: note: std.debug.enum:2320:80 declared here
fn handleSegfaultWindowsExtra(info: *windows.EXCEPTION_POINTERS, comptime msg: enum {fmt, segv, ill}, comptime format: ?[]const u8) noreturn {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah the infamous enum
bug, I think it stops being a problem if you don't make it a comptime param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, comptime does not make a difference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an issue for this? I'll take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3707, the anonymous enum is analyzed twice and produces two disjoint types.
Could this be related to 7336b75? |
@andrewrk no, that function actually not even called once when i tested. I've managed to make it work, now it points to ud2 asm block. I have no idea why adding 1 to ip fixes it. Also stack iterator won't return nulls now.
|
Thanks @Rocknest. This looks like a good change. Happy to merge after @LemonBoy's review comment #4319 (comment) is solved |
Hold your horses, this is not correct. Get a debugger and you'll see that the exception address is indeed correct and points to the |
@LemonBoy Yes the instruction is exactly where |
There's no -1 in |
@LemonBoy i suspect that off-by-one is debug.zig:474. |
If the comment above is to be trusted then yes, it should be |
The comment is from a60ecdc |
Looks like that's a proper fix. Stack traces look identical to linux (up to main fn). |
💯 Wonderful. Thank you both. Nevermind the sr.ht build failure. It appears to be a temporary CI issue. |
lib/std/os/windows/bits.zig
Outdated
LastExceptionFromRip: DWORD64, | ||
|
||
pub fn getRegs(ctx: *const CONTEXT) struct {bp: usize, ip: usize} { | ||
return .{.bp = @intCast(usize, ctx.Rbp), .ip = @intCast(usize, ctx.Rip)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@intCast
not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got another nonsensical compile error
D:\zig>zig run ill.zig
.\lib\zig\std\os\windows\bits.zig:1036:29: error: array access of non-array type 'std.os.windows.bits.struct:1035:49'
return .{ctx.Rbp, ctx.Rip};
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally the thing to do is to mark a workaround like this:
// TODO: The @as is a workaround for https://github.com/ziglang/zig/issues/4310
return .{.bp = @as(usize, ctx.Rbp), .ip = @as(usize, ctx.Rip)};
(replace 4310 with the issue number corresponding to this bug)
Does @as
provide a workaround? That would be a preferable workaround to @intCast
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a confusing compile error. Actually the problem is that anon list literal cannot coerce into given type.
I think it is #4148
Nice work! |
Adds a new way to dump stack traces on windows that closely resembles linux segfault handler. Works on i386, x86_64 (tested) and aarch64 (not tested).
I don't know where to put these definitions since there are no 'bits' for windows by architecture.
Basically changes are only seen on i386. Test code:
Before:
After:
Highlighted is a panic caused by underflow in
dumpStackTraceFromBase
when it received0
fromStackIterator
. I'm sure its a bug.There is also a problem that stack trace points to "nop" and not "ud2" instruction.