Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Attaching to a Running Program

The Visual Studio debugger has the ability to attach to a program that is running in a process outside of Visual Studio.

To attach to a running program

  1. From the Debug menu, choose Processes. (If no project is open, choose Debug Processes from the Tools menu.)
  2. In the Processes dialog box, find the program you want to attach to from the Available Processes list. If the program you want to debug is running on another machine, you must first select the remote machine. (For more information, see Selecting a Remote Machine.)
  3. Click the Attach button.
  4. In the Attach to Process dialog box, make sure the appropriate program type (for example, Win32 or Common Language Runtime) is selected in Choose the program types that you want to debug.
    To debug Choose
    Visual Basic Common Language Runtime
    C# Common Language Runtime
    C or C++ Native
    Managed Extensions for C++ Common Language Runtime
    ASP Script Script
    ASP.NET Script Script, Managed
  5. Click OK.
  6. At the bottom of the Processes dialog box is a drop-down list box labeled When debugging is stopped. Choose the behavior you want to occur when you stop debugging the selected program. In most cases, it is okay to terminate the program when debugging stops, but you may want to keep it running. (For example, the program might run on a server that has users depending on it or you might need to reattach to it later on.) If you attach to a system process, be especially careful. Terminating a system process can have sudden and undesirable effects, including crashing the system. If you do not want the program to terminate when the debugging session ends, choose Detach from this process rather than Terminate this process.

The Available processes list is displayed automatically when you open the Processes dialog box. Processes can start and stop in the background while the dialog box is open, however, so the contents may not always be current. You can refresh the list at any time to see the current list of processes. For more information, see Refreshing the Available Processes List.

You can be attached to multiple programs when you are debugging, but only one program is active in the debugger at any given time. You can set the active program in the Debug Location toolbar. For more information, see Setting the Current Program.

All Debug menu execution commands affect the active program. You can break any debugged program from the Processes dialog box. For more information, see Breaking Program Execution.

Note   For the debugger to attach to code written in Managed Extensions for C++, the code needs to emit DebuggableAttribute. You can add this to your code automatically by linking with the /ASSEMBLYDEBUG linker option.

See Also

Attaching to a Running Program or Multiple Programs | Processes Dialog Box

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft