Attaching the debugger to a running process
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
() next to its name
in the Project Explorer. The binary selected for running when you launch a project depends on the
launch configuration settings.
- 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.
- In the Launch Target dropdown (on the right), select the target on which your application is running.
- In the Launch Mode dropdown (on the left), select the Attach mode.
-
Click the 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. - 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 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
.