mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
move call stack code, add TODOs
(only disabled code is touched) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38494 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c786d93f25
commit
1d5e483b44
@ -22,16 +22,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#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 std;
|
||||||
using namespace lyx::support;
|
using namespace lyx::support;
|
||||||
@ -254,42 +244,5 @@ LyXErr & operator<<(LyXErr & l, ios_base &(*t)(ios_base &))
|
|||||||
LyXErr lyxerr;
|
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
|
} // namespace lyx
|
||||||
|
@ -124,8 +124,6 @@ namespace Debug {
|
|||||||
/// Show all the possible tags that can be used for debugging
|
/// Show all the possible tags that can be used for debugging
|
||||||
void showTags(std::ostream & os);
|
void showTags(std::ostream & os);
|
||||||
|
|
||||||
/// Print simple callstack to stderr
|
|
||||||
void printCallStack();
|
|
||||||
|
|
||||||
} // namespace Debug
|
} // namespace Debug
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* Licence details can be found in the file COPYING.
|
* Licence details can be found in the file COPYING.
|
||||||
*
|
*
|
||||||
* \author André Pönitz
|
* \author André Pönitz
|
||||||
|
* \author Peter Kümmel
|
||||||
*
|
*
|
||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
@ -14,13 +15,64 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#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 {
|
namespace lyx {
|
||||||
|
|
||||||
void doAssert(char const * expr, char const * file, long line)
|
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);
|
LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line);
|
||||||
// comment this out if not needed
|
// comment this out if not needed
|
||||||
BOOST_ASSERT(false);
|
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
|
} // namespace lyx
|
||||||
|
@ -18,6 +18,10 @@ namespace lyx {
|
|||||||
|
|
||||||
void doAssert(char const * expr, char const * file, long line);
|
void doAssert(char const * expr, char const * file, long line);
|
||||||
|
|
||||||
|
/// Print demangled callstack to stderr
|
||||||
|
void printCallStack();
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
#define LASSERT(expr, escape) \
|
#define LASSERT(expr, escape) \
|
||||||
|
Loading…
Reference in New Issue
Block a user