Skip to content

Commit 171d9df

Browse files
authored
Fix: Allow setting attributes on gdb Breakpoints (#2339)
* fix: Allow setting attributes on gdb Breakpoints * Update CHANGELOG * Add __getattr__ accidentally deleted from FinishBreakpoint
1 parent cb3fda4 commit 171d9df

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ The table below shows which release corresponds to each branch, and what date th
8383
- [#2334][2334] Speed up disasm commandline tool with colored output
8484
- [#2328][2328] Lookup using $PATHEXT file extensions in `which` on Windows
8585
- [#2189][2189] Explicitly define p64/u64 functions for IDE support
86+
- [#2339][2339] Fix: Allow setting attributes on gdb Breakpoints
8687

8788
[2242]: https://github.com/Gallopsled/pwntools/pull/2242
8889
[2277]: https://github.com/Gallopsled/pwntools/pull/2277
@@ -97,6 +98,7 @@ The table below shows which release corresponds to each branch, and what date th
9798
[2334]: https://github.com/Gallopsled/pwntools/pull/2334
9899
[2328]: https://github.com/Gallopsled/pwntools/pull/2328
99100
[2189]: https://github.com/Gallopsled/pwntools/pull/2189
101+
[2339]: https://github.com/Gallopsled/pwntools/pull/2339
100102

101103
## 4.12.0 (`beta`)
102104

pwnlib/gdb.py

+27-10
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,10 @@ def __init__(self, conn, *args, **kwargs):
652652
"""
653653
# Creates a real breakpoint and connects it with this mirror
654654
self.conn = conn
655-
self.server_breakpoint = conn.root.set_breakpoint(
655+
self.server_breakpoint = self._server_set_breakpoint(*args, **kwargs)
656+
657+
def _server_set_breakpoint(self, *args, **kwargs):
658+
return self.conn.root.set_breakpoint(
656659
self, hasattr(self, 'stop'), *args, **kwargs)
657660

658661
def __getattr__(self, item):
@@ -670,25 +673,43 @@ def __getattr__(self, item):
670673
raise AttributeError()
671674
return getattr(self.server_breakpoint, item)
672675

676+
def __setattr__(self, name, value):
677+
"""Set attributes of the real breakpoint."""
678+
if name in (
679+
'enabled',
680+
'silent',
681+
'thread',
682+
'task',
683+
'ignore_count',
684+
'hit_count'
685+
'condition',
686+
'commands',
687+
):
688+
return setattr(self.server_breakpoint, name, value)
689+
return super().__setattr__(name, value)
690+
673691
def exposed_stop(self):
674692
# Handle stop() call from the server.
675693
return self.stop()
676694

677-
class FinishBreakpoint:
695+
class FinishBreakpoint(Breakpoint):
678696
"""Mirror of ``gdb.FinishBreakpoint`` class.
679697
680698
See https://sourceware.org/gdb/onlinedocs/gdb/Finish-Breakpoints-in-Python.html
681699
for more information.
682700
"""
683701

684-
def __init__(self, conn, *args, **kwargs):
702+
def __init__(self, *args, **kwargs):
685703
"""Do not create instances of this class directly.
686704
687705
Use ``pwnlib.gdb.Gdb.FinishBreakpoint`` instead.
688706
"""
689-
# Creates a real finish breakpoint and connects it with this mirror
690-
self.conn = conn
691-
self.server_breakpoint = conn.root.set_finish_breakpoint(
707+
# See https://github.com/pylint-dev/pylint/issues/4228
708+
# pylint: disable=useless-super-delegation
709+
super().__init__(*args, **kwargs)
710+
711+
def _server_set_breakpoint(self, *args, **kwargs):
712+
return self.conn.root.set_finish_breakpoint(
692713
self, hasattr(self, 'stop'), hasattr(self, 'out_of_scope'),
693714
*args, **kwargs)
694715

@@ -708,10 +729,6 @@ def __getattr__(self, item):
708729
raise AttributeError()
709730
return getattr(self.server_breakpoint, item)
710731

711-
def exposed_stop(self):
712-
# Handle stop() call from the server.
713-
return self.stop()
714-
715732
def exposed_out_of_scope(self):
716733
# Handle out_of_scope() call from the server.
717734
return self.out_of_scope()

pwnlib/gdb_api_bridge.py

+1
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@ def exposed_quit(self):
110110
socket_path=socket_path,
111111
protocol_config={
112112
'allow_all_attrs': True,
113+
'allow_setattr': True,
113114
},
114115
).start)

0 commit comments

Comments
 (0)