Skip to content

Commit 7290d9a

Browse files
committed
---
yaml --- r: 67504 b: refs/heads/master c: 4700b00 h: refs/heads/master v: v3
1 parent 54ebd86 commit 7290d9a

File tree

8 files changed

+204
-1
lines changed

8 files changed

+204
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 05eff5f731fbdf0597bb6a4b94a7603571ff66b6
2+
refs/heads/master: 4700b00ef708f4babd86d72ba757e82d2369709e
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libextra/dbg.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Unsafe debugging functions for inspecting values.
12+
13+
#[allow(missing_doc)];
14+
15+
use std::cast::transmute;
16+
use std::unstable::intrinsics::{get_tydesc};
17+
18+
pub mod rustrt {
19+
use std::unstable::intrinsics::{TyDesc};
20+
21+
#[abi = "cdecl"]
22+
extern {
23+
pub unsafe fn debug_tydesc(td: *TyDesc);
24+
pub unsafe fn debug_opaque(td: *TyDesc, x: *());
25+
pub unsafe fn debug_box(td: *TyDesc, x: *());
26+
pub unsafe fn debug_tag(td: *TyDesc, x: *());
27+
pub unsafe fn debug_fn(td: *TyDesc, x: *());
28+
pub unsafe fn debug_ptrcast(td: *TyDesc, x: *()) -> *();
29+
pub unsafe fn rust_dbg_breakpoint();
30+
}
31+
}
32+
33+
pub fn debug_tydesc<T>() {
34+
unsafe {
35+
rustrt::debug_tydesc(get_tydesc::<T>());
36+
}
37+
}
38+
39+
pub fn debug_opaque<T>(x: T) {
40+
unsafe {
41+
rustrt::debug_opaque(get_tydesc::<T>(), transmute(&x));
42+
}
43+
}
44+
45+
pub fn debug_box<T>(x: @T) {
46+
unsafe {
47+
rustrt::debug_box(get_tydesc::<T>(), transmute(&x));
48+
}
49+
}
50+
51+
pub fn debug_tag<T>(x: T) {
52+
unsafe {
53+
rustrt::debug_tag(get_tydesc::<T>(), transmute(&x));
54+
}
55+
}
56+
57+
pub fn debug_fn<T>(x: T) {
58+
unsafe {
59+
rustrt::debug_fn(get_tydesc::<T>(), transmute(&x));
60+
}
61+
}
62+
63+
pub unsafe fn ptr_cast<T, U>(x: @T) -> @U {
64+
transmute(
65+
rustrt::debug_ptrcast(get_tydesc::<T>(), transmute(x)))
66+
}
67+
68+
/// Triggers a debugger breakpoint
69+
pub fn breakpoint() {
70+
unsafe {
71+
rustrt::rust_dbg_breakpoint();
72+
}
73+
}
74+
75+
#[test]
76+
fn test_breakpoint_should_not_abort_process_when_not_under_gdb() {
77+
// Triggering a breakpoint involves raising SIGTRAP, which terminates
78+
// the process under normal circumstances
79+
breakpoint();
80+
}

trunk/src/libextra/extra.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub mod sha2;
7878

7979
pub mod url;
8080
pub mod ebml;
81+
pub mod dbg;
8182
pub mod getopts;
8283
pub mod json;
8384
pub mod md4;

trunk/src/libstd/unstable/lang.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub mod rustrt {
4141

4242
#[rust_stack]
4343
pub fn rust_try_get_task() -> *rust_task;
44+
45+
pub fn rust_dbg_breakpoint();
4446
}
4547
}
4648

trunk/src/rt/rust_builtin.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,93 @@ debug_static_mut_check_four() {
150150
assert(debug_static_mut == 4);
151151
}
152152

