Skip to content

Commit 445d3fe

Browse files
committed
Add vec debugging utility to _vec module.
1 parent 5267b77 commit 445d3fe

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/lib/_vec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ native "rust" mod rustrt {
1010
* want to invoke this as vec_alloc[vec[U], U]. */
1111
fn vec_alloc[T, U](uint n_elts) -> vec[U];
1212
fn refcount[T](vec[T] v) -> uint;
13+
fn vec_print_debug_info[T](vec[T] v);
1314
}
1415

1516
fn alloc[T](uint n_elts) -> vec[T] {
@@ -58,6 +59,10 @@ fn buf_off[T](vec[T] v, uint offset) -> vbuf {
5859
ret rustrt.vec_buf[T](v, offset);
5960
}
6061

62+
fn print_debug_info[T](vec[T] v) {
63+
rustrt.vec_print_debug_info[T](v);
64+
}
65+
6166
// Returns elements from [start..end) from v.
6267
fn slice[T](vec[T] v, int start, int end) -> vec[T] {
6368
check(0 <= start);

src/rt/rust_builtin.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extern "C" CDECL rust_vec*
8282
vec_alloc(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
8383
{
8484
rust_dom *dom = task->dom;
85-
task->log(rust_log::MEM,
85+
task->log(rust_log::MEM | rust_log::STDLIB,
8686
"vec_alloc %" PRIdPTR " elements of size %" PRIdPTR,
8787
n_elts, elem_t->size);
8888
size_t fill = n_elts * elem_t->size;
@@ -108,6 +108,23 @@ vec_len(rust_task *task, type_desc *ty, rust_vec *v)
108108
return v->fill / ty->size;
109109
}
110110

111+
extern "C" CDECL void
112+
vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v)
113+
{
114+
task->log(rust_log::STDLIB,
115+
"vec_print_debug_info(%" PRIxPTR ")"
116+
" with tydesc %" PRIxPTR
117+
" (size = %" PRIdPTR ", align = %" PRIdPTR ")"
118+
" alloc = %" PRIdPTR ", fill = %" PRIdPTR
119+
" , data = ...", v, ty, ty->size, ty->align, v->alloc, v->fill);
120+
121+
for (size_t i = 0; i < v->fill; ++i) {
122+
task->log(rust_log::STDLIB,
123+
" %" PRIdPTR ": 0x%" PRIxPTR,
124+
i, v->data[i]);
125+
}
126+
}
127+
111128
/* Helper for str_alloc and str_from_vec. Returns NULL as failure. */
112129
static rust_str *
113130
str_alloc_with_data(rust_task *task,

src/rt/rust_log.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ read_type_bit_mask() {
2626
bits |= strstr(env_str, "cache") ? rust_log::CACHE : 0;
2727
bits |= strstr(env_str, "timer") ? rust_log::TIMER : 0;
2828
bits |= strstr(env_str, "gc") ? rust_log::GC : 0;
29+
bits |= strstr(env_str, "stdlib") ? rust_log::STDLIB : 0;
2930
bits |= strstr(env_str, "all") ? rust_log::ALL : 0;
3031
bits = strstr(env_str, "none") ? 0 : bits;
3132
}

src/rt/rust_log.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class rust_log {
4141
UPCALL = 0x200,
4242
TIMER = 0x400,
4343
GC = 0x800,
44+
STDLIB = 0x1000,
4445
ALL = 0xffffffff
4546
};
4647

0 commit comments

Comments
 (0)