Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Add MC_dump_stacks
authorGabriel Corona <gabriel.corona@loria.fr>
Thu, 6 Nov 2014 11:49:45 +0000 (12:49 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Thu, 6 Nov 2014 11:50:22 +0000 (12:50 +0100)
src/mc/mc_checkpoint.c
src/mc/mc_global.c
src/mc/mc_private.h

index 8c3c47d..5516255 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "../simix/smx_private.h"
 
+#define UNW_LOCAL_ONLY
 #include <libunwind.h>
 #include <libelf.h>
 
index dbdbc7c..5d163b1 100644 (file)
@@ -11,6 +11,9 @@
 #include <sys/mman.h>
 #include <libgen.h>
 
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+
 #include "simgrid/sg_config.h"
 #include "../surf/surf_private.h"
 #include "../simix/smx_private.h"
@@ -824,3 +827,33 @@ void MC_automaton_new_propositional_symbol(const char *id, void *fct)
     MC_SET_MC_HEAP;
 
 }
+
+void MC_dump_stacks(FILE* file)
+{
+  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
+  MC_SET_MC_HEAP;
+
+  int nstack = 0;
+  stack_region_t current_stack;
+  unsigned cursor;
+  xbt_dynar_foreach(stacks_areas, cursor, current_stack) {
+    unw_context_t * context = (unw_context_t *)current_stack->context;
+    fprintf(file, "Stack %i:\n", nstack);
+
+    int nframe = 0;
+    char buffer[100];
+    unw_cursor_t c;
+    unw_init_local (&c, context);
+    unw_word_t off;
+    do {
+      const char * name = !unw_get_proc_name(&c, buffer, 100, &off) ? buffer : "?";
+      fprintf(file, "  %i: %s\n", nframe, name);
+      ++nframe;
+    } while(unw_step(&c));
+
+    ++nstack;
+  }
+
+  if (raw_mem_set)
+    MC_SET_MC_HEAP;
+}
index 10fcbe9..a44df30 100644 (file)
@@ -909,6 +909,15 @@ void* mc_snapshot_read_pointer_region(void* addr, mc_mem_region_t region)
     xbt_free(req_str); \
   }
 
+/** @brief Dump the stacks of the application processes
+ *
+ *   This functions is currently not used but it is quite convenient
+ *   to call from the debugger.
+ *
+ *   Does not work when an application thread is running.
+ */
+void MC_dump_stacks(FILE* file);
+
 SG_END_DECL()
 
 #endif