Last active
December 20, 2015 14:18
-
-
Save fcamel/6144935 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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): | |
num = 0; | |
try: | |
num = int(arg) | |
except Exception, e: | |
pass | |
lines = [] | |
f = gdb.newest_frame() | |
fn = 0 | |
while f is not None: | |
symtab_and_line = gdb.Frame.find_sal(f) | |
frame_name = gdb.Frame.name(f) | |
if frame_name: | |
args = [ | |
fn, | |
frame_name, | |
symtab_and_line.symtab.filename, | |
symtab_and_line.line, | |
] | |
else: | |
args = [fn, '??', 'unknown', 0] | |
lines.append('#%2d %s at %s:%s' % tuple(args)) | |
f = gdb.Frame.older(f) | |
fn += 1 | |
if num > 0: | |
lines = lines[:num] | |
elif num < 0: | |
lines = lines[len(lines) + num:] | |
for line in lines: | |
print line | |
ShorternBacktraceCommand() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment