2011-09-23 13:02:04 -05:00
|
|
|
// Routines useful when debugging the Rust runtime.
|
|
|
|
|
|
|
|
#ifndef RUST_DEBUG_H
|
|
|
|
#define RUST_DEBUG_H
|
|
|
|
|
2011-09-23 13:42:20 -05:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2011-09-23 13:02:04 -05:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2012-06-01 02:11:51 -05:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#define BREAKPOINT_AWESOME \
|
|
|
|
do { \
|
|
|
|
signal(SIGTRAP, SIG_IGN); \
|
|
|
|
raise(SIGTRAP); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define BREAKPOINT_AWESOME
|
|
|
|
#endif
|
|
|
|
|
2011-09-23 13:42:20 -05:00
|
|
|
struct rust_task;
|
|
|
|
|
2011-09-23 13:02:04 -05:00
|
|
|
namespace debug {
|
|
|
|
|
|
|
|
class flag {
|
|
|
|
private:
|
|
|
|
const char *name;
|
|
|
|
bool valid;
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
flag(const char *in_name) : name(in_name), valid(false) {}
|
|
|
|
|
|
|
|
bool operator*() {
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2689): We ought to lock this.
|
2011-09-23 13:02:04 -05:00
|
|
|
if (!valid) {
|
|
|
|
char *ev = getenv(name);
|
|
|
|
value = ev && ev[0] != '\0' && ev[0] != '0';
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-23 13:42:20 -05:00
|
|
|
class task_debug_info {
|
|
|
|
public:
|
|
|
|
std::map<void *,std::string> origins;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string backtrace();
|
|
|
|
|
|
|
|
void maybe_track_origin(rust_task *task, void *ptr);
|
|
|
|
void maybe_untrack_origin(rust_task *task, void *ptr);
|
|
|
|
|
|
|
|
// This function is intended to be called by the debugger.
|
|
|
|
void dump_origin(rust_task *task, void *ptr);
|
|
|
|
|
2011-09-23 13:02:04 -05:00
|
|
|
} // end namespace debug
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|