From ac83de804e3d4a2ab9d261d7aa9a25c7176604cd Mon Sep 17 00:00:00 2001 From: William Tan <1284324+Ninja3047@users.noreply.github.com> Date: Mon, 20 Jan 2025 20:03:57 -0500 Subject: [PATCH 1/2] Allow setting debugger path via context --- pwnlib/context/__init__.py | 15 +++++++++++++++ pwnlib/gdb.py | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/pwnlib/context/__init__.py b/pwnlib/context/__init__.py index a95ec4310..a9410d8df 100644 --- a/pwnlib/context/__init__.py +++ b/pwnlib/context/__init__.py @@ -359,6 +359,7 @@ class ContextType(object): 'encoding': 'auto', 'endian': 'little', 'gdbinit': "", + 'gdb_binary': "", 'kernel': None, 'local_libcdb': "/var/lib/libc-database", 'log_level': logging.INFO, @@ -1539,6 +1540,20 @@ def gdbinit(self, value): """ return str(value) + @_validator + def gdb_binary(self, value): + """Path to the binary that is used when running GDB locally. + + This is useful when you have multiple versions of gdb installed or the gdb binary is + called something different. + + If set to an empty string, pwntools will try to search for a reasonable gdb binary from + the path. + + Default value is ``""``. + """ + return str(value) + @_validator def cyclic_alphabet(self, alphabet): """Cyclic alphabet. diff --git a/pwnlib/gdb.py b/pwnlib/gdb.py index 9dd509360..1c6c1bfc3 100644 --- a/pwnlib/gdb.py +++ b/pwnlib/gdb.py @@ -750,6 +750,12 @@ def binary(): >>> gdb.binary() # doctest: +SKIP '/usr/bin/gdb' """ + if context.gdb_binary: + gdb = misc.which(context.gdb_binary) + if not gdb: + log.warn_once('Path to gdb binary `{}` not found'.format(context.gdb_binary)) + return gdb + gdb = misc.which('pwntools-gdb') or misc.which('gdb') if not context.native: From 0203a0c6572641bd9f538ee5c63ded85a341c044 Mon Sep 17 00:00:00 2001 From: William Tan <1284324+Ninja3047@users.noreply.github.com> Date: Mon, 20 Jan 2025 20:32:29 -0500 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f809a8d24..c05027077 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,7 +73,7 @@ The table below shows which release corresponds to each branch, and what date th | [2.2.0](#220) | | Jan 5, 2015 ## 5.0.0 (`dev`) - +- [#2527][2527] Allow setting debugger path via `context.gdb_binary` ## 4.15.0 (`beta`) - [#2508][2508] Ignore a warning when compiling with asm on nix