From c6f0705e3baabea244292a9605529cc7a5e36b9d Mon Sep 17 00:00:00 2001 From: Zach Riggle Date: Sat, 5 Mar 2016 04:22:12 -0800 Subject: [PATCH] Experimental support for auto-reloading when switching threads This is particularly important when switching threads in a coredump, when you can't just single-step to ensure everything gets reloaded. --- pwndbg/__init__.py | 14 +++++++++++++- pwndbg/argv.py | 8 +++++++- pwndbg/events.py | 13 +++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py index 2897e931e..17b086384 100644 --- a/pwndbg/__init__.py +++ b/pwndbg/__init__.py @@ -111,8 +111,20 @@ for line in pre_commands.strip().splitlines(): msg = "Loaded %i commands. Type pwndbg for a list." % len(pwndbg.commands._Command.commands) print(pwndbg.color.red(msg)) -@pwndbg.memoize.reset_on_stop +cur = (gdb.selected_inferior(), gdb.selected_thread()) + def prompt_hook(*a): + global cur + new = (gdb.selected_inferior(), gdb.selected_thread()) + + if cur != new: + pwndbg.events.after_reload() + cur = new + + prompt_hook_on_stop(*a) + +@pwndbg.memoize.reset_on_stop +def prompt_hook_on_stop(*a): with pwndbg.stdio.stdio: pwndbg.commands.context.context() diff --git a/pwndbg/argv.py b/pwndbg/argv.py index 7613ae007..531032b94 100644 --- a/pwndbg/argv.py +++ b/pwndbg/argv.py @@ -1,3 +1,5 @@ +import gdb + import pwndbg.arch import pwndbg.events import pwndbg.memory @@ -21,7 +23,11 @@ def update(): ptrsize = pwndbg.arch.ptrsize ptrbits = 8 * ptrsize - argc = pwndbg.memory.u(sp, ptrbits) + try: + argc = pwndbg.memory.u(sp, ptrbits) + except: + return + sp += ptrsize argv = sp diff --git a/pwndbg/events.py b/pwndbg/events.py index f3dfcb9d0..847822778 100644 --- a/pwndbg/events.py +++ b/pwndbg/events.py @@ -110,12 +110,13 @@ def stop(func): return connect(func, gdb.events.stop, 'stop') def start(func): return connect(func, gdb.events.start, 'start') def after_reload(): - return - # if gdb.selected_inferior().pid: - # for f in registered[gdb.events.new_objfile]: - # f() - # for f in registered[gdb.events.stop]: - # f() + if gdb.selected_inferior().pid: + for f in registered[gdb.events.start]: + f() + for f in registered[gdb.events.new_objfile]: + f() + for f in registered[gdb.events.stop]: + f() def on_reload(): for event, functions in registered.items():