diff --git a/Ghidra/Debug/Debugger-agent-gdb/certification.manifest b/Ghidra/Debug/Debugger-agent-gdb/certification.manifest index 8d0b54e5e3..81acfa0106 100644 --- a/Ghidra/Debug/Debugger-agent-gdb/certification.manifest +++ b/Ghidra/Debug/Debugger-agent-gdb/certification.manifest @@ -3,7 +3,7 @@ Module.manifest||GHIDRA||||END| README.md||GHIDRA||||END| data/debugger-launchers/local-gdb.bat||GHIDRA||||END| -data/debugger-launchers/qemu-gdb.bat||GHIDRA||||END| +data/debugger-launchers/qemu-sys-gdb.bat||GHIDRA||||END| data/debugger-launchers/remote-gdb.bat||GHIDRA||||END| data/debugger-launchers/ssh-gdb.bat||GHIDRA||||END| data/debugger-launchers/ssh-gdbserver.bat||GHIDRA||||END| diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-gdb.sh b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-gdb.sh index 5aa6ad33da..37944e8a36 100755 --- a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-gdb.sh +++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-gdb.sh @@ -52,6 +52,7 @@ fi target_image="$1" +# No need to put QEMU_GDB on command line. It's already a recognized environment variable. if [ -z "$TTY_TARGET" ] then "$GHIDRA_LANG_EXTTOOL_qemu" $OPT_EXTRA_QEMU_ARGS $@ & @@ -69,7 +70,6 @@ gdb_args=( -ex "show version" -ex "python import ghidragdb" -ex "file \"$target_image\"" - -ex "set args $target_args" -ex "ghidra trace connect \"$GHIDRA_TRACE_RMI_ADDR\"" -ex "ghidra trace start" -ex "ghidra trace sync-enable" diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-gdb.bat b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-sys-gdb.bat similarity index 80% rename from Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-gdb.bat rename to Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-sys-gdb.bat index 65416c29a5..10c5242255 100644 --- a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-gdb.bat +++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-sys-gdb.bat @@ -1,9 +1,9 @@ -::@title qemu + gdb +::@title qemu-system + gdb ::@image-opt env:OPT_TARGET_IMG ::@desc
-::@desc-::@desc This will launch the target on the local machine using qemu. +::@desc This will launch the target on the local machine using qemu-system. ::@desc Then in a second terminal, it will connect gdb to QEMU's GDBstub. ::@desc For setup instructions, press F1. ::@desc
@@ -12,12 +12,11 @@ ::@icon icon.debugger ::@help TraceRmiLauncherServicePlugin#gdb_qemu ::@env OPT_TARGET_IMG:file!="" "Image" "The target binary executable image" -::@env OPT_TARGET_ARGS:str="" "Arguments" "Command-line arguments to pass to the target" -::@env GHIDRA_LANG_EXTTOOL_qemu:file="" "QEMU command" "The path to qemu for the target architecture." +::@env GHIDRA_LANG_EXTTOOL_qemu_system:file="" "QEMU command" "The path to qemu-system for the target architecture." ::@env QEMU_GDB:int=1234 "QEMU Port" "Port for gdb connection to qemu" ::@env OPT_EXTRA_QEMU_ARGS:str="" "Extra qemu arguments" "Extra arguments to pass to qemu. Use with care." ::@env OPT_GDB_PATH:file="gdb-multiarch" "gdb command" "The path to gdb. Omit the full path to resolve using the system PATH." -::@env OPT_EXTRA_TTY:bool=false "QEMU TTY" "Provide a separate terminal emulator for the target." +::@env OPT_EXTRA_TTY:bool=false "QEMU TTY" "Provide a separate terminal emulator for qemu." @echo off set PYTHONPATH0=%GHIDRA_HOME%\Ghidra\Debug\Debugger-agent-gdb\pypkg\src @@ -33,9 +32,9 @@ IF EXIST %GHIDRA_HOME%\ghidra\.git ( set PYTHONPATH=%PYTHONPATH1%;%PYTHONPATH0%;%PYTHONPATH% IF "%OPT_EXTRA_TTY%"=="true" ( - start "qemu" "%GHIDRA_LANG_EXTTOOL_qemu%" %OPT_EXTRA_QEMU_ARGS% -gdb tcp::%QEMU_GDB% -S "%OPT_TARGET_IMG%" %OPT_TARGET_ARGS% + start "qemu" "%GHIDRA_LANG_EXTTOOL_qemu%" %OPT_EXTRA_QEMU_ARGS% -gdb tcp::%QEMU_GDB% -S "%OPT_TARGET_IMG%" ) ELSE ( - start /B "qemu" "%GHIDRA_LANG_EXTTOOL_qemu%" %OPT_EXTRA_QEMU_ARGS% -gdb tcp::%QEMU_GDB% -S "%OPT_TARGET_IMG%" %OPT_TARGET_ARGS% + start /B "qemu" "%GHIDRA_LANG_EXTTOOL_qemu%" %OPT_EXTRA_QEMU_ARGS% -gdb tcp::%QEMU_GDB% -S "%OPT_TARGET_IMG%" ) :: Give QEMU a moment to open the socket @@ -48,7 +47,6 @@ powershell -nop -c "& {sleep -m 100}" -ex "show version" ^ -ex "python import ghidragdb" ^ -ex "target exec '%OPT_TARGET_IMG%'" ^ - -ex "set args %OPT_TARGET_ARGS%" ^ -ex "ghidra trace connect '%GHIDRA_TRACE_RMI_ADDR%'" ^ -ex "ghidra trace start" ^ -ex "ghidra trace sync-enable" ^ diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-sys-gdb.sh b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-sys-gdb.sh new file mode 100755 index 0000000000..b572ecee0c --- /dev/null +++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/qemu-sys-gdb.sh @@ -0,0 +1,90 @@ +#!/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 qemu-system + gdb +#@image-opt arg:1 +#@desc +#@desc+#@desc This will launch the target on the local machine using qemu-system. +#@desc Then in a second terminal, it will connect gdb to QEMU's GDBstub. +#@desc For setup instructions, press F1. +#@desc
+#@desc +#@menu-group cross +#@icon icon.debugger +#@help TraceRmiLauncherServicePlugin#gdb_qemu +#@arg :file! "Image" "The target binary executable image" +#@env GHIDRA_LANG_EXTTOOL_qemu_system:file="" "QEMU command" "The path to qemu-system for the target architecture." +#@env QEMU_GDB:int=1234 "QEMU Port" "Port for gdb connection to qemu" +#@env OPT_EXTRA_QEMU_ARGS:str="" "Extra qemu arguments" "Extra arguments to pass to qemu. Use with care." +#@env OPT_GDB_PATH:file="gdb-multiarch" "gdb command" "The path to gdb. Omit the full path to resolve using the system PATH." +#@env OPT_EXTRA_TTY:bool=false "QEMU TTY" "Provide a separate terminal emulator for qemu." +#@env OPT_PULL_ALL_SECTIONS:bool=false "Pull all section mappings" "Force gdb to send all mappings to Ghidra. This can be costly (see help)." +#@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" + +if [ -z "$TTY_TARGET" ] +then + "$GHIDRA_LANG_EXTTOOL_qemu" $OPT_EXTRA_QEMU_ARGS -gdb tcp::$QEMU_GDB -S $1 & +else + "$GHIDRA_LANG_EXTTOOL_qemu" $OPT_EXTRA_QEMU_ARGS -gdb tcp::$QEMU_GDB -S $1 <$TTY_TARGET >$TTY_TARGET 2>&1 & +fi + +# Give QEMU a moment to open the socket +sleep 0.1 + +gdb_args=( + -q + -ex "set pagination off" + -ex "set confirm off" + -ex "show version" + -ex "python import ghidragdb" + -ex "file \"$target_image\"" + -ex "ghidra trace connect \"$GHIDRA_TRACE_RMI_ADDR\"" + -ex "ghidra trace start" + -ex "ghidra trace sync-enable" + -ex "target remote localhost:$QEMU_GDB" + -ex "set confirm on" + -ex "set pagination on" +) + +# If using OPT_PULL_ALL_SECTIONS, append instructions to push all sections from qemu +if [ "$OPT_PULL_ALL_SECTIONS" = "true" ] +then + gdb_args+=( + -ex "ghidra trace tx-start put-all-sections" + -ex "ghidra trace put-sections -all-objects" + -ex "ghidra trace tx-commit" + ) +fi + +IFS="" +"$OPT_GDB_PATH" ${gdb_args[*]} 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 c9914a87df..2917e2b759 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 @@ -112,6 +112,12 @@ properly-configured build of GDB for your target. If you are working with an embedded system, it is probably safest to install the "multiarch" build of GDB from your package manager. +The plain "gdb" launch script defaults to launching the current program as a + user-mode process on the local system. If there is no current program, or if you clear the + Image option, this launcher will only start gdb and get it connected to a + Ghidra trace. You may then manually start or connect to your target. Note that this may also + require manual mapping of your program database(s) to the target memory.
+You must have GDB installed on the local system, and it must embed the Python 3 interpreter. @@ -157,6 +163,13 @@ python3 -m pip install --no-index -f Debugger-rmi-trace/pypkg/dist -f Debugger-a sys.version indicates 3.10, you should invoke Pip using python3.10 -m pip.
+Warning: Modern Linux distributions are beginning to adopt PEP 668, which prevents + installation of Python packages outside of a virtual environment (venv) even for non-root + user accounts. Unfortunately, gdb does not seem to honor the currently activated + venv, and so such configurations are not officially supported. You may be able to work around + this by modifying the PYTHONPATH lines of the launcher script, but your mileage may + vary. For now, we recommend using the --break-system-packages argument with Pip.
+This launcher orchestrates a QEMU user-mode target and connects to it using our Python - plugin for GDB. Ghidra will inspect the current program and attempt to map its language to the - appropriate QEMU command, but this may fail, or be subtly incorrect.
+These launchers orchestrate a QEMU user- or system-mode target and connect to it using our + Python plugin for GDB. Ghidra will inspect the current program and attempt to map its language + to the appropriate QEMU command, but due to subtle errors and/or outright failure, the default + value for the QEMU command option often requires careful inspection.
+ +There are two separate scripts for QEMU, one for user mode and one for system mode. Note + that QEMU does not support user-mode emulation on Windows, so that script is not available on + Windows hosts.
You must acquire a version of QEMU and GDB that support the target architecture. On many - distributions of Linux, you can install gdb-multiarch. Follow the steps given in GDB Setup.
+You must acquire versions of QEMU and GDB that support the target architecture. Aside from + the copy of QEMU required, setup is the same whether for user or system mode. As for GDB, on + many distributions of Linux, you can install gdb-multiarch. Follow the steps given in + GDB Setup.
This is hardly a launcher at all. It simply starts gdb, gets it connected to - Ghidra, and starts a trace. This allows you to create or connect to whatever target your copy - of GDB supports. While perhaps the most flexible, it is also the least convenient. It requires - no image, so it can be used without a current program. That also means it will make no effort - to ensure your target maps to the current program, if you happen to have one. You may have to - do it manually.
- -Follow the steps given in GDB Setup.
- -The following launchers based on the LLDB Debugger are included out of the box:
diff --git a/Ghidra/Processors/68000/data/languages/68000.ldefs b/Ghidra/Processors/68000/data/languages/68000.ldefs index 075e521cbe..5115f2d878 100644 --- a/Ghidra/Processors/68000/data/languages/68000.ldefs +++ b/Ghidra/Processors/68000/data/languages/68000.ldefs @@ -18,6 +18,7 @@