Debugging an already running process

It is often necessary to debug an already running process. It could be a service, an existing process, or a website running on a local or remote system. Visual Studio provides us with an option to debug a running process. When you are debugging a remote process, you will need the Microsoft Visual Studio Remote Debugging Monitor service running.

To get started, you will need to open the exact code that was used to build the process. If there is a change in the code, the debugging information will not be loaded. Once you open the solution, go to the Debug | Attach to Process... menu, which will open a dialog window, Attach to Process, on the screen. Alternatively, you can press Ctrl + Alt + P to invoke the window:

From the Connection Type dropdown, select the type of the connection that you want to attach. To attach a local process, keep the selection to Default. Based on your requirement, you can either select Remote (no authentication), SSH, or WebKit websocket (no authentication) as a connection type.

Select the Connection Target entry, which is the local system by default and then from the Available Processes list, you can select the process that you want to debug, if the same code has been loaded inside Visual Studio. You can also choose the Show processes from all users checkbox to get a list of processes running by other users in the same system.

At the end, click the Attach button to attach the process with Visual Studio. If everything goes fine, the process will get attached with the solution loaded inside the Visual Studio IDE.

While debugging an already running process, you should keep in mind that:

  • To debug the process properly, the debug version of the application must be used. A release build can also work but with reduced debugging functionalities.
  • The debugging information should be present (PDB File) and mapped with the process.

When the debugging information gets loaded, the breakpoint will hit by the debugger and you will debug the application as-is, as you did when you started the application from Visual Studio in debug mode.

In case you want to debug a remote application, you should run the MSVSMON.exe file, which comes along with Visual Studio, to start the remote debugging session.

Visual Studio 2017 provides a new feature which allows you to reattach to a process that you last attached in the Visual Studio current context. This saves time as you don't have find the process in the process list again and attach to it. Just navigate to the Visual Studio menu Debug | Reattach to Process... or press Shift + Alt + P to automatically attach with the previous selected process:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.47.253