Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where gdb.execute during object loading causes an exception. #1755

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pwndbg/gdblib/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _get_arch(ptrsize: int):
else:
endian = "big"

if pwndbg.gdblib.proc.alive:
if pwndbg.gdblib.proc.alive and not gdb.selected_thread().is_running():
arch = gdb.newest_frame().architecture().name()
else:
arch = gdb.execute("show architecture", to_string=True).strip()
Expand Down
29 changes: 22 additions & 7 deletions pwndbg/gdblib/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ def invoke_callbacks(self) -> None:
objfile_cache: Dict[str, Set[str]] = {}


class DelayedEventHandler:
def __init__(self, func):
self.func = func

def __call__(self):
self.func()


def connect(func, event_handler, name=""):
if debug:
print("Connecting", func.__name__, event_handler)
Expand All @@ -140,6 +148,15 @@ def caller(*a):
if debug:
sys.stdout.write("%r %s.%s %r\n" % (name, func.__module__, func.__name__, a))

def func_caller():
try:
func()
except Exception as e:
import pwndbg.exception

pwndbg.exception.handle()
raise e

if a and isinstance(a[0], gdb.NewObjFileEvent):
objfile = a[0].new_objfile
handler = f"{func.__module__}.{func.__name__}"
Expand All @@ -152,13 +169,11 @@ def caller(*a):
dispatched.add(handler)
objfile_cache[path] = dispatched

try:
func()
except Exception as e:
import pwndbg.exception

pwndbg.exception.handle()
raise e
# It does not seem calling gdb.execute during NewObjFileEvent
# is (always) safe. Delay execution of the callback.
gdb.post_event(DelayedEventHandler(func_caller))
else:
func_caller()

registered[event_handler].append(caller)
event_handler.connect(caller)
Expand Down
Loading