Ghidra is a software reverse engineering (SRE) framework
GP-3133: per review GP-3133: docs GP-3133: basic methods GP-3133: first pass
d-millar44c2a6dd2652
diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/local-rr.sh b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/local-rr.shnew file mode 100755index 0000000000..e2774bb28d--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/local-rr.sh@@ -0,0 +1,72 @@+#!/usr/bin/bash+## ###+# IP: GHIDRA+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+##+#@title gdb-rr+#@desc <html><body width="300px">+#@desc <h3>Launch with <tt>rr/gdb</tt></h3>+#@desc <p>+#@desc This will open a trace of a target on the local machine using <tt>rr/gdb</tt>.+#@desc For setup instructions, press <b>F1</b>.+#@desc </p>+#@desc </body></html>+#@menu-group local+#@icon icon.debugger+#@help TraceRmiLauncherServicePlugin#gdb_rr+#@enum StartCmd:str run start starti+#@enum Endian:str auto big little+#@arg :file "Trace Dir" "The target trace directory (e.g. .local/share/rr/trace)"+#@env OPT_RR_PATH:file="rr" "rr command" "The path to rr. Omit the full path to resolve using the system PATH."+#@env OPT_ARCH:str="i386:x86-64" "Architecture" "Target architecture"+#@env OPT_ENDIAN:Endian="auto" "Endian" "Target byte order"+#@env OPT_EXTRA_TTY:bool=false "Inferior TTY" "Provide a separate terminal emulator for the target."+#@tty TTY_TARGET if env:OPT_EXTRA_TTY++if [ -d ${GHIDRA_HOME}/ghidra/.git ]+then+ export PYTHONPATH=$GHIDRA_HOME/ghidra/Ghidra/Debug/Debugger-agent-gdb/build/pypkg/src:$PYTHONPATH+ export PYTHONPATH=$GHIDRA_HOME/ghidra/Ghidra/Debug/Debugger-rmi-trace/build/pypkg/src:$PYTHONPATH+elif [ -d ${GHIDRA_HOME}/.git ]+then+ export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-agent-gdb/build/pypkg/src:$PYTHONPATH+ export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-rmi-trace/build/pypkg/src:$PYTHONPATH+else+ export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-agent-gdb/pypkg/src:$PYTHONPATH+ export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-rmi-trace/pypkg/src:$PYTHONPATH+fi++target_image="$1"++# Ghidra will leave TTY_TARGET empty when OPT_EXTRA_TTY is false. Gdb takes empty to mean the same terminal.++RRINIT=$(mktemp)+echo '+set pagination off+set confirm off+set $use_trace="true"+show version+python import ghidragdb+set architecture ' $OPT_ARCH '+set endian ' $OPT_ENDIAN '+set inferior-tty ' $TTY_TARGET '+ghidra trace connect ' $GHIDRA_TRACE_RMI_ADDR '+ghidra trace start+ghidra trace sync-enable+set confirm on+set pagination on+' > $RRINIT++"$OPT_RR_PATH" replay -x $RRINIT "$target_image"+diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/methods.py b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/methods.pyindex 30263b3fe0..6e1da42120 100644--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/methods.py+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/methods.py@@ -520,6 +520,12 @@ def resume(inferior: sch.Schema('Inferior')):gdb.execute('continue')[email protected](action='step_ext', icon='icon.debugger.resume.back', condition=util.IS_TRACE)+def resume_back(thread: sch.Schema('Inferior')):+ """Continue execution of the inferior backwards."""+ gdb.execute('reverse-continue')++# Technically, inferior is not required, but it hints that the affected object# is the current inferior. This in turn queues the UI to enable or disable the# button appropriately@@ -569,6 +575,18 @@ def step_return(thread: sch.Schema('Thread'), value: int=None):gdb.execute(f'return {value}')[email protected](action='step_ext', icon='icon.debugger.step.back.into', condition=util.IS_TRACE)+def step_back_into(thread: sch.Schema('Thread'), n: ParamDesc(int, display='N')=1):+ """Step backwards one instruction exactly (reverse-stepi)."""+ gdb.execute('reverse-stepi')++[email protected](action='step_ext', icon='icon.debugger.step.back.over', condition=util.IS_TRACE)+def step_back_over(thread: sch.Schema('Thread'), n: ParamDesc(int, display='N')=1):+ """Step one instruction backwards, but proceed through subroutine calls (reverse-nexti)."""+ gdb.execute('reverse-nexti')++@REGISTRY.method(action='break_sw_execute')def break_sw_execute_address(inferior: sch.Schema('Inferior'), address: Address):"""Set a breakpoint (break)."""diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.pyindex bb58f7defa..83b74c728f 100644--- a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py+++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py@@ -34,6 +34,7 @@ def _compute_gdb_ver():GDB_VERSION = _compute_gdb_ver()+IS_TRACE = gdb.convenience_variable('use_trace').string() == "true"MODULES_CMD_V8 = 'maintenance info sections ALLOBJ'MODULES_CMD_V11 = 'maintenance info sections -all-objects'diff --git a/Ghidra/Debug/Debugger-rmi-trace/src/main/help/help/topics/TraceRmiLauncherServicePlugin/TraceRmiLauncherServicePlugin.html b/Ghidra/Debug/Debugger-rmi-trace/src/main/help/help/topics/TraceRmiLauncherServicePlugin/TraceRmiLauncherServicePlugin.htmlindex b2782f91df..a38d8d7d57 100644--- a/Ghidra/Debug/Debugger-rmi-trace/src/main/help/help/topics/TraceRmiLauncherServicePlugin/TraceRmiLauncherServicePlugin.html+++ b/Ghidra/Debug/Debugger-rmi-trace/src/main/help/help/topics/TraceRmiLauncherServicePlugin/TraceRmiLauncherServicePlugin.html@@ -525,6 +525,22 @@ target remote [host]:[port]<TT>gdb-multiarch</TT>.</LI></UL>+ <H3><A name="gdb_rr"></A>rr + GDB</H3>++ <P>This launcher runs <TT>rr</TT> in a <TT>gdb</TT> session on Linux for replaying rr-generated traces.</P>+++ <H4>Options</H4>++ <UL>+ <LI><B>Trace Dir</B>: This is the path to the trace directory, stored by default in the user's home+ directory in <TT>.local/share/rr/target_name</TT>.</LI>++ <LI><B><TT>rr</TT> command</B>: This is the command or path to <TT>rr</TT>.</LI>++ <LI><B>Other options are the same as in GDB.</LI>+ </UL>+<H2>Stock LLDB Launchers</H2><P>The following launchers based on the LLDB Debugger are included out of the box:</P>