Try to print backtraces on failure
This commit is contained in:
parent
99086292ac
commit
94cec74096
@ -6,30 +6,38 @@
|
||||
#include "rust_internal.h"
|
||||
#include "util/array_list.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <alloca.h>
|
||||
|
||||
static uint32_t
|
||||
read_type_bit_mask() {
|
||||
uint32_t bits = rust_log::ULOG | rust_log::ERR;
|
||||
char *env_str = getenv("RUST_LOG");
|
||||
if (env_str) {
|
||||
char *str = (char *)alloca(strlen(env_str) + 2);
|
||||
str[0] = ',';
|
||||
strcpy(str + 1, env_str);
|
||||
|
||||
bits = 0;
|
||||
bits |= strstr(env_str, "err") ? rust_log::ERR : 0;
|
||||
bits |= strstr(env_str, "mem") ? rust_log::MEM : 0;
|
||||
bits |= strstr(env_str, "comm") ? rust_log::COMM : 0;
|
||||
bits |= strstr(env_str, "task") ? rust_log::TASK : 0;
|
||||
bits |= strstr(env_str, "up") ? rust_log::UPCALL : 0;
|
||||
bits |= strstr(env_str, "dom") ? rust_log::DOM : 0;
|
||||
bits |= strstr(env_str, "ulog") ? rust_log::ULOG : 0;
|
||||
bits |= strstr(env_str, "trace") ? rust_log::TRACE : 0;
|
||||
bits |= strstr(env_str, "dwarf") ? rust_log::DWARF : 0;
|
||||
bits |= strstr(env_str, "cache") ? rust_log::CACHE : 0;
|
||||
bits |= strstr(env_str, "timer") ? rust_log::TIMER : 0;
|
||||
bits |= strstr(env_str, "gc") ? rust_log::GC : 0;
|
||||
bits |= strstr(env_str, "stdlib") ? rust_log::STDLIB : 0;
|
||||
bits |= strstr(env_str, "special") ? rust_log::SPECIAL : 0;
|
||||
bits |= strstr(env_str, "kern") ? rust_log::KERN : 0;
|
||||
bits |= strstr(env_str, "all") ? rust_log::ALL : 0;
|
||||
bits = strstr(env_str, "none") ? 0 : bits;
|
||||
bits |= strstr(str, ",err") ? rust_log::ERR : 0;
|
||||
bits |= strstr(str, ",mem") ? rust_log::MEM : 0;
|
||||
bits |= strstr(str, ",comm") ? rust_log::COMM : 0;
|
||||
bits |= strstr(str, ",task") ? rust_log::TASK : 0;
|
||||
bits |= strstr(str, ",up") ? rust_log::UPCALL : 0;
|
||||
bits |= strstr(str, ",dom") ? rust_log::DOM : 0;
|
||||
bits |= strstr(str, ",ulog") ? rust_log::ULOG : 0;
|
||||
bits |= strstr(str, ",trace") ? rust_log::TRACE : 0;
|
||||
bits |= strstr(str, ",dwarf") ? rust_log::DWARF : 0;
|
||||
bits |= strstr(str, ",cache") ? rust_log::CACHE : 0;
|
||||
bits |= strstr(str, ",timer") ? rust_log::TIMER : 0;
|
||||
bits |= strstr(str, ",gc") ? rust_log::GC : 0;
|
||||
bits |= strstr(str, ",stdlib") ? rust_log::STDLIB : 0;
|
||||
bits |= strstr(str, ",special") ? rust_log::SPECIAL : 0;
|
||||
bits |= strstr(str, ",kern") ? rust_log::KERN : 0;
|
||||
bits |= strstr(str, ",bt") ? rust_log::BT : 0;
|
||||
bits |= strstr(str, ",all") ? rust_log::ALL : 0;
|
||||
bits = strstr(str, ",none") ? 0 : bits;
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
STDLIB = 0x1000,
|
||||
SPECIAL = 0x2000,
|
||||
KERN = 0x4000,
|
||||
BT = 0x8000,
|
||||
ALL = 0xffffffff
|
||||
};
|
||||
|
||||
|
@ -4,6 +4,10 @@
|
||||
#include "valgrind.h"
|
||||
#include "memcheck.h"
|
||||
|
||||
#ifndef __WIN32__
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
// Stacks
|
||||
|
||||
// FIXME (issue #151): This should be 0x300; the change here is for
|
||||
@ -366,6 +370,7 @@ void
|
||||
rust_task::fail(size_t nargs) {
|
||||
// See note in ::kill() regarding who should call this.
|
||||
dom->log(rust_log::TASK, "task %s @0x%" PRIxPTR " failing", name, this);
|
||||
backtrace();
|
||||
// Unblock the task so it can unwind.
|
||||
unblock();
|
||||
if (this == dom->root_task)
|
||||
@ -632,6 +637,18 @@ rust_task::log(uint32_t type_bits, char const *fmt, ...) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rust_task::backtrace() {
|
||||
if (!dom->get_log().is_tracing(rust_log::BT))
|
||||
return;
|
||||
|
||||
#ifndef __WIN32__
|
||||
void *call_stack[256];
|
||||
int nframes = ::backtrace(call_stack, 256);
|
||||
backtrace_symbols_fd(call_stack + 1, nframes - 1, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
rust_handle<rust_task> *
|
||||
rust_task::get_handle() {
|
||||
if (handle == NULL) {
|
||||
|
@ -83,6 +83,9 @@ rust_task : public maybe_proxy<rust_task>,
|
||||
|
||||
void log(uint32_t type_bits, char const *fmt, ...);
|
||||
|
||||
// Print a backtrace, if the "bt" logging option is on.
|
||||
void backtrace();
|
||||
|
||||
// Swap in some glue code to run when we have returned to the
|
||||
// task's context (assuming we're the active task).
|
||||
void run_after_return(size_t nargs, uintptr_t glue);
|
||||
|
Loading…
x
Reference in New Issue
Block a user