Skip to content

Commit 3e285ce

Browse files
committed
Auto merge of #2315 - alexcrichton:decode-some-signals, r=brson
Instead of text that looks like Process failed (signal: 11) the text now looks like: Process failed (signal: 11, SIGSEGV: invalid memory reference) Closes #2315
2 parents b5e0a45 + b3a8bac commit 3e285ce

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/cargo/util/errors.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ pub fn process_error(msg: &str,
337337
status: Option<&ExitStatus>,
338338
output: Option<&Output>) -> ProcessError {
339339
let exit = match status {
340-
Some(s) => s.to_string(),
340+
Some(s) => status_to_string(s),
341341
None => "never executed".to_string(),
342342
};
343343
let mut desc = format!("{} ({})", &msg, exit);
@@ -359,11 +359,45 @@ pub fn process_error(msg: &str,
359359
}
360360
}
361361

362-
ProcessError {
362+
return ProcessError {
363363
desc: desc,
364364
exit: status.cloned(),
365365
output: output.cloned(),
366366
cause: cause,
367+
};
368+
369+
#[cfg(unix)]
370+
fn status_to_string(status: &ExitStatus) -> String {
371+
use std::os::unix::process::*;
372+
use libc;
373+
374+
if let Some(signal) = status.signal() {
375+
let name = match signal as libc::c_int {
376+
libc::SIGABRT => ", SIGABRT: process abort signal",
377+
libc::SIGALRM => ", SIGALRM: alarm clock",
378+
libc::SIGFPE => ", SIGFPE: erroneous arithmetic operation",
379+
libc::SIGHUP => ", SIGHUP: hangup",
380+
libc::SIGILL => ", SIGILL: illegal instruction",
381+
libc::SIGINT => ", SIGINT: terminal interrupt signal",
382+
libc::SIGKILL => ", SIGKILL: kill",
383+
libc::SIGPIPE => ", SIGPIPE: write on a pipe with no one to read",
384+
libc::SIGQUIT => ", SIGQUIT: terminal quite signal",
385+
libc::SIGSEGV => ", SIGSEGV: invalid memory reference",
386+
libc::SIGTERM => ", SIGTERM: termination signal",
387+
libc::SIGBUS => ", SIGBUS: access to undefined memory",
388+
libc::SIGSYS => ", SIGSYS: bad system call",
389+
libc::SIGTRAP => ", SIGTRAP: trace/breakpoint trap",
390+
_ => "",
391+
};
392+
format!("signal: {}{}", signal, name)
393+
} else {
394+
status.to_string()
395+
}
396+
}
397+
398+
#[cfg(windows)]
399+
fn status_to_string(status: &ExitStatus) -> String {
400+
status.to_string()
367401
}
368402
}
369403

0 commit comments

Comments
 (0)