Monday, November 01, 2010

How to debug a remote process

Introduction

Visual Studio supports remote debugging from one computer to another. When you are doing remote debugging, the host computer can be any platform that supports Visual Studio. The remote computer can be a 32-bit (, Windows 2000, Windows XP, or Windows Server 2003) or 64-bit (IA64, IA64 WOW mode, x64, or x64 WOW mode) platform.

Here is an example of a common case scenario: debugging a service on a remote server (e.g. the MyService):

Setting up the remote machine

  1. You must have the "Remote Debugging Monitor" (i.e. msvsmon.exe) application installed on your remote machine:
    • Visual Studio installs msvsmon.exe into one of these directories depending on your machine configuration:
      • Install path\Microsoft Visual Studio 8\Common7\IDE\Remote Debugger\x86
      • Install path\Microsoft Visual Studio 8\Common7\IDE\Remote Debugger\x64
      • Install path\Microsoft Visual Studio 8\Common7\IDE\Remote Debugger\ia64
    • You copy it into a local folder on the remote machine.
      • Make sure that you take the right one corresponding to the OS and hardware of the remote machine:
        • 32 bits OS => .. \x86
        • 64 bits OS on Intel Itanium CPU => ..\ia64
        • 64 bits OS on other than Itanium CPU => ..\x64

  2. Install the application you want to debug.
    • Make sure you have the same "PDB" files on the remote machine as on the local machine
    • Make sure that you have the code source corresponding to the PDB files deployed on both machines
  3. Launch the "Remote Debugging Monitor" application.


    • The important bit of information display by the application is the account name and machine name that must be used for the connection.
  4. Add permissions for the windows account used on the local machine to run Visual Studio.

    • Click on "Permissions ..."
      • Add the required Windows user account (e.g. "jmorais".
      • Make sure it has "Debug" access.

      • A warning popup window might be displayed, read the message and click "Yes":


Debugging from the local machine

  1. Launch Visual Studio (2005/2008).
  2. Open the solution you want to debug
  3. In the menu "Debug", Click on 'Attach to process ..."
    • Keep "Transport" as "Default"
    • In "Qualifier", enter the connection value displayed by the "Remote Debugging Monitor" application (e.g. "{MyDomain}\{MyAccount}@{MyMachineName}")
    • Select the type of debugging (usually "managed code")
    • Select the process you want to debug
    • click "Attach"

Monday, October 11, 2010

Configure KDiff3 in Visual Studio

KDiff3 is a very good comparison and merging tool (You can find it http://kdiff3.sourceforge.net/). For merging operations bewteen two branches, it allows to see the 3 source views : "base view" (or common ancestor view), "your local branch view" and the "target view". Also, at the bottom, it displays the final result in the "merged view".

The good thing is that if you are using Visual Studio with TFS as the source control system you can set KDiff3 up to help you during the comparison and merging operations.

In order to setup KDiff3 in Visual Studio (2005, 2008 or 2010) do as follow
:

  1. From Visual Studio's "Tools" menu, select "Options ...".
  2. Then select "Source Control \ Visual Studio Team Foundation Server" in the left treeview control.
  3. On the right side, click on "Configure user Tools ..."
  4. Then enter the following options (by clicking on "Add"):
    • Compare
      • .*
      • Compare
      • C:\Program Files\KDiff3\kdiff3.exe
      • %1 --fname %6 %2 --fname %7

    • Merging
      • .*
      • Merge
      • C:\Program Files\KDiff3\kdiff3.exe
      • %3 --fname %8 %2 --fname %7 %1 --fname %6 -o %4


In the end it should look like this:



Wednesday, July 30, 2008

How to Debug the Installation of Windows Service

Just setup in your Debug tab of your Visual Studio Windows Service project:

· Select Start external program” and find InstallUtil.exe (usually under <Windows\Microsoft.NET>)

· Then as command line argument put the name of your executable

· As a working directory, select the output folder of your project

It should look like this:


Setup the breakpoints and hit F5. The installation should start and stop at your breakpoint.

The service might be not be completely installed or removed. If that is the case, just use in a command line window installUtil /u <path:filename of your executable>