1
Fork 0

Add vec debugging utility to _vec module.

This commit is contained in:
Roy Frostig 2010-08-12 13:11:49 -07:00
parent 5267b77d3b
commit 445d3fe39c
4 changed files with 25 additions and 1 deletions

View file

@ -10,6 +10,7 @@ native "rust" mod rustrt {
* want to invoke this as vec_alloc[vec[U], U]. */
fn vec_alloc[T, U](uint n_elts) -> vec[U];
fn refcount[T](vec[T] v) -> uint;
fn vec_print_debug_info[T](vec[T] v);
}
fn alloc[T](uint n_elts) -> vec[T] {
@ -58,6 +59,10 @@ fn buf_off[T](vec[T] v, uint offset) -> vbuf {
ret rustrt.vec_buf[T](v, offset);
}
fn print_debug_info[T](vec[T] v) {
rustrt.vec_print_debug_info[T](v);
}
// Returns elements from [start..end) from v.
fn slice[T](vec[T] v, int start, int end) -> vec[T] {
check(0 <= start);

View file

@ -82,7 +82,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,
task->log(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;
@ -108,6 +108,23 @@ vec_len(rust_task *task, type_desc *ty, rust_vec *v)
return v->fill / ty->size;
}
extern "C" CDECL void
vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v)
{
task->log(rust_log::STDLIB,
"vec_print_debug_info(%" PRIxPTR ")"
" with tydesc %" PRIxPTR
" (size = %" PRIdPTR ", align = %" PRIdPTR ")"
" alloc = %" PRIdPTR ", fill = %" PRIdPTR
" , data = ...", v, ty, ty->size, ty->align, v->alloc, v->fill);
for (size_t i = 0; i < v->fill; ++i) {
task->log(rust_log::STDLIB,
" %" PRIdPTR ": 0x%" PRIxPTR,
i, v->data[i]);
}
}
/* Helper for str_alloc and str_from_vec. Returns NULL as failure. */
static rust_str *
str_alloc_with_data(rust_task *task,

View file

@ -26,6 +26,7 @@ read_type_bit_mask() {
bits |= strstr(env_str, "cache") ? rust_log::CACHE : 0;
bits |= strstr(env_str, "timer") ? rust_log::TIMER : 0;
bits |= strstr(env_str, "gc") ? rust_log::GC : 0;
bits |= strstr(env_str, "stdlib") ? rust_log::STDLIB : 0;
bits |= strstr(env_str, "all") ? rust_log::ALL : 0;
bits = strstr(env_str, "none") ? 0 : bits;
}

View file

@ -41,6 +41,7 @@ public:
UPCALL = 0x200,
TIMER = 0x400,
GC = 0x800,
STDLIB = 0x1000,
ALL = 0xffffffff
};