import gdb class ExhaustiveBacktrace(gdb.Command): """Get full backtraces for all threads. Also gets full xbacktrace for the first thread. This command assumes that the xbacktrace hook for backtrace has been disabled. """ def __init__(self): super(ExhaustiveBacktrace, self).__init__("exhaustive-backtrace", gdb.COMMAND_STACK) def invoke(self, arg, from_tty): # Turn pagination off until we're done. pagination = ("State of pagination is on." == gdb.execute("show pagination", to_string=True)) gdb.execute("set pagination off") initial_thread = gdb.selected_thread() gdb.execute("info threads") gdb.write("Full backtrace for main thread\n") gdb.execute("backtrace full") gdb.execute("xbacktrace full") threads = list(gdb.selected_inferior().threads()) threads.remove(initial_thread) threads.reverse() for t in threads: gdb.write("Full backtrace for thread {}\n".format(t.num)) t.switch() gdb.execute("backtrace full") # Turn pagination back on if it was on when we started. if pagination: gdb.execute("set pagination on") ExhaustiveBacktrace()