Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to macro-based logging checks in the C++ code #315

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/rt/circular_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ circular_buffer::circular_buffer(rust_dom *dom, size_t unit_sz) :

A(dom, unit_sz, "Unit size must be larger than zero.");

dom->log(rust_log::MEM | rust_log::COMM,
DLOG(dom, rust_log::MEM | rust_log::COMM,
"new circular_buffer(buffer_sz=%d, unread=%d)"
"-> circular_buffer=0x%" PRIxPTR,
_buffer_sz, _unread, this);
Expand All @@ -23,7 +23,7 @@ circular_buffer::circular_buffer(rust_dom *dom, size_t unit_sz) :
}

circular_buffer::~circular_buffer() {
dom->log(rust_log::MEM, "~circular_buffer 0x%" PRIxPTR, this);
DLOG(dom, rust_log::MEM, "~circular_buffer 0x%" PRIxPTR, this);
I(dom, _buffer);
W(dom, _unread == 0,
"freeing circular_buffer with %d unread bytes", _unread);
Expand Down Expand Up @@ -79,7 +79,7 @@ circular_buffer::enqueue(void *src) {
grow();
}

dom->log(rust_log::MEM | rust_log::COMM,
DLOG(dom, rust_log::MEM | rust_log::COMM,
"circular_buffer enqueue "
"unread: %d, next: %d, buffer_sz: %d, unit_sz: %d",
_unread, _next, _buffer_sz, unit_sz);
Expand All @@ -101,7 +101,7 @@ circular_buffer::enqueue(void *src) {
memcpy(&_buffer[dst_idx], src, unit_sz);
_unread += unit_sz;

dom->log(rust_log::MEM | rust_log::COMM,
DLOG(dom, rust_log::MEM | rust_log::COMM,
"circular_buffer pushed data at index: %d", dst_idx);
}

Expand All @@ -117,7 +117,7 @@ circular_buffer::dequeue(void *dst) {
I(dom, _unread <= _buffer_sz);
I(dom, _buffer);

dom->log(rust_log::MEM | rust_log::COMM,
DLOG(dom, rust_log::MEM | rust_log::COMM,
"circular_buffer dequeue "
"unread: %d, next: %d, buffer_sz: %d, unit_sz: %d",
_unread, _next, _buffer_sz, unit_sz);
Expand All @@ -126,7 +126,7 @@ circular_buffer::dequeue(void *dst) {
if (dst != NULL) {
memcpy(dst, &_buffer[_next], unit_sz);
}
dom->log(rust_log::MEM | rust_log::COMM,
DLOG(dom, rust_log::MEM | rust_log::COMM,
"shifted data from index %d", _next);
_unread -= unit_sz;
_next += unit_sz;
Expand All @@ -144,7 +144,7 @@ void
circular_buffer::grow() {
size_t new_buffer_sz = _buffer_sz * 2;
I(dom, new_buffer_sz <= MAX_CIRCULAR_BUFFER_SIZE);
dom->log(rust_log::MEM | rust_log::COMM,
DLOG(dom, rust_log::MEM | rust_log::COMM,
"circular_buffer is growing to %d bytes", new_buffer_sz);
void *new_buffer = dom->malloc(new_buffer_sz);
transfer(new_buffer);
Expand All @@ -158,7 +158,7 @@ void
circular_buffer::shrink() {
size_t new_buffer_sz = _buffer_sz / 2;
I(dom, initial_size() <= new_buffer_sz);
dom->log(rust_log::MEM | rust_log::COMM,
DLOG(dom, rust_log::MEM | rust_log::COMM,
"circular_buffer is shrinking to %d bytes", new_buffer_sz);
void *new_buffer = dom->malloc(new_buffer_sz);
transfer(new_buffer);
Expand Down
4 changes: 2 additions & 2 deletions src/rt/rust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ rust_start(uintptr_t main_fn, rust_crate const *crate, int argc,
rust_dom *dom = handle->referent();
command_line_args *args = new (dom) command_line_args(dom, argc, argv);

dom->log(rust_log::DOM, "startup: %d args in 0x%" PRIxPTR,
DLOG(dom, rust_log::DOM, "startup: %d args in 0x%" PRIxPTR,
args->argc, (uintptr_t)args->args);
for (int i = 0; i < args->argc; i++) {
dom->log(rust_log::DOM,
DLOG(dom, rust_log::DOM,
"startup: arg[%d] = '%s'", i, args->argv[i]);
}

Expand Down
54 changes: 27 additions & 27 deletions src/rt/rust_builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern "C" CDECL rust_str*
last_os_error(rust_task *task) {
rust_dom *dom = task->dom;
task->log(rust_log::TASK, "last_os_error()");
LOG(task, rust_log::TASK, "last_os_error()");

#if defined(__WIN32__)
LPTSTR buf;
Expand Down Expand Up @@ -91,7 +91,7 @@ extern "C" CDECL rust_vec*
vec_alloc(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
{
rust_dom *dom = task->dom;
task->log(rust_log::MEM | rust_log::STDLIB,
LOG(task, rust_log::MEM | rust_log::STDLIB,
"vec_alloc %" PRIdPTR " elements of size %" PRIdPTR,
n_elts, elem_t->size);
size_t fill = n_elts * elem_t->size;
Expand Down Expand Up @@ -126,7 +126,7 @@ vec_len(rust_task *task, type_desc *ty, rust_vec *v)
extern "C" CDECL void
vec_len_set(rust_task *task, type_desc *ty, rust_vec *v, size_t len)
{
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
"vec_len_set(0x%" PRIxPTR ", %" PRIdPTR ") on vec with "
"alloc = %" PRIdPTR
", fill = %" PRIdPTR
Expand All @@ -139,7 +139,7 @@ vec_len_set(rust_task *task, type_desc *ty, rust_vec *v, size_t len)
extern "C" CDECL void
vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v)
{
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
"vec_print_debug_info(0x%" PRIxPTR ")"
" with tydesc 0x%" PRIxPTR
" (size = %" PRIdPTR ", align = %" PRIdPTR ")"
Expand All @@ -154,7 +154,7 @@ vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v)
v->fill / ty->size);

for (size_t i = 0; i < v->fill; ++i) {
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
" %" PRIdPTR ": 0x%" PRIxPTR,
i, v->data[i]);
}
Expand Down Expand Up @@ -306,7 +306,7 @@ task_sleep(rust_task *task, size_t time_in_us) {
static void
debug_tydesc_helper(rust_task *task, type_desc *t)
{
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
" size %" PRIdPTR ", align %" PRIdPTR
", stateful %" PRIdPTR ", first_param 0x%" PRIxPTR,
t->size, t->align, t->is_stateful, t->first_param);
Expand All @@ -315,19 +315,19 @@ debug_tydesc_helper(rust_task *task, type_desc *t)
extern "C" CDECL void
debug_tydesc(rust_task *task, type_desc *t)
{
task->log(rust_log::STDLIB, "debug_tydesc");
LOG(task, rust_log::STDLIB, "debug_tydesc");
debug_tydesc_helper(task, t);
}

extern "C" CDECL void
debug_opaque(rust_task *task, type_desc *t, uint8_t *front)
{
task->log(rust_log::STDLIB, "debug_opaque");
LOG(task, rust_log::STDLIB, "debug_opaque");
debug_tydesc_helper(task, t);
// FIXME may want to actually account for alignment. `front` may not
// indeed be the front byte of the passed-in argument.
for (uintptr_t i = 0; i < t->size; ++front, ++i) {
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
" byte %" PRIdPTR ": 0x%" PRIx8, i, *front);
}
}
Expand All @@ -340,14 +340,14 @@ struct rust_box : rc_base<rust_box> {
extern "C" CDECL void
debug_box(rust_task *task, type_desc *t, rust_box *box)
{
task->log(rust_log::STDLIB, "debug_box(0x%" PRIxPTR ")", box);
LOG(task, rust_log::STDLIB, "debug_box(0x%" PRIxPTR ")", box);
debug_tydesc_helper(task, t);
task->log(rust_log::STDLIB, " refcount %" PRIdPTR,
LOG(task, rust_log::STDLIB, " refcount %" PRIdPTR,
box->ref_count == CONST_REFCOUNT
? CONST_REFCOUNT
: box->ref_count - 1); // -1 because we ref'ed for this call
for (uintptr_t i = 0; i < t->size; ++i) {
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
" byte %" PRIdPTR ": 0x%" PRIx8, i, box->data[i]);
}
}
Expand All @@ -360,13 +360,13 @@ struct rust_tag {
extern "C" CDECL void
debug_tag(rust_task *task, type_desc *t, rust_tag *tag)
{
task->log(rust_log::STDLIB, "debug_tag");
LOG(task, rust_log::STDLIB, "debug_tag");
debug_tydesc_helper(task, t);
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
" discriminant %" PRIdPTR, tag->discriminant);

for (uintptr_t i = 0; i < t->size - sizeof(tag->discriminant); ++i)
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
" byte %" PRIdPTR ": 0x%" PRIx8, i, tag->variant[i]);
}

Expand All @@ -379,17 +379,17 @@ extern "C" CDECL void
debug_obj(rust_task *task, type_desc *t, rust_obj *obj,
size_t nmethods, size_t nbytes)
{
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
"debug_obj with %" PRIdPTR " methods", nmethods);
debug_tydesc_helper(task, t);
task->log(rust_log::STDLIB, " vtbl at 0x%" PRIxPTR, obj->vtbl);
task->log(rust_log::STDLIB, " body at 0x%" PRIxPTR, obj->body);
LOG(task, rust_log::STDLIB, " vtbl at 0x%" PRIxPTR, obj->vtbl);
LOG(task, rust_log::STDLIB, " body at 0x%" PRIxPTR, obj->body);

for (uintptr_t *p = obj->vtbl; p < obj->vtbl + nmethods; ++p)
task->log(rust_log::STDLIB, " vtbl word: 0x%" PRIxPTR, *p);
LOG(task, rust_log::STDLIB, " vtbl word: 0x%" PRIxPTR, *p);

for (uintptr_t i = 0; i < nbytes; ++i)
task->log(rust_log::STDLIB,
LOG(task, rust_log::STDLIB,
" body byte %" PRIdPTR ": 0x%" PRIxPTR,
i, obj->body->data[i]);
}
Expand All @@ -402,12 +402,12 @@ struct rust_fn {
extern "C" CDECL void
debug_fn(rust_task *task, type_desc *t, rust_fn *fn)
{
task->log(rust_log::STDLIB, "debug_fn");
LOG(task, rust_log::STDLIB, "debug_fn");
debug_tydesc_helper(task, t);
task->log(rust_log::STDLIB, " thunk at 0x%" PRIxPTR, fn->thunk);
task->log(rust_log::STDLIB, " closure at 0x%" PRIxPTR, fn->closure);
LOG(task, rust_log::STDLIB, " thunk at 0x%" PRIxPTR, fn->thunk);
LOG(task, rust_log::STDLIB, " closure at 0x%" PRIxPTR, fn->closure);
if (fn->closure) {
task->log(rust_log::STDLIB, " refcount %" PRIdPTR,
LOG(task, rust_log::STDLIB, " refcount %" PRIdPTR,
fn->closure->ref_count);
}
}
Expand All @@ -418,17 +418,17 @@ debug_ptrcast(rust_task *task,
type_desc *to_ty,
void *ptr)
{
task->log(rust_log::STDLIB, "debug_ptrcast from");
LOG(task, rust_log::STDLIB, "debug_ptrcast from");
debug_tydesc_helper(task, from_ty);
task->log(rust_log::STDLIB, "to");
LOG(task, rust_log::STDLIB, "to");
debug_tydesc_helper(task, to_ty);
return ptr;
}

extern "C" CDECL void
debug_trap(rust_task *task, rust_str *s)
{
task->log(rust_log::STDLIB, "trapping: %s", s->data);
LOG(task, rust_log::STDLIB, "trapping: %s", s->data);
// FIXME: x86-ism.
__asm__("int3");
}
Expand Down
10 changes: 5 additions & 5 deletions src/rt/rust_chan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ rust_chan::rust_chan(rust_task *task,
if (port) {
associate(port);
}
task->log(rust_log::MEM | rust_log::COMM,
LOG(task, rust_log::MEM | rust_log::COMM,
"new rust_chan(task=0x%" PRIxPTR
", port=0x%" PRIxPTR ") -> chan=0x%" PRIxPTR,
(uintptr_t) task, (uintptr_t) port, (uintptr_t) this);
}

rust_chan::~rust_chan() {
task->log(rust_log::MEM | rust_log::COMM,
LOG(task, rust_log::MEM | rust_log::COMM,
"del rust_chan(task=0x%" PRIxPTR ")", (uintptr_t) this);

A(task->dom, is_associated() == false,
Expand All @@ -33,7 +33,7 @@ rust_chan::~rust_chan() {
void rust_chan::associate(maybe_proxy<rust_port> *port) {
this->port = port;
if (port->is_proxy() == false) {
task->log(rust_log::TASK,
LOG(task, rust_log::TASK,
"associating chan: 0x%" PRIxPTR " with port: 0x%" PRIxPTR,
this, port);
this->port->referent()->chans.push(this);
Expand All @@ -51,7 +51,7 @@ void rust_chan::disassociate() {
A(task->dom, is_associated(), "Channel must be associated with a port.");

if (port->is_proxy() == false) {
task->log(rust_log::TASK,
LOG(task, rust_log::TASK,
"disassociating chan: 0x%" PRIxPTR " from port: 0x%" PRIxPTR,
this, port->referent());
port->referent()->chans.swap_delete(this);
Expand Down Expand Up @@ -84,7 +84,7 @@ void rust_chan::send(void *sptr) {
} else {
rust_port *target_port = port->referent();
if (target_port->task->blocked_on(target_port)) {
dom->log(rust_log::COMM, "dequeued in rendezvous_ptr");
DLOG(dom, rust_log::COMM, "dequeued in rendezvous_ptr");
buffer.dequeue(target_port->task->rendezvous_ptr);
target_port->task->rendezvous_ptr = 0;
target_port->task->wakeup(target_port);
Expand Down
2 changes: 1 addition & 1 deletion src/rt/rust_crate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ rust_crate::mem_area::mem_area(rust_dom *dom, uintptr_t pos, size_t sz)
base(pos),
lim(pos + sz)
{
dom->log(rust_log::MEM, "new mem_area [0x%" PRIxPTR ",0x%" PRIxPTR "]",
DLOG(dom, rust_log::MEM, "new mem_area [0x%" PRIxPTR ",0x%" PRIxPTR "]",
base, lim);
}

Expand Down
Loading