Skip to content

Commit 9971980

Browse files
committed
xrCore: add print stack trace in linux
1 parent 4ea4f93 commit 9971980

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/xrCore/xrDebug.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static BOOL bException = FALSE;
5151
#elif defined(LINUX)
5252
#include <sys/user.h>
5353
#include <sys/ptrace.h>
54+
#include <execinfo.h>
5455
#endif
5556
#pragma comment(lib, "FaultRep.lib")
5657

@@ -444,6 +445,20 @@ void xrDebug::GatherInfo(char* assertionInfo, size_t bufferSize, const ErrorLoca
444445
buffer += xr_sprintf(buffer, bufferSize, "%s\n", stackTrace[i].c_str());
445446
#endif // USE_OWN_ERROR_MESSAGE_WINDOW
446447
}
448+
#elif defined(LINUX)
449+
void *array[20];
450+
int nptrs = backtrace(array, 20); // get void*'s for all entries on the stack
451+
char **strings = backtrace_symbols(array, nptrs);
452+
453+
if(strings)
454+
for (size_t i = 0; i < nptrs; i++)
455+
{
456+
if (shared_str_initialized)
457+
Log(strings[i]);
458+
#ifdef USE_OWN_ERROR_MESSAGE_WINDOW
459+
buffer += xr_sprintf(buffer, bufferSize, "%s\n", strings[i]);
460+
#endif // USE_OWN_ERROR_MESSAGE_WINDOW
461+
}
447462
#endif
448463
if (shared_str_initialized)
449464
FlushLog();

0 commit comments

Comments
 (0)