Dela via


Debug a process which is attached to another Debugger

For any process, we can attach only one debugger at a time. We might hit upon a need to attach more than one debugger to a process for various reasons while troubleshooting/debugging an issue, some of which that I had come across are scenarios like

 

1) A need to attach another debugger (WinDBG) while debugging the code in Visual Studio.

2) Troubleshooting issues when we get an exception only while having the process attached to a debugger.

 

We might see the following error message while trying to attach WinDBG to a process that is being debugged by Visual Studio.

“An attempt to set a processes DebugPort or ExceptionPort was made, but a port already exists in the process.”

One way to debug such a process from another debugger is to use the noninvasive debugging mode support provided by WinDBG. To debug a running process noninvasively, we need to

  • Select File -> Attach to a Process from WinDBG menu.
  • Select the required target process in the Attach to Process dialog box.
  • Select the Noninvasive check box.
  • Click OK

We can also make use of the WinDBG command line by using the –pv option and specifying the Process Name by using –pn.

Here’s an example:

WinDBG -pv -pn <Process Name>

Note that we might not have many of the functionalities of the debugger while in noninvasive mode – we might not be able to set breakpoints, step-into or step-over the code, etc. This is because while in noninvasive debugging mode, the debugger does not actually attach to the target application. The debugger will suspend all of the target process’ threads and will have access to its memory, registers, and other such information.

Some of the useful commands that we can make use of while in noninvasive debugging mode using WinDBG are

.dump /ma <DumpPath> To create a user mini dump file with full memory for the application

~ Thread status

~*kb Call stack for all the threads

There are a lot of other useful commands that come along with WinDBG, you may want to take a look at the Help that comes along with WinDBG for more information.

 

Incase we are just looking at creating a memory dump of the process that is being debugged using the Visual Studio debugger, we can also make use of the “Save Dump As” option that comes with Visual Studio 2005 Debugger. A very useful option which eliminates the need for making use of another debugger when we just need to create a dump of the debugged process for later analysis.

We can access this option from Debug menu -> Save Dump As option -> select Minidump or Minidump with Heap based on the requirement. Here is a link from MSDN for more information on saving and opening dump files using Visual Studio 2005 Debugger.

 

 

Links for reference:

Comments