Skip to content

Commit

Permalink
Add configurable gdbinit (#1007)
Browse files Browse the repository at this point in the history
* fix typo in comment

* new config option: context.gdbinit

This allows setting the default gdbinit for GDB, which is helpful when you want
to enable some GDB extension only when using pwntools and not by default.
  • Loading branch information
bennofs authored and zachriggle committed Sep 6, 2017
1 parent 3e33180 commit 5831796
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pwnlib/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _Tls_DictStack(threading.local, _DictStack):

def _validator(validator):
"""
Validator that tis tightly coupled to the implementation
Validator that is tightly coupled to the implementation
of the classes here.
This expects that the object has a ._tls property which
Expand Down Expand Up @@ -340,6 +340,7 @@ class ContextType(object):
'delete_corefiles': False,
'device': os.getenv('ANDROID_SERIAL', None) or None,
'endian': 'little',
'gdbinit': "",
'kernel': None,
'log_level': logging.INFO,
'log_file': _devnull(),
Expand Down Expand Up @@ -1231,6 +1232,23 @@ def rename_corefiles(self, v):
"""
return bool(v)


@_validator
def gdbinit(self, value):
"""Path to the gdbinit that is used when running GDB locally.
This is useful if you want pwntools-launched GDB to include some additional modules,
like PEDA but you do not want to have GDB include them by default.
The setting will only apply when GDB is launched locally since remote hosts may not have
the necessary requirements for the gdbinit.
If set to an empty string, GDB will use the default `~/.gdbinit`.
Default value is ``""``.
"""
return str(value)

#*************************************************************************
# ALIASES
#*************************************************************************
Expand Down
4 changes: 4 additions & 0 deletions pwnlib/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ def findexe():
cmd += ' '
cmd += ' '.join(gdb_args)

if context.gdbinit:
cmd += ' -nh ' # ignore ~/.gdbinit
cmd += ' -x %s ' % context.gdbinit # load custom gdbinit

cmd += ' -q '

if exe and context.native:
Expand Down

0 comments on commit 5831796

Please sign in to comment.