]> git.lyx.org Git - features.git/commitdiff
move call stack code, add TODOs
authorPeter Kümmel <syntheticpp@gmx.net>
Mon, 25 Apr 2011 09:14:50 +0000 (09:14 +0000)
committerPeter Kümmel <syntheticpp@gmx.net>
Mon, 25 Apr 2011 09:14:50 +0000 (09:14 +0000)
(only disabled code is touched)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38494 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/debug.cpp
src/support/debug.h
src/support/lassert.cpp
src/support/lassert.h

index 21182b4b5b689eadec7373ee3ec7761c84bcd124..29a167af917418a242c46100a9926cd7e41a788b 100644 (file)
 #include <iostream>
 #include <iomanip>
 
-//#define LYX_CALLSTACK_PRINTING
-// must be linked with -rdynamic
-#ifdef LYX_CALLSTACK_PRINTING
-#include <stdio.h>
-#include <stdlib.h>
-#include <execinfo.h>
-#include <cxxabi.h>
-#endif
-
-
 
 using namespace std;
 using namespace lyx::support;
@@ -254,42 +244,5 @@ LyXErr & operator<<(LyXErr & l, ios_base &(*t)(ios_base &))
 LyXErr lyxerr;
 
 
-void Debug::printCallStack()
-{
-#ifdef LYX_CALLSTACK_PRINTING
-       const int depth = 50;
-       
-       // get void*'s for all entries on the stack
-       void* array[depth];
-       size_t size = backtrace(array, depth);
-       
-       char** messages = backtrace_symbols(array, size);
-       
-       for (size_t i = 0; i < size && messages != NULL; i++) {
-               std::string orig(messages[i]);
-               // extract mangled: bin/lyx2.0(_ZN3lyx7support7packageEv+0x32) [0x8a2e02b]
-               char* mangled = 0;
-               for (char *p = messages[i]; *p; ++p) {
-                       if (*p == '(') {
-                               *p = 0;
-                               mangled = p + 1;
-                       } else if (*p == '+') {
-                               *p = 0;
-                               break;
-                       }
-               }
-               int err = 0;
-               char* demangled = abi::__cxa_demangle(mangled, 0, 0, &err);
-               if (err == 0) {
-                       fprintf(stderr, "[bt]: (%d) %s %s\n", i, messages[i], demangled);
-                       free((void*)demangled);
-               } else {
-                       fprintf(stderr, "[bt]: (%d) %s\n", i, orig.c_str());
-               }
-               
-       }
-#endif
-}
-
 
 } // namespace lyx
index 3835242b366f7e3e34e35f4ce9fd530857afeb80..d636e4c5c32a3c4d1487a82a3a803e47be86cfd4 100644 (file)
@@ -124,8 +124,6 @@ namespace Debug {
        /// Show all the possible tags that can be used for debugging
        void showTags(std::ostream & os);
 
-       /// Print simple callstack to stderr
-       void printCallStack();
 
 } // namespace Debug
 
index b384007f6087027beed63d91915a597e85be068f..9c0daff32876de3f9e8d7e1b7048db458da5b6ca 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author André Pönitz
+ * \author Peter Kümmel
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include <boost/assert.hpp>
 
+
+//#define LYX_CALLSTACK_PRINTING
+// must be linked with -rdynamic
+#ifdef LYX_CALLSTACK_PRINTING
+#include <cstdio>
+#include <cstdlib>
+#include <execinfo.h>
+#include <cxxabi.h>
+#endif
+
+
 namespace lyx {
 
 void doAssert(char const * expr,  char const * file, long line)
 {
+    // TODO Should we try to print the call stack before exiting?
+
        LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line);
        // comment this out if not needed
        BOOST_ASSERT(false);
 }
 
+
+//TODO Return as string, so call stack could be used in dialogs.
+void printCallStack()
+{
+#ifdef LYX_CALLSTACK_PRINTING
+       const int depth = 50;
+       
+       // get void*'s for all entries on the stack
+       void* array[depth];
+       size_t size = backtrace(array, depth);
+       
+       char** messages = backtrace_symbols(array, size);
+       
+       for (size_t i = 0; i < size && messages != NULL; i++) {
+               std::string orig(messages[i]);
+               // extract mangled: bin/lyx2.0(_ZN3lyx7support7packageEv+0x32) [0x8a2e02b]
+               char* mangled = 0;
+               for (char *p = messages[i]; *p; ++p) {
+                       if (*p == '(') {
+                               *p = 0;
+                               mangled = p + 1;
+                       } else if (*p == '+') {
+                               *p = 0;
+                               break;
+                       }
+               }
+               int err = 0;
+               char* demangled = abi::__cxa_demangle(mangled, 0, 0, &err);
+               if (err == 0) {
+                       fprintf(stderr, "[bt]: (%d) %s %s\n", i, messages[i], demangled);
+                       free((void*)demangled);
+               } else {
+                       fprintf(stderr, "[bt]: (%d) %s\n", i, orig.c_str());
+               }               
+       }
+#endif
+}
+
 } // namespace lyx
index 60ee570fa300d3b957bfd014325b434eddf911b4..66d73cefbf01cca02b8d399115ee0297202bd7b5 100644 (file)
@@ -18,6 +18,10 @@ namespace lyx {
 
 void doAssert(char const * expr, char const * file, long line);
 
+/// Print demangled callstack to stderr
+void printCallStack();
+
+
 } // namespace lyx
 
 #define LASSERT(expr, escape) \