Skip to content

Commit e51bc74

Browse files
authored
Allow setting debugger path via context.gdb_binary (#2527)
* Allow setting debugger path via context * Update changelog
1 parent cff58e1 commit e51bc74

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,19 @@ The table below shows which release corresponds to each branch, and what date th
7373
| [2.2.0](#220) | | Jan 5, 2015
7474

7575
## 5.0.0 (`dev`)
76-
7776
- [#2507][2507] Add `+LINUX` and `+WINDOWS` doctest options and start proper testing on Windows
7877
- [#2522][2522] Support starting a kitty debugging window with the 'kitten' command
7978
- [#2524][2524] Raise EOFError during `process.recv` when stdout closes on Windows
8079
- [#2526][2526] Properly make use of extra arguments in `packing` utilities. `sign` parameter requires keyword syntax to specify it.
8180
- [#2517][2517] Allow to passthru kwargs on `ssh.__getattr__` convenience function to fix SSH motd problems
81+
- [#2527][2527] Allow setting debugger path via `context.gdb_binary`
8282

8383
[2507]: https://github.com/Gallopsled/pwntools/pull/2507
8484
[2522]: https://github.com/Gallopsled/pwntools/pull/2522
8585
[2524]: https://github.com/Gallopsled/pwntools/pull/2524
8686
[2526]: https://github.com/Gallopsled/pwntools/pull/2526
8787
[2517]: https://github.com/Gallopsled/pwntools/pull/2517
88+
[2527]: https://github.com/Gallopsled/pwntools/pull/2527
8889

8990
## 4.15.0 (`beta`)
9091
- [#2508][2508] Ignore a warning when compiling with asm on nix

pwnlib/context/__init__.py

+15
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ class ContextType(object):
363363
'encoding': 'auto',
364364
'endian': 'little',
365365
'gdbinit': "",
366+
'gdb_binary': "",
366367
'kernel': None,
367368
'local_libcdb': "/var/lib/libc-database",
368369
'log_level': logging.INFO,
@@ -1546,6 +1547,20 @@ def gdbinit(self, value):
15461547
"""
15471548
return str(value)
15481549

1550+
@_validator
1551+
def gdb_binary(self, value):
1552+
"""Path to the binary that is used when running GDB locally.
1553+
1554+
This is useful when you have multiple versions of gdb installed or the gdb binary is
1555+
called something different.
1556+
1557+
If set to an empty string, pwntools will try to search for a reasonable gdb binary from
1558+
the path.
1559+
1560+
Default value is ``""``.
1561+
"""
1562+
return str(value)
1563+
15491564
@_validator
15501565
def cyclic_alphabet(self, alphabet):
15511566
"""Cyclic alphabet.

pwnlib/gdb.py

+6
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,12 @@ def binary():
750750
>>> gdb.binary() # doctest: +SKIP
751751
'/usr/bin/gdb'
752752
"""
753+
if context.gdb_binary:
754+
gdb = misc.which(context.gdb_binary)
755+
if not gdb:
756+
log.warn_once('Path to gdb binary `{}` not found'.format(context.gdb_binary))
757+
return gdb
758+
753759
gdb = misc.which('pwntools-gdb') or misc.which('gdb')
754760

755761
if not context.native:

0 commit comments

Comments
 (0)