]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Demangle stacktraces whenever possible
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 14 Mar 2006 18:20:58 +0000 (18:20 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 14 Mar 2006 18:20:58 +0000 (18:20 +0000)
git-svn-id: https://svn.dealii.org/trunk@12582 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/exceptions.cc
deal.II/doc/news/changes.html

index 192c39095325e9b16b99a0ebb5c91b6ada2a9911..fe688670f13b7ba2ffa42468a41aba0bec335bf4 100644 (file)
 #  include <execinfo.h>
 #endif
 
+#ifdef HAVE_LIBSTDCXX_DEMANGLER
+#  include <cxxabi.h>
+#endif
+
 
 namespace deal_II_exceptions
 {
@@ -154,10 +158,67 @@ void ExceptionBase::print_stack_trace (std::ostream &out) const
                                    // output the rest
    const unsigned int first_significant_frame = frame;
    for (; frame < n_stacktrace_frames; ++frame)
-     out << '#' << frame - first_significant_frame
-         << "  "
-         << stacktrace[frame]
-         << std::endl;
+     {
+       out << '#' << frame - first_significant_frame
+          << "  ";
+
+                                       // the stacktrace frame is
+                                       // actually of the format
+                                       // "filename(functionname+offset)
+                                       // [address]". let's try to
+                                       // get the mangled
+                                       // functionname out:
+       std::string stacktrace_entry (stacktrace[frame]);
+       const unsigned int pos_start = stacktrace_entry.find('('),
+                         pos_end   = stacktrace_entry.find('+');
+       std::string functionname = stacktrace_entry.substr (pos_start+1,
+                                                          pos_end-pos_start-1);
+
+                                       // demangle, and if successful
+                                       // replace old mangled string
+                                       // by unmangled one (skipping
+                                       // address and offset). treat
+                                       // "main" differently, since
+                                       // it is apparently demangled
+                                       // as "unsigned int" for
+                                       // unknown reasons :-)
+                                       // if we can, demangle the
+                                       // function name
+#ifdef HAVE_LIBSTDCXX_DEMANGLER
+       int     status;
+       char   *realname;
+
+       realname = abi::__cxa_demangle(functionname.c_str(), 0, 0, &status);
+       if ((status == 0) && (functionname != "main"))
+        stacktrace_entry = stacktrace_entry.substr(0, pos_start)
+                           +
+                           ": "
+                           +
+                           realname;
+       else
+        stacktrace_entry = stacktrace_entry.substr(0, pos_start)
+                           +
+                           ": "
+                           +
+                           functionname;
+
+                                       // free memory allocated by
+                                       // the demangler
+       free (realname);
+
+#else   
+
+       stacktrace_entry = stacktrace_entry.substr(0, pos_start)
+                         +
+                         ": "
+                         +
+                         functionname;
+#endif
+       
+                                       // then output what we have
+       out << stacktrace_entry
+          << std::endl;
+     }
 }
 
 
index bdccf3f67c1e2ffd9155d61039685cf7352f7a1e..8eb0ad7a3f6a7612b135992aaa23736bb5b8a683 100644 (file)
@@ -259,12 +259,18 @@ inconvenience this causes.
 
 <ol>
 
+  <li> <p> Improved: If the C++ runtime environment allows it, we now
+       demangle stacktraces generated whenever an exception is thrown.
+       <br>
+       (WB 2006/03/14)
+       </p>
+
   <li> <p> Improved: The function <code class="class">Subscriptor</code>::<code
-  class="member">list_subscribers</code> logs all current subscribers of an
-  object to <tt>deallog</tt>.
-  <br>
-  (GK 2006/03/08)
-  </p>
+       class="member">list_subscribers</code> logs all current subscribers of an
+       object to <tt>deallog</tt>.
+       <br>
+       (GK 2006/03/08)
+       </p>
 
   <li> <p>Fixed: Writing a denormal "NaN" through <code
        class="class">LogStream</code> objects such as 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.