Created
August 3, 2013 02:41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gdb | |
import re | |
class ShorternBacktraceCommand(gdb.Command): | |
'''Show a backtrace without argument info in each frame.''' | |
def __init__(self): | |
super(ShorternBacktraceCommand, self).__init__ ("bt", | |
gdb.COMMAND_SUPPORT, | |
gdb.COMPLETE_NONE) | |
def invoke(self, arg, from_tty): | |
if not arg: | |
arg = '' | |
raw = gdb.execute("backtrace %s" % arg, True, True) | |
lines = raw.split('\n') | |
for i, line in enumerate(lines): | |
if not line: | |
continue | |
tokens = line.split() | |
# first line format: e.g., #0 A::hello (...) at a.cpp:8 | |
# the rest : e.g., #2 0x0..0 in A::foo (...) at a.cpp:18 | |
func_index = 1 if i == 0 else 3 | |
print ('\033[1;33m%2s\033[m %s at %s' | |
'' % (tokens[0], tokens[func_index], tokens[-1])) | |
ShorternBacktraceCommand() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment