diff --git a/Ghidra/Debug/Debugger-agent-drgn/data/debugger-launchers/local-drgn.sh b/Ghidra/Debug/Debugger-agent-drgn/data/debugger-launchers/local-drgn.sh
index c28859be13..ea0a87a00a 100755
--- a/Ghidra/Debug/Debugger-agent-drgn/data/debugger-launchers/local-drgn.sh
+++ b/Ghidra/Debug/Debugger-agent-drgn/data/debugger-launchers/local-drgn.sh
@@ -26,7 +26,7 @@
#@icon icon.debugger
#@help drgn#attach
#@depends Debugger-rmi-trace
-#@env OPT_TARGET_PID:int=44068 "PID" "The target's process id"
+#@env OPT_TARGET_PID:int=-1 "PID" "The target's process id"
export OPT_TARGET_KIND="user"
# sudo -E drgn -p "$OPT_TARGET_PID" ../support/local-drgn.py
diff --git a/Ghidra/Debug/Debugger-agent-drgn/src/main/help/help/topics/drgn/drgn.html b/Ghidra/Debug/Debugger-agent-drgn/src/main/help/help/topics/drgn/drgn.html
index a15e5e142c..90b811038d 100644
--- a/Ghidra/Debug/Debugger-agent-drgn/src/main/help/help/topics/drgn/drgn.html
+++ b/Ghidra/Debug/Debugger-agent-drgn/src/main/help/help/topics/drgn/drgn.html
@@ -66,8 +66,19 @@ echo 0 > /proc/sys/kernel/yama/ptrace_scope
Setup
- You must have Meta's drgn installed on the local system. No other setup is required.
- Note: requires root access - you will be prompted for a password in the Terminal.
+ You must have Meta's drgn installed on the local system. Symbols for the running kernel
+ should also be installed, as described in the drgn documentation, e.g. using:
+
+
+ Note: this launcher requires root access - you will be prompted for a password in the Terminal.
+ Also note: running drgn as root may leave artifacts in the active python cache with root
+ permissions, which may need to be deleted manually when rebuilding.
Options
diff --git a/Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py b/Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py
index cf22128a8b..3272679a85 100644
--- a/Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py
+++ b/Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py
@@ -266,16 +266,17 @@ def ghidra_trace_create(start_trace: bool = True) -> None:
global prog
prog = Program()
+
kind = os.getenv('OPT_TARGET_KIND')
if kind == "kernel":
prog.set_kernel()
+ util.selected_pid = 0
elif kind == "coredump":
img = os.getenv('OPT_TARGET_IMG')
if img is None:
return
prog.set_core_dump(img)
- if '/' in img:
- img = img[img.rindex('/')+1:]
+ util.selected_pid = 0
else:
pid = os.getenv('OPT_TARGET_PID')
if pid is not None:
@@ -288,18 +289,34 @@ def ghidra_trace_create(start_trace: bool = True) -> None:
except drgn.MissingDebugInfoError as e:
print(e)
- if hasattr(drgn, 'Module') or kind == "coredump":
- if kind == "kernel":
- img = prog.main_module().name # type: ignore
- util.selected_tid = next(prog.threads()).tid
- elif kind == "coredump":
- util.selected_tid = prog.crashed_thread().tid
- else:
- img = prog.main_module().name # type: ignore
- util.selected_tid = prog.main_thread().tid
+ # Set display name and active thread
+ display = "noname"
+ if kind == "kernel":
+ display = "kernel"
+ if hasattr(prog, "main_module"):
+ if hasattr(prog.main_module(), "name"):
+ display = prog.main_module().name # type: ignore
+ try:
+ threads = prog.threads()
+ except Exception as e:
+ print(f"ERROR: {e}")
+ return
+ util.selected_tid = next(prog.threads()).tid
+ elif kind == "coredump":
+ display = img
+ if '/' in display:
+ display = display[display.rindex('/')+1:]
+ util.selected_tid = prog.crashed_thread().tid
+ else:
+ display = str(pid)
+ if hasattr(prog, "main_thread"):
+ if hasattr(prog.main_thread(), "name"):
+ display = prog.main_thread().name
+ util.selected_tid = prog.main_thread().tid
+ util.selected_level = 0
if start_trace:
- ghidra_trace_start(img)
+ ghidra_trace_start(display)
PROGRAMS[util.selected_pid] = prog
@@ -1108,7 +1125,11 @@ def put_threads(running: bool = False) -> None:
trace = STATE.require_trace()
keys = []
# Set running=True to avoid thread changes, even while stopped
- threads = prog.threads()
+ try:
+ threads = prog.threads()
+ except Exception as e:
+ print(f"ERROR: {e}")
+ return
for i, t in enumerate(threads):
nthrd = t.tid
tpath = THREAD_PATTERN.format(procnum=nproc, tnum=nthrd)