Date: Friday, January 20, 2006 @ 22:27:38
  Author: marc
    Path: /cvsroot/carob/carob/test

Modified: CarobProtector.hpp (1.11 -> 1.12)

Implemented C++ demangling of local stack traces


--------------------+
 CarobProtector.hpp |   43 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 39 insertions(+), 4 deletions(-)


Index: carob/test/CarobProtector.hpp
diff -u carob/test/CarobProtector.hpp:1.11 carob/test/CarobProtector.hpp:1.12
--- carob/test/CarobProtector.hpp:1.11  Thu Jan 12 19:55:10 2006
+++ carob/test/CarobProtector.hpp       Fri Jan 20 22:27:38 2006
@@ -25,6 +25,10 @@
 #include <cppunit/Protector.h>
 #include <cppunit/Message.h>
 
+#ifdef __GLIBC__ // probably not the right macro
+#include <cxxabi.h>
+#define CAROB_CXX_DEMANGLING 1
+#endif
 
 static const std::wstring BEPREFIX(L"BackendException: ");
 static const std::wstring COPREFIX(L"ControllerException: ");
@@ -47,9 +51,40 @@
 static void cerrBackTrace(const std::wstring& prefix,
     const CarobNS::CarobException& cex)
 {
-  const CarobNS::BackTrace& stvect = cex.getBackTrace();
-  for (CarobNS::BackTrace::const_iterator btframe = stvect.begin(); btframe != 
stvect.end(); btframe++) {
-    std::wcerr << BEPREFIX; std::cerr << *btframe << std::endl;
+    const CarobNS::BackTrace& stvect = cex.getBackTrace();
+  
+    int status;
+    char *demangled;
+
+
+    for (CarobNS::BackTrace::const_iterator btframe = stvect.begin(); btframe 
!= stvect.end(); btframe++) {
+
+        std::string sframe(*btframe);
+
+#ifdef CAROB_CXX_DEMANGLING
+        typedef std::string::size_type ssize;
+
+        ssize start(sframe.find('('));
+        ssize end(sframe.find('+'));
+
+        if (std::string::npos != start && std::string::npos != end)
+        {   
+            start++;
+            ssize len(end-start);
+            
+            std::string mangled(sframe.substr(start, len));
+
+            demangled = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status);
+            if (demangled) {
+                sframe.replace(start, len, demangled);
+                free(demangled);
+            }
+        }
+#endif
+
+        std::wcerr << BEPREFIX;
+        std::cerr << sframe << std::endl;
+
   }
 }
 
@@ -134,7 +169,7 @@
 /*
  * Local Variables:
  * c-file-style: "bsd"
- * c-basic-offset: 2
+ * c-basic-offset: 4
  * indent-tabs-mode: nil
  * End:
  */

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to