Last active
April 12, 2016 14:17
-
-
Save groleo/4731938c7a207f388f8ed2233661c3b1 to your computer and use it in GitHub Desktop.
GDB extension to automatically get the source files when doing a "backtrace"
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
# GDB python extension to pull the source files from a server, when executing "gdb backtrace" | |
# Modify file_server to match your needs | |
# Tested on gdb 7.10 | |
# It depends on scp and password-less login. | |
# Adapted from a GDB example [https://sourceware.org/gdb/onlinedocs/gdb/Python.html#Python] | |
import gdb | |
from gdb.FrameDecorator import FrameDecorator | |
file_server='host where you've built' | |
gdb_dir="gdb-sources" | |
# Note: doesn't check if the files have changed, only if they exist | |
def get_file(fname): | |
os.makedirs(gdb_dir,exist_ok=True) | |
local_file = gdb_dir + os.path.sep + os.path.basename(fname) | |
if not os.path.isfile(local_file): | |
os.system('scp %s:%s %s' % (file_server,fname,local_file) ) | |
class InlinedFrameDecorator(FrameDecorator): | |
def __init__(self, fobj): | |
super(InlinedFrameDecorator, self).__init__(fobj) | |
self.fobj = fobj | |
def filename(self): | |
fname = self.fobj.filename() | |
get_file(fname) | |
return fname | |
class InlineFilter(): | |
def __init__(self): | |
# Frame filter attribute creation. | |
# | |
# 'name' is the name of the filter that GDB will display. | |
# | |
# 'priority' is the priority of the filter relative to other | |
# filters. | |
# | |
# 'enabled' is a boolean that indicates whether this filter is | |
# enabled and should be executed. | |
self.name = "InlinedFrameFilter" | |
self.priority = 100 | |
self.enabled = True | |
# Register this frame filter with the global frame_filters | |
# dictionary. | |
gdb.frame_filters[self.name] = self | |
gdb.execute("dir %s" % gdb_dir) | |
def filter(self, frame_iter): | |
frame_iter = map(InlinedFrameDecorator, | |
frame_iter) | |
return frame_iter | |
InlineFilter() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment