Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-4136: pre review GP-4136: fix interrupt button GP-4136: fix for duplicates GP-4136: base thread-selected action on last wait status GP-4136: better behavior for dbgeng

d-millar881dfa2a547f
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py
index 81ce49f254..50fe43f74f 100644
--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py
+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py
@@ -494,7 +494,7 @@ def putreg():
value = regs._get_register_by_index(i)
try:
values.append(mapper.map_value(nproc, name, value))
- robj.set_value(name, value)
+ robj.set_value(name, hex(value))
except Exception:
pass
return {'missing': STATE.trace.put_registers(space, values)}
@@ -867,6 +867,12 @@ def put_state(event_process):
state = compute_proc_state(event_process)
procobj.set_value('_state', state)
procobj.insert()
+ tnum = util.selected_thread()
+ if tnum is not None:
+ ipath = THREAD_PATTERN.format(procnum=event_process, tnum=tnum)
+ threadobj = STATE.trace.create_object(ipath)
+ threadobj.set_value('_state', state)
+ threadobj.insert()
STATE.require_tx().commit()
STATE.reset_tx()
@@ -1334,7 +1340,7 @@ def repl():
cmd = input().strip()
if not cmd:
continue
- dbg().cmd(cmd, quiet=False)
+ dbg().cmd(cmd, quiet=True)
stat = dbg().exec_status()
if stat != 'BREAK':
dbg().wait()
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py
index 984d86e7d9..831a38b16b 100644
--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py
+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py
@@ -36,7 +36,7 @@ class HookState(object):
class ProcessState(object):
- __slots__ = ('first', 'regions', 'modules', 'threads', 'breaks', 'watches', 'visited')
+ __slots__ = ('first', 'regions', 'modules', 'threads', 'breaks', 'watches', 'visited', 'waiting')
def __init__(self):
self.first = True
@@ -48,8 +48,10 @@ class ProcessState(object):
self.watches = False
# For frames and threads that have already been synced since last stop
self.visited = set()
+ self.waiting = True
def record(self, description=None):
+ #print("RECORDING")
first = self.first
self.first = False
if description is not None:
@@ -72,7 +74,7 @@ class ProcessState(object):
hashable_frame = (thread, frame)
if first or hashable_frame not in self.visited:
self.visited.add(hashable_frame)
- if first or self.regions or self.threads or self.modules:
+ if first or self.regions:
commands.put_regions()
self.regions = False
if first or self.modules:
@@ -122,7 +124,6 @@ PROC_STATE = {}
def on_state_changed(*args):
#print("ON_STATE_CHANGED")
- #print(args[0])
if args[0] == DbgEng.DEBUG_CES_CURRENT_THREAD:
return on_thread_selected(args)
elif args[0] == DbgEng.DEBUG_CES_BREAKPOINTS:
@@ -131,8 +132,12 @@ def on_state_changed(*args):
util.set_convenience_variable('output-radix', args[1])
return DbgEng.DEBUG_STATUS_GO
elif args[0] == DbgEng.DEBUG_CES_EXECUTION_STATUS:
+ proc = util.selected_process()
if args[1] & DbgEng.DEBUG_STATUS_INSIDE_WAIT:
+ PROC_STATE[proc].waiting = True
return DbgEng.DEBUG_STATUS_GO
+ PROC_STATE[proc].waiting = False
+ commands.put_state(proc)
if args[1] == DbgEng.DEBUG_STATUS_BREAK:
return on_stop(args)
else:
@@ -246,8 +251,13 @@ def on_thread_selected(*args):
return
with commands.STATE.client.batch():
with trace.open_tx("Thread {}.{} selected".format(nproc, nthrd)):
- PROC_STATE[nproc].record()
- commands.activate()
+ commands.put_state(nproc)
+ state = PROC_STATE[nproc]
+ if state.waiting:
+ state.record_continued()
+ else:
+ state.record()
+ commands.activate()
def on_register_changed(regnum):
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py
index 5b4fe2421f..c4094d2a07 100644
--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py
+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py
@@ -376,7 +376,7 @@ def _continue(process: sch.Schema('Process')):
@REGISTRY.method
-def interrupt():
+def interrupt(process: sch.Schema('Process')):
"""Interrupt the execution of the debugged program."""
dbg()._control.SetInterrupt(DbgEng.DEBUG_INTERRUPT_ACTIVE)