]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
backtrace on SalomeException and SALOME_SalomeException (unexpected exceptions)
authorPaul RASCLE <paul.rascle@edf.fr>
Thu, 8 Feb 2018 07:02:42 +0000 (08:02 +0100)
committerPaul RASCLE <paul.rascle@edf.fr>
Fri, 16 Feb 2018 14:15:05 +0000 (15:15 +0100)
src/Utils/Utils_ExceptHandlers.cxx

index e77e7d8981e34b588311438d51442085f47e7c4c..e8778229b3a3a2386d2c6e52dc339c4e6537258d 100644 (file)
 #include "Utils_CorbaException.hxx"
 #include "Utils_SALOME_Exception.hxx"
 
+#include <sstream>
+#include <execinfo.h>
+#include <dlfcn.h>
+#include <cxxabi.h>
+
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Exception)
 
+//#define NBLINES_BACKTRACE 64
+
 void SalomeException ()
 {
-  throw SALOME_Exception("Salome Exception");
+  void *stacklines[64];
+  char **stackSymbols;
+  size_t nbLines;
+  nbLines = backtrace(stacklines, 64);
+  stackSymbols = backtrace_symbols(stacklines, nbLines);
+  std::stringstream txt;
+  txt << "Salome Exception" << std::endl;
+  for (int i=0; i<nbLines; i++)
+    txt << stackSymbols[i] << std::endl;
+  throw SALOME_Exception(txt.str().c_str());
 }
 
-void SALOME_SalomeException() {
-  THROW_SALOME_CORBA_EXCEPTION("INTERNAL ERROR", SALOME::INTERNAL_ERROR);
+void SALOME_SalomeException()
+{
+  void *stacklines[64];
+  char **stackSymbols;
+  size_t nbLines;
+  nbLines = backtrace(stacklines, 64);
+  stackSymbols = backtrace_symbols(stacklines, nbLines);
+  std::stringstream txt;
+  txt << "INTERNAL_ERROR, backtrace stack:" << nbLines << std::endl;
+  for (int i = 0; i < nbLines; i++)
+    {
+      Dl_info infodl;
+      if (dladdr(stacklines[i], &infodl))
+        {
+          txt << i << " " << infodl.dli_fname << " " << infodl.dli_fbase << " ";
+          char *demangled = NULL;
+          int status = 0;
+          demangled = abi::__cxa_demangle(infodl.dli_sname, NULL, 0, &status);
+          if (status == 0 && demangled != NULL)
+            {
+              std::string demangstr = demangled; // copy
+              txt << demangstr;
+            }
+          else
+            {
+              if (infodl.dli_sname != 0 && infodl.dli_sname[0] != 0)
+                {
+                  std::string sname = infodl.dli_sname;
+                  if (sname.size() > 0)
+                    txt << infodl.dli_sname;
+                }
+            }
+          txt << " " << infodl.dli_saddr;
+
+          txt << std::endl;
+          free(demangled);
+        }
+      else
+        txt << i << " " << stackSymbols[i] << std::endl;
+    }
+  THROW_SALOME_CORBA_EXCEPTION(txt.str().c_str(), SALOME::INTERNAL_ERROR);
 }