Commit 60689442 authored by Pavel Vainerman's avatar Pavel Vainerman

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

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