rust/src/rt/rust_debug.cpp
Jon Morton 632a4c9326 Refactor includes structure, getting rid of rust_internal.h
Many changes to code structure are included:
- removed TIME_SLICE_IN_MS
- removed sychronized_indexed_list
- removed region_owned
- kernel_owned move to kernel.h, task_owned moved to task.h
- global configs moved to rust_globals.h
- changed #pragma once to standard guard in rust_upcall.h
- got rid of memory.h
2012-04-03 16:02:38 -07:00

52 lines
1.3 KiB
C++

// Routines useful when debugging the Rust runtime.
#include "rust_globals.h"
#include "rust_abi.h"
#include "rust_debug.h"
#include "rust_task.h"
#include <iostream>
#include <string>
#include <sstream>
namespace {
debug::flag track_origins("RUST_TRACK_ORIGINS");
} // end anonymous namespace
namespace debug {
void
maybe_track_origin(rust_task *task, void *ptr) {
if (!*track_origins)
return;
task->debug.origins[ptr] =
stack_walk::symbolicate(stack_walk::backtrace());
}
void
maybe_untrack_origin(rust_task *task, void *ptr) {
if (!*track_origins)
return;
task->debug.origins.erase(ptr);
}
// This function is intended to be called by the debugger.
void
dump_origin(rust_task *task, void *ptr) {
if (!*track_origins) {
std::cerr << "Try again with RUST_TRACK_ORIGINS=1." << std::endl;
} else if (task->debug.origins.find(ptr) == task->debug.origins.end()) {
std::cerr << "Pointer " << std::hex << (uintptr_t)ptr <<
" does not have a tracked origin." << std::endl;
} else {
std::cerr << "Origin of pointer " << std::hex << (uintptr_t)ptr <<
":" << std::endl << task->debug.origins[ptr] <<
std::endl;
}
}
} // end namespace debug