Commits

Anonymous committed 1e3d012

Allow specifying the binary used for symbolization.

Comments (0)

Files changed (4)

 2011-04-21  scott snyder  <snyder@bnl.gov>
 
+	* Tagging CxxUtils-00-00-75.
+	* CxxUtils/SealDebug.h, src/SealDebug.cxx: Allow specifying the
+	binary used for symbolization.
+	* test/stacktrace_test.cxx: Force use of addr2line, to get
+	consistent results across platforms.
+
 	* Tagging CxxUtils-00-00-74.
 	* CxxUtils/hashtable.h: Fix clang warnings.
 

CxxUtils/SealDebug.h

     // sss
     static void                        stacktraceLine (IOFD fd,
                                                        unsigned long addr);
+    static void                 setStackTraceAddr2Line (const char* path);
 
 private:
     static IOFD			s_stackTraceFd;

src/SealDebug.cxx

 namespace {
 
 
+std::string addr2LinePath = "/usr/bin/addr2line";
+
+
 struct BacktraceInit
 {
   BacktraceInit()
     // so call it once now.
     void* trace[1];
     backtrace (trace, 1);
+
+    // Also test for eu-addr2line.
+    if (access ("/usr/bin/eu-addr2line", F_OK) == 0)
+      addr2LinePath = "/usr/bin/eu-addr2line";
   }
 };
 BacktraceInit backtraceInit;
 
 /** The default output file descriptor for #stacktrace().  */
 IOFD			DebugAids::s_stackTraceFd = IOFD_INVALID;
-unsigned int            DebugAids::s_have_eu_addr2line=0;
 
 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
 
       if (getenv ("LD_PRELOAD"))
         unsetenv ("LD_PRELOAD");
       
-      // check, if we have eu-addr2line (from elfutils)
-      // just check, if it's in /usr/bin/eu-addr2line, because if the user installs elfutils by hand
-      // the eu- prefix is probably missing, checking for F_OK (existence) should be enough
-      if ( DebugAids::s_have_eu_addr2line == 0 )
-	{
-	  if ( access("/usr/bin/eu-addr2line",F_OK) == 0 )
-	    {
-	      DebugAids::s_have_eu_addr2line=1;
-	    }
-	  else
-	    {
-	      DebugAids::s_have_eu_addr2line=2;
-	    }
-	}
-      
-      if ( DebugAids::s_have_eu_addr2line == 1 )
-	{
-	  snprintf (line, LINE_MAX, "/usr/bin/eu-addr2line -f -C -e %s %p", info.dli_fname,
-		    (void*)relative_address);
-	}
-      else
-	{
-	  snprintf (line, LINE_MAX, "addr2line -f -C -e %s %p", info.dli_fname,
-		    (void*)relative_address);
-	}
+      snprintf (line, LINE_MAX, "%s -f -C -e %s %p",
+                addr2LinePath.c_str(),
+                info.dli_fname,
+                (void*)relative_address);
 
       pfd = stacktracePopenFD( line, child_pid );
 
 
 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
 
+// Change the path of the binary used for symbolization.
+void DebugAids::setStackTraceAddr2Line (const char* path)
+{
+  addr2LinePath = path;
+}
+
+
 #if HAVE_U_STACK_TRACE
 // HP-UX stack walker (http://devresource.hp.com/STK/partner/unwind.pdf)
 extern "C" void U_STACK_TRACE (void);

test/stacktrace_test.cxx

 
 int main()
 {
+  Athena::DebugAids::setStackTraceAddr2Line ("/usr/bin/addr2line");
   fromhere();
   return 0;
 }