2012-12-10 17:44:02 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2011-09-23 13:42:20 -05:00
|
|
|
// Routines useful when debugging the Rust runtime.
|
|
|
|
|
2012-04-02 22:18:01 -05:00
|
|
|
#include "rust_globals.h"
|
2011-09-23 17:05:24 -05:00
|
|
|
#include "rust_abi.h"
|
2011-09-23 13:42:20 -05:00
|
|
|
#include "rust_debug.h"
|
2012-04-02 22:18:01 -05:00
|
|
|
#include "rust_task.h"
|
2011-09-23 13:42:20 -05:00
|
|
|
|
|
|
|
#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;
|
2011-09-23 17:05:24 -05:00
|
|
|
task->debug.origins[ptr] =
|
|
|
|
stack_walk::symbolicate(stack_walk::backtrace());
|
2011-09-23 13:42:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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 <<
|
2011-09-23 14:27:13 -05:00
|
|
|
" does not have a tracked origin." << std::endl;
|
2011-09-23 13:42:20 -05:00
|
|
|
} else {
|
2011-09-23 14:27:13 -05:00
|
|
|
std::cerr << "Origin of pointer " << std::hex << (uintptr_t)ptr <<
|
|
|
|
":" << std::endl << task->debug.origins[ptr] <<
|
|
|
|
std::endl;
|
2011-09-23 13:42:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace debug
|
|
|
|
|