Debug One or More Processes in Visual Studio
Here’s how to start debugging processes, switch between processes, break and continue execution, step through source, stop debugging, and terminate or detach from processes.
Contents
Configure the execution behavior of multiple processes
Find the source and symbol (.pdb) files
Start multiple processes in a VS solution, attach to a process, automatically start a process in the debugger
Switch processes, break and continue execution, step through source
Stop debugging, terminate or detach from processes
Configure the execution behavior of multiple processes
By default, when multiple processes are running in the debugger, the breaking, stepping, and stopping debugger commands usually affect all the processes. For example, when one process is suspended at a breakpoint, the execution of all other processes is also suspended. You can change this default behavior to gain more control over the targets of execution commands.
On the Debug menu, choose Options and Settings.
On the Debugging, General page, clear the Break all processes when one process breaks check box.
Contents
Find the source and symbol (.pdb) files
To navigate the source code of a process, the debugger needs access to the source files and symbol files of the process. See Specify Symbol (.pdb) and Source Files in the Visual Studio Debugger.
If you can’t access the files for a process, you can navigate by using the Disassemby window. See How to: Use the Disassembly Window
Contents
Start multiple processes in a VS solution, attach to a process, automatically start a process in the debugger
- Start debugging multiple processes in a Visual Studio solution • Change the startup project • Start a specific project in a solution • Start multiple projects in a solution • Attach to a process • Automatically start an process in the debugger
Note
The debugger does not automatically attach to a child process that is started by a debugged process, even if the child project is in the same solution. To debug a child process:
-
Attach to the child process after it has been started.
-or-
-
Configure Windows to automatically start the child process in a new instance of the debugger.
Start debugging multiple processes in a Visual Studio solution
When you have more than one project in a Visual Studio solution that can run independently (projects that run in separate processes), you can select which projects the debugger starts.
Change the startup project
To change the startup project for a solution, select the project in Solution Explorer and then choose Set as Startup Project from the context menu.
Start a specific project in a solution
To start a project for a solution without changing the default startup project, select the project in Solution Explorer and then choose Debug from the context menu. You can then choose Start new instance or Step Into new instance.
Contents
Start multiple projects in a solution
Select the solution in Solution Explorer and then choose Properties on the context menu.
Select Common Properties, Startup Project on the Properties dialog box.
For each project that you want to change, choose either Start, Start without debugging, or None.
Contents
Attach to a process
The debugger can also to attach to programs that are running in processes outside of Visual Studio, including programs that are running on a remote device. After you attach to a program, you can use debugger execution commands, inspect the program state, and so on. Your ability to inspect the program might be limited, depending on whether the program was built with debug information and whether you have access to the program's source code, and whether the common language runtime JIT compiler is tracking debug information.
See Attach to Running Processes with the Visual Studio Debugger for more information.
Attach to a process that is running on your local machine
Choose Debug, Attach to Process. On the Attach to Process dialog box, select the process from the Available Processes list, and then choose Attach.
Contents
Automatically start a process in the debugger
Sometimes, you might need to debug the startup code for a program that is launched by another process. Examples include services and custom setup actions. In these scenarios, you can have the debugger launch and automatically attach when your application starts.
Start the Registry Editor (regedit.exe).
Navigate to the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options folder.
Select the folder of the app that you want to start in the debugger.
If the name of the app is not listed as a child folder, select Image File Execution Options and then choose New, Key on the context menu. Select the new key, choose Rename on the shortcut menu, and then enter the name of the app.
On the context menu of the app folder, choose New, String Value.
Change the name of the new value from New Value to debugger.
On the context menu of the debugger entry, choose Modify.
On the Edit String dialog box, type vsjitdebugger.exe in the Value data box.
Contents
Switch processes, break and continue execution, step through source
- Switch between processes • Break, step, and continue commands
Switch between processes
You can attach to multiple processes when you are debugging, but only one process is active in the debugger at any given time. You can set the active or current process in the Debug Location toolbar or in the Processes window. To switch between processes, both processes must be in break mode.
To set the current process
On the Debug Location toolbar, choose Process to view the Process list box. Select the process that you want to designate as current process.
If the Debug Location toolbar is not visible, choose Tools, Customize. On the Toolbars tab, choose Debug Location.
Open the Processes window (shortcut Ctrl+Alt+Z), find the process that you want to set as the current process, and double-click it.
The current process is marked by a yellow arrow.
Switching to a project sets it the current process for debugging purposes. Any debugger window that you view will show the state for the current process, and all stepping commands affect only the current process.
Switch processes, break and continue execution, step through source
Contents
Break, step, and continue commands
Note
By default, the break, continue and step debugger commands affect all processes that are being debugged. To change this behavior, see Configure the execution behavior of multiple processes
Command |
Break all processes when one process breaks Checked (Default) |
Break all processes when one process breaks Cleared |
Debug menu:
|
All processes break. |
All processes break. |
Debug menu:
|
All processes resume. |
All suspended processes resume. |
Debug menu:
|
All processes run while current process steps. Then all processes break. |
Current process steps. Suspended processes resume. Running processes continue. |
Debug menu:
|
N/A |
Current process steps. Other processes maintain their existing state (suspended or running). |
Source window
|
All processes break. |
Only source window process breaks. |
Source window context menu:
The source window must be in the current process. |
All processes run while source window process runs to cursor and then breaks. Then all other processes break. |
Source window process runs to cursor. Other processes maintain their existing state (suspended or running). |
Processes window context menu:
|
N/A |
Selected process breaks. Other processes maintain their existing state (suspended or running). |
Processes window context menu:
|
N/A |
Selected process resumes. Other processes maintain their existing state (suspended or running). |
Switch processes, break and continue execution, step through source
Contents
Stop debugging, terminate or detach from processes
- Stop, terminate, and detach commands
By default, when you choose Debug, Stop Debugging when multiple processes are open in the debugger, the debugger terminates or detaches from all processes depending on how the process was opened in the debugger:
If the current process was launched in the debugger, that process is terminated.
If you attached the debugger to the current process, the debugger detaches from the process and leaves the process running.
For example, if you start debugging a process from a Visual Studio solution, attach to another process that is already running, and then choose Stop Debugging, the debugging session ends, the process that was started in Visual Studio is terminated, while the process that you attached is left running. You can use the following procedures to control the way that you stop debugging.
Note
The Break all processes when one process breaks option does not affect stopping debugging or terminating and detaching from processes.
To change how Stop Debugging affects an individual process
- Open the Processes window (shortcut Ctrl+Alt+Z). Select a process and then select or clear the Detach when debugging stopped check box.
Stop, terminate, and detach commands
Command |
Description |
Debug menu:
|
Unless the behavior is changed by Processes window Detach when debugging stops option:
|
Debug menu:
|
All processes are terminated. |
Debug menu:
|
The debugger detaches from all processes. |
Processes window context menu:
|
The debugger detaches from the selected process. Other processes maintain their existing state (suspended or running). |
Processes window context menu:
|
The selected process is terminated. Other processes maintain their existing state (suspended or running). |
Processes window context menu:
|
Toggles the behavior of Debug, Stop Debugging for the selected process:
|
Stop debugging, terminate or detach from processes
Contents
See Also
Concepts
Start, Break, Step, Run through Code, and Stop Debugging in Visual Studio
Just-In-Time Debugging in Visual Studio
Other Resources
Specify Symbol (.pdb) and Source Files in the Visual Studio Debugger