diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-06-01 00:11:51 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-06-06 23:39:55 -0700 |
| commit | c816eea000f56e250bb251dc1a1d357efd5a0438 (patch) | |
| tree | 1796e02f98bdc5dbf627b4a7d577b37125c622f0 | |
| parent | 469ff08e646d4f56403a8d6dbd97d146bd8eeefb (diff) | |
| download | rust-c816eea000f56e250bb251dc1a1d357efd5a0438.tar.gz rust-c816eea000f56e250bb251dc1a1d357efd5a0438.zip | |
std: Add debug::breakpoint
| -rw-r--r-- | src/libstd/dbg.rs | 14 | ||||
| -rw-r--r-- | src/rt/rust_builtin.cpp | 5 | ||||
| -rw-r--r-- | src/rt/rust_debug.h | 13 | ||||
| -rw-r--r-- | src/rt/rustrt.def.in | 1 |
4 files changed, 33 insertions, 0 deletions
diff --git a/src/libstd/dbg.rs b/src/libstd/dbg.rs index 6b8a4f36002..b0abd8cb73a 100644 --- a/src/libstd/dbg.rs +++ b/src/libstd/dbg.rs @@ -9,6 +9,7 @@ export debug_tag; export debug_fn; export ptr_cast; export refcount; +export breakpoint; #[abi = "cdecl"] native mod rustrt { @@ -18,6 +19,7 @@ native mod rustrt { fn debug_tag(td: *sys::type_desc, x: *()); fn debug_fn(td: *sys::type_desc, x: *()); fn debug_ptrcast(td: *sys::type_desc, x: *()) -> *(); + fn rust_dbg_breakpoint(); } fn debug_tydesc<T>() { @@ -51,6 +53,18 @@ fn refcount<T>(a: @T) -> uint unsafe { 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: // mode: rust; // fill-column: 78; diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 0af08c84f19..2a65012b52a 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -805,6 +805,11 @@ rust_dbg_call(dbg_callback cb, void *data) { return cb(data); } +extern "C" CDECL void +rust_dbg_breakpoint() { + BREAKPOINT_AWESOME; +} + extern "C" CDECL rust_sched_id rust_osmain_sched_id() { rust_task *task = rust_get_current_task(); diff --git a/src/rt/rust_debug.h b/src/rt/rust_debug.h index da9838ba341..40a4c28f052 100644 --- a/src/rt/rust_debug.h +++ b/src/rt/rust_debug.h @@ -7,6 +7,19 @@ #include <string> #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; namespace debug { diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 8a627795850..f51d4c502b0 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -151,6 +151,7 @@ rust_dbg_lock_unlock rust_dbg_lock_wait rust_dbg_lock_signal rust_dbg_call +rust_dbg_breakpoint rust_osmain_sched_id rust_compare_and_swap_ptr rust_atomic_increment |
