aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2010-10-11 16:40:18 -0700
committerPatrick Walton <[email protected]>2010-10-11 16:40:18 -0700
commit94cec74096280509083798bfcbd1be169fd43562 (patch)
treee10dbce1e72079b4ebddf5a9ad58a92776e92715
parentBind labels explicitly in fe/cexp.ml. Should fix issue #169. (diff)
downloadrust-94cec74096280509083798bfcbd1be169fd43562.tar.xz
rust-94cec74096280509083798bfcbd1be169fd43562.zip
Try to print backtraces on failure
-rw-r--r--src/rt/rust_log.cpp42
-rw-r--r--src/rt/rust_log.h1
-rw-r--r--src/rt/rust_task.cpp17
-rw-r--r--src/rt/rust_task.h3
4 files changed, 46 insertions, 17 deletions
diff --git a/src/rt/rust_log.cpp b/src/rt/rust_log.cpp
index a57f7cb4..74a5d00e 100644
--- a/src/rt/rust_log.cpp
+++ b/src/rt/rust_log.cpp
@@ -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;
}
diff --git a/src/rt/rust_log.h b/src/rt/rust_log.h
index 66246eb6..59aa504f 100644
--- a/src/rt/rust_log.h
+++ b/src/rt/rust_log.h
@@ -42,6 +42,7 @@ public:
STDLIB = 0x1000,
SPECIAL = 0x2000,
KERN = 0x4000,
+ BT = 0x8000,
ALL = 0xffffffff
};
diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp
index 97eeb4bf..530e5997 100644
--- a/src/rt/rust_task.cpp
+++ b/src/rt/rust_task.cpp
@@ -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) {
diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h
index 26ba872d..9fbc67ac 100644
--- a/src/rt/rust_task.h
+++ b/src/rt/rust_task.h
@@ -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);