Commit 60689442 authored by Pavel Vainerman's avatar Pavel Vainerman

(UActivator): переделал реализацию printStackTrace

parent 7ea7bb95
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
// -------------------- // --------------------
#include <execinfo.h> #include <execinfo.h>
#include <cxxabi.h> #include <cxxabi.h>
#include <dlfcn.h>
#include <iomanip> #include <iomanip>
// -------------------- // --------------------
...@@ -166,70 +167,37 @@ static inline void printStackTrace() ...@@ -166,70 +167,37 @@ static inline void printStackTrace()
TRACELOG << std::left; TRACELOG << std::left;
size_t funcnamesize = FUNCNAMESIZE;
char funcname[FUNCNAMESIZE];
// iterate over the returned symbol lines. skip the first, it is the // iterate over the returned symbol lines. skip the first, it is the
// address of this function. // address of this function.
for ( unsigned int i = 4; i < addrlen; i++ ) for ( unsigned int i = 4; i < addrlen; i++ )
{ {
char* begin_name = NULL; Dl_info dl;
char* begin_offset = NULL;
char* end_offset = NULL;
// find parentheses and +address offset surrounding the mangled name
for ( char* p = symbollist[i]; *p; ++p )
{
if ( *p == '(' )
begin_name = p;
else if ( *p == '+' )
begin_offset = p;
else if ( *p == ')' && ( begin_offset || begin_name ))
end_offset = p;
}
if ( begin_name && end_offset && ( begin_name < end_offset ))
{
*begin_name++ = '\0';
*end_offset++ = '\0';
if ( begin_offset ) if(!dladdr(addrlist[i], &dl))
*begin_offset++ = '\0'; break;
// mangled name is now in [begin_name, begin_offset) and caller const char* sym = dl.dli_sname;
// offset in [begin_offset, end_offset). now apply
// __cxa_demangle():
int status = 0; int status = 0;
char* ret = abi::__cxa_demangle( begin_name, funcname, char* ret = abi::__cxa_demangle( sym, NULL, 0, &status );
&funcnamesize, &status );
char* fname = begin_name;
if ( status == 0 ) if( status == 0 && ret )
fname = ret; sym = ret;
if ( begin_offset ) if( dl.dli_fname && sym )
{ {
TRACELOG << setw(30) << symbollist[i] TRACELOG << setw(30) << symbollist[i]
<< " ( " << setw(40) << fname << " ( " << setw(40) << dl.dli_fname
<< " +" << setw(6) << begin_offset << " ): " << sym
<< ") " << end_offset << endl << flush;
<< endl;
}
else
{
TRACELOG << setw(30) << symbollist[i]
<< " ( " << setw(40) << fname
<< " " << setw(6) << ""
<< ") " << end_offset
<< endl;
}
} }
else else
{ {
// couldn't parse the line? print the whole line. TRACELOG << setw(30) << symbollist[i] << endl << flush;
TRACELOG << setw(40) << symbollist[i] << endl;
} }
if( ret )
std::free(ret);
} }
std::free(symbollist); std::free(symbollist);
...@@ -262,6 +230,7 @@ bool gdb_print_trace() ...@@ -262,6 +230,7 @@ bool gdb_print_trace()
if( child_pid == 0 ) // CHILD if( child_pid == 0 ) // CHILD
{ {
msleep(300); // пауза чтобы родитель успел подготовиться.. msleep(300); // пауза чтобы родитель успел подготовиться..
dup2(2,1); // redirect output to stderr
if( g_act && !g_act->getAbortScript().empty() ) if( g_act && !g_act->getAbortScript().empty() )
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment