During this testing phase, you will likely encounter many bugs, which is why these features are not yet included in our binary release. As is, the debugger is poised to support debugging native user-mode applications for Windows and Linux on 64-bit x86. This is accomplished by "connecting" to the respective debugger for each platform: MS dbgeng.dll on Windows, and GDB/MI on Linux. A variety of configurations are possible, and we are already developing more connectors, but native desktop applications are the target for this initial roll-out. See the Developer's Guide if you would like to contribute.
There's still quite a bit of polish to get right, which is why this release is currently source only. One of those areas deals with error handling and error reporting. Many actions are taken automatically on behalf of the user, e.g., reading registers when a target is paused. In most cases, errors on automatic actions are dropped to the console, as displaying them could become a pest. That said, if things don't seem right, please check the Eclipse console for log messages.
Starting up the Ghidra Debugger for the simplest use case, user-mode debugging of a local process, entails four steps:
To load the default Debugger tool, from the main Ghidra application window select from the menus. Select "defaultTools/Debugger.tool", and hit "OK". The Debugger tool will be added to the Tool Chest.
To launch the tool, you have several options, identical to those you might use to launch the CodeBrowser tool. You can double-click the Debugger icon to launch an empty Debugger tool. You can drag a program that you have already imported from the Active Project window onto the tool icon in the Tool Chest, or you can right-click on one of the project programs and pick . If you open an empty Debugger tool, you can add programs to it later in the usual ways, e.g. via or by dragging-and-dropping programs onto the running tool.
The default tool is pre-configured with a collection of plugins relevant for the Listing and for Debugger-related operations. As always, there is some chance that the tool will launch with some portion of the plugins not displayed or with a less-than-optimal layout. To verify which plugins you have, you can select . "Debugger" should already be selected. Choosing "Configure All Plugins" (the plug icon near the top right), should show the full list of pre-selected plugins. Debugger-related plugins all begin with "Debugger". At a bare minimum, you will need the "DebuggerTargetsPlugin" and the "DebuggerObjectsPlugin", and the plugins on which they depend (DebuggerInterpreterPlugin, DebuggerModelServiceProxyPlugin, DebuggerTraceMangerServicePlugin).
Steps 3 and 4 can be initiated together by hitting the bug icon in the main tool bar entitled "Debug /path/to/my_program". For this to work, you must (a) have the program you wish to run visible and selected in the static Listing window, and (b) have imported the program from the place it lives on the local system. In other words, the file path associated with the program should be the path to the executable for the current file system. You can verify this using the menu item in the main tool bar. For example, on a Linux system, if you've imported "xclock", should have an entry at the bottom of the page for "Executable Location: /usr/bin/xclock".
When you launch the target by this method, a number of changes should be evident in the GUI. A blank "Agent" window should appear, indicating the agent status and connection port. An interpreter console will appear, potentially including various information about the launch. A connection will be added to the Targets window. A new tree-structure will be populated within the Objects window. The remaining windows will be populated with current trace information.
Each of these pieces require some explanation.
The "agent" is a process running on the local system, which acts as the mediator between the Ghidra GUI and the native debugger. For systems such as Linux that support GDB, the agent wraps the native GDB functionality via a Java container that implements the GDB machine interface (GDB/MI). For Windows, the agent wraps the native dbgeng.dll functionality in a similar fashion. The blank "Agent" window allows you to see the current status of the agent. If the agent dies or is killed, the debugging session will be terminated. Of particular note, the protocol used to communicate between the GUI and the agent is the Ghidra Asynchronous Debug Protocol (GADP). It is not the native protocol associated with the debugger. Direct communications with a native target are not currently supported, although that functionality may be added in the future.
The interpreter window allows a user command-line access to the native debugger. For Linux, this means the standard GDB command line interface; for Windows, the WinDbg/kd command set. While basic tasks may not require using the command line interface, more complicated debugging scenarios invariably require commands specific to the target which cannot or have not been implemented generically in the GUI.
The "Debugger Targets" window adds an entry for every new GUI-to-agent connection. These may be added directly from this window using the "Connect" button. This allows the user to select non-default connection options and/or to initiate a connection without launching or attaching to a target. For Linux, the default connection is equivalent to the menu choice, "GNU gdb local agent via GADP/TCP". For Windows, the default is "MS dbgeng.dll (WinDbg) local agent via GADP/TCP". Using this method of starting a connection requires the additional step of launching or attaching to a specific target.
To launch or attach to a target without using the tool-bar "Debug" option, you will need to use the "Objects" window. The "Objects" window provides a default tree-structured list of everything the debugger knows about the target. On its tool bar are buttons for "Quick Launch', "Launch", and "Attach". "Quick Launch", like the "Debug" button on the main tool bar, runs the executable associated with the active program in the Listing view. "Launch" allows you to specify a target and its parameters, typically, in the form of a command line. This target can be any executable on the system and need not be associated with an imported program. The "Attach" button populates a list with potential targets from the running process list for the system, which the user may select and attach to.
The Targets, Objects, and Interpreter windows are the only windows populated directly using information gleaned directly from the target. All other windows derive information from the current trace. Once triggered, Ghidra captures information from the current debugging session and uses this information to fill the other windows. The most important of these is the "Threads" provider. The Threads window has two parts: one on the left listing the set of traced target threads and one on the right indicating the current position in the trace by thread. If no process is being traced or no thread is selected, all of the remaining windows will be empty. If the current position (indicated by the draggable caret at the top of the right display) lies outside the bounds of the current trace, all of the remaining windows will be empty. Selecting a thread and a position causes the trace-based windows to display information for that thread and time tick.
The control buttons in the Objects window or commands issued in the Interpreter cause the target to advance in the usual ways. (The control buttons in the Thread window, by contrast, cause the trace to move forward or backward without affecting the target.) Breakpoints can be set from either the "Breakpoints" window or the listing. Breakpoints are typically aggregated by target. The "Registers" and "Stack" display, on the other hand, reflect the selected thread from the "Threads" window. Typically, the thread selected for the trace in the Threads display is kept in sync with the active thread for the debugger selected in the Objects view, but this need not be the case. Similarly, the "Dynamic Listing", marked RIP or RSP in most case, shows the bytes from the target's actual memory and may or may not match the bytes from the imported executable in the primary "Listing". When it can, the Ghidra debugger attempts to keep the Static and Dynamic Listings synchronized.