Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
backtrace: kill two unused functions
[simgrid.git] / src / xbt / backtrace_linux.cpp
index abedb81..e0f687a 100644 (file)
 #include "xbt/log.h"
 #include "xbt/module.h"         /* xbt_binary_name */
 #include "src/xbt_modinter.h"       /* backtrace initialization headers */
-#if SIMGRID_HAVE_MC
-#define UNW_LOCAL_ONLY
-#include <libunwind.h>
-#endif
 /* end of "useless" inclusions */
 
-extern char **environ;          /* the environment, as specified by the opengroup */
-
-#include <unwind.h>
-struct trace_arg {
-  void** array;
-  int cnt;
-  int size;
-};
-
-static _Unwind_Reason_Code backtrace_helper(_Unwind_Context* ctx, void* a)
-{
-  trace_arg* arg = static_cast<trace_arg*>(a);
-
-  /* We are first called with address in the __backtrace function.
-     Skip it.  */
-  if (arg->cnt != -1)
-    {
-      arg->array[arg->cnt] = (void *) _Unwind_GetIP(ctx);
-
-      /* Check whether we make any progress.  */
-      if (arg->cnt > 0 && arg->array[arg->cnt - 1] == arg->array[arg->cnt])
-        return _URC_END_OF_STACK;
-    }
-  if (++arg->cnt == arg->size)
-    return _URC_END_OF_STACK;
-  return _URC_NO_REASON;
-}
-
-/** @brief reimplementation of glibc backtrace based directly on gcc library, without implicit malloc
- *
- * See http://people.irisa.fr/Martin.Quinson/blog/2012/0208/system_programming_fun_in_SimGrid/
- * for the motivation behind this function
- * */
-
-int xbt_backtrace_no_malloc(void **array, int size) {
-  int i = 0;
-  for(i=0; i < size; i++)
-    array[i] = nullptr;
-
-  struct trace_arg arg;
-  arg .array = array;
-  arg.size = size;
-  arg.cnt = -1;
-
-  if (size >= 1)
-    _Unwind_Backtrace(backtrace_helper, &arg);
-
-  /* _Unwind_Backtrace on IA-64 seems to put nullptr address above
-     _start.  Fix it up here.  */
-  if (arg.cnt > 1 && arg.array[arg.cnt - 1] == nullptr)
-    --arg.cnt;
-  return arg.cnt != -1 ? arg.cnt : 0;
-}
-
 size_t xbt_backtrace_current(xbt_backtrace_location_t* loc, std::size_t count)
 {
   std::size_t used = backtrace(loc, count);
@@ -138,8 +80,7 @@ static std::string get_binary_path()
 
 //FIXME: This code could be greatly improved/simplifyied with
 //   http://cairo.sourcearchive.com/documentation/1.9.4/backtrace-symbols_8c-source.html
-std::vector<std::string> resolveBacktrace(
-  xbt_backtrace_location_t const* loc, std::size_t count)
+std::vector<std::string> resolve_backtrace(xbt_backtrace_location_t const* loc, std::size_t count)
 {
   std::vector<std::string> result;
 
@@ -187,9 +128,7 @@ std::vector<std::string> resolveBacktrace(
 
   XBT_VERB("Fire a first command: '%s'", cmd.c_str());
   FILE* pipe = popen(cmd.c_str(), "r");
-  if (not pipe) {
-    xbt_die("Cannot fork addr2line to display the backtrace");
-  }
+  xbt_assert(pipe, "Cannot fork addr2line to display the backtrace");
 
   /* To read the output of addr2line */
   char line_func[1024];
@@ -200,7 +139,7 @@ std::vector<std::string> resolveBacktrace(
       line_func[strlen(line_func) - 1] = '\0';
     } else {
       XBT_VERB("Cannot run fgets to look for symbol %zu, addr %s", i, addrs[i].c_str());
-      strncpy(line_func, "???",3);
+      strncpy(line_func, "???", 4);
     }
     if (fgets(line_pos, 1024, pipe)) {
       line_pos[strlen(line_pos) - 1] = '\0';
@@ -286,7 +225,7 @@ std::vector<std::string> resolveBacktrace(
 
         /* Here we go, fire an addr2line up */
         std::string subcmd = std::string(ADDR2LINE) + " -f -e " + p + " " + addrs[i];
-        XBT_VERB("Fire a new command: '%s'", subcmd.c_str());
+        XBT_VERB("Fire another command: '%s'", subcmd.c_str());
         FILE* subpipe = popen(subcmd.c_str(), "r");
         if (not subpipe) {
           xbt_die("Cannot fork addr2line to display the backtrace");
@@ -295,7 +234,7 @@ std::vector<std::string> resolveBacktrace(
           line_func[strlen(line_func) - 1] = '\0';
         } else {
           XBT_VERB("Cannot read result of subcommand %s", subcmd.c_str());
-          strncpy(line_func, "???",3);
+          strncpy(line_func, "???", 4);
         }
         if (fgets(line_pos, 1024, subpipe)) {
           line_pos[strlen(line_pos) - 1] = '\0';
@@ -344,27 +283,3 @@ std::vector<std::string> resolveBacktrace(
 
 }
 }
-
-#if SIMGRID_HAVE_MC
-int xbt_libunwind_backtrace(void** bt, int size){
-  for (int i = 0; i < size; i++)
-    bt[i] = nullptr;
-
-  unw_cursor_t c;
-  unw_context_t uc;
-
-  unw_getcontext (&uc);
-  unw_init_local (&c, &uc);
-
-  unw_step(&c);
-
-  int i;
-  for (i = 0; unw_step(&c) >= 0 && i < size; i++) {
-    unw_word_t ip;
-    unw_get_reg(&c, UNW_REG_IP, &ip);
-    bt[i] = (void*)(long)ip;
-  }
-
-  return i;
-}
-#endif