Enabling Attach to Process support in NetCF v2

By default, support for attaching the debugger to a .NET Compact Framework application is disabled in NetCF v2.  This is done to optimize the runtime performance of the application on the device.  When attach to process support is enabled, the Just-In-Time compiler generates debuggable code.  Debuggable code is larger (to accomodate breakpoints, some optimizations will be disabled) and as a consequence runs slower.  Since all NetCF debugging is remote debugging, communications transports are also loaded, which increases the application's working set.

It is important to remember that attach to process support is a device global setting and that every application that runs on NetCF v2 will be run in attachable / debuggable mode.  Because of this, I highly recommend enabling attach to process support only when you required and disabling it once you are finished debugging.

To ensure that the transports are properly installed on the device, I recommend deploying / debugging your application once using F5.

Enabling attach to process support
Attach to process support can be enabled (and disabled) using the Remote Registry Editor that is installed by Visual Studio 2005 Beta 2.

WARNING: Using Remote Registry Editor incorrectly can cause serious problems that may require you to hard reset your device. Microsoft cannot guarantee that problems resulting from the incorrect use of Remote Registry Editor can be solved. Use Remote Registry Editor at your own risk.

  1. Start the Remote Registry Editor
    • Open the Start menu
    •  Select All Programs
    • Select Microsoft Visual Studio 2005 Beta 2
    • Select Visual Studio Remote Tools
    • Select Remote Registry Editor
  2. Connect to your device
    • On the Target menu, select Connect
    • Select your device
    • Click OK
  3. Enable attach to process support
    • In the left hand pane, expand the device
    • Expand HKEY_LOCAL_MACHINE
    • Expand SOFTWARE
    • Expand Microsoft
    • Expand .NETCompactFramework
    • Expand Managed Debugger
      If this key does not exist, you will need to create it
      • Right click on .NETCompactFramework
      • Select New > Key
      • Type "Managed Debugger" (without quotes)
      • Click Ok
    • Set the value of AttachEnabled to 1
      If this value does not exist, you will need to create it
      • Right click on Managed Debugger
      • Select New > DWORD Value
      • Set the Name to AttachEnabled
      • Set the value to 1
      • Click OK

To disable attach to process support, follow the above steps and either delete the AttachEnabled value or set it to 0.

If you have Visual Studio 2005 Beta 2 installed, you can now start your applications without debugging support (ex: Ctrl+F5) and then attach to the process while it is running.  I will discuss this more in future posts.

Take care,
-- DK

Disclaimer(s):
This posting is provided "AS IS" with no warranties, and confers no rights.
Some of the information contained within this post may be in relation to beta software. Any and all details are subject to change.

Comments

  • Anonymous
    March 15, 2006
    During my recent MEDC session, I demonstrated how to debug both the managed and native code sides of...
  • Anonymous
    August 25, 2006
    Being able to attach to a running process is a very powerful debugger feature.  It is especially...
  • Anonymous
    October 15, 2007
    Una delle caratteristiche più "accattivati" del debug offerto da Visula Studio è la possibilità