Skip to content

Commit bcfd006

Browse files
committed
---
yaml --- r: 767 b: refs/heads/master c: 94cec74 h: refs/heads/master i: 765: 169a85b 763: 967567a 759: 7354726 751: 7e4213b 735: 2bfa588 703: b017c57 639: d9e1cf5 511: 5692310 v: v3
1 parent f2015a3 commit bcfd006

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 99086292ac50458244722aedbad53c5047214429
2+
refs/heads/master: 94cec74096280509083798bfcbd1be169fd43562

trunk/src/rt/rust_log.cpp

+25-17
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,38 @@
66
#include "rust_internal.h"
77
#include "util/array_list.h"
88
#include <stdarg.h>
9+
#include <stdlib.h>
10+
#include <string.h>
11+
#include <alloca.h>
912

1013
static uint32_t
1114
read_type_bit_mask() {
1215
uint32_t bits = rust_log::ULOG | rust_log::ERR;
1316
char *env_str = getenv("RUST_LOG");
1417
if (env_str) {
18+
char *str = (char *)alloca(strlen(env_str) + 2);
19+
str[0] = ',';
20+
strcpy(str + 1, env_str);
21+
1522
bits = 0;
16-
bits |= strstr(env_str, "err") ? rust_log::ERR : 0;
17-
bits |= strstr(env_str, "mem") ? rust_log::MEM : 0;
18-
bits |= strstr(env_str, "comm") ? rust_log::COMM : 0;
19-
bits |= strstr(env_str, "task") ? rust_log::TASK : 0;
20-
bits |= strstr(env_str, "up") ? rust_log::UPCALL : 0;
21-
bits |= strstr(env_str, "dom") ? rust_log::DOM : 0;
22-
bits |= strstr(env_str, "ulog") ? rust_log::ULOG : 0;
23-
bits |= strstr(env_str, "trace") ? rust_log::TRACE : 0;
24-
bits |= strstr(env_str, "dwarf") ? rust_log::DWARF : 0;
25-
bits |= strstr(env_str, "cache") ? rust_log::CACHE : 0;
26-
bits |= strstr(env_str, "timer") ? rust_log::TIMER : 0;
27-
bits |= strstr(env_str, "gc") ? rust_log::GC : 0;
28-
bits |= strstr(env_str, "stdlib") ? rust_log::STDLIB : 0;
29-
bits |= strstr(env_str, "special") ? rust_log::SPECIAL : 0;
30-
bits |= strstr(env_str, "kern") ? rust_log::KERN : 0;
31-
bits |= strstr(env_str, "all") ? rust_log::ALL : 0;
32-
bits = strstr(env_str, "none") ? 0 : bits;
23+
bits |= strstr(str, ",err") ? rust_log::ERR : 0;
24+
bits |= strstr(str, ",mem") ? rust_log::MEM : 0;
25+
bits |= strstr(str, ",comm") ? rust_log::COMM : 0;
26+
bits |= strstr(str, ",task") ? rust_log::TASK : 0;
27+
bits |= strstr(str, ",up") ? rust_log::UPCALL : 0;
28+
bits |= strstr(str, ",dom") ? rust_log::DOM : 0;
29+
bits |= strstr(str, ",ulog") ? rust_log::ULOG : 0;
30+
bits |= strstr(str, ",trace") ? rust_log::TRACE : 0;
31+
bits |= strstr(str, ",dwarf") ? rust_log::DWARF : 0;
32+
bits |= strstr(str, ",cache") ? rust_log::CACHE : 0;
33+
bits |= strstr(str, ",timer") ? rust_log::TIMER : 0;
34+
bits |= strstr(str, ",gc") ? rust_log::GC : 0;
35+
bits |= strstr(str, ",stdlib") ? rust_log::STDLIB : 0;
36+
bits |= strstr(str, ",special") ? rust_log::SPECIAL : 0;
37+
bits |= strstr(str, ",kern") ? rust_log::KERN : 0;
38+
bits |= strstr(str, ",bt") ? rust_log::BT : 0;
39+
bits |= strstr(str, ",all") ? rust_log::ALL : 0;
40+
bits = strstr(str, ",none") ? 0 : bits;
3341
}
3442
return bits;
3543
}

trunk/src/rt/rust_log.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class rust_log {
4242
STDLIB = 0x1000,
4343
SPECIAL = 0x2000,
4444
KERN = 0x4000,
45+
BT = 0x8000,
4546
ALL = 0xffffffff
4647
};
4748

trunk/src/rt/rust_task.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include "valgrind.h"
55
#include "memcheck.h"
66

7+
#ifndef __WIN32__
8+
#include <execinfo.h>
9+
#endif
10+
711
// Stacks
812

913
// FIXME (issue #151): This should be 0x300; the change here is for
@@ -366,6 +370,7 @@ void
366370
rust_task::fail(size_t nargs) {
367371
// See note in ::kill() regarding who should call this.
368372
dom->log(rust_log::TASK, "task %s @0x%" PRIxPTR " failing", name, this);
373+
backtrace();
369374
// Unblock the task so it can unwind.
370375
unblock();
371376
if (this == dom->root_task)
@@ -632,6 +637,18 @@ rust_task::log(uint32_t type_bits, char const *fmt, ...) {
632637
}
633638
}
634639

640+
void
641+
rust_task::backtrace() {
642+
if (!dom->get_log().is_tracing(rust_log::BT))
643+
return;
644+
645+
#ifndef __WIN32__
646+
void *call_stack[256];
647+
int nframes = ::backtrace(call_stack, 256);
648+
backtrace_symbols_fd(call_stack + 1, nframes - 1, 2);
649+
#endif
650+
}
651+
635652
rust_handle<rust_task> *
636653
rust_task::get_handle() {
637654
if (handle == NULL) {

trunk/src/rt/rust_task.h

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ rust_task : public maybe_proxy<rust_task>,
8383

8484
void log(uint32_t type_bits, char const *fmt, ...);
8585

86+
// Print a backtrace, if the "bt" logging option is on.
87+
void backtrace();
88+
8689
// Swap in some glue code to run when we have returned to the
8790
// task's context (assuming we're the active task).
8891
void run_after_return(size_t nargs, uintptr_t glue);

0 commit comments

Comments
 (0)