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.sh new file mode 100755 index 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
+#@desc+#@desc This will open a trace of a target on the local machine using rr/gdb. +#@desc For setup instructions, press F1. +#@desc
+#@desc +#@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.py index 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') +@REGISTRY.method(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}') +@REGISTRY.method(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') + + +@REGISTRY.method(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.py index 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.html index 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] gdb-multiarch. +This launcher runs rr in a gdb session on Linux for replaying rr-generated traces.
+ + +The following launchers based on the LLDB Debugger are included out of the box: