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

Launch with qemu and connect with gdb

+::@desc

Launch with qemu-system and connect with gdb

::@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

Launch with qemu-system and connect with gdb

+#@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.

+

Setup

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.

+

Options

@@ -339,15 +352,21 @@ target remote | ssh user@host gdbserver - /path/to/image

QEMU + GDB

-

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.

Setup

-

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.

Options

@@ -356,17 +375,18 @@ target remote | ssh user@host gdbserver - /path/to/image in GDB, but is passed to QEMU. This will also provide the name to GDB using its "file ..." command. -
  • Arguments: These are the command-line arguments to pass into the target process. - These are passed as is on QEMU's command line.
  • +
  • Arguments (User-mode only): These are the command-line arguments to pass into the + target process. These are passed as is on QEMU's command line.
  • QEMU command: The command or path to QEMU.
  • QEMU Port: An available TCP port for QEMU to listen on for GDB.
  • -
  • Extra qemu arguments: Extra arguments to pass to qemu. These are - inserted immediately after the qemu command but before the target program and - arguments. Beware that syntax errors may cause strange behavior, and that not all features - may be compatible with this launcher.
  • +
  • Extra qemu arguments: Extra arguments to pass to qemu or + qemu-system. These are inserted immediately after the qemu command but + before the target image. Run qemu[-system]-arch --help to see the options + supported. Beware that syntax errors may cause strange behavior, and that not all QEMU + features may be compatible with Ghidra.
  • gdb command: This works the same as in GDB, but defaults to "gdb-multiarch."
  • @@ -374,12 +394,14 @@ target remote | ssh user@host gdbserver - /path/to/image
  • QEMU TTY: This works similarly as in GDB, but just runs QEMU in the second Terminal window.
  • -
  • Pull all section mappings: For some targets the memory mappings for the target - are not correctly relayed to Ghidra. This setting forces gdb to send the mappings to Ghidra. - This option is disabled by default because for large targets the action could be expensive, - so it should only be enabled if required (e.g. unable to correctly place breakpoints). - Auto-Map by Section must be enabled in the Modules debugger window for this to work. -
  • +
  • Pull all section mappings: For some targets the memory mappings cannot be + correctly conveyed to Ghidra module by module. This setting forces GDB to send the + section mappings to Ghidra. Warning: This operation is expensive for large + targets, so it should only be enabled if required (e.g. unable to correctly place + breakpoints). Auto-Map by + Section is required when this option is enabled, or else address translation may + still be incorrect.
  • Wine + GDB

    @@ -488,30 +510,6 @@ target remote [host]:[port] gdb-multiarch. -

    Raw GDB

    - -

    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.

    - -

    Setup

    - -

    Follow the steps given in GDB Setup.

    - -

    Options

    - - -

    Stock LLDB Launchers

    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 @@ + + + + diff --git a/Ghidra/Processors/AARCH64/data/languages/AARCH64.ldefs b/Ghidra/Processors/AARCH64/data/languages/AARCH64.ldefs index dad5496b43..58bb44108b 100644 --- a/Ghidra/Processors/AARCH64/data/languages/AARCH64.ldefs +++ b/Ghidra/Processors/AARCH64/data/languages/AARCH64.ldefs @@ -17,6 +17,7 @@ + + + + diff --git a/Ghidra/Processors/ARM/data/languages/ARM.ldefs b/Ghidra/Processors/ARM/data/languages/ARM.ldefs index c541c73afc..695e6bd3e7 100644 --- a/Ghidra/Processors/ARM/data/languages/ARM.ldefs +++ b/Ghidra/Processors/ARM/data/languages/ARM.ldefs @@ -21,6 +21,7 @@ + + + + + + + + + + + + + + + + + + diff --git a/Ghidra/Processors/Loongarch/data/languages/loongarch.ldefs b/Ghidra/Processors/Loongarch/data/languages/loongarch.ldefs index e0ea214f42..97627b450b 100644 --- a/Ghidra/Processors/Loongarch/data/languages/loongarch.ldefs +++ b/Ghidra/Processors/Loongarch/data/languages/loongarch.ldefs @@ -42,6 +42,7 @@ + + \ No newline at end of file diff --git a/Ghidra/Processors/MIPS/data/languages/mips.ldefs b/Ghidra/Processors/MIPS/data/languages/mips.ldefs index bb5e61c939..91b44bce2d 100644 --- a/Ghidra/Processors/MIPS/data/languages/mips.ldefs +++ b/Ghidra/Processors/MIPS/data/languages/mips.ldefs @@ -18,6 +18,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Ghidra/Processors/Sparc/data/languages/SparcV9.ldefs b/Ghidra/Processors/Sparc/data/languages/SparcV9.ldefs index 97599ce7df..dddf7c4ed7 100644 --- a/Ghidra/Processors/Sparc/data/languages/SparcV9.ldefs +++ b/Ghidra/Processors/Sparc/data/languages/SparcV9.ldefs @@ -15,6 +15,7 @@ + + diff --git a/Ghidra/Processors/SuperH4/data/languages/SuperH4.ldefs b/Ghidra/Processors/SuperH4/data/languages/SuperH4.ldefs index e1ab74b65d..93b21c8ff1 100644 --- a/Ghidra/Processors/SuperH4/data/languages/SuperH4.ldefs +++ b/Ghidra/Processors/SuperH4/data/languages/SuperH4.ldefs @@ -15,6 +15,7 @@ + + diff --git a/Ghidra/Processors/Xtensa/data/languages/xtensa.ldefs b/Ghidra/Processors/Xtensa/data/languages/xtensa.ldefs index 94989266b8..a696ec196b 100644 --- a/Ghidra/Processors/Xtensa/data/languages/xtensa.ldefs +++ b/Ghidra/Processors/Xtensa/data/languages/xtensa.ldefs @@ -15,6 +15,7 @@ + + diff --git a/Ghidra/Processors/x86/data/languages/x86.ldefs b/Ghidra/Processors/x86/data/languages/x86.ldefs index f56f88394d..a5f79795e7 100644 --- a/Ghidra/Processors/x86/data/languages/x86.ldefs +++ b/Ghidra/Processors/x86/data/languages/x86.ldefs @@ -31,6 +31,7 @@ + +