Skip to content

[Driver] SR-3175: Include the terminating signal number in the driver output #6787

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
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
6 changes: 4 additions & 2 deletions docs/DriverParseableOutput.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,17 @@ As with all task-based message, it will include the task's PID under the "pid"
key. It may include an error message describing the signal under the
"error-message" key. As with the "finished" message, it may include the
stdout/stderr of the task under the "output" key; if this key is missing, no
output was generated by the task.
output was generated by the task. It may include the "signal" key,
the terminating signal number. (This may not be available on all platforms.)

Example::

{
"kind": "signalled",
"name": "compile",
"pid": 12345,
"error-message": "Segmentation fault: 11"
"error-message": "Segmentation fault: 11",
"signal": 4
// "output" key omitted because there was no stdout/stderr.
}

Expand Down
4 changes: 3 additions & 1 deletion include/swift/AST/DiagnosticsDriver.def
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ WARNING(warning_parallel_execution_not_supported,none,

ERROR(error_unable_to_execute_command,none,
"unable to execute command: %0", (StringRef))
ERROR(error_command_signalled,none,
ERROR(error_command_signalled_without_signal_number,none,
"%0 command failed due to signal (use -v to see invocation)", (StringRef))
ERROR(error_command_signalled,none,
"%0 command failed due to signal %1 (use -v to see invocation)", (StringRef, int))
ERROR(error_command_failed,none,
"%0 command failed with exit code %1 (use -v to see invocation)",
(StringRef, int))
Expand Down
6 changes: 5 additions & 1 deletion include/swift/Basic/TaskQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ class TaskQueue {
/// available and SeparateErrors was true. (This may not be available on all
/// platforms.)
/// \param Context the context which was passed when the task was added
/// \param Signal the terminating signal number, if available.
/// This may not be available on all platforms. If it is ever provided,
/// it should not be removed in future versions of the compiler.
///
/// \returns a TaskFinishedResponse indicating whether or not execution
/// should proceed
typedef std::function<TaskFinishedResponse(ProcessId Pid, StringRef ErrorMsg,
StringRef Output, StringRef Errors, void *Context)>
StringRef Output, StringRef Errors,
void *Context, Optional<int> Signal)>
TaskSignalledCallback;
#pragma clang diagnostic pop

Expand Down
2 changes: 1 addition & 1 deletion include/swift/Driver/ParseableOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void emitFinishedMessage(raw_ostream &os, const Job &Cmd, ProcessId Pid,

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

/// \brief Emits a "skipped" message to the given stream.
void emitSkippedMessage(raw_ostream &os, const Job &Cmd);
Expand Down
7 changes: 4 additions & 3 deletions lib/Basic/Default/TaskQueue.inc
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ unsigned TaskQueue::getNumberOfParallelTasks() const {
}

void TaskQueue::addTask(const char *ExecPath, ArrayRef<const char *> Args,
ArrayRef<const char *> Env, void *Context) {
std::unique_ptr<Task> T(new Task(ExecPath, Args, Env, Context));
ArrayRef<const char *> Env, void *Context,
bool SeparateErrors) {
std::unique_ptr<Task> T(new Task(ExecPath, Args, Env, Context, SeparateErrors));
QueuedTasks.push(std::move(T));
}

Expand Down Expand Up @@ -113,7 +114,7 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
// a signal during execution.
if (Signalled) {
TaskFinishedResponse Response =
Signalled(PI.Pid, ErrMsg, StringRef(), StringRef(), T->Context);
Signalled(PI.Pid, ErrMsg, StringRef(), StringRef(), T->Context, None);
ContinueExecution = Response != TaskFinishedResponse::StopExecution;
} else {
// If we don't have a Signalled callback, unconditionally stop.
Expand Down
2 changes: 1 addition & 1 deletion lib/Basic/Unix/TaskQueue.inc
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
if (Signalled) {
TaskFinishedResponse Response =
Signalled(T.getPid(), ErrorMsg, T.getOutput(), T.getErrors(),
T.getContext());
T.getContext(), Signal);
if (Response == TaskFinishedResponse::StopExecution)
// If we have a TaskCrashedCallback, only set SubtaskFailed to
// true if the callback returns StopExecution.
Expand Down
15 changes: 10 additions & 5 deletions lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ int Compilation::performJobsImpl() {

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

if (ShowDriverTimeCompilation) {
Expand All @@ -625,7 +625,7 @@ int Compilation::performJobsImpl() {
if (Level == OutputLevel::Parseable) {
// Parseable output was requested.
parseable_output::emitSignalledMessage(llvm::errs(), *SignalledCmd, Pid,
ErrorMsg, Output);
ErrorMsg, Output, Signal);
} else {
// Otherwise, send the buffered output to stderr, though only if we
// support getting buffered output.
Expand All @@ -636,9 +636,14 @@ int Compilation::performJobsImpl() {
if (!ErrorMsg.empty())
Diags.diagnose(SourceLoc(), diag::error_unable_to_execute_command,
ErrorMsg);

Diags.diagnose(SourceLoc(), diag::error_command_signalled,
SignalledCmd->getSource().getClassName());

if (Signal.hasValue()) {
Diags.diagnose(SourceLoc(), diag::error_command_signalled,
SignalledCmd->getSource().getClassName(), Signal.getValue());
} else {
Diags.diagnose(SourceLoc(), diag::error_command_signalled_without_signal_number,
SignalledCmd->getSource().getClassName());
}

// Since the task signalled, unconditionally set result to -2.
Result = -2;
Expand Down
13 changes: 8 additions & 5 deletions lib/Driver/ParseableOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,17 @@ class FinishedMessage : public TaskOutputMessage {

class SignalledMessage : public TaskOutputMessage {
std::string ErrorMsg;
Optional<int> Signal;
public:
SignalledMessage(const Job &Cmd, ProcessId Pid, StringRef Output,
StringRef ErrorMsg) : TaskOutputMessage("signalled", Cmd,
Pid, Output),
ErrorMsg(ErrorMsg) {}
StringRef ErrorMsg, Optional<int> Signal) :
TaskOutputMessage("signalled", Cmd, Pid, Output), ErrorMsg(ErrorMsg),
Signal(Signal) {}

void provideMapping(swift::json::Output &out) override {
TaskOutputMessage::provideMapping(out);
out.mapOptional("error-message", ErrorMsg, std::string());
out.mapOptional("signal", Signal);
}
};

Expand Down Expand Up @@ -260,8 +262,9 @@ void parseable_output::emitFinishedMessage(raw_ostream &os,
void parseable_output::emitSignalledMessage(raw_ostream &os,
const Job &Cmd, ProcessId Pid,
StringRef ErrorMsg,
StringRef Output) {
SignalledMessage msg(Cmd, Pid, Output, ErrorMsg);
StringRef Output,
Optional<int> Signal) {
SignalledMessage msg(Cmd, Pid, Output, ErrorMsg, Signal);
emitMessage(os, msg);
}

Expand Down
2 changes: 1 addition & 1 deletion test/Driver/crash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

func anchor() {}
anchor()
Expand Down