Skip to content

Commit 5497bfb

Browse files
SR-3175: Include the terminating signal number in the driver output
* Add the signal number of the terminated task to the output of the driver on platforms for which the signal number is available. The new key in the parseable driver output is "signal". * Add a test to verify that the signal number is emitted. * Add documentation for the new "signal" key emitted in the parseable driver output. https://bugs.swift.org/browse/SR-3175
1 parent f88ef97 commit 5497bfb

File tree

9 files changed

+33
-17
lines changed

9 files changed

+33
-17
lines changed

docs/DriverParseableOutput.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,17 @@ As with all task-based message, it will include the task's PID under the "pid"
104104
key. It may include an error message describing the signal under the
105105
"error-message" key. As with the "finished" message, it may include the
106106
stdout/stderr of the task under the "output" key; if this key is missing, no
107-
output was generated by the task.
107+
output was generated by the task. It may include the "signal" key,
108+
the terminating signal number. (This may not be available on all platforms.)
108109

109110
Example::
110111

111112
{
112113
"kind": "signalled",
113114
"name": "compile",
114115
"pid": 12345,
115-
"error-message": "Segmentation fault: 11"
116+
"error-message": "Segmentation fault: 11",
117+
"signal": 4
116118
// "output" key omitted because there was no stdout/stderr.
117119
}
118120

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ WARNING(warning_parallel_execution_not_supported,none,
4444

4545
ERROR(error_unable_to_execute_command,none,
4646
"unable to execute command: %0", (StringRef))
47-
ERROR(error_command_signalled,none,
47+
ERROR(error_command_signalled_without_signal_number,none,
4848
"%0 command failed due to signal (use -v to see invocation)", (StringRef))
49+
ERROR(error_command_signalled,none,
50+
"%0 command failed due to signal %1 (use -v to see invocation)", (StringRef, int))
4951
ERROR(error_command_failed,none,
5052
"%0 command failed with exit code %1 (use -v to see invocation)",
5153
(StringRef, int))

include/swift/Basic/TaskQueue.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ class TaskQueue {
9595
/// available and SeparateErrors was true. (This may not be available on all
9696
/// platforms.)
9797
/// \param Context the context which was passed when the task was added
98+
/// \param Signal the terminating signal number, if available.
99+
/// This may not be available on all platforms. If it is ever provided,
100+
/// it should not be removed in future versions of the compiler.
98101
///
99102
/// \returns a TaskFinishedResponse indicating whether or not execution
100103
/// should proceed
101104
typedef std::function<TaskFinishedResponse(ProcessId Pid, StringRef ErrorMsg,
102-
StringRef Output, StringRef Errors, void *Context)>
105+
StringRef Output, StringRef Errors,
106+
void *Context, Optional<int> Signal)>
103107
TaskSignalledCallback;
104108
#pragma clang diagnostic pop
105109

include/swift/Driver/ParseableOutput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void emitFinishedMessage(raw_ostream &os, const Job &Cmd, ProcessId Pid,
3939

4040
/// \brief Emits a "signalled" message to the given stream.
4141
void emitSignalledMessage(raw_ostream &os, const Job &Cmd, ProcessId Pid,
42-
StringRef ErrorMsg, StringRef Output);
42+
StringRef ErrorMsg, StringRef Output, Optional<int> Signal);
4343

4444
/// \brief Emits a "skipped" message to the given stream.
4545
void emitSkippedMessage(raw_ostream &os, const Job &Cmd);

lib/Basic/Default/TaskQueue.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
113113
// a signal during execution.
114114
if (Signalled) {
115115
TaskFinishedResponse Response =
116-
Signalled(PI.Pid, ErrMsg, StringRef(), StringRef(), T->Context);
116+
Signalled(PI.Pid, ErrMsg, StringRef(), StringRef(), T->Context, None);
117117
ContinueExecution = Response != TaskFinishedResponse::StopExecution;
118118
} else {
119119
// If we don't have a Signalled callback, unconditionally stop.

lib/Basic/Unix/TaskQueue.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
419419
if (Signalled) {
420420
TaskFinishedResponse Response =
421421
Signalled(T.getPid(), ErrorMsg, T.getOutput(), T.getErrors(),
422-
T.getContext());
422+
T.getContext(), Signal);
423423
if (Response == TaskFinishedResponse::StopExecution)
424424
// If we have a TaskCrashedCallback, only set SubtaskFailed to
425425
// true if the callback returns StopExecution.

lib/Driver/Compilation.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ int Compilation::performJobsImpl() {
615615

616616
auto taskSignalled = [&](ProcessId Pid, StringRef ErrorMsg, StringRef Output,
617617
StringRef Errors,
618-
void *Context) -> TaskFinishedResponse {
618+
void *Context, Optional<int> Signal) -> TaskFinishedResponse {
619619
const Job *SignalledCmd = (const Job *)Context;
620620

621621
if (ShowDriverTimeCompilation) {
@@ -625,7 +625,7 @@ int Compilation::performJobsImpl() {
625625
if (Level == OutputLevel::Parseable) {
626626
// Parseable output was requested.
627627
parseable_output::emitSignalledMessage(llvm::errs(), *SignalledCmd, Pid,
628-
ErrorMsg, Output);
628+
ErrorMsg, Output, Signal);
629629
} else {
630630
// Otherwise, send the buffered output to stderr, though only if we
631631
// support getting buffered output.
@@ -636,9 +636,15 @@ int Compilation::performJobsImpl() {
636636
if (!ErrorMsg.empty())
637637
Diags.diagnose(SourceLoc(), diag::error_unable_to_execute_command,
638638
ErrorMsg);
639-
640-
Diags.diagnose(SourceLoc(), diag::error_command_signalled,
641-
SignalledCmd->getSource().getClassName());
639+
640+
if (Signal.hasValue()) {
641+
Diags.diagnose(SourceLoc(), diag::error_command_signalled,
642+
SignalledCmd->getSource().getClassName(), Signal.getValue());
643+
}
644+
else {
645+
Diags.diagnose(SourceLoc(), diag::error_command_signalled_without_signal_number,
646+
SignalledCmd->getSource().getClassName());
647+
}
642648

643649
// Since the task signalled, unconditionally set result to -2.
644650
Result = -2;

lib/Driver/ParseableOutput.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,17 @@ class FinishedMessage : public TaskOutputMessage {
201201

202202
class SignalledMessage : public TaskOutputMessage {
203203
std::string ErrorMsg;
204+
Optional<int> Signal;
204205
public:
205206
SignalledMessage(const Job &Cmd, ProcessId Pid, StringRef Output,
206-
StringRef ErrorMsg) : TaskOutputMessage("signalled", Cmd,
207+
StringRef ErrorMsg, Optional<int> Signal) : TaskOutputMessage("signalled", Cmd,
207208
Pid, Output),
208-
ErrorMsg(ErrorMsg) {}
209+
ErrorMsg(ErrorMsg), Signal(Signal) {}
209210

210211
void provideMapping(swift::json::Output &out) override {
211212
TaskOutputMessage::provideMapping(out);
212213
out.mapOptional("error-message", ErrorMsg, std::string());
214+
out.mapOptional("signal", Signal);
213215
}
214216
};
215217

@@ -260,8 +262,8 @@ void parseable_output::emitFinishedMessage(raw_ostream &os,
260262
void parseable_output::emitSignalledMessage(raw_ostream &os,
261263
const Job &Cmd, ProcessId Pid,
262264
StringRef ErrorMsg,
263-
StringRef Output) {
264-
SignalledMessage msg(Cmd, Pid, Output, ErrorMsg);
265+
StringRef Output, Optional<int> Signal) {
266+
SignalledMessage msg(Cmd, Pid, Output, ErrorMsg, Signal);
265267
emitMessage(os, msg);
266268
}
267269

test/Driver/crash.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
// CHECK: error: compile command failed due to signal
5+
// CHECK: error: compile command failed due to signal {{-?[0-9]+}}
66

77
func anchor() {}
88
anchor()

0 commit comments

Comments
 (0)