GP-6541: post-review

GP-6541: tests working
GP-6541: docs
GP-6541: basic errors
This commit is contained in:
d-millar
2026-03-10 10:21:09 -04:00
committed by Ryan Kurtz
parent 6a931fab6b
commit 5c80a44a03
3 changed files with 48 additions and 16 deletions

View File

@@ -26,7 +26,7 @@
#@icon icon.debugger #@icon icon.debugger
#@help drgn#attach #@help drgn#attach
#@depends Debugger-rmi-trace #@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" export OPT_TARGET_KIND="user"
# sudo -E drgn -p "$OPT_TARGET_PID" ../support/local-drgn.py # sudo -E drgn -p "$OPT_TARGET_PID" ../support/local-drgn.py

View File

@@ -66,8 +66,19 @@ echo 0 > /proc/sys/kernel/yama/ptrace_scope
<H3>Setup</H3> <H3>Setup</H3>
<P>You must have Meta's <B>drgn</B> installed on the local system. No other setup is required. <P>You must have Meta's <B>drgn</B> installed on the local system. Symbols for the running kernel
Note: requires root access - you will be prompted for a password in the Terminal.</P> should also be installed, as described in the <B>drgn</B> documentation, e.g. using:</P>
<UL style="list-style-type: none">
<LI>
<PRE>
sudo dnf debuginfo-install kernel-$(uname -r)
</PRE>
</LI>
</UL>
<P>Note: this launcher requires root access - you will be prompted for a password in the Terminal.
Also note: running <B>drgn</B> as root may leave artifacts in the active python cache with root
permissions, which may need to be deleted manually when rebuilding.</P>
<H3>Options</H3> <H3>Options</H3>

View File

@@ -266,16 +266,17 @@ def ghidra_trace_create(start_trace: bool = True) -> None:
global prog global prog
prog = Program() prog = Program()
kind = os.getenv('OPT_TARGET_KIND') kind = os.getenv('OPT_TARGET_KIND')
if kind == "kernel": if kind == "kernel":
prog.set_kernel() prog.set_kernel()
util.selected_pid = 0
elif kind == "coredump": elif kind == "coredump":
img = os.getenv('OPT_TARGET_IMG') img = os.getenv('OPT_TARGET_IMG')
if img is None: if img is None:
return return
prog.set_core_dump(img) prog.set_core_dump(img)
if '/' in img: util.selected_pid = 0
img = img[img.rindex('/')+1:]
else: else:
pid = os.getenv('OPT_TARGET_PID') pid = os.getenv('OPT_TARGET_PID')
if pid is not None: if pid is not None:
@@ -288,18 +289,34 @@ def ghidra_trace_create(start_trace: bool = True) -> None:
except drgn.MissingDebugInfoError as e: except drgn.MissingDebugInfoError as e:
print(e) print(e)
if hasattr(drgn, 'Module') or kind == "coredump": # Set display name and active thread
if kind == "kernel": display = "noname"
img = prog.main_module().name # type: ignore if kind == "kernel":
util.selected_tid = next(prog.threads()).tid display = "kernel"
elif kind == "coredump": if hasattr(prog, "main_module"):
util.selected_tid = prog.crashed_thread().tid if hasattr(prog.main_module(), "name"):
else: display = prog.main_module().name # type: ignore
img = prog.main_module().name # type: ignore try:
util.selected_tid = prog.main_thread().tid 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: if start_trace:
ghidra_trace_start(img) ghidra_trace_start(display)
PROGRAMS[util.selected_pid] = prog PROGRAMS[util.selected_pid] = prog
@@ -1108,7 +1125,11 @@ def put_threads(running: bool = False) -> None:
trace = STATE.require_trace() trace = STATE.require_trace()
keys = [] keys = []
# Set running=True to avoid thread changes, even while stopped # 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): for i, t in enumerate(threads):
nthrd = t.tid nthrd = t.tid
tpath = THREAD_PATTERN.format(procnum=nproc, tnum=nthrd) tpath = THREAD_PATTERN.format(procnum=nproc, tnum=nthrd)