2/09/2009

Remote Debugging Using Visual Studio

When developing distributed system or GUI applications, remote debugging is a basic requirement. In this article, I will show how to do remote debugging with VS2005.

1. The need for remote debugging
- for GUI application, remote debugging can help to avoid bothering GUI elements when developers are doing debug works
- for distributed system, "one box" can't expose all the potential problems and bugs, you HAVE TO deploy them to a REAL distributed environment to do test. When investigating bugs/problems found in this kind of environment, remote debugging is a great facility: it can brings you the real distributed context.

2. Software Requirement
To enable remote debugging, you should install Visual Studio Remote Debugging Monitor, which should be located at:$YourMSVSRootDir\Common7\IDE\Remote Debugger\X64"(for x64 version).

Some additional components are needed for .Net application, Web application and HPC application. See Remote Debugging Components for detail information.

3. Security Consideration
When debugging native applications, you should either:
- be the owner user account of the debuggee process
- be the admin group on the remote machine, where debuggee process runs

As to the user account problem between Visual Studio Debugger and the Remote Debugger Monitor, see Remote Debugging Across Domains and Remote Debugging Permission for more information.

4. Attatch to remote process
Open Visual Studio -> Tool -> Attach to Process

In the qualifier text box, input the machine name where a MSVSMON.exe runs

Click Refresh button at the right-bottom corner, all processes on the remote machine will appear. You can now choose the target process and debug it as a local one.

5. Some tips
- the local debugging machine, where debugger runs, should be where the debuggee binaries are build out, otherwise, you should configure the source server
- some remote processes may be produced/deployed dynamically and only runs a very short time(very common in modern data intensive computing infrastructure), to get more opportunity to attach to this kind of process, you can add some Sleep(n)/system("pause") statements at the beginning of the entry(main) function.

Update on 02/11/2009:
- Microsoft NtDebug Team Blog has an great article on Remote Debugging using WinDbg.

No comments: