Overhaul logging system in runtime

See https://github.com/graydon/rust/wiki/Logging-vision

The runtime logging categories are now treated in the same way as
modules in compiled code. Each domain now has a log_lvl that can be
used to restrict the logging from that domain (will be used to allow
logging to be restricted to a single domain).

Features dropped (can be brought back to life if there is interest):
  - Logger indentation
  - Multiple categories per log statement
  - I possibly broke some of the color code -- it confuses me
This commit is contained in:
Marijn Haverbeke
2011-04-19 12:21:57 +02:00
parent 6511d471ba
commit 880be6a940
24 changed files with 463 additions and 637 deletions

View File

@@ -2664,11 +2664,11 @@ let trans_visitor
nabi_rust (upcall_fixup name) args); nabi_rust (upcall_fixup name) args);
and trans_log_int lev (a:Ast.atom) : unit = and trans_log_int lev (a:Ast.atom) : unit =
trans_void_upcall "upcall_log_int" [| simm (Int64.of_int lev); trans_void_upcall "upcall_log_int_rustboot" [| simm (Int64.of_int lev);
trans_atom a |] trans_atom a |]
and trans_log_str lev (a:Ast.atom) : unit = and trans_log_str lev (a:Ast.atom) : unit =
trans_void_upcall "upcall_log_str" [| simm (Int64.of_int lev); trans_void_upcall "upcall_log_str_rustboot" [| simm (Int64.of_int lev);
trans_atom a |] trans_atom a |]
and trans_spawn and trans_spawn

View File

@@ -14,8 +14,7 @@ circular_buffer::circular_buffer(rust_dom *dom, size_t unit_sz) :
A(dom, unit_sz, "Unit size must be larger than zero."); A(dom, unit_sz, "Unit size must be larger than zero.");
DLOG(dom, rust_log::MEM | rust_log::COMM, DLOG(dom, mem, "new circular_buffer(buffer_sz=%d, unread=%d)"
"new circular_buffer(buffer_sz=%d, unread=%d)"
"-> circular_buffer=0x%" PRIxPTR, "-> circular_buffer=0x%" PRIxPTR,
_buffer_sz, _unread, this); _buffer_sz, _unread, this);
@@ -23,7 +22,7 @@ circular_buffer::circular_buffer(rust_dom *dom, size_t unit_sz) :
} }
circular_buffer::~circular_buffer() { circular_buffer::~circular_buffer() {
DLOG(dom, rust_log::MEM, "~circular_buffer 0x%" PRIxPTR, this); DLOG(dom, mem, "~circular_buffer 0x%" PRIxPTR, this);
I(dom, _buffer); I(dom, _buffer);
W(dom, _unread == 0, W(dom, _unread == 0,
"freeing circular_buffer with %d unread bytes", _unread); "freeing circular_buffer with %d unread bytes", _unread);
@@ -79,8 +78,7 @@ circular_buffer::enqueue(void *src) {
grow(); grow();
} }
DLOG(dom, rust_log::MEM | rust_log::COMM, DLOG(dom, mem, "circular_buffer enqueue "
"circular_buffer enqueue "
"unread: %d, next: %d, buffer_sz: %d, unit_sz: %d", "unread: %d, next: %d, buffer_sz: %d, unit_sz: %d",
_unread, _next, _buffer_sz, unit_sz); _unread, _next, _buffer_sz, unit_sz);
@@ -101,8 +99,7 @@ circular_buffer::enqueue(void *src) {
memcpy(&_buffer[dst_idx], src, unit_sz); memcpy(&_buffer[dst_idx], src, unit_sz);
_unread += unit_sz; _unread += unit_sz;
DLOG(dom, rust_log::MEM | rust_log::COMM, DLOG(dom, mem, "circular_buffer pushed data at index: %d", dst_idx);
"circular_buffer pushed data at index: %d", dst_idx);
} }
/** /**
@@ -117,7 +114,7 @@ circular_buffer::dequeue(void *dst) {
I(dom, _unread <= _buffer_sz); I(dom, _unread <= _buffer_sz);
I(dom, _buffer); I(dom, _buffer);
DLOG(dom, rust_log::MEM | rust_log::COMM, DLOG(dom, mem,
"circular_buffer dequeue " "circular_buffer dequeue "
"unread: %d, next: %d, buffer_sz: %d, unit_sz: %d", "unread: %d, next: %d, buffer_sz: %d, unit_sz: %d",
_unread, _next, _buffer_sz, unit_sz); _unread, _next, _buffer_sz, unit_sz);
@@ -126,8 +123,7 @@ circular_buffer::dequeue(void *dst) {
if (dst != NULL) { if (dst != NULL) {
memcpy(dst, &_buffer[_next], unit_sz); memcpy(dst, &_buffer[_next], unit_sz);
} }
DLOG(dom, rust_log::MEM | rust_log::COMM, DLOG(dom, mem, "shifted data from index %d", _next);
"shifted data from index %d", _next);
_unread -= unit_sz; _unread -= unit_sz;
_next += unit_sz; _next += unit_sz;
if (_next == _buffer_sz) { if (_next == _buffer_sz) {
@@ -144,8 +140,7 @@ void
circular_buffer::grow() { circular_buffer::grow() {
size_t new_buffer_sz = _buffer_sz * 2; size_t new_buffer_sz = _buffer_sz * 2;
I(dom, new_buffer_sz <= MAX_CIRCULAR_BUFFER_SIZE); I(dom, new_buffer_sz <= MAX_CIRCULAR_BUFFER_SIZE);
DLOG(dom, rust_log::MEM | rust_log::COMM, DLOG(dom, mem, "circular_buffer is growing to %d bytes", new_buffer_sz);
"circular_buffer is growing to %d bytes", new_buffer_sz);
void *new_buffer = dom->malloc(new_buffer_sz); void *new_buffer = dom->malloc(new_buffer_sz);
transfer(new_buffer); transfer(new_buffer);
dom->free(_buffer); dom->free(_buffer);
@@ -158,8 +153,7 @@ void
circular_buffer::shrink() { circular_buffer::shrink() {
size_t new_buffer_sz = _buffer_sz / 2; size_t new_buffer_sz = _buffer_sz / 2;
I(dom, initial_size() <= new_buffer_sz); I(dom, initial_size() <= new_buffer_sz);
DLOG(dom, rust_log::MEM | rust_log::COMM, DLOG(dom, mem, "circular_buffer is shrinking to %d bytes", new_buffer_sz);
"circular_buffer is shrinking to %d bytes", new_buffer_sz);
void *new_buffer = dom->malloc(new_buffer_sz); void *new_buffer = dom->malloc(new_buffer_sz);
transfer(new_buffer); transfer(new_buffer);
dom->free(_buffer); dom->free(_buffer);

View File

@@ -82,6 +82,8 @@ rust_start(uintptr_t main_fn, rust_crate const *crate, int argc,
if (crate->abi_tag != ABI_X86_RUSTBOOT_CDECL) if (crate->abi_tag != ABI_X86_RUSTBOOT_CDECL)
update_log_settings(crate_map, getenv("RUST_LOG")); update_log_settings(crate_map, getenv("RUST_LOG"));
else
update_log_settings(NULL, getenv("RUST_LOG"));
rust_srv *srv = new rust_srv(); rust_srv *srv = new rust_srv();
rust_kernel *kernel = new rust_kernel(srv); rust_kernel *kernel = new rust_kernel(srv);
kernel->start(); kernel->start();
@@ -89,14 +91,13 @@ rust_start(uintptr_t main_fn, rust_crate const *crate, int argc,
rust_dom *dom = handle->referent(); rust_dom *dom = handle->referent();
command_line_args *args = new (dom) command_line_args(dom, argc, argv); command_line_args *args = new (dom) command_line_args(dom, argc, argv);
DLOG(dom, rust_log::DOM, "startup: %d args in 0x%" PRIxPTR, DLOG(dom, dom, "startup: %d args in 0x%" PRIxPTR,
args->argc, (uintptr_t)args->args); args->argc, (uintptr_t)args->args);
for (int i = 0; i < args->argc; i++) { for (int i = 0; i < args->argc; i++) {
DLOG(dom, rust_log::DOM, DLOG(dom, dom, "startup: arg[%d] = '%s'", i, args->argv[i]);
"startup: arg[%d] = '%s'", i, args->argv[i]);
} }
if (dom->_log.is_tracing(rust_log::DWARF)) { if (log_rt_dwarf) {
rust_crate_reader create_reader(dom, crate); rust_crate_reader create_reader(dom, crate);
} }

View File

@@ -6,7 +6,7 @@
extern "C" CDECL rust_str* extern "C" CDECL rust_str*
last_os_error(rust_task *task) { last_os_error(rust_task *task) {
rust_dom *dom = task->dom; rust_dom *dom = task->dom;
LOG(task, rust_log::TASK, "last_os_error()"); LOG(task, task, "last_os_error()");
#if defined(__WIN32__) #if defined(__WIN32__)
LPTSTR buf; LPTSTR buf;
@@ -91,8 +91,7 @@ extern "C" CDECL rust_vec*
vec_alloc(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts) vec_alloc(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
{ {
rust_dom *dom = task->dom; rust_dom *dom = task->dom;
LOG(task, rust_log::MEM | rust_log::STDLIB, LOG(task, mem, "vec_alloc %" PRIdPTR " elements of size %" PRIdPTR,
"vec_alloc %" PRIdPTR " elements of size %" PRIdPTR,
n_elts, elem_t->size); n_elts, elem_t->size);
size_t fill = n_elts * elem_t->size; size_t fill = n_elts * elem_t->size;
size_t alloc = next_power_of_two(sizeof(rust_vec) + fill); size_t alloc = next_power_of_two(sizeof(rust_vec) + fill);
@@ -126,8 +125,7 @@ vec_len(rust_task *task, type_desc *ty, rust_vec *v)
extern "C" CDECL void extern "C" CDECL void
vec_len_set(rust_task *task, type_desc *ty, rust_vec *v, size_t len) vec_len_set(rust_task *task, type_desc *ty, rust_vec *v, size_t len)
{ {
LOG(task, rust_log::STDLIB, LOG(task, stdlib, "vec_len_set(0x%" PRIxPTR ", %" PRIdPTR ") on vec with "
"vec_len_set(0x%" PRIxPTR ", %" PRIdPTR ") on vec with "
"alloc = %" PRIdPTR "alloc = %" PRIdPTR
", fill = %" PRIdPTR ", fill = %" PRIdPTR
", len = %" PRIdPTR ", len = %" PRIdPTR
@@ -139,7 +137,7 @@ vec_len_set(rust_task *task, type_desc *ty, rust_vec *v, size_t len)
extern "C" CDECL void extern "C" CDECL void
vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v) vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v)
{ {
LOG(task, rust_log::STDLIB, LOG(task, stdlib,
"vec_print_debug_info(0x%" PRIxPTR ")" "vec_print_debug_info(0x%" PRIxPTR ")"
" with tydesc 0x%" PRIxPTR " with tydesc 0x%" PRIxPTR
" (size = %" PRIdPTR ", align = %" PRIdPTR ")" " (size = %" PRIdPTR ", align = %" PRIdPTR ")"
@@ -154,9 +152,7 @@ vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v)
v->fill / ty->size); v->fill / ty->size);
for (size_t i = 0; i < v->fill; ++i) { for (size_t i = 0; i < v->fill; ++i) {
LOG(task, rust_log::STDLIB, LOG(task, stdlib, " %" PRIdPTR ": 0x%" PRIxPTR, i, v->data[i]);
" %" PRIdPTR ": 0x%" PRIxPTR,
i, v->data[i]);
} }
} }
@@ -306,8 +302,7 @@ task_sleep(rust_task *task, size_t time_in_us) {
static void static void
debug_tydesc_helper(rust_task *task, type_desc *t) debug_tydesc_helper(rust_task *task, type_desc *t)
{ {
LOG(task, rust_log::STDLIB, LOG(task, stdlib, " size %" PRIdPTR ", align %" PRIdPTR
" size %" PRIdPTR ", align %" PRIdPTR
", stateful %" PRIdPTR ", first_param 0x%" PRIxPTR, ", stateful %" PRIdPTR ", first_param 0x%" PRIxPTR,
t->size, t->align, t->is_stateful, t->first_param); t->size, t->align, t->is_stateful, t->first_param);
} }
@@ -315,20 +310,19 @@ debug_tydesc_helper(rust_task *task, type_desc *t)
extern "C" CDECL void extern "C" CDECL void
debug_tydesc(rust_task *task, type_desc *t) debug_tydesc(rust_task *task, type_desc *t)
{ {
LOG(task, rust_log::STDLIB, "debug_tydesc"); LOG(task, stdlib, "debug_tydesc");
debug_tydesc_helper(task, t); debug_tydesc_helper(task, t);
} }
extern "C" CDECL void extern "C" CDECL void
debug_opaque(rust_task *task, type_desc *t, uint8_t *front) debug_opaque(rust_task *task, type_desc *t, uint8_t *front)
{ {
LOG(task, rust_log::STDLIB, "debug_opaque"); LOG(task, stdlib, "debug_opaque");
debug_tydesc_helper(task, t); debug_tydesc_helper(task, t);
// FIXME may want to actually account for alignment. `front` may not // FIXME may want to actually account for alignment. `front` may not
// indeed be the front byte of the passed-in argument. // indeed be the front byte of the passed-in argument.
for (uintptr_t i = 0; i < t->size; ++front, ++i) { for (uintptr_t i = 0; i < t->size; ++front, ++i) {
LOG(task, rust_log::STDLIB, LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, *front);
" byte %" PRIdPTR ": 0x%" PRIx8, i, *front);
} }
} }
@@ -340,15 +334,14 @@ struct rust_box : rc_base<rust_box> {
extern "C" CDECL void extern "C" CDECL void
debug_box(rust_task *task, type_desc *t, rust_box *box) debug_box(rust_task *task, type_desc *t, rust_box *box)
{ {
LOG(task, rust_log::STDLIB, "debug_box(0x%" PRIxPTR ")", box); LOG(task, stdlib, "debug_box(0x%" PRIxPTR ")", box);
debug_tydesc_helper(task, t); debug_tydesc_helper(task, t);
LOG(task, rust_log::STDLIB, " refcount %" PRIdPTR, LOG(task, stdlib, " refcount %" PRIdPTR,
box->ref_count == CONST_REFCOUNT box->ref_count == CONST_REFCOUNT
? CONST_REFCOUNT ? CONST_REFCOUNT
: box->ref_count - 1); // -1 because we ref'ed for this call : box->ref_count - 1); // -1 because we ref'ed for this call
for (uintptr_t i = 0; i < t->size; ++i) { for (uintptr_t i = 0; i < t->size; ++i) {
LOG(task, rust_log::STDLIB, LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, box->data[i]);
" byte %" PRIdPTR ": 0x%" PRIx8, i, box->data[i]);
} }
} }
@@ -360,14 +353,13 @@ struct rust_tag {
extern "C" CDECL void extern "C" CDECL void
debug_tag(rust_task *task, type_desc *t, rust_tag *tag) debug_tag(rust_task *task, type_desc *t, rust_tag *tag)
{ {
LOG(task, rust_log::STDLIB, "debug_tag"); LOG(task, stdlib, "debug_tag");
debug_tydesc_helper(task, t); debug_tydesc_helper(task, t);
LOG(task, rust_log::STDLIB, LOG(task, stdlib, " discriminant %" PRIdPTR, tag->discriminant);
" discriminant %" PRIdPTR, tag->discriminant);
for (uintptr_t i = 0; i < t->size - sizeof(tag->discriminant); ++i) for (uintptr_t i = 0; i < t->size - sizeof(tag->discriminant); ++i)
LOG(task, rust_log::STDLIB, LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i,
" byte %" PRIdPTR ": 0x%" PRIx8, i, tag->variant[i]); tag->variant[i]);
} }
struct rust_obj { struct rust_obj {
@@ -379,18 +371,16 @@ extern "C" CDECL void
debug_obj(rust_task *task, type_desc *t, rust_obj *obj, debug_obj(rust_task *task, type_desc *t, rust_obj *obj,
size_t nmethods, size_t nbytes) size_t nmethods, size_t nbytes)
{ {
LOG(task, rust_log::STDLIB, LOG(task, stdlib, "debug_obj with %" PRIdPTR " methods", nmethods);
"debug_obj with %" PRIdPTR " methods", nmethods);
debug_tydesc_helper(task, t); debug_tydesc_helper(task, t);
LOG(task, rust_log::STDLIB, " vtbl at 0x%" PRIxPTR, obj->vtbl); LOG(task, stdlib, " vtbl at 0x%" PRIxPTR, obj->vtbl);
LOG(task, rust_log::STDLIB, " body at 0x%" PRIxPTR, obj->body); LOG(task, stdlib, " body at 0x%" PRIxPTR, obj->body);
for (uintptr_t *p = obj->vtbl; p < obj->vtbl + nmethods; ++p) for (uintptr_t *p = obj->vtbl; p < obj->vtbl + nmethods; ++p)
LOG(task, rust_log::STDLIB, " vtbl word: 0x%" PRIxPTR, *p); LOG(task, stdlib, " vtbl word: 0x%" PRIxPTR, *p);
for (uintptr_t i = 0; i < nbytes; ++i) for (uintptr_t i = 0; i < nbytes; ++i)
LOG(task, rust_log::STDLIB, LOG(task, stdlib, " body byte %" PRIdPTR ": 0x%" PRIxPTR,
" body byte %" PRIdPTR ": 0x%" PRIxPTR,
i, obj->body->data[i]); i, obj->body->data[i]);
} }
@@ -402,13 +392,12 @@ struct rust_fn {
extern "C" CDECL void extern "C" CDECL void
debug_fn(rust_task *task, type_desc *t, rust_fn *fn) debug_fn(rust_task *task, type_desc *t, rust_fn *fn)
{ {
LOG(task, rust_log::STDLIB, "debug_fn"); LOG(task, stdlib, "debug_fn");
debug_tydesc_helper(task, t); debug_tydesc_helper(task, t);
LOG(task, rust_log::STDLIB, " thunk at 0x%" PRIxPTR, fn->thunk); LOG(task, stdlib, " thunk at 0x%" PRIxPTR, fn->thunk);
LOG(task, rust_log::STDLIB, " closure at 0x%" PRIxPTR, fn->closure); LOG(task, stdlib, " closure at 0x%" PRIxPTR, fn->closure);
if (fn->closure) { if (fn->closure) {
LOG(task, rust_log::STDLIB, " refcount %" PRIdPTR, LOG(task, stdlib, " refcount %" PRIdPTR, fn->closure->ref_count);
fn->closure->ref_count);
} }
} }
@@ -418,9 +407,9 @@ debug_ptrcast(rust_task *task,
type_desc *to_ty, type_desc *to_ty,
void *ptr) void *ptr)
{ {
LOG(task, rust_log::STDLIB, "debug_ptrcast from"); LOG(task, stdlib, "debug_ptrcast from");
debug_tydesc_helper(task, from_ty); debug_tydesc_helper(task, from_ty);
LOG(task, rust_log::STDLIB, "to"); LOG(task, stdlib, "to");
debug_tydesc_helper(task, to_ty); debug_tydesc_helper(task, to_ty);
return ptr; return ptr;
} }
@@ -428,7 +417,7 @@ debug_ptrcast(rust_task *task,
extern "C" CDECL void extern "C" CDECL void
debug_trap(rust_task *task, rust_str *s) debug_trap(rust_task *task, rust_str *s)
{ {
LOG(task, rust_log::STDLIB, "trapping: %s", s->data); LOG(task, stdlib, "trapping: %s", s->data);
// FIXME: x86-ism. // FIXME: x86-ism.
__asm__("int3"); __asm__("int3");
} }

View File

@@ -13,15 +13,13 @@ rust_chan::rust_chan(rust_task *task,
if (port) { if (port) {
associate(port); associate(port);
} }
LOG(task, rust_log::MEM | rust_log::COMM, LOG(task, comm, "new rust_chan(task=0x%" PRIxPTR
"new rust_chan(task=0x%" PRIxPTR
", port=0x%" PRIxPTR ") -> chan=0x%" PRIxPTR, ", port=0x%" PRIxPTR ") -> chan=0x%" PRIxPTR,
(uintptr_t) task, (uintptr_t) port, (uintptr_t) this); (uintptr_t) task, (uintptr_t) port, (uintptr_t) this);
} }
rust_chan::~rust_chan() { rust_chan::~rust_chan() {
LOG(task, rust_log::MEM | rust_log::COMM, LOG(task, comm, "del rust_chan(task=0x%" PRIxPTR ")", (uintptr_t) this);
"del rust_chan(task=0x%" PRIxPTR ")", (uintptr_t) this);
A(task->dom, is_associated() == false, A(task->dom, is_associated() == false,
"Channel must be disassociated before being freed."); "Channel must be disassociated before being freed.");
@@ -33,7 +31,7 @@ rust_chan::~rust_chan() {
void rust_chan::associate(maybe_proxy<rust_port> *port) { void rust_chan::associate(maybe_proxy<rust_port> *port) {
this->port = port; this->port = port;
if (port->is_proxy() == false) { if (port->is_proxy() == false) {
LOG(task, rust_log::TASK, LOG(task, task,
"associating chan: 0x%" PRIxPTR " with port: 0x%" PRIxPTR, "associating chan: 0x%" PRIxPTR " with port: 0x%" PRIxPTR,
this, port); this, port);
this->port->referent()->chans.push(this); this->port->referent()->chans.push(this);
@@ -51,7 +49,7 @@ void rust_chan::disassociate() {
A(task->dom, is_associated(), "Channel must be associated with a port."); A(task->dom, is_associated(), "Channel must be associated with a port.");
if (port->is_proxy() == false) { if (port->is_proxy() == false) {
LOG(task, rust_log::TASK, LOG(task, task,
"disassociating chan: 0x%" PRIxPTR " from port: 0x%" PRIxPTR, "disassociating chan: 0x%" PRIxPTR " from port: 0x%" PRIxPTR,
this, port->referent()); this, port->referent());
port->referent()->chans.swap_delete(this); port->referent()->chans.swap_delete(this);
@@ -84,7 +82,7 @@ void rust_chan::send(void *sptr) {
} else { } else {
rust_port *target_port = port->referent(); rust_port *target_port = port->referent();
if (target_port->task->blocked_on(target_port)) { if (target_port->task->blocked_on(target_port)) {
DLOG(dom, rust_log::COMM, "dequeued in rendezvous_ptr"); DLOG(dom, comm, "dequeued in rendezvous_ptr");
buffer.dequeue(target_port->task->rendezvous_ptr); buffer.dequeue(target_port->task->rendezvous_ptr);
target_port->task->rendezvous_ptr = 0; target_port->task->rendezvous_ptr = 0;
target_port->task->wakeup(target_port); target_port->task->wakeup(target_port);

View File

@@ -41,7 +41,7 @@ rust_crate::mem_area::mem_area(rust_dom *dom, uintptr_t pos, size_t sz)
base(pos), base(pos),
lim(pos + sz) lim(pos + sz)
{ {
DLOG(dom, rust_log::MEM, "new mem_area [0x%" PRIxPTR ",0x%" PRIxPTR "]", DLOG(dom, mem, "new mem_area [0x%" PRIxPTR ",0x%" PRIxPTR "]",
base, lim); base, lim);
} }

View File

@@ -10,12 +10,12 @@ rust_crate_cache::lib::lib(rust_dom *dom, char const *name)
#else #else
handle = (uintptr_t)dlopen(name, RTLD_GLOBAL|RTLD_LAZY); handle = (uintptr_t)dlopen(name, RTLD_GLOBAL|RTLD_LAZY);
#endif #endif
DLOG(dom, rust_log::CACHE, "loaded library '%s' as 0x%" PRIxPTR, DLOG(dom, cache, "loaded library '%s' as 0x%" PRIxPTR,
name, handle); name, handle);
} }
rust_crate_cache::lib::~lib() { rust_crate_cache::lib::~lib() {
DLOG(dom, rust_log::CACHE, "~rust_crate_cache::lib(0x%" PRIxPTR ")", DLOG(dom, cache, "~rust_crate_cache::lib(0x%" PRIxPTR ")",
handle); handle);
if (handle) { if (handle) {
#if defined(__WIN32__) #if defined(__WIN32__)
@@ -46,17 +46,15 @@ rust_crate_cache::c_sym::c_sym(rust_dom *dom, lib *library, char const *name)
#else #else
val = (uintptr_t)dlsym((void*)handle, name); val = (uintptr_t)dlsym((void*)handle, name);
#endif #endif
DLOG(dom, rust_log::CACHE, "resolved symbol '%s' to 0x%" PRIxPTR, DLOG(dom, cache, "resolved symbol '%s' to 0x%" PRIxPTR,
name, val); name, val);
} else { } else {
DLOG(dom, rust_log::CACHE | rust_log::ERR, DLOG_ERR(dom, cache, "unresolved symbol '%s', null lib handle", name);
"unresolved symbol '%s', null lib handle",
name);
} }
} }
rust_crate_cache::c_sym::~c_sym() { rust_crate_cache::c_sym::~c_sym() {
DLOG(dom, rust_log::CACHE, DLOG(dom, cache,
"~rust_crate_cache::c_sym(0x%" PRIxPTR ")", val); "~rust_crate_cache::c_sym(0x%" PRIxPTR ")", val);
library->deref(); library->deref();
} }
@@ -80,8 +78,7 @@ rust_crate_cache::rust_sym::rust_sym(rust_dom *dom,
typedef rust_crate_reader::die die; typedef rust_crate_reader::die die;
rust_crate const *crate = (rust_crate*)crate_sym->get_val(); rust_crate const *crate = (rust_crate*)crate_sym->get_val();
if (!crate) { if (!crate) {
DLOG(dom, rust_log::CACHE | rust_log::ERR, DLOG_ERR(dom, cache, "failed to resolve symbol, null crate symbol");
"failed to resolve symbol, null crate symbol");
return; return;
} }
rust_crate_reader rdr(dom, crate); rust_crate_reader rdr(dom, crate);
@@ -98,16 +95,13 @@ rust_crate_cache::rust_sym::rust_sym(rust_dom *dom,
&& !t1.is_null() && !t1.is_null()
&& t1.find_child_by_name(crate_rel(curr_crate, *c), t2)); && t1.find_child_by_name(crate_rel(curr_crate, *c), t2));
++c, t1=t2) { ++c, t1=t2) {
DLOG(dom, rust_log::DWARF|rust_log::CACHE, DLOG(dom, dwarf, "matched die <0x%" PRIxPTR
"matched die <0x%" PRIxPTR
">, child '%s' = die<0x%" PRIxPTR ">", ">, child '%s' = die<0x%" PRIxPTR ">",
t1.off, crate_rel(curr_crate, *c), t2.off); t1.off, crate_rel(curr_crate, *c), t2.off);
found_root = found_root || true; found_root = found_root || true;
if (!*(c+1) && t2.find_num_attr(DW_AT_low_pc, val)) { if (!*(c+1) && t2.find_num_attr(DW_AT_low_pc, val)) {
DLOG(dom, rust_log::DWARF|rust_log::CACHE, DLOG(dom, dwarf, "found relative address: 0x%" PRIxPTR, val);
"found relative address: 0x%" PRIxPTR, val); DLOG(dom, dwarf, "plus image-base 0x%" PRIxPTR,
DLOG(dom, rust_log::DWARF|rust_log::CACHE,
"plus image-base 0x%" PRIxPTR,
crate->get_image_base()); crate->get_image_base());
val += crate->get_image_base(); val += crate->get_image_base();
found_leaf = true; found_leaf = true;
@@ -118,15 +112,14 @@ rust_crate_cache::rust_sym::rust_sym(rust_dom *dom,
break; break;
} }
if (found_leaf) { if (found_leaf) {
DLOG(dom, rust_log::CACHE, "resolved symbol to 0x%" PRIxPTR, val); DLOG(dom, cache, "resolved symbol to 0x%" PRIxPTR, val);
} else { } else {
DLOG(dom, rust_log::CACHE | rust_log::ERR, DLOG_ERR(dom, cache, "failed to resolve symbol");
"failed to resolve symbol");
} }
} }
rust_crate_cache::rust_sym::~rust_sym() { rust_crate_cache::rust_sym::~rust_sym() {
DLOG(dom, rust_log::CACHE, DLOG(dom, cache,
"~rust_crate_cache::rust_sym(0x%" PRIxPTR ")", val); "~rust_crate_cache::rust_sym(0x%" PRIxPTR ")", val);
crate_sym->deref(); crate_sym->deref();
} }
@@ -155,7 +148,7 @@ rust_crate_cache::get_c_sym(size_t n, lib *library, char const *name)
{ {
I(dom, n < crate->n_c_syms); I(dom, n < crate->n_c_syms);
c_sym *sym = c_syms[n]; c_sym *sym = c_syms[n];
DLOG(dom, rust_log::CACHE, "cached C symbol %s = 0x%" PRIxPTR, name, sym); DLOG(dom, cache, "cached C symbol %s = 0x%" PRIxPTR, name, sym);
if (!sym) { if (!sym) {
sym = new (dom) c_sym(dom, library, name); sym = new (dom) c_sym(dom, library, name);
c_syms[n] = sym; c_syms[n] = sym;
@@ -199,10 +192,10 @@ rust_crate_cache::get_type_desc(size_t size,
size_t keysz = n_descs * sizeof(type_desc*); size_t keysz = n_descs * sizeof(type_desc*);
HASH_FIND(hh, this->type_descs, descs, keysz, td); HASH_FIND(hh, this->type_descs, descs, keysz, td);
if (td) { if (td) {
DLOG(dom, rust_log::CACHE, "rust_crate_cache::get_type_desc hit"); DLOG(dom, cache, "rust_crate_cache::get_type_desc hit");
return td; return td;
} }
DLOG(dom, rust_log::CACHE, "rust_crate_cache::get_type_desc miss"); DLOG(dom, cache, "rust_crate_cache::get_type_desc miss");
td = (type_desc*) dom->malloc(sizeof(type_desc) + keysz); td = (type_desc*) dom->malloc(sizeof(type_desc) + keysz);
if (!td) if (!td)
return NULL; return NULL;
@@ -214,7 +207,7 @@ rust_crate_cache::get_type_desc(size_t size,
td->size = size; td->size = size;
td->align = align; td->align = align;
for (size_t i = 0; i < n_descs; ++i) { for (size_t i = 0; i < n_descs; ++i) {
DLOG(dom, rust_log::CACHE, DLOG(dom, cache,
"rust_crate_cache::descs[%" PRIdPTR "] = 0x%" PRIxPTR, "rust_crate_cache::descs[%" PRIdPTR "] = 0x%" PRIxPTR,
i, descs[i]); i, descs[i]);
td->descs[i] = descs[i]; td->descs[i] = descs[i];
@@ -251,11 +244,11 @@ rust_crate_cache::rust_crate_cache(rust_dom *dom,
void void
rust_crate_cache::flush() { rust_crate_cache::flush() {
DLOG(dom, rust_log::CACHE, "rust_crate_cache::flush()"); DLOG(dom, cache, "rust_crate_cache::flush()");
for (size_t i = 0; i < crate->n_rust_syms; ++i) { for (size_t i = 0; i < crate->n_rust_syms; ++i) {
rust_sym *s = rust_syms[i]; rust_sym *s = rust_syms[i];
if (s) { if (s) {
DLOG(dom, rust_log::CACHE, DLOG(dom, cache,
"rust_crate_cache::flush() deref rust_sym %" "rust_crate_cache::flush() deref rust_sym %"
PRIdPTR " (rc=%" PRIdPTR ")", i, s->ref_count); PRIdPTR " (rc=%" PRIdPTR ")", i, s->ref_count);
s->deref(); s->deref();
@@ -266,7 +259,7 @@ rust_crate_cache::flush() {
for (size_t i = 0; i < crate->n_c_syms; ++i) { for (size_t i = 0; i < crate->n_c_syms; ++i) {
c_sym *s = c_syms[i]; c_sym *s = c_syms[i];
if (s) { if (s) {
DLOG(dom, rust_log::CACHE, DLOG(dom, cache,
"rust_crate_cache::flush() deref c_sym %" "rust_crate_cache::flush() deref c_sym %"
PRIdPTR " (rc=%" PRIdPTR ")", i, s->ref_count); PRIdPTR " (rc=%" PRIdPTR ")", i, s->ref_count);
s->deref(); s->deref();
@@ -277,7 +270,7 @@ rust_crate_cache::flush() {
for (size_t i = 0; i < crate->n_libs; ++i) { for (size_t i = 0; i < crate->n_libs; ++i) {
lib *l = libs[i]; lib *l = libs[i];
if (l) { if (l) {
DLOG(dom, rust_log::CACHE, "rust_crate_cache::flush() deref lib %" DLOG(dom, cache, "rust_crate_cache::flush() deref lib %"
PRIdPTR " (rc=%" PRIdPTR ")", i, l->ref_count); PRIdPTR " (rc=%" PRIdPTR ")", i, l->ref_count);
l->deref(); l->deref();
} }
@@ -287,8 +280,7 @@ rust_crate_cache::flush() {
while (type_descs) { while (type_descs) {
type_desc *d = type_descs; type_desc *d = type_descs;
HASH_DEL(type_descs, d); HASH_DEL(type_descs, d);
DLOG(dom, rust_log::MEM, DLOG(dom, mem, "rust_crate_cache::flush() tydesc %" PRIxPTR, d);
"rust_crate_cache::flush() tydesc %" PRIxPTR, d);
dom->free(d); dom->free(d);
} }
} }

View File

@@ -92,7 +92,7 @@ rust_crate_reader::mem_reader::adv(size_t amt)
ok = false; ok = false;
if (!ok) if (!ok)
return; return;
// mem.DLOG(dom, rust_log::MEM, "adv %d bytes", amt); // mem.DLOG(dom, mem, "adv %d bytes", amt);
pos += amt; pos += amt;
ok &= !at_end(); ok &= !at_end();
I(mem.dom, at_end() || (mem.base <= pos && pos < mem.lim)); I(mem.dom, at_end() || (mem.base <= pos && pos < mem.lim));
@@ -120,7 +120,7 @@ rust_crate_reader::abbrev_reader::abbrev_reader
rust_dom *dom = mem.dom; rust_dom *dom = mem.dom;
while (is_ok() && !at_end()) { while (is_ok() && !at_end()) {
// DLOG(dom, rust_log::DWARF, "reading new abbrev at 0x%" PRIxPTR, // DLOG(dom, dwarf, "reading new abbrev at 0x%" PRIxPTR,
// tell_off()); // tell_off());
uintptr_t idx, tag; uintptr_t idx, tag;
@@ -133,13 +133,13 @@ rust_crate_reader::abbrev_reader::abbrev_reader
size_t body_off = tell_off(); size_t body_off = tell_off();
while (is_ok() && step_attr_form_pair(attr, form)); while (is_ok() && step_attr_form_pair(attr, form));
// DLOG(dom, rust_log::DWARF, // DLOG(dom, dwarf,
// "finished scanning attr/form pairs, pos=0x%" // "finished scanning attr/form pairs, pos=0x%"
// PRIxPTR ", lim=0x%" PRIxPTR ", is_ok=%d, at_end=%d", // PRIxPTR ", lim=0x%" PRIxPTR ", is_ok=%d, at_end=%d",
// pos, mem.lim, is_ok(), at_end()); // pos, mem.lim, is_ok(), at_end());
if (is_ok() || at_end()) { if (is_ok() || at_end()) {
DLOG(dom, rust_log::DWARF, "read abbrev: %" PRIdPTR, idx); DLOG(dom, dwarf, "read abbrev: %" PRIdPTR, idx);
I(dom, idx = abbrevs.length() + 1); I(dom, idx = abbrevs.length() + 1);
abbrevs.push(new (dom) abbrev(dom, body_off, abbrevs.push(new (dom) abbrev(dom, body_off,
tell_off() - body_off, tell_off() - body_off,
@@ -162,11 +162,11 @@ rust_crate_reader::abbrev_reader::step_attr_form_pair(uintptr_t &attr,
{ {
attr = 0; attr = 0;
form = 0; form = 0;
// mem.DLOG(dom, rust_log::DWARF, "reading attr/form pair at 0x%" PRIxPTR, // mem.DLOG(dom, dwarf, "reading attr/form pair at 0x%" PRIxPTR,
// tell_off()); // tell_off());
get_uleb(attr); get_uleb(attr);
get_uleb(form); get_uleb(form);
// mem.DLOG(dom, rust_log::DWARF, "attr 0x%" PRIxPTR ", form 0x%" PRIxPTR, // mem.DLOG(dom, dwarf, "attr 0x%" PRIxPTR ", form 0x%" PRIxPTR,
// attr, form); // attr, form);
return ! (attr == 0 && form == 0); return ! (attr == 0 && form == 0);
} }
@@ -254,19 +254,17 @@ rust_crate_reader::die::die(die_reader *rdr, uintptr_t off)
rdr->get_uleb(ab_idx); rdr->get_uleb(ab_idx);
if (!ab_idx) { if (!ab_idx) {
ab = NULL; ab = NULL;
DLOG(dom, rust_log::DWARF, "DIE <0x%" PRIxPTR "> (null)", off); DLOG(dom, dwarf, "DIE <0x%" PRIxPTR "> (null)", off);
if (dom->get_log().is_tracing(rust_log::DWARF))
dom->get_log().outdent();
} else { } else {
ab = rdr->abbrevs.get_abbrev(ab_idx); ab = rdr->abbrevs.get_abbrev(ab_idx);
if (!ab) { if (!ab) {
DLOG(dom, rust_log::DWARF, " bad abbrev number: 0x%" DLOG(dom, dwarf, " bad abbrev number: 0x%"
PRIxPTR, ab_idx); PRIxPTR, ab_idx);
rdr->fail(); rdr->fail();
} else { } else {
DLOG(dom, rust_log::DWARF, "DIE <0x%" PRIxPTR "> abbrev 0x%" DLOG(dom, dwarf, "DIE <0x%" PRIxPTR "> abbrev 0x%"
PRIxPTR, off, ab_idx); PRIxPTR, off, ab_idx);
DLOG(dom, rust_log::DWARF, " tag 0x%x, has children: %d", DLOG(dom, dwarf, " tag 0x%x, has children: %d",
ab->tag, ab->has_children); ab->tag, ab->has_children);
} }
} }
@@ -354,7 +352,7 @@ rust_crate_reader::die::step_attr(attr &a) const
break; break;
default: default:
DLOG(rdr->mem.dom, rust_log::DWARF, " unknown dwarf form: 0x%" DLOG(rdr->mem.dom, dwarf, " unknown dwarf form: 0x%"
PRIxPTR, a.form); PRIxPTR, a.form);
rdr->fail(); rdr->fail();
break; break;
@@ -474,17 +472,15 @@ rust_crate_reader::die::next() const
while (step_attr(a)) { while (step_attr(a)) {
I(dom, !(a.is_numeric() && a.is_string())); I(dom, !(a.is_numeric() && a.is_string()));
if (a.is_numeric()) if (a.is_numeric())
DLOG(dom, rust_log::DWARF, " attr num: 0x%" DLOG(dom, dwarf, " attr num: 0x%"
PRIxPTR, a.get_num(dom)); PRIxPTR, a.get_num(dom));
else if (a.is_string()) else if (a.is_string())
DLOG(dom, rust_log::DWARF, " attr str: %s", DLOG(dom, dwarf, " attr str: %s",
a.get_str(dom)); a.get_str(dom));
else else
DLOG(dom, rust_log::DWARF, " attr ??:"); DLOG(dom, dwarf, " attr ??:");
} }
} }
if (has_children() && dom->get_log().is_tracing(rust_log::DWARF))
dom->get_log().indent();
} }
return die(rdr, rdr->tell_off()); return die(rdr, rdr->tell_off());
} }
@@ -494,12 +490,12 @@ rust_crate_reader::die::next_sibling() const
{ {
// FIXME: use DW_AT_sibling, when present. // FIXME: use DW_AT_sibling, when present.
if (has_children()) { if (has_children()) {
// DLOG(rdr->mem.dom, rust_log::DWARF, "+++ children of die 0x%" // DLOG(rdr->mem.dom, dwarf, "+++ children of die 0x%"
// PRIxPTR, off); // PRIxPTR, off);
die child = next(); die child = next();
while (!child.is_null()) while (!child.is_null())
child = child.next_sibling(); child = child.next_sibling();
// DLOG(rdr->mem.dom, rust_log::DWARF, "--- children of die 0x%" // DLOG(rdr->mem.dom, dwarf, "--- children of die 0x%"
// PRIxPTR, off); // PRIxPTR, off);
return child.next(); return child.next();
} else { } else {
@@ -554,16 +550,16 @@ rust_crate_reader::die_reader::die_reader(rust_crate::mem_area &die_mem,
get(sizeof_addr); get(sizeof_addr);
if (is_ok()) { if (is_ok()) {
DLOG(dom, rust_log::DWARF, "new root CU at 0x%" PRIxPTR, die_mem.base); DLOG(dom, dwarf, "new root CU at 0x%" PRIxPTR, die_mem.base);
DLOG(dom, rust_log::DWARF, "CU unit length: %" PRId32, cu_unit_length); DLOG(dom, dwarf, "CU unit length: %" PRId32, cu_unit_length);
DLOG(dom, rust_log::DWARF, "dwarf version: %" PRId16, dwarf_vers); DLOG(dom, dwarf, "dwarf version: %" PRId16, dwarf_vers);
DLOG(dom, rust_log::DWARF, "CU abbrev off: %" PRId32, cu_abbrev_off); DLOG(dom, dwarf, "CU abbrev off: %" PRId32, cu_abbrev_off);
DLOG(dom, rust_log::DWARF, "size of address: %" PRId8, sizeof_addr); DLOG(dom, dwarf, "size of address: %" PRId8, sizeof_addr);
I(dom, sizeof_addr == sizeof(uintptr_t)); I(dom, sizeof_addr == sizeof(uintptr_t));
I(dom, dwarf_vers >= 2); I(dom, dwarf_vers >= 2);
I(dom, cu_base + cu_unit_length == die_mem.lim - die_mem.base); I(dom, cu_base + cu_unit_length == die_mem.lim - die_mem.base);
} else { } else {
DLOG(dom, rust_log::DWARF, "failed to read root CU header"); DLOG(dom, dwarf, "failed to read root CU header");
} }
} }
@@ -580,9 +576,9 @@ rust_crate_reader::rust_crate_reader(rust_dom *dom,
die_mem(crate->get_debug_info(dom)), die_mem(crate->get_debug_info(dom)),
dies(die_mem, abbrevs) dies(die_mem, abbrevs)
{ {
DLOG(dom, rust_log::MEM, "crate_reader on crate: 0x%" PRIxPTR, this); DLOG(dom, mem, "crate_reader on crate: 0x%" PRIxPTR, this);
DLOG(dom, rust_log::MEM, "debug_abbrev: 0x%" PRIxPTR, abbrev_mem.base); DLOG(dom, mem, "debug_abbrev: 0x%" PRIxPTR, abbrev_mem.base);
DLOG(dom, rust_log::MEM, "debug_info: 0x%" PRIxPTR, die_mem.base); DLOG(dom, mem, "debug_info: 0x%" PRIxPTR, die_mem.base);
// For now, perform diagnostics only. // For now, perform diagnostics only.
dies.dump(); dies.dump();
} }

View File

@@ -8,6 +8,7 @@ rust_dom::rust_dom(rust_kernel *kernel,
interrupt_flag(0), interrupt_flag(0),
root_crate(root_crate), root_crate(root_crate),
_log(srv, this), _log(srv, this),
log_lvl(log_note),
srv(srv), srv(srv),
local_region(&srv->local_region), local_region(&srv->local_region),
synchronized_region(&srv->synchronized_region), synchronized_region(&srv->synchronized_region),
@@ -34,8 +35,7 @@ rust_dom::rust_dom(rust_kernel *kernel,
} }
rust_dom::~rust_dom() { rust_dom::~rust_dom() {
DLOG(this, rust_log::MEM | rust_log::DOM, DLOG(this, dom, "~rust_dom %s @0x%" PRIxPTR, name, (uintptr_t)this);
"~rust_dom %s @0x%" PRIxPTR, name, (uintptr_t)this);
newborn_tasks.delete_all(); newborn_tasks.delete_all();
running_tasks.delete_all(); running_tasks.delete_all();
blocked_tasks.delete_all(); blocked_tasks.delete_all();
@@ -56,43 +56,18 @@ rust_dom::activate(rust_task *task) {
} }
void void
rust_dom::log(rust_task *task, uint32_t type_bits, char const *fmt, ...) { rust_dom::log(rust_task* task, uint32_t level, char const *fmt, ...) {
char buf[BUF_BYTES]; char buf[BUF_BYTES];
if (_log.is_tracing(type_bits)) {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args); vsnprintf(buf, sizeof(buf), fmt, args);
_log.trace_ln(task, type_bits, buf); _log.trace_ln(task, level, buf);
va_end(args); va_end(args);
}
} }
void
rust_dom::log(uint32_t type_bits, char const *fmt, ...) {
char buf[BUF_BYTES];
if (_log.is_tracing(type_bits)) {
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
_log.trace_ln(NULL, type_bits, buf);
va_end(args);
}
}
void
rust_dom::logptr(char const *msg, uintptr_t ptrval) {
log(rust_log::MEM, "%s 0x%" PRIxPTR, msg, ptrval);
}
template<typename T> void
rust_dom::logptr(char const *msg, T* ptrval) {
log(rust_log::MEM, "%s 0x%" PRIxPTR, msg, (uintptr_t)ptrval);
}
void void
rust_dom::fail() { rust_dom::fail() {
log(rust_log::DOM, "domain %s @0x%" PRIxPTR " root task failed", log(NULL, log_err, "domain %s @0x%" PRIxPTR " root task failed",
name, this); name, this);
I(this, rval == 0); I(this, rval == 0);
rval = 1; rval = 1;
@@ -151,7 +126,7 @@ rust_dom::free(void *mem) {
void void
rust_dom::free(void *mem, memory_region::memory_region_type type) { rust_dom::free(void *mem, memory_region::memory_region_type type) {
DLOG(this, rust_log::MEM, "rust_dom::free(0x%" PRIxPTR ")", mem); DLOG(this, mem, "rust_dom::free(0x%" PRIxPTR ")", mem);
if (type == memory_region::LOCAL) { if (type == memory_region::LOCAL) {
local_region.free(mem); local_region.free(mem);
} else if (type == memory_region::SYNCHRONIZED) { } else if (type == memory_region::SYNCHRONIZED) {
@@ -172,8 +147,7 @@ rust_dom::win32_require(LPCTSTR fn, BOOL ok) {
NULL, err, NULL, err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &buf, 0, NULL ); (LPTSTR) &buf, 0, NULL );
DLOG(this, rust_log::ERR, "%s failed with error %ld: %s", DLOG_ERR(this, dom, "%s failed with error %ld: %s", fn, err, buf);
fn, err, buf);
LocalFree((HLOCAL)buf); LocalFree((HLOCAL)buf);
I(this, ok); I(this, ok);
} }
@@ -195,7 +169,7 @@ rust_dom::reap_dead_tasks() {
if (task->ref_count == 0) { if (task->ref_count == 0) {
I(this, task->tasks_waiting_to_join.is_empty()); I(this, task->tasks_waiting_to_join.is_empty());
dead_tasks.remove(task); dead_tasks.remove(task);
DLOG(this, rust_log::TASK, DLOG(this, task,
"deleting unreferenced dead task %s @0x%" PRIxPTR, "deleting unreferenced dead task %s @0x%" PRIxPTR,
task->name, task); task->name, task);
delete task; delete task;
@@ -211,7 +185,7 @@ rust_dom::reap_dead_tasks() {
void rust_dom::drain_incoming_message_queue(bool process) { void rust_dom::drain_incoming_message_queue(bool process) {
rust_message *message; rust_message *message;
while (message_queue->dequeue(&message)) { while (message_queue->dequeue(&message)) {
DLOG(this, rust_log::COMM, "<== receiving \"%s\" " PTR, DLOG(this, comm, "<== receiving \"%s\" " PTR,
message->label, message); message->label, message);
if (process) { if (process) {
message->process(); message->process();
@@ -244,12 +218,12 @@ rust_dom::schedule_task() {
void void
rust_dom::log_state() { rust_dom::log_state() {
if (log_rt_task < log_note) return;
if (!running_tasks.is_empty()) { if (!running_tasks.is_empty()) {
log(rust_log::TASK, "running tasks:"); log(NULL, log_note, "running tasks:");
for (size_t i = 0; i < running_tasks.length(); i++) { for (size_t i = 0; i < running_tasks.length(); i++) {
log(rust_log::TASK, log(NULL, log_note, "\t task: %s @0x%" PRIxPTR " timeout: %d",
"\t task: %s @0x%" PRIxPTR
" timeout: %d",
running_tasks[i]->name, running_tasks[i]->name,
running_tasks[i], running_tasks[i],
running_tasks[i]->yield_timer.get_timeout()); running_tasks[i]->yield_timer.get_timeout());
@@ -257,20 +231,19 @@ rust_dom::log_state() {
} }
if (!blocked_tasks.is_empty()) { if (!blocked_tasks.is_empty()) {
log(rust_log::TASK, "blocked tasks:"); log(NULL, log_note, "blocked tasks:");
for (size_t i = 0; i < blocked_tasks.length(); i++) { for (size_t i = 0; i < blocked_tasks.length(); i++) {
log(rust_log::TASK, log(NULL, log_note, "\t task: %s @0x%" PRIxPTR ", blocked on: 0x%"
"\t task: %s @0x%" PRIxPTR ", blocked on: 0x%" PRIxPTR PRIxPTR " '%s'",
" '%s'",
blocked_tasks[i]->name, blocked_tasks[i], blocked_tasks[i]->name, blocked_tasks[i],
blocked_tasks[i]->cond, blocked_tasks[i]->cond_name); blocked_tasks[i]->cond, blocked_tasks[i]->cond_name);
} }
} }
if (!dead_tasks.is_empty()) { if (!dead_tasks.is_empty()) {
log(rust_log::TASK, "dead tasks:"); log(NULL, log_note, "dead tasks:");
for (size_t i = 0; i < dead_tasks.length(); i++) { for (size_t i = 0; i < dead_tasks.length(); i++) {
log(rust_log::TASK, "\t task: %s 0x%" PRIxPTR ", ref_count: %d", log(NULL, log_note, "\t task: %s 0x%" PRIxPTR ", ref_count: %d",
dead_tasks[i]->name, dead_tasks[i], dead_tasks[i]->name, dead_tasks[i],
dead_tasks[i]->ref_count); dead_tasks[i]->ref_count);
} }
@@ -288,9 +261,8 @@ rust_dom::start_main_loop() {
// Make sure someone is watching, to pull us out of infinite loops. // Make sure someone is watching, to pull us out of infinite loops.
rust_timer timer(this); rust_timer timer(this);
DLOG(this, rust_log::DOM, "started domain loop"); DLOG(this, dom, "started domain loop");
DLOG(this, rust_log::DOM | rust_log::MEM, DLOG(this, dom, "activate glue: " PTR ", exit glue: " PTR,
"activate glue: " PTR ", exit glue: " PTR,
root_crate->get_activate_glue(), root_crate->get_exit_task_glue()); root_crate->get_activate_glue(), root_crate->get_exit_task_glue());
while (number_of_live_tasks() > 0) { while (number_of_live_tasks() > 0) {
@@ -305,20 +277,18 @@ rust_dom::start_main_loop() {
// for a minimum amount of time. // for a minimum amount of time.
if (scheduled_task == NULL) { if (scheduled_task == NULL) {
if (_log.is_tracing(rust_log::TASK)) {
log_state(); log_state();
} DLOG(this, task,
DLOG(this, rust_log::TASK,
"all tasks are blocked, scheduler yielding ..."); "all tasks are blocked, scheduler yielding ...");
sync::sleep(100); sync::sleep(100);
DLOG(this, rust_log::TASK, DLOG(this, task,
"scheduler resuming ..."); "scheduler resuming ...");
continue; continue;
} }
I(this, scheduled_task->running()); I(this, scheduled_task->running());
DLOG(this, rust_log::TASK, DLOG(this, task,
"activating task %s 0x%" PRIxPTR "activating task %s 0x%" PRIxPTR
", sp=0x%" PRIxPTR ", sp=0x%" PRIxPTR
", ref_count=%d" ", ref_count=%d"
@@ -333,7 +303,7 @@ rust_dom::start_main_loop() {
activate(scheduled_task); activate(scheduled_task);
DLOG(this, rust_log::TASK, DLOG(this, task,
"returned from task %s @0x%" PRIxPTR "returned from task %s @0x%" PRIxPTR
" in state '%s', sp=0x%" PRIxPTR, " in state '%s', sp=0x%" PRIxPTR,
scheduled_task->name, scheduled_task->name,
@@ -348,18 +318,16 @@ rust_dom::start_main_loop() {
reap_dead_tasks(); reap_dead_tasks();
} }
DLOG(this, rust_log::DOM, DLOG(this, dom,
"terminated scheduler loop, reaping dead tasks ..."); "terminated scheduler loop, reaping dead tasks ...");
while (dead_tasks.length() > 0) { while (dead_tasks.length() > 0) {
if (message_queue->is_empty()) { if (message_queue->is_empty()) {
DLOG(this, rust_log::DOM, DLOG(this, dom,
"waiting for %d dead tasks to become dereferenced, " "waiting for %d dead tasks to become dereferenced, "
"scheduler yielding ...", "scheduler yielding ...",
dead_tasks.length()); dead_tasks.length());
if (_log.is_tracing(rust_log::TASK)) {
log_state(); log_state();
}
sync::yield(); sync::yield();
} else { } else {
drain_incoming_message_queue(true); drain_incoming_message_queue(true);
@@ -367,15 +335,14 @@ rust_dom::start_main_loop() {
reap_dead_tasks(); reap_dead_tasks();
} }
DLOG(this, rust_log::DOM, "finished main-loop (dom.rval = %d)", rval); DLOG(this, dom, "finished main-loop (dom.rval = %d)", rval);
return rval; return rval;
} }
rust_crate_cache * rust_crate_cache *
rust_dom::get_cache(rust_crate const *crate) { rust_dom::get_cache(rust_crate const *crate) {
DLOG(this, rust_log::CACHE, DLOG(this, cache, "looking for crate-cache for crate 0x%" PRIxPTR, crate);
"looking for crate-cache for crate 0x%" PRIxPTR, crate);
rust_crate_cache *cache = NULL; rust_crate_cache *cache = NULL;
for (size_t i = 0; i < caches.length(); ++i) { for (size_t i = 0; i < caches.length(); ++i) {
rust_crate_cache *c = caches[i]; rust_crate_cache *c = caches[i];
@@ -385,7 +352,7 @@ rust_dom::get_cache(rust_crate const *crate) {
} }
} }
if (!cache) { if (!cache) {
DLOG(this, rust_log::CACHE, DLOG(this, cache,
"making new crate-cache for crate 0x%" PRIxPTR, crate); "making new crate-cache for crate 0x%" PRIxPTR, crate);
cache = new (this) rust_crate_cache(this, crate); cache = new (this) rust_crate_cache(this, crate);
caches.push(cache); caches.push(cache);
@@ -398,7 +365,7 @@ rust_task *
rust_dom::create_task(rust_task *spawner, const char *name) { rust_dom::create_task(rust_task *spawner, const char *name) {
rust_task *task = rust_task *task =
new (this) rust_task (this, &newborn_tasks, spawner, name); new (this) rust_task (this, &newborn_tasks, spawner, name);
DLOG(this, rust_log::TASK, "created task: " PTR ", spawner: %s, name: %s", DLOG(this, task, "created task: " PTR ", spawner: %s, name: %s",
task, spawner ? spawner->name : "null", name); task, spawner ? spawner->name : "null", name);
newborn_tasks.append(task); newborn_tasks.append(task);
return task; return task;

View File

@@ -14,6 +14,7 @@ struct rust_dom : public kernel_owned<rust_dom>, rc_base<rust_dom>
// glue. // glue.
rust_crate const *root_crate; rust_crate const *root_crate;
rust_log _log; rust_log _log;
uint32_t log_lvl;
rust_srv *srv; rust_srv *srv;
memory_region local_region; memory_region local_region;
memory_region synchronized_region; memory_region synchronized_region;
@@ -51,12 +52,8 @@ struct rust_dom : public kernel_owned<rust_dom>, rc_base<rust_dom>
rust_crate const *root_crate, const char *name); rust_crate const *root_crate, const char *name);
~rust_dom(); ~rust_dom();
void activate(rust_task *task); void activate(rust_task *task);
void log(rust_task *task, uint32_t logbit, char const *fmt, ...); void log(rust_task *task, uint32_t level, char const *fmt, ...);
void log(uint32_t logbit, char const *fmt, ...);
rust_log & get_log(); rust_log & get_log();
void logptr(char const *msg, uintptr_t ptrval);
template<typename T>
void logptr(char const *msg, T* ptrval);
void fail(); void fail();
void *malloc(size_t size); void *malloc(size_t size);
void *malloc(size_t size, memory_region::memory_region_type type); void *malloc(size_t size, memory_region::memory_region_type type);
@@ -83,7 +80,6 @@ struct rust_dom : public kernel_owned<rust_dom>, rc_base<rust_dom>
int start_main_loop(); int start_main_loop();
void log_state(); void log_state();
static void log_all_state();
rust_task *create_task(rust_task *spawner, const char *name); rust_task *create_task(rust_task *spawner, const char *name);
}; };

View File

@@ -48,8 +48,8 @@ extern "C" {
#include "sync/lock_free_queue.h" #include "sync/lock_free_queue.h"
class rust_dom; class rust_dom;
class rust_log;
class rust_task; class rust_task;
class rust_log;
class rust_port; class rust_port;
class rust_chan; class rust_chan;
struct rust_token; struct rust_token;

View File

@@ -2,10 +2,10 @@
#define KLOG(...) \ #define KLOG(...) \
do { \ do { \
if (_log.is_tracing(rust_log::KERN)) { \ if (log_rt_kern >= log_note) { \
log(rust_log::KERN, __VA_ARGS__); \ log(log_note, __VA_ARGS__); \
} \ } \
} while(0) } while (0)
rust_kernel::rust_kernel(rust_srv *srv) : rust_kernel::rust_kernel(rust_srv *srv) :
_region(&srv->local_region), _region(&srv->local_region),
@@ -123,15 +123,13 @@ rust_kernel::is_deadlocked() {
} }
void void
rust_kernel::log(uint32_t type_bits, char const *fmt, ...) { rust_kernel::log(uint32_t level, char const *fmt, ...) {
char buf[BUF_BYTES]; char buf[BUF_BYTES];
if (_log.is_tracing(type_bits)) {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args); vsnprintf(buf, sizeof(buf), fmt, args);
_log.trace_ln(NULL, type_bits, buf); _log.trace_ln(NULL, level, buf);
va_end(args); va_end(args);
}
} }
void void

View File

@@ -107,7 +107,7 @@ public:
void join_all_domains(); void join_all_domains();
void log_all_domain_state(); void log_all_domain_state();
void log(uint32_t type_bits, char const *fmt, ...); void log(uint32_t level, char const *fmt, ...);
virtual ~rust_kernel(); virtual ~rust_kernel();
void *malloc(size_t size); void *malloc(size_t size);

View File

@@ -1,5 +1,5 @@
/* /*
* Logging infrastructure that aims to support multi-threading, indentation * Logging infrastructure that aims to support multi-threading,
* and ansi colors. * and ansi colors.
*/ */
@@ -9,58 +9,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
// FIXME somehow unify this with the parsing happening in rust_crate.cpp
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 = new char[strlen(env_str) + 2];
str[0] = ',';
strcpy(str + 1, env_str);
bits = rust_log::ULOG;
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, ",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;
delete[] str;
}
return bits;
}
rust_log::ansi_color
get_type_color(rust_log::log_type type) {
rust_log::ansi_color color = rust_log::WHITE;
if (type & rust_log::ERR)
color = rust_log::RED;
if (type & rust_log::MEM)
color = rust_log::YELLOW;
if (type & rust_log::UPCALL)
color = rust_log::GREEN;
if (type & rust_log::COMM)
color = rust_log::MAGENTA;
if (type & rust_log::DOM)
color = rust_log::LIGHTTEAL;
if (type & rust_log::TASK)
color = rust_log::LIGHTTEAL;
return color;
}
static const char * _foreground_colors[] = { "[37m", static const char * _foreground_colors[] = { "[37m",
"[31m", "[1;31m", "[31m", "[1;31m",
"[32m", "[1;32m", "[32m", "[1;32m",
@@ -78,9 +26,7 @@ static uint32_t _last_thread_id;
rust_log::rust_log(rust_srv *srv, rust_dom *dom) : rust_log::rust_log(rust_srv *srv, rust_dom *dom) :
_srv(srv), _srv(srv),
_dom(dom), _dom(dom),
_type_bit_mask(read_type_bit_mask()), _use_colors(getenv("RUST_COLOR_LOG")) {
_use_colors(getenv("RUST_COLOR_LOG")),
_indent(0) {
} }
rust_log::~rust_log() { rust_log::~rust_log() {
@@ -141,9 +87,6 @@ rust_log::trace_ln(uint32_t thread_id, char *prefix, char *message) {
char buffer[BUF_BYTES] = ""; char buffer[BUF_BYTES] = "";
_log_lock.lock(); _log_lock.lock();
append_string(buffer, "%-34s", prefix); append_string(buffer, "%-34s", prefix);
for (uint32_t i = 0; i < _indent; i++) {
append_string(buffer, " ");
}
append_string(buffer, "%s", message); append_string(buffer, "%s", message);
if (_last_thread_id != thread_id) { if (_last_thread_id != thread_id) {
_last_thread_id = thread_id; _last_thread_id = thread_id;
@@ -154,7 +97,7 @@ rust_log::trace_ln(uint32_t thread_id, char *prefix, char *message) {
} }
void void
rust_log::trace_ln(rust_task *task, char *message) { rust_log::trace_ln(rust_task *task, uint32_t level, char *message) {
#if defined(__WIN32__) #if defined(__WIN32__)
uint32_t thread_id = 0; uint32_t thread_id = 0;
#else #else
@@ -178,55 +121,16 @@ rust_log::trace_ln(rust_task *task, char *message) {
trace_ln(thread_id, prefix, message); trace_ln(thread_id, prefix, message);
} }
/** // Reading log directives and setting log level vars
* Traces a log message if the specified logging type is not filtered.
*/
void
rust_log::trace_ln(rust_task *task, uint32_t type_bits, char *message) {
trace_ln(task, get_type_color((rust_log::log_type) type_bits),
type_bits, message);
}
/**
* Traces a log message using the specified ANSI color code.
*/
void
rust_log::trace_ln(rust_task *task, ansi_color color,
uint32_t type_bits, char *message) {
if (is_tracing(type_bits)) {
if (_use_colors) {
char buffer[BUF_BYTES] = "";
append_string(buffer, color, "%s", message);
trace_ln(task, buffer);
} else {
trace_ln(task, message);
}
}
}
void
rust_log::indent() {
_indent++;
}
void
rust_log::outdent() {
_indent--;
}
void
rust_log::reset_indent(uint32_t indent) {
_indent = indent;
}
struct mod_entry { struct mod_entry {
const char* name; const char* name;
int* state; size_t* state;
}; };
struct cratemap { struct cratemap {
mod_entry* entries; const mod_entry* entries;
cratemap* children[1]; const cratemap* children[1];
}; };
struct log_directive { struct log_directive {
@@ -235,11 +139,12 @@ struct log_directive {
}; };
const size_t max_log_directives = 255; const size_t max_log_directives = 255;
const size_t max_log_level = 1;
const size_t default_log_level = 0;
// This is a rather ugly parser for strings in the form // This is a rather ugly parser for strings in the form
// "crate1,crate2.mod3,crate3.x=2". Log levels range 0=err, 1=warn, 2=info, // "crate1,crate2.mod3,crate3.x=1". Log levels are 0-1 for now,
// 3=debug. Default is 1. Words without an '=X' part set the log level for // eventually we'll have 0-3.
// that module (and submodules) to 3.
size_t parse_logging_spec(char* spec, log_directive* dirs) { size_t parse_logging_spec(char* spec, log_directive* dirs) {
size_t dir = 0; size_t dir = 0;
while (dir < max_log_directives && *spec) { while (dir < max_log_directives && *spec) {
@@ -251,10 +156,10 @@ size_t parse_logging_spec(char* spec, log_directive* dirs) {
if (start == spec) {spec++; break;} if (start == spec) {spec++; break;}
*spec = '\0'; *spec = '\0';
spec++; spec++;
size_t level = 3; size_t level = max_log_level;
if (cur == '=') { if (cur == '=') {
level = *spec - '0'; level = *spec - '0';
if (level > 3) level = 1; if (level > max_log_level) level = max_log_level;
if (*spec) ++spec; if (*spec) ++spec;
} }
dirs[dir].name = start; dirs[dir].name = start;
@@ -267,10 +172,10 @@ size_t parse_logging_spec(char* spec, log_directive* dirs) {
return dir; return dir;
} }
void update_crate_map(cratemap* map, log_directive* dirs, size_t n_dirs) { void update_module_map(const mod_entry* map, log_directive* dirs,
// First update log levels for this crate size_t n_dirs) {
for (mod_entry* cur = map->entries; cur->name; cur++) { for (const mod_entry* cur = map; cur->name; cur++) {
size_t level = 1, longest_match = 0; size_t level = default_log_level, longest_match = 0;
for (size_t d = 0; d < n_dirs; d++) { for (size_t d = 0; d < n_dirs; d++) {
if (strstr(cur->name, dirs[d].name) == cur->name && if (strstr(cur->name, dirs[d].name) == cur->name &&
strlen(dirs[d].name) > longest_match) { strlen(dirs[d].name) > longest_match) {
@@ -280,24 +185,69 @@ void update_crate_map(cratemap* map, log_directive* dirs, size_t n_dirs) {
} }
*cur->state = level; *cur->state = level;
} }
}
void update_crate_map(const cratemap* map, log_directive* dirs,
size_t n_dirs) {
// First update log levels for this crate
update_module_map(map->entries, dirs, n_dirs);
// Then recurse on linked crates // Then recurse on linked crates
// FIXME this does double work in diamond-shaped deps. could keep
// a set of visited addresses, if it turns out to be actually slow
for (size_t i = 0; map->children[i]; i++) { for (size_t i = 0; map->children[i]; i++) {
update_crate_map(map->children[i], dirs, n_dirs); update_crate_map(map->children[i], dirs, n_dirs);
} }
} }
// These are pseudo-modules used to control logging in the runtime.
size_t log_rt_mem;
size_t log_rt_comm;
size_t log_rt_task;
size_t log_rt_dom;
size_t log_rt_trace;
size_t log_rt_dwarf;
size_t log_rt_cache;
size_t log_rt_upcall;
size_t log_rt_timer;
size_t log_rt_gc;
size_t log_rt_stdlib;
size_t log_rt_kern;
size_t log_rt_backtrace;
// Used to turn logging for rustboot-compiled code on and off
size_t log_rustboot;
static const mod_entry _rt_module_map[] =
{{"rt.mem", &log_rt_mem},
{"rt.comm", &log_rt_comm},
{"rt.task", &log_rt_task},
{"rt.dom", &log_rt_dom},
{"rt.trace", &log_rt_trace},
{"rt.dwarf", &log_rt_dwarf},
{"rt.cache", &log_rt_cache},
{"rt.upcall", &log_rt_upcall},
{"rt.timer", &log_rt_timer},
{"rt.gc", &log_rt_gc},
{"rt.stdlib", &log_rt_stdlib},
{"rt.kern", &log_rt_kern},
{"rt.backtrace", &log_rt_backtrace},
{"rustboot", &log_rustboot},
{NULL, NULL}};
void update_log_settings(void* crate_map, char* settings) { void update_log_settings(void* crate_map, char* settings) {
char* buffer = NULL; char* buffer = NULL;
log_directive dirs[256]; log_directive dirs[256];
size_t dir = 0; size_t n_dirs = 0;
if (settings) { if (settings) {
buffer = (char*)malloc(strlen(settings)); buffer = (char*)malloc(strlen(settings));
strcpy(buffer, settings); strcpy(buffer, settings);
dir = parse_logging_spec(buffer, &dirs[0]); n_dirs = parse_logging_spec(buffer, &dirs[0]);
} }
update_crate_map((cratemap*)crate_map, &dirs[0], dir); update_module_map(_rt_module_map, &dirs[0], n_dirs);
// FIXME check can be dropped when rustboot is gone
if (crate_map)
update_crate_map((const cratemap*)crate_map, &dirs[0], n_dirs);
free(buffer); free(buffer);
} }

View File

@@ -1,28 +1,26 @@
#ifndef RUST_LOG_H #ifndef RUST_LOG_H
#define RUST_LOG_H #define RUST_LOG_H
#define DLOG(dom, mask, ...) \ const uint32_t log_err = 0;
do { \ const uint32_t log_note = 1;
rust_dom *_dom = dom; \
uint32_t _mask = mask; \ #define LOG(task, field, ...) \
if ((_dom)->get_log().is_tracing(_mask)) { \ DLOG_LVL(log_note, task, task->dom, field, __VA_ARGS__)
(_dom)->log(_mask, __VA_ARGS__); \ #define LOG_ERR(task, field, ...) \
} \ DLOG_LVL(log_err, task, task->dom, field, __VA_ARGS__)
} while(0) #define DLOG(dom, field, ...) \
#define LOG(task, mask, ...) \ DLOG_LVL(log_note, NULL, dom, field, __VA_ARGS__)
DLOG((task)->dom, mask, __VA_ARGS__) #define DLOG_ERR(dom, field, ...) \
#define LOG_I(task, mask, ...) \ DLOG_LVL(log_err, NULL, dom, field, __VA_ARGS__)
do { \
rust_task *_task = task; \
uint32_t _mask = mask; \
if ((_task)->dom->get_log().is_tracing(_mask)) { \
(_task)->dom->get_log().reset_indent(0); \
(_task)->dom->log(_mask, __VA_ARGS__); \
(_task)->dom->get_log().indent(); \
} \
} while(0)
#define LOGPTR(dom, msg, ptrval) \ #define LOGPTR(dom, msg, ptrval) \
DLOG(dom, rust_log::MEM, "%s 0x%" PRIxPTR, msg, ptrval) DLOG_LVL(log_note, NULL, dom, mem, "%s 0x%" PRIxPTR, msg, ptrval)
#define DLOG_LVL(lvl, task, dom, field, ...) \
do { \
rust_dom* _d_ = dom; \
if (log_rt_##field >= lvl && _d_->log_lvl >= lvl) { \
_d_->log(task, lvl, __VA_ARGS__); \
} \
} while (0)
class rust_dom; class rust_dom;
class rust_task; class rust_task;
@@ -49,50 +47,33 @@ public:
LIGHTTEAL LIGHTTEAL
}; };
enum log_type { void trace_ln(rust_task *task, uint32_t level, char *message);
ERR = 0x1,
MEM = 0x2,
COMM = 0x4,
TASK = 0x8,
DOM = 0x10,
ULOG = 0x20,
TRACE = 0x40,
DWARF = 0x80,
CACHE = 0x100,
UPCALL = 0x200,
TIMER = 0x400,
GC = 0x800,
STDLIB = 0x1000,
SPECIAL = 0x2000,
KERN = 0x4000,
BT = 0x8000,
ALL = 0xffffffff
};
void indent();
void outdent();
void reset_indent(uint32_t indent);
void trace_ln(uint32_t thread_id, char *prefix, char *message); void trace_ln(uint32_t thread_id, char *prefix, char *message);
void trace_ln(rust_task *task, uint32_t type_bits, char *message);
void trace_ln(rust_task *task, ansi_color color,
uint32_t type_bits, char *message);
bool is_tracing(uint32_t type_bits); bool is_tracing(uint32_t type_bits);
private: private:
rust_srv *_srv; rust_srv *_srv;
rust_dom *_dom; rust_dom *_dom;
uint32_t _type_bit_mask;
bool _use_labels; bool _use_labels;
bool _use_colors; bool _use_colors;
uint32_t _indent;
void trace_ln(rust_task *task, char *message); void trace_ln(rust_task *task, char *message);
}; };
inline bool
rust_log::is_tracing(uint32_t type_bits) {
return type_bits & _type_bit_mask;
}
void update_log_settings(void* crate_map, char* settings); void update_log_settings(void* crate_map, char* settings);
extern size_t log_rt_mem;
extern size_t log_rt_comm;
extern size_t log_rt_task;
extern size_t log_rt_dom;
extern size_t log_rt_trace;
extern size_t log_rt_dwarf;
extern size_t log_rt_cache;
extern size_t log_rt_upcall;
extern size_t log_rt_timer;
extern size_t log_rt_gc;
extern size_t log_rt_stdlib;
extern size_t log_rt_kern;
extern size_t log_rt_backtrace;
extern size_t log_rustboot;
#endif /* RUST_LOG_H */ #endif /* RUST_LOG_H */

View File

@@ -51,9 +51,6 @@ send(notification_type type, const char* label,
memory_region *region = &target->message_queue->region; memory_region *region = &target->message_queue->region;
notify_message *message = notify_message *message =
new (region) notify_message(region, type, label, source, target); new (region) notify_message(region, type, label, source, target);
// target->referent()->log(rust_log::COMM,
// "==> sending \"%s\" " PTR " in queue " PTR,
// label, message, &target->message_queue);
target->message_queue->enqueue(message); target->message_queue->enqueue(message);
} }
@@ -99,16 +96,13 @@ send(uint8_t *buffer, size_t buffer_sz, const char* label,
data_message *message = data_message *message =
new (region) data_message(region, buffer, buffer_sz, label, source, new (region) data_message(region, buffer, buffer_sz, label, source,
port); port);
source->referent()->log(rust_log::COMM, LOG(source->referent(), comm, "==> sending \"%s\"" PTR " in queue " PTR,
"==> sending \"%s\"" PTR " in queue " PTR,
label, message, &port->message_queue); label, message, &port->message_queue);
port->message_queue->enqueue(message); port->message_queue->enqueue(message);
} }
void data_message::process() { void data_message::process() {
_port->referent()->remote_channel->send(_buffer); _port->referent()->remote_channel->send(_buffer);
// _target->referent()->log(rust_log::COMM,
// "<=== received data via message ===");
} }
void data_message::kernel_process() { void data_message::kernel_process() {

View File

@@ -5,7 +5,7 @@ rust_port::rust_port(rust_task *task, size_t unit_sz) :
maybe_proxy<rust_port>(this), task(task), maybe_proxy<rust_port>(this), task(task),
unit_sz(unit_sz), writers(task->dom), chans(task->dom) { unit_sz(unit_sz), writers(task->dom), chans(task->dom) {
LOG(task, rust_log::MEM | rust_log::COMM, LOG(task, comm,
"new rust_port(task=0x%" PRIxPTR ", unit_sz=%d) -> port=0x%" "new rust_port(task=0x%" PRIxPTR ", unit_sz=%d) -> port=0x%"
PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this); PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this);
@@ -14,8 +14,7 @@ rust_port::rust_port(rust_task *task, size_t unit_sz) :
} }
rust_port::~rust_port() { rust_port::~rust_port() {
LOG(task, rust_log::COMM | rust_log::MEM, LOG(task, comm, "~rust_port 0x%" PRIxPTR, (uintptr_t) this);
"~rust_port 0x%" PRIxPTR, (uintptr_t) this);
// log_state(); // log_state();
@@ -25,7 +24,7 @@ rust_port::~rust_port() {
chan->disassociate(); chan->disassociate();
if (chan->ref_count == 0) { if (chan->ref_count == 0) {
LOG(task, rust_log::COMM, LOG(task, comm,
"chan: 0x%" PRIxPTR " is dormant, freeing", chan); "chan: 0x%" PRIxPTR " is dormant, freeing", chan);
delete chan; delete chan;
} }
@@ -39,7 +38,7 @@ bool rust_port::receive(void *dptr) {
rust_chan *chan = chans[i]; rust_chan *chan = chans[i];
if (chan->buffer.is_empty() == false) { if (chan->buffer.is_empty() == false) {
chan->buffer.dequeue(dptr); chan->buffer.dequeue(dptr);
LOG(task, rust_log::COMM, "<=== read data ==="); LOG(task, comm, "<=== read data ===");
return true; return true;
} }
} }
@@ -47,12 +46,12 @@ bool rust_port::receive(void *dptr) {
} }
void rust_port::log_state() { void rust_port::log_state() {
LOG(task, rust_log::COMM, LOG(task, comm,
"rust_port: 0x%" PRIxPTR ", associated channel(s): %d", "rust_port: 0x%" PRIxPTR ", associated channel(s): %d",
this, chans.length()); this, chans.length());
for (uint32_t i = 0; i < chans.length(); i++) { for (uint32_t i = 0; i < chans.length(); i++) {
rust_chan *chan = chans[i]; rust_chan *chan = chans[i];
LOG(task, rust_log::COMM, LOG(task, comm,
"\tchan: 0x%" PRIxPTR ", size: %d, remote: %s", "\tchan: 0x%" PRIxPTR ", size: %d, remote: %s",
chan, chan,
chan->buffer.size(), chan->buffer.size(),

View File

@@ -11,11 +11,7 @@ rust_srv::rust_srv() :
// Nop. // Nop.
} }
rust_srv::~rust_srv() { rust_srv::~rust_srv() {}
// char msg[BUF_BYTES];
// snprintf(msg, sizeof(msg), "~rust_srv %" PRIxPTR, (uintptr_t) this);
// log(msg);
}
void void
rust_srv::free(void *p) { rust_srv::free(void *p) {

View File

@@ -102,24 +102,23 @@ rust_task::rust_task(rust_dom *dom, rust_task_list *state,
rust_task::~rust_task() rust_task::~rust_task()
{ {
DLOG(dom, rust_log::MEM|rust_log::TASK, DLOG(dom, task, "~rust_task %s @0x%" PRIxPTR ", refcnt=%d",
"~rust_task %s @0x%" PRIxPTR ", refcnt=%d",
name, (uintptr_t)this, ref_count); name, (uintptr_t)this, ref_count);
/* /*
for (uintptr_t fp = get_fp(); fp; fp = get_previous_fp(fp)) { for (uintptr_t fp = get_fp(); fp; fp = get_previous_fp(fp)) {
frame_glue_fns *glue_fns = get_frame_glue_fns(fp); frame_glue_fns *glue_fns = get_frame_glue_fns(fp);
DLOG(dom, rust_log::MEM|rust_log::TASK, DLOG(dom, task,
"~rust_task, frame fp=0x%" PRIxPTR ", glue_fns=0x%" PRIxPTR, "~rust_task, frame fp=0x%" PRIxPTR ", glue_fns=0x%" PRIxPTR,
fp, glue_fns); fp, glue_fns);
if (glue_fns) { if (glue_fns) {
DLOG(dom, rust_log::MEM|rust_log::TASK, DLOG(dom, task,
"~rust_task, mark_glue=0x%" PRIxPTR, "~rust_task, mark_glue=0x%" PRIxPTR,
glue_fns->mark_glue); glue_fns->mark_glue);
DLOG(dom, rust_log::MEM|rust_log::TASK, DLOG(dom, task,
"~rust_task, drop_glue=0x%" PRIxPTR, "~rust_task, drop_glue=0x%" PRIxPTR,
glue_fns->drop_glue); glue_fns->drop_glue);
DLOG(dom, rust_log::MEM|rust_log::TASK, DLOG(dom, task,
"~rust_task, reloc_glue=0x%" PRIxPTR, "~rust_task, reloc_glue=0x%" PRIxPTR,
glue_fns->reloc_glue); glue_fns->reloc_glue);
} }
@@ -266,23 +265,21 @@ rust_task::grow(size_t n_frame_bytes)
uintptr_t old_bottom = (uintptr_t) &old_stk->data[0]; uintptr_t old_bottom = (uintptr_t) &old_stk->data[0];
uintptr_t rust_sp_disp = old_top - this->rust_sp; uintptr_t rust_sp_disp = old_top - this->rust_sp;
size_t ssz = old_top - old_bottom; size_t ssz = old_top - old_bottom;
DLOG(dom, rust_log::MEM|rust_log::TASK|rust_log::UPCALL, DLOG(dom, task, "upcall_grow_task(%" PRIdPTR
"upcall_grow_task(%" PRIdPTR "), old size %" PRIdPTR " bytes (old lim: 0x%" PRIxPTR ")",
"), old size %" PRIdPTR
" bytes (old lim: 0x%" PRIxPTR ")",
n_frame_bytes, ssz, old_top); n_frame_bytes, ssz, old_top);
ssz *= 2; ssz *= 2;
if (ssz < n_frame_bytes) if (ssz < n_frame_bytes)
ssz = n_frame_bytes; ssz = n_frame_bytes;
ssz = next_power_of_two(ssz); ssz = next_power_of_two(ssz);
DLOG(dom, rust_log::MEM|rust_log::TASK, "upcall_grow_task growing stk 0x%" DLOG(dom, task, "upcall_grow_task growing stk 0x%"
PRIxPTR " to %d bytes", old_stk, ssz); PRIxPTR " to %d bytes", old_stk, ssz);
stk_seg *nstk = new_stk(dom, ssz); stk_seg *nstk = new_stk(dom, ssz);
uintptr_t new_top = (uintptr_t) &nstk->data[ssz]; uintptr_t new_top = (uintptr_t) &nstk->data[ssz];
size_t n_copy = old_top - old_bottom; size_t n_copy = old_top - old_bottom;
DLOG(dom, rust_log::MEM|rust_log::TASK, DLOG(dom, task,
"copying %d bytes of stack from [0x%" PRIxPTR ", 0x%" PRIxPTR "]" "copying %d bytes of stack from [0x%" PRIxPTR ", 0x%" PRIxPTR "]"
" to [0x%" PRIxPTR ", 0x%" PRIxPTR "]", " to [0x%" PRIxPTR ", 0x%" PRIxPTR "]",
n_copy, n_copy,
@@ -296,7 +293,7 @@ rust_task::grow(size_t n_frame_bytes)
this->stk = nstk; this->stk = nstk;
this->rust_sp = new_top - rust_sp_disp; this->rust_sp = new_top - rust_sp_disp;
DLOG(dom, rust_log::MEM|rust_log::TASK, "processing relocations"); DLOG(dom, task, "processing relocations");
// FIXME (issue #32): this is the most ridiculously crude // FIXME (issue #32): this is the most ridiculously crude
// relocation scheme ever. Try actually, you know, writing out // relocation scheme ever. Try actually, you know, writing out
@@ -305,14 +302,13 @@ rust_task::grow(size_t n_frame_bytes)
for (uintptr_t* p = (uintptr_t*)(new_top - n_copy); for (uintptr_t* p = (uintptr_t*)(new_top - n_copy);
p < (uintptr_t*)new_top; ++p) { p < (uintptr_t*)new_top; ++p) {
if (old_bottom <= *p && *p < old_top) { if (old_bottom <= *p && *p < old_top) {
//DLOG(dom, rust_log::MEM, "relocating pointer 0x%" PRIxPTR //DLOG(dom, mem, "relocating pointer 0x%" PRIxPTR
// " by %d bytes", *p, (new_top - old_top)); // " by %d bytes", *p, (new_top - old_top));
n_relocs++; n_relocs++;
*p += (new_top - old_top); *p += (new_top - old_top);
} }
} }
DLOG(dom, rust_log::MEM|rust_log::TASK, DLOG(dom, task, "processed %d relocations", n_relocs);
"processed %d relocations", n_relocs);
del_stk(dom, old_stk); del_stk(dom, old_stk);
LOGPTR(dom, "grown stk limit", new_top); LOGPTR(dom, "grown stk limit", new_top);
#endif #endif
@@ -342,7 +338,7 @@ rust_task::run_after_return(size_t nargs, uintptr_t glue)
sp = align_down(sp - nargs * sizeof(uintptr_t)); sp = align_down(sp - nargs * sizeof(uintptr_t));
uintptr_t *retpc = ((uintptr_t *) sp) - 1; uintptr_t *retpc = ((uintptr_t *) sp) - 1;
DLOG(dom, rust_log::TASK|rust_log::MEM, DLOG(dom, task,
"run_after_return: overwriting retpc=0x%" PRIxPTR "run_after_return: overwriting retpc=0x%" PRIxPTR
" @ runtime_sp=0x%" PRIxPTR " @ runtime_sp=0x%" PRIxPTR
" with glue=0x%" PRIxPTR, " with glue=0x%" PRIxPTR,
@@ -363,7 +359,7 @@ rust_task::run_on_resume(uintptr_t glue)
// Inject glue as resume address in the suspended frame. // Inject glue as resume address in the suspended frame.
uintptr_t* rsp = (uintptr_t*) rust_sp; uintptr_t* rsp = (uintptr_t*) rust_sp;
rsp += n_callee_saves; rsp += n_callee_saves;
DLOG(dom, rust_log::TASK|rust_log::MEM, DLOG(dom, task,
"run_on_resume: overwriting retpc=0x%" PRIxPTR "run_on_resume: overwriting retpc=0x%" PRIxPTR
" @ rust_sp=0x%" PRIxPTR " @ rust_sp=0x%" PRIxPTR
" with glue=0x%" PRIxPTR, " with glue=0x%" PRIxPTR,
@@ -378,8 +374,7 @@ rust_task::yield(size_t nargs) {
void void
rust_task::yield(size_t nargs, size_t time_in_us) { rust_task::yield(size_t nargs, size_t time_in_us) {
log(rust_log::TASK, LOG(this, task, "task %s @0x%" PRIxPTR " yielding for %d us",
"task %s @0x%" PRIxPTR " yielding for %d us",
name, this, time_in_us); name, this, time_in_us);
yield_timer.reset(time_in_us); yield_timer.reset(time_in_us);
run_after_return(nargs, dom->root_crate->get_yield_glue()); run_after_return(nargs, dom->root_crate->get_yield_glue());
@@ -401,21 +396,21 @@ rust_task::kill() {
// Note the distinction here: kill() is when you're in an upcall // Note the distinction here: kill() is when you're in an upcall
// from task A and want to force-fail task B, you do B->kill(). // from task A and want to force-fail task B, you do B->kill().
// If you want to fail yourself you do self->fail(upcall_nargs). // If you want to fail yourself you do self->fail(upcall_nargs).
log(rust_log::TASK, "killing task %s @0x%" PRIxPTR, name, this); LOG(this, task, "killing task %s @0x%" PRIxPTR, name, this);
// Unblock the task so it can unwind. // Unblock the task so it can unwind.
unblock(); unblock();
if (this == dom->root_task) if (this == dom->root_task)
dom->fail(); dom->fail();
log(rust_log::TASK, "preparing to unwind task: 0x%" PRIxPTR, this); LOG(this, task, "preparing to unwind task: 0x%" PRIxPTR, this);
run_on_resume(dom->root_crate->get_unwind_glue()); run_on_resume(dom->root_crate->get_unwind_glue());
} }
void void
rust_task::fail(size_t nargs) { rust_task::fail(size_t nargs) {
// See note in ::kill() regarding who should call this. // See note in ::kill() regarding who should call this.
DLOG(dom, rust_log::TASK, "task %s @0x%" PRIxPTR " failing", name, this); DLOG(dom, task, "task %s @0x%" PRIxPTR " failing", name, this);
backtrace(); backtrace();
// Unblock the task so it can unwind. // Unblock the task so it can unwind.
unblock(); unblock();
@@ -423,7 +418,7 @@ rust_task::fail(size_t nargs) {
dom->fail(); dom->fail();
run_after_return(nargs, dom->root_crate->get_unwind_glue()); run_after_return(nargs, dom->root_crate->get_unwind_glue());
if (supervisor) { if (supervisor) {
DLOG(dom, rust_log::TASK, DLOG(dom, task,
"task %s @0x%" PRIxPTR "task %s @0x%" PRIxPTR
" propagating failure to supervisor %s @0x%" PRIxPTR, " propagating failure to supervisor %s @0x%" PRIxPTR,
name, this, supervisor->name, supervisor); name, this, supervisor->name, supervisor);
@@ -434,7 +429,7 @@ rust_task::fail(size_t nargs) {
void void
rust_task::gc(size_t nargs) rust_task::gc(size_t nargs)
{ {
DLOG(dom, rust_log::TASK|rust_log::MEM, DLOG(dom, task,
"task %s @0x%" PRIxPTR " garbage collecting", name, this); "task %s @0x%" PRIxPTR " garbage collecting", name, this);
run_after_return(nargs, dom->root_crate->get_gc_glue()); run_after_return(nargs, dom->root_crate->get_gc_glue());
} }
@@ -442,7 +437,7 @@ rust_task::gc(size_t nargs)
void void
rust_task::unsupervise() rust_task::unsupervise()
{ {
DLOG(dom, rust_log::TASK, DLOG(dom, task,
"task %s @0x%" PRIxPTR "task %s @0x%" PRIxPTR
" disconnecting from supervisor %s @0x%" PRIxPTR, " disconnecting from supervisor %s @0x%" PRIxPTR,
name, this, supervisor->name, supervisor); name, this, supervisor->name, supervisor);
@@ -452,7 +447,7 @@ rust_task::unsupervise()
void void
rust_task::notify_tasks_waiting_to_join() { rust_task::notify_tasks_waiting_to_join() {
while (tasks_waiting_to_join.is_empty() == false) { while (tasks_waiting_to_join.is_empty() == false) {
log(rust_log::TASK, "notify_tasks_waiting_to_join: %d", LOG(this, task, "notify_tasks_waiting_to_join: %d",
tasks_waiting_to_join.size()); tasks_waiting_to_join.size());
maybe_proxy<rust_task> *waiting_task = 0; maybe_proxy<rust_task> *waiting_task = 0;
tasks_waiting_to_join.pop(&waiting_task); tasks_waiting_to_join.pop(&waiting_task);
@@ -551,8 +546,7 @@ rust_task::malloc(size_t sz, type_desc *td)
return mem; return mem;
if (td) { if (td) {
gc_alloc *gcm = (gc_alloc*) mem; gc_alloc *gcm = (gc_alloc*) mem;
DLOG(dom, rust_log::TASK|rust_log::MEM|rust_log::GC, DLOG(dom, task, "task %s @0x%" PRIxPTR
"task %s @0x%" PRIxPTR
" allocated %d GC bytes = 0x%" PRIxPTR, " allocated %d GC bytes = 0x%" PRIxPTR,
name, (uintptr_t)this, sz, gcm); name, (uintptr_t)this, sz, gcm);
memset((void*) gcm, 0, sizeof(gc_alloc)); memset((void*) gcm, 0, sizeof(gc_alloc));
@@ -575,8 +569,7 @@ rust_task::realloc(void *data, size_t sz, bool is_gc)
unlink_gc(gcm); unlink_gc(gcm);
sz += sizeof(gc_alloc); sz += sizeof(gc_alloc);
gcm = (gc_alloc*) dom->realloc((void*)gcm, sz); gcm = (gc_alloc*) dom->realloc((void*)gcm, sz);
DLOG(dom, rust_log::TASK|rust_log::MEM|rust_log::GC, DLOG(dom, task, "task %s @0x%" PRIxPTR
"task %s @0x%" PRIxPTR
" reallocated %d GC bytes = 0x%" PRIxPTR, " reallocated %d GC bytes = 0x%" PRIxPTR,
name, (uintptr_t)this, sz, gcm); name, (uintptr_t)this, sz, gcm);
if (!gcm) if (!gcm)
@@ -598,7 +591,7 @@ rust_task::free(void *p, bool is_gc)
if (is_gc) { if (is_gc) {
gc_alloc *gcm = (gc_alloc*)(((char *)p) - sizeof(gc_alloc)); gc_alloc *gcm = (gc_alloc*)(((char *)p) - sizeof(gc_alloc));
unlink_gc(gcm); unlink_gc(gcm);
DLOG(dom, rust_log::TASK|rust_log::MEM|rust_log::GC, DLOG(dom, mem,
"task %s @0x%" PRIxPTR " freeing GC memory = 0x%" PRIxPTR, "task %s @0x%" PRIxPTR " freeing GC memory = 0x%" PRIxPTR,
name, (uintptr_t)this, gcm); name, (uintptr_t)this, gcm);
dom->free(gcm); dom->free(gcm);
@@ -610,7 +603,7 @@ rust_task::free(void *p, bool is_gc)
void void
rust_task::transition(rust_task_list *src, rust_task_list *dst) { rust_task::transition(rust_task_list *src, rust_task_list *dst) {
I(dom, state == src); I(dom, state == src);
DLOG(dom, rust_log::TASK, DLOG(dom, task,
"task %s " PTR " state change '%s' -> '%s'", "task %s " PTR " state change '%s' -> '%s'",
name, (uintptr_t)this, src->name, dst->name); name, (uintptr_t)this, src->name, dst->name);
src->remove(this); src->remove(this);
@@ -620,7 +613,7 @@ rust_task::transition(rust_task_list *src, rust_task_list *dst) {
void void
rust_task::block(rust_cond *on, const char* name) { rust_task::block(rust_cond *on, const char* name) {
log(rust_log::TASK, "Blocking on 0x%" PRIxPTR ", cond: 0x%" PRIxPTR, LOG(this, task, "Blocking on 0x%" PRIxPTR ", cond: 0x%" PRIxPTR,
(uintptr_t) on, (uintptr_t) cond); (uintptr_t) on, (uintptr_t) cond);
A(dom, cond == NULL, "Cannot block an already blocked task."); A(dom, cond == NULL, "Cannot block an already blocked task.");
A(dom, on != NULL, "Cannot block on a NULL object."); A(dom, on != NULL, "Cannot block on a NULL object.");
@@ -633,7 +626,7 @@ rust_task::block(rust_cond *on, const char* name) {
void void
rust_task::wakeup(rust_cond *from) { rust_task::wakeup(rust_cond *from) {
A(dom, cond != NULL, "Cannot wake up unblocked task."); A(dom, cond != NULL, "Cannot wake up unblocked task.");
log(rust_log::TASK, "Blocked on 0x%" PRIxPTR " woken up on 0x%" PRIxPTR, LOG(this, task, "Blocked on 0x%" PRIxPTR " woken up on 0x%" PRIxPTR,
(uintptr_t) cond, (uintptr_t) from); (uintptr_t) cond, (uintptr_t) from);
A(dom, cond == from, "Cannot wake up blocked task on wrong condition."); A(dom, cond == from, "Cannot wake up blocked task on wrong condition.");
@@ -658,36 +651,22 @@ rust_crate_cache *
rust_task::get_crate_cache(rust_crate const *curr_crate) rust_task::get_crate_cache(rust_crate const *curr_crate)
{ {
if (cache && cache->crate != curr_crate) { if (cache && cache->crate != curr_crate) {
DLOG(dom, rust_log::TASK, "switching task crate-cache to crate 0x%" DLOG(dom, task, "switching task crate-cache to crate 0x%"
PRIxPTR, curr_crate); PRIxPTR, curr_crate);
cache->deref(); cache->deref();
cache = NULL; cache = NULL;
} }
if (!cache) { if (!cache) {
DLOG(dom, rust_log::TASK, "fetching cache for current crate"); DLOG(dom, task, "fetching cache for current crate");
cache = dom->get_cache(curr_crate); cache = dom->get_cache(curr_crate);
} }
return cache; return cache;
} }
void
rust_task::log(uint32_t type_bits, char const *fmt, ...) {
char buf[BUF_BYTES];
if (dom->get_log().is_tracing(type_bits)) {
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
dom->get_log().trace_ln(this, type_bits, buf);
va_end(args);
}
}
void void
rust_task::backtrace() { rust_task::backtrace() {
if (!dom->get_log().is_tracing(rust_log::BT)) if (!log_rt_backtrace) return;
return;
#ifndef __WIN32__ #ifndef __WIN32__
void *call_stack[256]; void *call_stack[256];
int nframes = ::backtrace(call_stack, 256); int nframes = ::backtrace(call_stack, 256);

View File

@@ -82,8 +82,6 @@ rust_task : public maybe_proxy<rust_task>,
void check_active() { I(dom, dom->curr_task == this); } void check_active() { I(dom, dom->curr_task == this); }
void check_suspended() { I(dom, dom->curr_task != this); } void check_suspended() { I(dom, dom->curr_task != this); }
void log(uint32_t type_bits, char const *fmt, ...);
// Print a backtrace, if the "bt" logging option is on. // Print a backtrace, if the "bt" logging option is on.
void backtrace(); void backtrace();

View File

@@ -7,10 +7,10 @@ rust_task_list::rust_task_list (rust_dom *dom, const char* name) :
void void
rust_task_list::delete_all() { rust_task_list::delete_all() {
DLOG(dom, rust_log::TASK, "deleting all %s tasks", name); DLOG(dom, task, "deleting all %s tasks", name);
while (is_empty() == false) { while (is_empty() == false) {
rust_task *task = pop_value(); rust_task *task = pop_value();
DLOG(dom, rust_log::TASK, "deleting task " PTR, task); DLOG(dom, task, "deleting task " PTR, task);
delete task; delete task;
} }
} }

View File

@@ -30,7 +30,7 @@ timer_loop(void *ptr) {
// We were handed the rust_timer that owns us. // We were handed the rust_timer that owns us.
rust_timer *timer = (rust_timer *)ptr; rust_timer *timer = (rust_timer *)ptr;
rust_dom *dom = timer->dom; rust_dom *dom = timer->dom;
DLOG(dom, rust_log::TIMER, "in timer 0x%" PRIxPTR, (uintptr_t)timer); DLOG(dom, timer, "in timer 0x%" PRIxPTR, (uintptr_t)timer);
size_t ms = TIME_SLICE_IN_MS; size_t ms = TIME_SLICE_IN_MS;
while (!timer->exit_flag) { while (!timer->exit_flag) {
@@ -39,7 +39,7 @@ timer_loop(void *ptr) {
#else #else
usleep(ms * 1000); usleep(ms * 1000);
#endif #endif
DLOG(dom, rust_log::TIMER, "timer 0x%" PRIxPTR DLOG(dom, timer, "timer 0x%" PRIxPTR
" interrupting domain 0x%" PRIxPTR, (uintptr_t) timer, " interrupting domain 0x%" PRIxPTR, (uintptr_t) timer,
(uintptr_t) dom); (uintptr_t) dom);
dom->interrupt_flag = 1; dom->interrupt_flag = 1;
@@ -54,7 +54,7 @@ timer_loop(void *ptr) {
rust_timer::rust_timer(rust_dom *dom) : rust_timer::rust_timer(rust_dom *dom) :
dom(dom), exit_flag(0) { dom(dom), exit_flag(0) {
DLOG(dom, rust_log::TIMER, "creating timer for domain 0x%" PRIxPTR, dom); DLOG(dom, timer, "creating timer for domain 0x%" PRIxPTR, dom);
#if defined(__WIN32__) #if defined(__WIN32__)
thread = CreateThread(NULL, 0, timer_loop, this, 0, NULL); thread = CreateThread(NULL, 0, timer_loop, this, 0, NULL);
dom->win32_require("CreateThread", thread != NULL); dom->win32_require("CreateThread", thread != NULL);

View File

@@ -4,7 +4,7 @@
#ifdef __GNUC__ #ifdef __GNUC__
#define LOG_UPCALL_ENTRY(task) \ #define LOG_UPCALL_ENTRY(task) \
LOG_I(task, rust_log::UPCALL, \ LOG(task, upcall, \
"> UPCALL %s - task: %s 0x%" PRIxPTR \ "> UPCALL %s - task: %s 0x%" PRIxPTR \
" retpc: x%" PRIxPTR \ " retpc: x%" PRIxPTR \
" ref_count: %d", \ " ref_count: %d", \
@@ -14,8 +14,7 @@
(task->ref_count)); (task->ref_count));
#else #else
#define LOG_UPCALL_ENTRY(task) \ #define LOG_UPCALL_ENTRY(task) \
LOG_I(task, rust_log::UPCALL, \ LOG(task, upcall, "> UPCALL task: %s @x%" PRIxPTR, \
"> UPCALL task: %s @x%" PRIxPTR, \
(task)->name, (task)); (task)->name, (task));
#endif #endif
@@ -29,52 +28,70 @@ upcall_grow_task(rust_task *task, size_t n_frame_bytes) {
} }
extern "C" CDECL extern "C" CDECL
void upcall_log_int(rust_task *task, int32_t level, int32_t i) { void upcall_log_int(rust_task *task, uint32_t level, int32_t i) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::ULOG, if (task->dom->log_lvl >= level)
"rust: %" PRId32 " (0x%" PRIx32 ")", i, i); task->dom->log(task, level, "rust: %" PRId32 " (0x%" PRIx32 ")",
i, i);
} }
extern "C" CDECL extern "C" CDECL
void upcall_log_float(rust_task *task, int32_t level, float f) { void upcall_log_int_rustboot(rust_task *task, uint32_t level, int32_t i) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::ULOG, if (task->dom->log_lvl >= level && log_rustboot >= level)
"rust: %12.12f", f); task->dom->log(task, level, "rust: %" PRId32 " (0x%" PRIx32 ")",
i, i);
} }
extern "C" CDECL extern "C" CDECL
void upcall_log_double(rust_task *task, int32_t level, double *f) { void upcall_log_float(rust_task *task, uint32_t level, float f) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::ULOG, if (task->dom->log_lvl >= level)
"rust: %12.12f", *f); task->dom->log(task, level, "rust: %12.12f", f);
}
extern "C" CDECL
void upcall_log_double(rust_task *task, uint32_t level, double *f) {
LOG_UPCALL_ENTRY(task);
if (task->dom->log_lvl >= level)
task->dom->log(task, level, "rust: %12.12f", *f);
} }
extern "C" CDECL void extern "C" CDECL void
upcall_log_str(rust_task *task, int32_t level, rust_str *str) { upcall_log_str_rustboot(rust_task *task, uint32_t level, rust_str *str) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
if (task->dom->log_lvl >= level && log_rustboot >= level) {
const char *c = str_buf(task, str); const char *c = str_buf(task, str);
LOG(task, rust_log::UPCALL | rust_log::ULOG, "rust: %s", c); task->dom->log(task, level, "rust: %s", c);
}
}
extern "C" CDECL void
upcall_log_str(rust_task *task, uint32_t level, rust_str *str) {
LOG_UPCALL_ENTRY(task);
if (task->dom->log_lvl >= level) {
const char *c = str_buf(task, str);
task->dom->log(task, level, "rust: %s", c);
}
} }
extern "C" CDECL void extern "C" CDECL void
upcall_trace_word(rust_task *task, uintptr_t i) { upcall_trace_word(rust_task *task, uintptr_t i) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::TRACE, "trace: 0x%" PRIxPTR "", i, task->dom->log(task, 2, "trace: 0x%" PRIxPTR "", i, i, (char) i);
i, (char) i);
} }
extern "C" CDECL void extern "C" CDECL void
upcall_trace_str(rust_task *task, char const *c) { upcall_trace_str(rust_task *task, char const *c) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::TRACE, "trace: %s", c); task->dom->log(task, 2, "trace: %s", c);
} }
extern "C" CDECL rust_port* extern "C" CDECL rust_port*
upcall_new_port(rust_task *task, size_t unit_sz) { upcall_new_port(rust_task *task, size_t unit_sz) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_dom *dom = task->dom; rust_dom *dom = task->dom;
LOG(task, rust_log::UPCALL | rust_log::MEM | rust_log::COMM, LOG(task, comm, "upcall_new_port(task=0x%" PRIxPTR " (%s), unit_sz=%d)",
"upcall_new_port(task=0x%" PRIxPTR " (%s), unit_sz=%d)",
(uintptr_t) task, task->name, unit_sz); (uintptr_t) task, task->name, unit_sz);
return new (dom) rust_port(task, unit_sz); return new (dom) rust_port(task, unit_sz);
} }
@@ -82,8 +99,7 @@ upcall_new_port(rust_task *task, size_t unit_sz) {
extern "C" CDECL void extern "C" CDECL void
upcall_del_port(rust_task *task, rust_port *port) { upcall_del_port(rust_task *task, rust_port *port) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::MEM | rust_log::COMM, LOG(task, comm, "upcall del_port(0x%" PRIxPTR ")", (uintptr_t) port);
"upcall del_port(0x%" PRIxPTR ")", (uintptr_t) port);
I(task->dom, !port->ref_count); I(task->dom, !port->ref_count);
delete port; delete port;
} }
@@ -95,8 +111,7 @@ extern "C" CDECL rust_chan*
upcall_new_chan(rust_task *task, rust_port *port) { upcall_new_chan(rust_task *task, rust_port *port) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_dom *dom = task->dom; rust_dom *dom = task->dom;
LOG(task, rust_log::UPCALL | rust_log::MEM | rust_log::COMM, LOG(task, comm, "upcall_new_chan("
"upcall_new_chan("
"task=0x%" PRIxPTR " (%s), port=0x%" PRIxPTR ")", "task=0x%" PRIxPTR " (%s), port=0x%" PRIxPTR ")",
(uintptr_t) task, task->name, port); (uintptr_t) task, task->name, port);
I(dom, port); I(dom, port);
@@ -124,8 +139,7 @@ extern "C" CDECL
void upcall_del_chan(rust_task *task, rust_chan *chan) { void upcall_del_chan(rust_task *task, rust_chan *chan) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::MEM | rust_log::COMM, LOG(task, comm, "upcall del_chan(0x%" PRIxPTR ")", (uintptr_t) chan);
"upcall del_chan(0x%" PRIxPTR ")", (uintptr_t) chan);
A(task->dom, chan->ref_count == 0, A(task->dom, chan->ref_count == 0,
"Channel's ref count should be zero."); "Channel's ref count should be zero.");
@@ -175,7 +189,7 @@ upcall_clone_chan(rust_task *task, maybe_proxy<rust_task> *target,
rust_handle<rust_port> *handle = rust_handle<rust_port> *handle =
task->dom->kernel->get_port_handle(port->as_referent()); task->dom->kernel->get_port_handle(port->as_referent());
maybe_proxy<rust_port> *proxy = new rust_proxy<rust_port> (handle); maybe_proxy<rust_port> *proxy = new rust_proxy<rust_port> (handle);
LOG(task, rust_log::MEM, "new proxy: " PTR, proxy); LOG(task, mem, "new proxy: " PTR, proxy);
port = proxy; port = proxy;
target_task = target->as_proxy()->handle()->referent(); target_task = target->as_proxy()->handle()->referent();
} }
@@ -185,16 +199,16 @@ upcall_clone_chan(rust_task *task, maybe_proxy<rust_task> *target,
extern "C" CDECL void extern "C" CDECL void
upcall_yield(rust_task *task) { upcall_yield(rust_task *task) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::COMM, "upcall yield()"); LOG(task, comm, "upcall yield()");
task->yield(1); task->yield(1);
} }
extern "C" CDECL void extern "C" CDECL void
upcall_sleep(rust_task *task, size_t time_in_us) { upcall_sleep(rust_task *task, size_t time_in_us) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::TASK, "elapsed %d", LOG(task, task, "elapsed %d",
task->yield_timer.get_elapsed_time()); task->yield_timer.get_elapsed_time());
LOG(task, rust_log::UPCALL | rust_log::TASK, "sleep %d us", time_in_us); LOG(task, task, "sleep %d us", time_in_us);
task->yield(2, time_in_us); task->yield(2, time_in_us);
} }
@@ -228,14 +242,13 @@ extern "C" CDECL void
upcall_send(rust_task *task, rust_chan *chan, void *sptr) { upcall_send(rust_task *task, rust_chan *chan, void *sptr) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
chan->send(sptr); chan->send(sptr);
LOG(task, rust_log::COMM, "=== sent data ===>"); LOG(task, comm, "=== sent data ===>");
} }
extern "C" CDECL void extern "C" CDECL void
upcall_recv(rust_task *task, uintptr_t *dptr, rust_port *port) { upcall_recv(rust_task *task, uintptr_t *dptr, rust_port *port) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::COMM, LOG(task, comm, "port: 0x%" PRIxPTR ", dptr: 0x%" PRIxPTR
"port: 0x%" PRIxPTR ", dptr: 0x%" PRIxPTR
", size: 0x%" PRIxPTR ", chan_no: %d", ", size: 0x%" PRIxPTR ", chan_no: %d",
(uintptr_t) port, (uintptr_t) dptr, port->unit_sz, (uintptr_t) port, (uintptr_t) dptr, port->unit_sz,
port->chans.length()); port->chans.length());
@@ -248,7 +261,7 @@ upcall_recv(rust_task *task, uintptr_t *dptr, rust_port *port) {
// on the port. Remember the rendezvous location so that any sender // on the port. Remember the rendezvous location so that any sender
// task can write to it before waking up this task. // task can write to it before waking up this task.
LOG(task, rust_log::COMM, "<=== waiting for rendezvous data ==="); LOG(task, comm, "<=== waiting for rendezvous data ===");
task->rendezvous_ptr = dptr; task->rendezvous_ptr = dptr;
task->block(port, "waiting for rendezvous data"); task->block(port, "waiting for rendezvous data");
task->yield(3); task->yield(3);
@@ -260,8 +273,7 @@ upcall_fail(rust_task *task,
char const *file, char const *file,
size_t line) { size_t line) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::ERR, LOG_ERR(task, upcall, "upcall fail '%s', %s:%" PRIdPTR, expr, file, line);
"upcall fail '%s', %s:%" PRIdPTR, expr, file, line);
task->fail(4); task->fail(4);
if (getenv("RUST_TRAP_FAILURE")) { if (getenv("RUST_TRAP_FAILURE")) {
// FIXME: x86-ism. // FIXME: x86-ism.
@@ -292,8 +304,7 @@ upcall_kill(rust_task *task, maybe_proxy<rust_task> *target) {
extern "C" CDECL void extern "C" CDECL void
upcall_exit(rust_task *task) { upcall_exit(rust_task *task) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::TASK, LOG(task, task, "task ref_count: %d", task->ref_count);
"task ref_count: %d", task->ref_count);
A(task->dom, task->ref_count >= 0, A(task->dom, task->ref_count >= 0,
"Task ref_count should not be negative on exit!"); "Task ref_count should not be negative on exit!");
task->die(); task->die();
@@ -305,12 +316,12 @@ extern "C" CDECL uintptr_t
upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) { upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL|rust_log::MEM, LOG(task, mem,
"upcall malloc(%" PRIdPTR ", 0x%" PRIxPTR ")" "upcall malloc(%" PRIdPTR ", 0x%" PRIxPTR ")"
" with gc-chain head = 0x%" PRIxPTR, " with gc-chain head = 0x%" PRIxPTR,
nbytes, td, task->gc_alloc_chain); nbytes, td, task->gc_alloc_chain);
void *p = task->malloc(nbytes, td); void *p = task->malloc(nbytes, td);
LOG(task, rust_log::UPCALL|rust_log::MEM, LOG(task, mem,
"upcall malloc(%" PRIdPTR ", 0x%" PRIxPTR "upcall malloc(%" PRIdPTR ", 0x%" PRIxPTR
") = 0x%" PRIxPTR ") = 0x%" PRIxPTR
" with gc-chain head = 0x%" PRIxPTR, " with gc-chain head = 0x%" PRIxPTR,
@@ -325,7 +336,7 @@ extern "C" CDECL void
upcall_free(rust_task *task, void* ptr, uintptr_t is_gc) { upcall_free(rust_task *task, void* ptr, uintptr_t is_gc) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_dom *dom = task->dom; rust_dom *dom = task->dom;
DLOG(dom, rust_log::UPCALL|rust_log::MEM, DLOG(dom, mem,
"upcall free(0x%" PRIxPTR ", is_gc=%" PRIdPTR ")", "upcall free(0x%" PRIxPTR ", is_gc=%" PRIdPTR ")",
(uintptr_t)ptr, is_gc); (uintptr_t)ptr, is_gc);
task->free(ptr, (bool) is_gc); task->free(ptr, (bool) is_gc);
@@ -339,8 +350,7 @@ upcall_mark(rust_task *task, void* ptr) {
if (ptr) { if (ptr) {
gc_alloc *gcm = (gc_alloc*) (((char*)ptr) - sizeof(gc_alloc)); gc_alloc *gcm = (gc_alloc*) (((char*)ptr) - sizeof(gc_alloc));
uintptr_t marked = (uintptr_t) gcm->mark(); uintptr_t marked = (uintptr_t) gcm->mark();
DLOG(dom, rust_log::UPCALL|rust_log::MEM|rust_log::GC, DLOG(dom, gc, "upcall mark(0x%" PRIxPTR ") = %" PRIdPTR,
"upcall mark(0x%" PRIxPTR ") = %" PRIdPTR,
(uintptr_t)gcm, marked); (uintptr_t)gcm, marked);
return marked; return marked;
} }
@@ -358,7 +368,7 @@ upcall_new_str(rust_task *task, char const *s, size_t fill) {
return NULL; return NULL;
} }
rust_str *st = new (mem) rust_str(dom, alloc, fill, (uint8_t const *) s); rust_str *st = new (mem) rust_str(dom, alloc, fill, (uint8_t const *) s);
LOG(task, rust_log::UPCALL | rust_log::MEM, LOG(task, mem,
"upcall new_str('%s', %" PRIdPTR ") = 0x%" PRIxPTR, "upcall new_str('%s', %" PRIdPTR ") = 0x%" PRIxPTR,
s, fill, st); s, fill, st);
return st; return st;
@@ -368,9 +378,7 @@ extern "C" CDECL rust_vec *
upcall_new_vec(rust_task *task, size_t fill, type_desc *td) { upcall_new_vec(rust_task *task, size_t fill, type_desc *td) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_dom *dom = task->dom; rust_dom *dom = task->dom;
DLOG(dom, rust_log::UPCALL|rust_log::MEM, DLOG(dom, mem, "upcall new_vec(%" PRIdPTR ")", fill);
"upcall new_vec(%" PRIdPTR ")",
fill);
size_t alloc = next_power_of_two(sizeof(rust_vec) + fill); size_t alloc = next_power_of_two(sizeof(rust_vec) + fill);
void *mem = task->malloc(alloc, td); void *mem = task->malloc(alloc, td);
if (!mem) { if (!mem) {
@@ -378,7 +386,7 @@ upcall_new_vec(rust_task *task, size_t fill, type_desc *td) {
return NULL; return NULL;
} }
rust_vec *v = new (mem) rust_vec(dom, alloc, 0, NULL); rust_vec *v = new (mem) rust_vec(dom, alloc, 0, NULL);
LOG(task, rust_log::UPCALL | rust_log::MEM, LOG(task, mem,
"upcall new_vec(%" PRIdPTR ") = 0x%" PRIxPTR, fill, v); "upcall new_vec(%" PRIdPTR ") = 0x%" PRIxPTR, fill, v);
return v; return v;
} }
@@ -392,7 +400,7 @@ upcall_vec_grow(rust_task *task,
{ {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_dom *dom = task->dom; rust_dom *dom = task->dom;
LOG(task, rust_log::UPCALL | rust_log::MEM, LOG(task, mem,
"upcall vec_grow(0x%" PRIxPTR ", %" PRIdPTR "upcall vec_grow(0x%" PRIxPTR ", %" PRIdPTR
"), alloc=%" PRIdPTR ", fill=%" PRIdPTR "), alloc=%" PRIdPTR ", fill=%" PRIdPTR
", need_copy=0x%" PRIxPTR, ", need_copy=0x%" PRIxPTR,
@@ -405,12 +413,12 @@ upcall_vec_grow(rust_task *task,
// Fastest path: already large enough. // Fastest path: already large enough.
if (v->alloc >= alloc) { if (v->alloc >= alloc) {
LOG(task, rust_log::UPCALL | rust_log::MEM, "no-growth path"); LOG(task, mem, "no-growth path");
return v; return v;
} }
// Second-fastest path: can at least realloc. // Second-fastest path: can at least realloc.
LOG(task, rust_log::UPCALL | rust_log::MEM, "realloc path"); LOG(task, mem, "realloc path");
v = (rust_vec*) task->realloc(v, alloc, td->is_stateful); v = (rust_vec*) task->realloc(v, alloc, td->is_stateful);
if (!v) { if (!v) {
task->fail(4); task->fail(4);
@@ -432,7 +440,7 @@ upcall_vec_grow(rust_task *task,
* need_copy outparam flag to indicate to our caller (vec-copy glue) * need_copy outparam flag to indicate to our caller (vec-copy glue)
* that we need the copies performed for us. * that we need the copies performed for us.
*/ */
LOG(task, rust_log::UPCALL | rust_log::MEM, "new vec path"); LOG(task, mem, "new vec path");
void *mem = task->malloc(alloc, td); void *mem = task->malloc(alloc, td);
if (!mem) { if (!mem) {
task->fail(4); task->fail(4);
@@ -472,24 +480,22 @@ upcall_require_rust_sym(rust_task *task,
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_dom *dom = task->dom; rust_dom *dom = task->dom;
LOG(task, rust_log::UPCALL | rust_log::CACHE, LOG(task, cache, "upcall require rust sym: lib #%" PRIdPTR
"upcall require rust sym: lib #%" PRIdPTR
" = %s, c_sym #%" PRIdPTR " = %s, c_sym #%" PRIdPTR
", rust_sym #%" PRIdPTR ", rust_sym #%" PRIdPTR
", curr_crate = 0x%" PRIxPTR, lib_num, library, c_sym_num, ", curr_crate = 0x%" PRIxPTR, lib_num, library, c_sym_num,
rust_sym_num, curr_crate); rust_sym_num, curr_crate);
for (char const **c = crate_rel(curr_crate, path); *c; ++c) { for (char const **c = crate_rel(curr_crate, path); *c; ++c) {
LOG(task, rust_log::UPCALL, " + %s", crate_rel(curr_crate, *c)); LOG(task, upcall, " + %s", crate_rel(curr_crate, *c));
} }
LOG(task, rust_log::UPCALL | rust_log::CACHE, LOG(task, cache, "require C symbol 'rust_crate' from lib #%" PRIdPTR,
"require C symbol 'rust_crate' from lib #%" PRIdPTR, lib_num); lib_num);
rust_crate_cache::c_sym *c = rust_crate_cache::c_sym *c =
fetch_c_sym(task, curr_crate, lib_num, c_sym_num, library, fetch_c_sym(task, curr_crate, lib_num, c_sym_num, library,
"rust_crate"); "rust_crate");
LOG(task, rust_log::UPCALL | rust_log::CACHE, LOG(task, cache, "require rust symbol inside crate");
"require rust symbol inside crate");
rust_crate_cache::rust_sym *s = task->cache->get_rust_sym(rust_sym_num, rust_crate_cache::rust_sym *s = task->cache->get_rust_sym(rust_sym_num,
dom, dom,
curr_crate, c, curr_crate, c,
@@ -497,11 +503,9 @@ upcall_require_rust_sym(rust_task *task,
uintptr_t addr = s->get_val(); uintptr_t addr = s->get_val();
if (addr) { if (addr) {
LOG(task, rust_log::UPCALL | rust_log::CACHE, LOG(task, cache, "found-or-cached addr: 0x%" PRIxPTR, addr);
"found-or-cached addr: 0x%" PRIxPTR, addr);
} else { } else {
LOG(task, rust_log::UPCALL | rust_log::CACHE | rust_log::ERR, LOG_ERR(task, cache, "failed to resolve symbol");
"failed to resolve symbol");
task->fail(7); task->fail(7);
} }
return addr; return addr;
@@ -516,8 +520,7 @@ upcall_require_c_sym(rust_task *task,
char const *symbol) { char const *symbol) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::CACHE, LOG(task, cache, "upcall require c sym: lib #%" PRIdPTR
"upcall require c sym: lib #%" PRIdPTR
" = %s, c_sym #%" PRIdPTR " = %s, c_sym #%" PRIdPTR
" = %s" " = %s"
", curr_crate = 0x%" PRIxPTR, lib_num, library, c_sym_num, ", curr_crate = 0x%" PRIxPTR, lib_num, library, c_sym_num,
@@ -528,11 +531,11 @@ upcall_require_c_sym(rust_task *task,
uintptr_t addr = c->get_val(); uintptr_t addr = c->get_val();
if (addr) { if (addr) {
LOG(task, rust_log::UPCALL | rust_log::CACHE, LOG(task, cache,
"found-or-cached addr: 0x%" PRIxPTR, addr); "found-or-cached addr: 0x%" PRIxPTR, addr);
} else { } else {
LOG(task, rust_log::UPCALL | rust_log::CACHE | rust_log::ERR, LOG_ERR(task, cache, "failed to resolve symbol %s in %s",
"failed to resolve symbol %s in %s", symbol, library); symbol, library);
task->fail(6); task->fail(6);
} }
return addr; return addr;
@@ -546,14 +549,12 @@ upcall_get_type_desc(rust_task *task,
size_t n_descs, size_t n_descs,
type_desc const **descs) { type_desc const **descs) {
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, rust_log::UPCALL | rust_log::CACHE, LOG(task, cache, "upcall get_type_desc with size=%" PRIdPTR
"upcall get_type_desc with size=%" PRIdPTR
", align=%" PRIdPTR ", %" PRIdPTR " descs", size, align, ", align=%" PRIdPTR ", %" PRIdPTR " descs", size, align,
n_descs); n_descs);
rust_crate_cache *cache = task->get_crate_cache(curr_crate); rust_crate_cache *cache = task->get_crate_cache(curr_crate);
type_desc *td = cache->get_type_desc(size, align, n_descs, descs); type_desc *td = cache->get_type_desc(size, align, n_descs, descs);
LOG(task, rust_log::UPCALL | rust_log::CACHE, LOG(task, cache, "returning tydesc 0x%" PRIxPTR, td);
"returning tydesc 0x%" PRIxPTR, td);
return td; return td;
} }
@@ -575,7 +576,7 @@ upcall_start_task(rust_task *spawner,
LOG_UPCALL_ENTRY(spawner); LOG_UPCALL_ENTRY(spawner);
rust_dom *dom = spawner->dom; rust_dom *dom = spawner->dom;
DLOG(dom, rust_log::UPCALL | rust_log::MEM | rust_log::TASK, DLOG(dom, task,
"upcall start_task(task %s @0x%" PRIxPTR "upcall start_task(task %s @0x%" PRIxPTR
" exit_task_glue 0x%" PRIxPTR " exit_task_glue 0x%" PRIxPTR
", spawnee 0x%" PRIxPTR ", spawnee 0x%" PRIxPTR
@@ -598,8 +599,7 @@ upcall_new_thread(rust_task *task, const char *name) {
kernel->create_domain(parent_dom->root_crate, name); kernel->create_domain(parent_dom->root_crate, name);
rust_handle<rust_task> *child_task_handle = rust_handle<rust_task> *child_task_handle =
kernel->get_task_handle(child_dom_handle->referent()->root_task); kernel->get_task_handle(child_dom_handle->referent()->root_task);
LOG(task, rust_log::UPCALL | rust_log::MEM, LOG(task, mem, "child name: %s, child_dom_handle: " PTR
"child name: %s, child_dom_handle: " PTR
", child_task_handle: " PTR, ", child_task_handle: " PTR,
name, child_dom_handle, child_task_handle); name, child_dom_handle, child_task_handle);
rust_proxy<rust_task> *child_task_proxy = rust_proxy<rust_task> *child_task_proxy =
@@ -641,7 +641,7 @@ upcall_start_thread(rust_task *task,
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_dom *parenet_dom = task->dom; rust_dom *parenet_dom = task->dom;
rust_handle<rust_task> *child_task_handle = child_task_proxy->handle(); rust_handle<rust_task> *child_task_handle = child_task_proxy->handle();
LOG(task, rust_log::UPCALL | rust_log::MEM | rust_log::TASK, LOG(task, task,
"exit_task_glue: " PTR ", spawnee_fn " PTR "exit_task_glue: " PTR ", spawnee_fn " PTR
", callsz %" PRIdPTR ")", ", callsz %" PRIdPTR ")",
exit_task_glue, spawnee_fn, callsz); exit_task_glue, spawnee_fn, callsz);

View File

@@ -24,8 +24,7 @@ ptr_vec<T>::ptr_vec(rust_dom *dom) :
data(new (dom) T*[alloc]) data(new (dom) T*[alloc])
{ {
I(dom, data); I(dom, data);
DLOG(dom, rust_log::MEM, DLOG(dom, mem, "new ptr_vec(data=0x%" PRIxPTR ") -> 0x%" PRIxPTR,
"new ptr_vec(data=0x%" PRIxPTR ") -> 0x%" PRIxPTR,
(uintptr_t)data, (uintptr_t)this); (uintptr_t)data, (uintptr_t)this);
} }
@@ -33,8 +32,7 @@ template <typename T>
ptr_vec<T>::~ptr_vec() ptr_vec<T>::~ptr_vec()
{ {
I(dom, data); I(dom, data);
DLOG(dom, rust_log::MEM, DLOG(dom, mem, "~ptr_vec 0x%" PRIxPTR ", data=0x%" PRIxPTR,
"~ptr_vec 0x%" PRIxPTR ", data=0x%" PRIxPTR,
(uintptr_t)this, (uintptr_t)data); (uintptr_t)this, (uintptr_t)data);
I(dom, fill == 0); I(dom, fill == 0);
dom->free(data); dom->free(data);