]> git.lyx.org Git - lyx.git/blobdiff - src/support/debug.cpp
add toFilesystemEncoding for --binary-dir argument
[lyx.git] / src / support / debug.cpp
index 21182b4b5b689eadec7373ee3ec7761c84bcd124..3a6f9018feb3926549c5af73e125c406b6279d7f 100644 (file)
 
 #include "support/convert.h"
 #include "support/debug.h"
+#include "support/FileName.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
-#include "support/FileName.h"
 #include "support/ProgressInterface.h"
+#include "support/regex.h"
 
 #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;
@@ -207,13 +198,29 @@ void LyXErr::endl()
 }
 
 
+char const * LyXErr::stripName(char const * n)
+{
+       string const name = n;
+       // find the last occurence of /src/ in name
+       static regex re("[\\/]src[\\/]");
+       string::const_iterator const begin = name.begin();
+       string::const_iterator it = begin;
+       string::const_iterator const end = name.end();
+       smatch results;
+       while (regex_search(it, end, results, re)) {
+               it = results[0].second;
+       }
+       return n + std::distance(begin, it);
+}
+
+
 // It seems not possible to instantiate operator template out of class body
 template<class T>
 LyXErr & toStream(LyXErr & l, T t)     
 {
        if (l.enabled()){
                l.stream() << t;
-                if (l.secondEnabled()) {
+               if (l.secondEnabled()) {
                        l.secondStream() << t;
                        ProgressInterface::instance()->lyxerrFlush();
                }
@@ -254,42 +261,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