about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-05-01 20:23:07 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-05-01 20:23:07 -0400
commitd231c427e655b7164571a1a712563ba5fd2e4a3c (patch)
tree514b0a5b40c9e12bec74a0f5bc5e72c5437fa395
parentef6b24d1350ad658faee68f7eddd2c05a56900ce (diff)
downloadrust-d231c427e655b7164571a1a712563ba5fd2e4a3c.tar.gz
rust-d231c427e655b7164571a1a712563ba5fd2e4a3c.zip
core: add more debugging printouts to borrowing
-rw-r--r--src/libcore/unstable/lang.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/libcore/unstable/lang.rs b/src/libcore/unstable/lang.rs
index d0e3c2b0678..283f2329649 100644
--- a/src/libcore/unstable/lang.rs
+++ b/src/libcore/unstable/lang.rs
@@ -51,6 +51,8 @@ pub mod rustrt {
 
         #[rust_stack]
         fn rust_set_task_borrow_list(task: *rust_task, map: *c_void);
+
+        fn rust_dbg_breakpoint();
     }
 }
 
@@ -88,6 +90,8 @@ fn swap_task_borrow_list(f: &fn(~[BorrowRecord]) -> ~[BorrowRecord]) {
 }
 
 pub fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) {
+    debug_ptr("fail_borrowed: ", box);
+
     if !::rt::env::get().debug_borrows {
         let msg = "borrowed";
         do str::as_buf(msg) |msg_p, _| {
@@ -130,7 +134,7 @@ pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
 static ENABLE_DEBUG_PTR: bool = false;
 
 #[inline]
-pub fn debug_ptr<T>(tag: &'static str, p: *T) {
+pub fn debug_ptr<T>(tag: &'static str, p: *const T) {
     //! A useful debugging function that prints a pointer + tag + newline
     //! without allocating memory.
 
@@ -138,7 +142,7 @@ pub fn debug_ptr<T>(tag: &'static str, p: *T) {
         debug_ptr_slow(tag, p);
     }
 
-    fn debug_ptr_slow<T>(tag: &'static str, p: *T) {
+    fn debug_ptr_slow<T>(tag: &'static str, p: *const T) {
         use io;
         let dbg = STDERR_FILENO as io::fd_t;
         let letters = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
@@ -209,14 +213,17 @@ fn add_borrow_to_task_list(a: *mut BoxRepr, file: *c_char, line: size_t) {
 #[inline(always)]
 pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint {
     let a: *mut BoxRepr = transmute(a);
-
     let ref_count = (*a).header.ref_count;
+
+    debug_ptr("borrow_as_imm (ptr): ", a);
+    debug_ptr("borrow_as_imm (ref): ", ref_count as *());
+
     if (ref_count & MUT_BIT) != 0 {
         fail_borrowed(a, file, line);
     } else {
         (*a).header.ref_count |= FROZEN_BIT;
         if ::rt::env::get().debug_borrows {
-            add_borrow_to_list(a, file, line);
+            add_borrow_to_task_list(a, file, line);
         }
     }
     ref_count
@@ -228,13 +235,16 @@ pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint {
 pub unsafe fn borrow_as_mut(a: *u8, file: *c_char, line: size_t) -> uint {
     let a: *mut BoxRepr = transmute(a);
 
+    debug_ptr("borrow_as_mut (ptr): ", a);
+    debug_ptr("borrow_as_mut (line): ", line as *());
+
     let ref_count = (*a).header.ref_count;
     if (ref_count & (MUT_BIT|FROZEN_BIT)) != 0 {
         fail_borrowed(a, file, line);
     } else {
         (*a).header.ref_count |= (MUT_BIT|FROZEN_BIT);
         if ::rt::env::get().debug_borrows {
-            add_borrow_to_list(a, file, line);
+            add_borrow_to_task_list(a, file, line);
         }
     }
     ref_count
@@ -261,6 +271,9 @@ pub unsafe fn return_to_mut(a: *u8, old_ref_count: uint) {
     if !a.is_null() {
         let a: *mut BoxRepr = transmute(a);
 
+        debug_ptr("return_to_mut (ptr): ", a);
+        debug_ptr("return_to_mut (ref): ", old_ref_count as *());
+
         let ref_count = (*a).header.ref_count & !ALL_BITS;
         let old_bits = old_ref_count & ALL_BITS;
         (*a).header.ref_count = ref_count | old_bits;