Attaching the debugger to a running process

Updated: October 26, 2022

You can attach the debugger to a process running on a target machine.

To debug an active program, you must attach to a binary built with debug information, so the debugger can match binary instructions with lines of code. Any binary with debug information has a bug icon (Icon: Small blue bug) next to its name in the Project Explorer. The binary selected for running when you launch a project depends on the launch configuration settings.

Note: You can't attach the debugger to a running process over a serial link—your host machine must have an IP connection to your target machine.
Note: All application binaries—executable and library—on your host must match those on your target so GDB can step through the code. To debug, the host and target must run the same SDP build. Even a minor difference in library binaries prevents the debugger from working correctly.
To attach the debugger to a running process:
  1. In the launch bar, expand the Launch Configuration dropdown (which is in the middle) and select the project defining the application that you want to debug.
  2. In the Launch Target dropdown (on the right), select the target on which your application is running.
  3. In the Launch Mode dropdown (on the left), select the Attach mode.
  4. Click the Attach button (Icon: Attach button).
    You don't need to manually enable the debugger in the launch configuration because by default, this tool is enabled when you select the Attach mode. This applies even for new projects on which you have not yet run the debugger.
    The IDE switches to the Debug perspective and opens the Select Process window, which lists the processes with the same name as the binary specified in the launch configuration settings.
  5. Click the process that you want to attach to, then click OK.

The IDE attaches the debugger to the process and stops execution immediately. The Debug view displays information about the active threads and their stack frames. More details on this view are found in the Reference > Debug views > Debug view entry in the C/C++ Development User Guide.

You may not see any source code when the application is initially stopped. For example, if it had just issued a sleep() call, there's no code to display. In this case, you can open a source file, add breakpoints, and click the Resume button to make GDB continue executing (after the sleep period finishes) to a certain line of code. You will then see the corresponding stack trace and code displayed.

For information on the debugging controls, see Debug perspective controls.