Skip to content

Commit 3eba4fd

Browse files
authored
Merge pull request #6787 from matthewcarroll/SR-3175-Include-signal-number-in-parseable-output-message
SR-3175: Include the terminating signal number in the driver output
2 parents 24a61b5 + 09abbfe commit 3eba4fd

File tree

9 files changed

+37
-20
lines changed

9 files changed

+37
-20
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ unsigned TaskQueue::getNumberOfParallelTasks() const {
6868
}
6969

7070
void TaskQueue::addTask(const char *ExecPath, ArrayRef<const char *> Args,
71-
ArrayRef<const char *> Env, void *Context) {
72-
std::unique_ptr<Task> T(new Task(ExecPath, Args, Env, Context));
71+
ArrayRef<const char *> Env, void *Context,
72+
bool SeparateErrors) {
73+
std::unique_ptr<Task> T(new Task(ExecPath, Args, Env, Context, SeparateErrors));
7374
QueuedTasks.push(std::move(T));
7475
}
7576

@@ -113,7 +114,7 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
113114
// a signal during execution.
114115
if (Signalled) {
115116
TaskFinishedResponse Response =
116-
Signalled(PI.Pid, ErrMsg, StringRef(), StringRef(), T->Context);
117+
Signalled(PI.Pid, ErrMsg, StringRef(), StringRef(), T->Context, None);
117118
ContinueExecution = Response != TaskFinishedResponse::StopExecution;
118119
} else {
119120
// 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: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ int Compilation::performJobsImpl() {
625625

626626
auto taskSignalled = [&](ProcessId Pid, StringRef ErrorMsg, StringRef Output,
627627
StringRef Errors,
628-
void *Context) -> TaskFinishedResponse {
628+
void *Context, Optional<int> Signal) -> TaskFinishedResponse {
629629
const Job *SignalledCmd = (const Job *)Context;
630630

631631
if (ShowDriverTimeCompilation) {
@@ -635,7 +635,7 @@ int Compilation::performJobsImpl() {
635635
if (Level == OutputLevel::Parseable) {
636636
// Parseable output was requested.
637637
parseable_output::emitSignalledMessage(llvm::errs(), *SignalledCmd, Pid,
638-
ErrorMsg, Output);
638+
ErrorMsg, Output, Signal);
639639
} else {
640640
// Otherwise, send the buffered output to stderr, though only if we
641641
// support getting buffered output.
@@ -646,9 +646,14 @@ int Compilation::performJobsImpl() {
646646
if (!ErrorMsg.empty())
647647
Diags.diagnose(SourceLoc(), diag::error_unable_to_execute_command,
648648
ErrorMsg);
649-
650-
Diags.diagnose(SourceLoc(), diag::error_command_signalled,
651-
SignalledCmd->getSource().getClassName());
649+
650+
if (Signal.hasValue()) {
651+
Diags.diagnose(SourceLoc(), diag::error_command_signalled,
652+
SignalledCmd->getSource().getClassName(), Signal.getValue());
653+
} else {
654+
Diags.diagnose(SourceLoc(), diag::error_command_signalled_without_signal_number,
655+
SignalledCmd->getSource().getClassName());
656+
}
652657

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

lib/Driver/ParseableOutput.cpp

Lines changed: 8 additions & 5 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-
Pid, Output),
208-
ErrorMsg(ErrorMsg) {}
207+
StringRef ErrorMsg, Optional<int> Signal) :
208+
TaskOutputMessage("signalled", Cmd, Pid, Output), ErrorMsg(ErrorMsg),
209+
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,9 @@ 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,
266+
Optional<int> Signal) {
267+
SignalledMessage msg(Cmd, Pid, Output, ErrorMsg, Signal);
265268
emitMessage(os, msg);
266269
}
267270

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)