std: Add debug::breakpoint

This commit is contained in:
Brian Anderson
2012-06-01 00:11:51 -07:00
parent 469ff08e64
commit c816eea000
4 changed files with 33 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ export debug_tag;
export debug_fn; export debug_fn;
export ptr_cast; export ptr_cast;
export refcount; export refcount;
export breakpoint;
#[abi = "cdecl"] #[abi = "cdecl"]
native mod rustrt { native mod rustrt {
@@ -18,6 +19,7 @@ native mod rustrt {
fn debug_tag(td: *sys::type_desc, x: *()); fn debug_tag(td: *sys::type_desc, x: *());
fn debug_fn(td: *sys::type_desc, x: *()); fn debug_fn(td: *sys::type_desc, x: *());
fn debug_ptrcast(td: *sys::type_desc, x: *()) -> *(); fn debug_ptrcast(td: *sys::type_desc, x: *()) -> *();
fn rust_dbg_breakpoint();
} }
fn debug_tydesc<T>() { fn debug_tydesc<T>() {
@@ -51,6 +53,18 @@ fn refcount<T>(a: @T) -> uint unsafe {
ret *p; ret *p;
} }
#[doc = "Triggers a debugger breakpoint"]
fn breakpoint() {
rustrt::rust_dbg_breakpoint();
}
#[test]
fn test_breakpoint_should_not_abort_process_when_not_under_gdb() {
// Triggering a breakpoint involves raising SIGTRAP, which terminates
// the process under normal circumstances
breakpoint();
}
// Local Variables: // Local Variables:
// mode: rust; // mode: rust;
// fill-column: 78; // fill-column: 78;

View File

@@ -805,6 +805,11 @@ rust_dbg_call(dbg_callback cb, void *data) {
return cb(data); return cb(data);
} }
extern "C" CDECL void
rust_dbg_breakpoint() {
BREAKPOINT_AWESOME;
}
extern "C" CDECL rust_sched_id extern "C" CDECL rust_sched_id
rust_osmain_sched_id() { rust_osmain_sched_id() {
rust_task *task = rust_get_current_task(); rust_task *task = rust_get_current_task();

View File

@@ -7,6 +7,19 @@
#include <string> #include <string>
#include <cstdlib> #include <cstdlib>
#ifndef _WIN32
#include <signal.h>
#define BREAKPOINT_AWESOME \
do { \
signal(SIGTRAP, SIG_IGN); \
raise(SIGTRAP); \
} while (0)
#else
#define BREAKPOINT_AWESOME
#endif
struct rust_task; struct rust_task;
namespace debug { namespace debug {

View File

@@ -151,6 +151,7 @@ rust_dbg_lock_unlock
rust_dbg_lock_wait rust_dbg_lock_wait
rust_dbg_lock_signal rust_dbg_lock_signal
rust_dbg_call rust_dbg_call
rust_dbg_breakpoint
rust_osmain_sched_id rust_osmain_sched_id
rust_compare_and_swap_ptr rust_compare_and_swap_ptr
rust_atomic_increment rust_atomic_increment