How to: Attach to Managed Device Processes
You attach to a process on a device much like you would on the desktop, except that you must set a registry key on the device to enable managed debugging if the process is already running without the debugger. The setting of this key persists until you change it, or, for an emulator, until the emulator is closed without saving its settings.
Note
Setting the device debug key reduces performance. When you are not debugging, reset the key.
You may receive an error message if you try to attach two debuggers or try to attach with a managed debugger when the device registry key has not been set.
You can start a process in several ways, such as File Explorer, a command prompt, and so on. In the following step, you start the process by starting from the Debug menu. You can also start a process without the managed debugger, and then attach it later.
If you are targeting a Windows CE platform generated from Platform Builder, you must have the toolhelp.dll library to populate the Available Processes pane. This library is included in the Windows Mobile SDKs.
Note
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.
Debug a Managed Process
To debug a managed process
On the Debug menu, click Start.
Note
If you detach from processes started from the Debug menu, you cannot reattach without performing the following steps for attaching after a process is running. That is, the registry key on the device has to be set.
Attach to an Already Running Managed Process
If you plan to attach to a process that is already running, by, for example, clicking Start Without Debugging and then attaching to a running managed process, you must first set the device registry key before the process starts and before you try to attach by using the Attach to Process dialog box. The following steps detail the process.
To set the device registry key to enable attaching to a running process
On the Windows Start menu, point to All Programs, point to Microsoft Visual Studio 2008, point to Visual Studio Remote Tools, and then click Remote Registry Editor.
Using the Remote Registry Editor, connect to the device.
Navigate to or create the following key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\Managed Debugger
Set or create a DWORD value named AttachEnabled.
Set the data for the value at 1.
Note
Setting the device debug key significantly reduces performance. When you are not debugging, disable managed attach by resetting the data value to 0 or deleting the AttachEnabled value.
Close the Remote Registry Editor.
Managed attach is now enabled, and you will be able to start a process without the debugger and then attach to the process using the Attach to Process dialog box.
To attach to a managed process after the process is running
After setting the registry key as described in the previous steps, start a process without the debugger.
On the Tools menu, click Attach to Process.
In the Transport box, click Smart Device.
In the Qualifier box, click Browse.
Note
The Qualifier box is prepopulated with the most recently used devices from the current session.
In the Connect to Device dialog box, select the platform, select the device, and then click Connect.
In the Available Processes pane, select one or more processes to attach to, and then click Attach.
Note
By default, code type is set automatically to Managed (.NET Compact Framework) if available, otherwise to Native (Smart Device). To override the default settings, click Select to open the Select Code Type dialog box. Note that you cannot select both.
Note
Interop debugging is not supported. That is, you cannot debug both managed and native code types at the same time.
Detach From or Terminate a Process
To detach from or terminate a process
On the Debug menu, point to Windows, and then click Processes.
In the Processes window, right-click the process you want to detach from or terminate.
On the shortcut menu, click Terminate Process or Detach from Process.
Note
You can reopen the Attach to Process dialog box from this same shortcut menu.
Populate the Available Processes Pane
To populate the Available Processes pane in Windows CE projects
Include the file toolhelp.dll in the Windows CE OS image.
—or—
Manually copy the file toolhelp.dll to the target device.
See Also
Tasks
Walkthrough: Debugging a Solution that Includes Both Managed and Native Code
Concepts
Building and Debugging Visual C++ Device Projects