Skip to content

Commit 0b0fe7d

Browse files
committed
run stacktrace to c++filt automatically, when available
1 parent 4061445 commit 0b0fe7d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/app/main.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,30 @@ void myMessageOutput( QtMsgType type, const char *msg )
254254
{
255255
fprintf( stderr, "Fatal: %s\n", msg );
256256
#if defined(linux) && !defined(ANDROID)
257-
( void ) write( STDERR_FILENO, "Stacktrace (run through c++filt):\n", 34 );
257+
if( access( "/usr/bin/c++filt", X_OK) )
258+
{
259+
( void ) write( STDERR_FILENO, "Stacktrace (c++filt NOT FOUND):\n", 32 );
260+
}
261+
else
262+
{
263+
int fd[2];
264+
265+
if( pipe(fd)==0 && fork()==0 )
266+
{
267+
close( STDIN_FILENO );
268+
close( fd[1] );
269+
dup( fd[0] );
270+
execl( "/usr/bin/c++filt", "c++filt", (char *) 0 );
271+
exit(1);
272+
}
273+
274+
( void ) write( STDERR_FILENO, "Stacktrace (piped through c++filt):\n", 36 );
275+
276+
close( STDERR_FILENO );
277+
close( fd[0] );
278+
dup( fd[1] );
279+
}
280+
258281
void *buffer[256];
259282
int nptrs = backtrace( buffer, sizeof( buffer ) / sizeof( *buffer ) );
260283
backtrace_symbols_fd( buffer, nptrs, STDERR_FILENO );

0 commit comments

Comments
 (0)