]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: debug macros FACTOR_PRINT and FACTOR_PRINT_MARK to make better debug
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 3 May 2015 12:13:28 +0000 (14:13 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 10 May 2015 03:04:21 +0000 (20:04 -0700)
printing messages than just using std::cout

GNUmakefile
vm/contexts.hpp
vm/debug.cpp
vm/debug.hpp [new file with mode: 0644]
vm/inline_cache.cpp
vm/master.hpp
vm/slot_visitor.hpp

index 760c0d59c9faeae02f6dbc000060b3a71a8823d2..8bb924a995c2ca03175b5fc20cd492d16a9a949e 100644 (file)
@@ -68,6 +68,7 @@ ifdef CONFIG
 
        MASTER_HEADERS = $(PLAF_MASTER_HEADERS) \
                vm/assert.hpp \
+               vm/debug.hpp \
                vm/layouts.hpp \
                vm/platform.hpp \
                vm/primitives.hpp \
index d892ed156f8afb55a6822d0888ded8cbdaf5b20f..eeb0bf5e0649c1c5be3aca1d217d8925b90522fc 100644 (file)
@@ -48,7 +48,6 @@ struct context {
   void reset_context_objects();
   void reset();
   void fix_stacks();
-  void scrub_stacks(gc_info* info, cell index);
 
   cell peek() { return *(cell*)datastack; }
 
index 6a7f332c70ab579b69a08b507962922f9acbaea6..16cb7c26de1868d2fe079542c516d5f5c30fb5ca 100644 (file)
@@ -4,6 +4,8 @@ using namespace std;
 
 namespace factor {
 
+bool factor_print_p = true;
+
 ostream& operator<<(ostream& out, const string* str) {
   for (cell i = 0; i < string_capacity(str); i++)
     out << (char)str->data()[i];
diff --git a/vm/debug.hpp b/vm/debug.hpp
new file mode 100644 (file)
index 0000000..3a52431
--- /dev/null
@@ -0,0 +1,25 @@
+namespace factor {
+
+extern bool factor_print_p;
+
+}
+
+#ifdef FACTOR_DEBUG
+
+#define FACTOR_PRINT(x)                                          \
+  do {                                                           \
+    if (factor_print_p) {                                        \
+      std::cerr                                                  \
+          << std::setw(28) << std::left << __FILE__              \
+          << " " << std::setw(4) << std::right << __LINE__       \
+          << " " << std::setw(20) << std::left << __FUNCTION__   \
+          << " " << x                                            \
+          << std::endl;                                          \
+    }                                                            \
+  } while (0)
+#define FACTOR_PRINT_MARK FACTOR_PRINT("")
+
+#else
+#define FACTOR_PRINT(fmt, ...) ((void)0)
+#define FACTOR_PRINT_MARK ((void)0)
+#endif
index adf7210f564d3dc8d427f28aca0e6b82ef08aaf2..2e63f9a13f277fdd8c907c8238c9a30dda346bad 100644 (file)
@@ -169,9 +169,10 @@ cell factor_vm::inline_cache_miss(cell return_address_) {
   bool tail_call_site = tail_call_site_p(return_address.value);
 
 #ifdef PIC_DEBUG
-  std::cout << "Inline cache miss at " << (tail_call_site ? "tail" : "non-tail")
-            << " call site 0x" << std::hex << return_address.value << std::dec
-            << std::endl;
+  FACTOR_PRINT("Inline cache miss at "
+               << (tail_call_site ? "tail" : "non-tail")
+               << " call site 0x" << std::hex << return_address.value
+               << std::dec);
   print_callstack();
 #endif
 
@@ -210,9 +211,9 @@ cell factor_vm::inline_cache_miss(cell return_address_) {
     set_call_target(return_address.value, xt);
 
 #ifdef PIC_DEBUG
-    std::cout << "Updated " << (tail_call_site ? "tail" : "non-tail")
-              << " call site 0x" << std::hex << return_address.value << std::dec
-              << " with 0x" << std::hex << (cell)xt << std::dec << std::endl;
+    FACTOR_PRINT("Updated " << (tail_call_site ? "tail" : "non-tail")
+                 << " call site 0x" << std::hex << return_address.value << std::dec
+                 << " with 0x" << std::hex << (cell)xt << std::dec);
     print_callstack();
 #endif
   }
index 75c8f5e8d05b69528681657c6e54abcf6dfaa0cf..2110ddd230e5428b25127ce37d24fd1578bd00c4 100644 (file)
@@ -87,6 +87,7 @@ namespace factor { struct factor_vm; }
 
 /* Factor headers */
 #include "assert.hpp"
+#include "debug.hpp"
 #include "layouts.hpp"
 #include "platform.hpp"
 #include "utilities.hpp"
index 92da352ea00a58f716a57a70b98c9e42341a3ed0..6db92c592e82c7070c8ecfaace05498f1041047a 100644 (file)
@@ -279,7 +279,7 @@ template <typename Fixup> struct call_frame_slot_visitor {
     for (cell loc = 0; loc < count; loc++) {
       if (bitmap_p(bitmap, base + loc)) {
 #ifdef DEBUG_GC_MAPS
-        std::cout << "scrubbing stack location " << loc << std::endl;
+        FACTOR_PRINT("scrubbing stack location " << loc);
 #endif
         *((cell*)stack - loc) = 0;
       }
@@ -310,8 +310,8 @@ template <typename Fixup> struct call_frame_slot_visitor {
       return;
 
 #ifdef DEBUG_GC_MAPS
-    std::cout << "call frame code block " << compiled << " with offset "
-              << return_address << std::endl;
+    FACTOR_PRINT("call frame code block " << compiled << " with offset "
+                 << return_address);
 #endif
     cell* stack_pointer = (cell*)frame_top;
     uint8_t* bitmap = info->gc_info_bitmap();
@@ -334,8 +334,8 @@ template <typename Fixup> struct call_frame_slot_visitor {
       uint32_t base_pointer = info->lookup_base_pointer(callsite, spill_slot);
       if (base_pointer != (uint32_t)-1) {
 #ifdef DEBUG_GC_MAPS
-        std::cout << "visiting derived root " << spill_slot
-                  << " with base pointer " << base_pointer << std::endl;
+        FACTOR_PRINT("visiting derived root " << spill_slot
+                     << " with base pointer " << base_pointer);
 #endif
         stack_pointer[spill_slot] -= stack_pointer[base_pointer];
       }
@@ -347,7 +347,7 @@ template <typename Fixup> struct call_frame_slot_visitor {
     for (cell spill_slot = 0; spill_slot < info->gc_root_count; spill_slot++) {
       if (bitmap_p(bitmap, callsite_gc_roots + spill_slot)) {
 #ifdef DEBUG_GC_MAPS
-        std::cout << "visiting GC root " << spill_slot << std::endl;
+        FACTOR_PRINT("visiting GC root " << spill_slot);
 #endif
         visitor->visit_handle(stack_pointer + spill_slot);
       }