Skip to content

Commit

Permalink
Fix stack printing with gdb.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Brzozowski committed Oct 31, 2016
1 parent 499c285 commit e521a37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gdb_input.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bt full
thread apply all bt
quit
17 changes: 12 additions & 5 deletions stack_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ int addr2line(char const * const program_name, void const * const addr)

int printStacktraceWithGdb(const char* gdb) {
char gdbcmd[512] = {0};
sprintf(gdbcmd, "%s %s -batch -q -p %d -x gdb_input.txt >> stacktrace.out", gdb, icky_global_program_name, getpid());
sprintf(gdbcmd, "%s keeper.exe -batch -q -p %d -x gdb_input.txt >> stacktrace.out", gdb, GetCurrentProcessId());
fputs(gdbcmd, stderr);
fflush(stderr);
return system(gdbcmd);
}

#ifdef WINDOWS
void windows_print_stacktrace(CONTEXT* context)
{
if (!printStacktraceWithGdb("gdb.exe")) {
fputs("Successfully printed stacktrace using GDB.\n", stderr);
return;
}
SymInitialize(GetCurrentProcess(), 0, true);

STACKFRAME frame = { 0 };
Expand Down Expand Up @@ -98,6 +96,15 @@ int printStacktraceWithGdb(const char* gdb) {

LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS * ExceptionInfo)
{
fputs("Printing windows stack.\n", stderr);
if (!printStacktraceWithGdb("gdb.exe")) {
fputs("Successfully printed stacktrace using GDB.\n", stderr);
fflush(stderr);
return EXCEPTION_EXECUTE_HANDLER;
}
fputs("Failed to print stacktrace using GDB. Using built-in stack printer.\n", stderr);
fflush(stderr);

switch(ExceptionInfo->ExceptionRecord->ExceptionCode)
{
case EXCEPTION_ACCESS_VIOLATION:
Expand Down

0 comments on commit e521a37

Please sign in to comment.