153+
/* Debug builtins for std::dbg. */
154+
155+
static void
156+
debug_tydesc_helper(type_desc *t)
157+
{
158+
rust_task *task = rust_get_current_task();
159+
LOG(task, stdlib, " size %" PRIdPTR ", align %" PRIdPTR,
160+
t->size, t->align);
161+
}
162+
163+
extern "C" CDECL void
164+
debug_tydesc(type_desc *t) {
165+
rust_task *task = rust_get_current_task();
166+
LOG(task, stdlib, "debug_tydesc");
167+
debug_tydesc_helper(t);
168+
}
169+
170+
extern "C" CDECL void
171+
debug_opaque(type_desc *t, uint8_t *front) {
172+
rust_task *task = rust_get_current_task();
173+
LOG(task, stdlib, "debug_opaque");
174+
debug_tydesc_helper(t);
175+
// Account for alignment. `front` may not indeed be the
176+
// front byte of the passed-in argument
177+
if (((uintptr_t)front % t->align) != 0) {
178+
front = (uint8_t *)align_to((uintptr_t)front, (size_t)t->align);
179+
}
180+
for (uintptr_t i = 0; i < t->size; ++front, ++i) {
181+
LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, *front);
182+
}
183+
}
184+
185+
extern "C" CDECL void
186+
debug_box(type_desc *t, rust_opaque_box *box) {
187+
rust_task *task = rust_get_current_task();
188+
LOG(task, stdlib, "debug_box(0x%" PRIxPTR ")", box);
189+
debug_tydesc_helper(t);
190+
LOG(task, stdlib, " refcount %" PRIdPTR,
191+
box->ref_count - 1); // -1 because we ref'ed for this call
192+
uint8_t *data = (uint8_t *)box_body(box);
193+
for (uintptr_t i = 0; i < t->size; ++i) {
194+
LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, data[i]);
195+
}
196+
}
197+
198+
struct rust_tag {
199+
uintptr_t discriminant;
200+
uint8_t variant[];
201+
};
202+
203+
extern "C" CDECL void
204+
debug_tag(type_desc *t, rust_tag *tag) {
205+
rust_task *task = rust_get_current_task();
206+
207+
LOG(task, stdlib, "debug_tag");
208+
debug_tydesc_helper(t);
209+
LOG(task, stdlib, " discriminant %" PRIdPTR, tag->discriminant);
210+
211+
for (uintptr_t i = 0; i < t->size - sizeof(tag->discriminant); ++i)
212+
LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i,
213+
tag->variant[i]);
214+
}
215+
216+
extern "C" CDECL void
217+
debug_fn(type_desc *t, fn_env_pair *fn) {
218+
rust_task *task = rust_get_current_task();
219+
LOG(task, stdlib, "debug_fn");
220+
debug_tydesc_helper(t);
221+
LOG(task, stdlib, " fn at 0x%" PRIxPTR, fn->f);
222+
LOG(task, stdlib, " env at 0x%" PRIxPTR, fn->env);
223+
if (fn->env) {
224+
LOG(task, stdlib, " refcount %" PRIdPTR, fn->env->ref_count);
225+
}
226+
}
227+
228+
extern "C" CDECL void *
229+
debug_ptrcast(type_desc *from_ty,
230+
type_desc *to_ty,
231+
void *ptr) {
232+
rust_task *task = rust_get_current_task();
233+
LOG(task, stdlib, "debug_ptrcast from");
234+
debug_tydesc_helper(from_ty);
235+
LOG(task, stdlib, "to");
236+
debug_tydesc_helper(to_ty);
237+
return ptr;
238+
}
239+
153240
extern "C" CDECL void *
154241
debug_get_stk_seg() {
155242
rust_task *task = rust_get_current_task();
@@ -496,6 +583,11 @@ rust_should_log_console() {
496583
return (uintptr_t)should_log_console();
497584
}
498585

586+
extern "C" CDECL void
587+
rust_dbg_breakpoint() {
588+
BREAKPOINT_AWESOME;
589+
}
590+
499591
extern "C" CDECL rust_sched_id
500592
rust_osmain_sched_id() {
501593
rust_task *task = rust_get_current_task();

trunk/src/rt/rust_debug.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
#include <string>
1818
#include <cstdlib>
1919

20+
#ifndef _WIN32
21+
22+
#include <signal.h>
23+
#define BREAKPOINT_AWESOME \
24+
do { \
25+
signal(SIGTRAP, SIG_IGN); \
26+
raise(SIGTRAP); \
27+
} while (0)
28+
29+
#else
30+
#define BREAKPOINT_AWESOME
31+
#endif
32+
2033
struct rust_task;
2134

2235
namespace debug {

trunk/src/rt/rustrt.def.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
debug_box
2+
debug_fn
3+
debug_opaque
4+
debug_ptrcast
5+
debug_tag
6+
debug_tydesc
17
debug_get_stk_seg
28
debug_abi_1
39
debug_abi_2
@@ -172,6 +178,7 @@ rust_dbg_lock_wait
172178
rust_dbg_lock_signal
173179
rust_dbg_call
174180
rust_dbg_do_nothing
181+
rust_dbg_breakpoint
175182
rust_osmain_sched_id
176183
rust_task_inhibit_kill
177184
rust_task_allow_kill

trunk/src/snapshots.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
S 2013-07-31 389aba0
2+
freebsd-x86_64 c9783bb5723404be8ae371d265bbb9a1c679e4db
3+
linux-i386 7413d98325b23dc461ced92757e5e19bec750dbd
4+
linux-x86_64 cd3fedbb02423f330aedaae6173914659ccb98e5
5+
macos-i386 fef296e534b5e12d382708e658370957d5df9a0e
6+
macos-x86_64 57bd3da763607386a08b2a50ecf5a7778aea8356
7+
winnt-i386 a532aaabf043370a21458fd6874be41d432b5696
8+
19
S 2013-07-25 4cf3072
210
macos-i386 f682d6e9ca0d56768bd36a0c05b7e58e12694dff
311
macos-x86_64 2f4e85c9756ba31a04fa8dd1c999fbaf8e1d3d1a

0 commit comments

Comments
 (0)