Skip to content

Have Windows Call Signaled Callback on Crashes #23018

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

Merged
merged 1 commit into from
Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/Basic/Default/TaskQueue.inc
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,22 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
stderrContents = stderrBuffer.get()->getBuffer();
}

if (ReturnCode == -2) {
#if defined(_WIN32)
// Wait() sets the upper two bits of the return code to indicate warnings
// (10) and errors (11).
//
// This isn't a true signal on Windows, but we'll treat it as such so that
// we clean up after it properly
bool crashed = ReturnCode & 0xC0000000;
#else
// Wait() returning a return code of -2 indicates the process received
// a signal during execution.
bool crashed = ReturnCode == -2;
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I dislike #ifs that don't surround a whole unit of AST. Mind factoring this out into a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

if (crashed) {
if (Signalled) {
TaskFinishedResponse Response =
Signalled(PI.Pid, ErrMsg, stdoutContents, stderrContents, T->Context, None, TaskProcessInformation(PI.Pid));
Signalled(PI.Pid, ErrMsg, stdoutContents, stderrContents, T->Context, ReturnCode, TaskProcessInformation(PI.Pid));
ContinueExecution = Response != TaskFinishedResponse::StopExecution;
} else {
// If we don't have a Signalled callback, unconditionally stop.
Expand Down
2 changes: 0 additions & 2 deletions test/Driver/assert.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Windows programs cannot fail due to a signal
// UNSUPPORTED: windows
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-assert-immediately 2>&1 | %FileCheck %s
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-assert-after-parse 2>&1 | %FileCheck %s

Expand Down
2 changes: 0 additions & 2 deletions test/Driver/crash.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Windows programs cannot fail due to a signal
// UNSUPPORTED: windows
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-crash-immediately 2>&1 | %FileCheck %s

// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-crash-after-parse 2>&1 | %FileCheck %s
Expand Down