Поделиться через


How to: Attach to a Running Process

This topic applies to:

Edition

Visual Basic

C#

F#

C++

Web Developer

Express

Topic does not apply Topic does not apply Topic does not apply Topic does not apply Topic does not apply

Pro, Premium, and Ultimate

Topic applies Topic applies Topic applies

Topic applies

Topic applies

You can attach the Visual Studio debugger to any running process.

To attach to a running process

  1. On the Debug menu, select Attach to Process. If no project is open, select Attach to Process on the Tools menu.

  2. In the Attach to Process dialog box, find the program that you want to attach to from the Available Processes list.

    1. If the program that you want to debug is running on another computer, use the Qualifier list box to select the remote computer. For more information, see How to: Select a Remote Machine.

    2. If the process is running under a different user account, select the Show processes from all users check box.

    3. If you are connected through Remote Desktop Connection, select the Show processes in all sessions check box.

  3. In the Attach to box, make sure that the type of code you will debug is listed. The default Automatic setting tries to determine what type of code you want to debug. If the automatic setting is not appropriate:

    1. Click Select.

    2. In the Select Code Type dialog box, click Debug these code types and select the types to debug.

    3. Click OK.

  4. Click Attach.

    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, the contents are not always current. You can refresh the list at any time to see the current list of processes by clicking Refresh.

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

    All Debug menu execution commands affect the active program. You can break any debugged program from the Processes dialog box or break all attached programs from the Debug menu. For more information, see How to: Break Execution.

    Note

    For the debugger to attach to managed code written in Visual C++, the code must emit DebuggableAttribute. You can add this to your code automatically by linking with the /ASSEMBLYDEBUG linker option.

    If you try to attach to a process owned by an untrusted user account, a security warning dialog box confirmation will appear. For more information see Security Warning: Attaching to a process owned by an untrusted user can be dangerous. If the following information looks suspicious or you are unsure, do not attach to this process.

    In some cases, when you debug in a Remote Desktop (Terminal Services) session, the Available Processes list will not display all available processes. On Windows Server 2003 or later versions, if you are running Visual Studio as a user who has a limited user account, the Available Processes list will not show processes that are running in Session 0, which is used for services and other server processes, including w3wp.exe. You can solve the problem by running Visual Studio under an administrator account or by running Visual Studio from the server console instead of a Terminal Services session. If neither of those workarounds is possible, a third option is to attach to the process by running vsjitdebugger.exe -p ProcessId from the Windows command line. You can determine the process id using tlist.exe. To obtain tlist.exe, download and install Debugging Tools for Windows, available at https://go.microsoft.com/fwlink/?LinkId=168279.

See Also

Reference

Security Warning: Attaching to a process owned by an untrusted user can be dangerous. If the following information looks suspicious or you are unsure, do not attach to this process

Concepts

Debugger Security

Other Resources

Attaching to Running Processes