Share via


Command Line Debugging Revisited - Part 1: Getting started with MDbg and .NET Compact Framework Version 2 Service Pack 1

It's been a while since I last wrote about using the command line debugger (cordbg) with the .NET Compact Framework.  Quite a bit has changed in the world of .NET Compact Framework command line debugging since that time.

With the release, last year, of version 2 of the .NET Framework SDK, a new command line debugger (MDbg) became available.  MDbg is written in managed code and supports adding functionality via extension assemblies (DLLs).  At the time we released version 2, the extension which adds .NET Compact Framework support was not ready.  With the release of .NET Compact Framework version 2 service pack 1, our extension assembly (mdbgnetcf.dll) is now available.

If you followed my original command line debugger series, you may recall that there were several steps to getting a command line debugging session established with a .NET Compact Framework application in version 1.  I'm happy to say that we have made the process of getting started quite a bit easier with our MDbg extension.  I'm going to spend today's post talking about the device and run commands that are added by the mdbgnetcf extension.

Preliminary steps
Before we can get started using MDbg to debug a .NET Compact Framework application, there are a few preliminary tasks we must perform.

  1. Download and install .NET Compact Framework version 2 service pack 1
  2. Update your device to the service pack 1 release
  3. Copy the following files to the \Windows folder on the device
    • from <drive>:\Program Files\Common Files\Microsoft Shared\CoreCon\1.0\Target\wce400\<cpu>
      • edbgtl.dll
      • tcpconnectiona.dll
    • from the service pack 1 installation folder (typically <drive>:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\<version>\<cpu>
      • netcfrtl.dll
      • netcflaunch.exe
  4. Deploy your application file(s) to the device.

Steps 2 & 3 typically need to be performed only once per device.  Step 1 once per development / debugging PC.  Step 4 needs to be performed whenever the application file(s) have changed.

Getting started
Once the preliminary tasks have been performed, we can get started debugging our application using MDbg. 

  1. Run mdbg.exe
    I recommend running MDbg from either a Visual Studio 2005 Command Prompt (Start Menu\All Programs\Microsoft Visual Studio 2005\Visual Studio Tools) or a SDK Command Prompt (Start Menu\All Programs\Microsoft .NET Framework SDK v2.0).  This will ensure that MDbg.exe is on the search path.

    I also recommend running MDbg from within the folder containing both your target executable and the symbol (.pdb) file.  This allows MDbg to match the symbols to the exe and display the correct source code without any additional steps.
     

  2. Load the mdbgnetcf extension

    mdbg>load <path>\mdbgnetcf

    It is important to note that the file extension (.dll) is left off when using the load command.

    When the extension is loaded, the following message will be displayed.

    .NET Compact Framework extension loaded successfully.
     

  3. On your device, run NetCFLaunch.exe

    When NetCFLaunch starts, it will display the transport parameters (ex: 169.254.2.1 6510) required to connect to the device.  We will use the transport parameters in the next step.
     

  4. Connect to the device using the device command

    device 169.254.2.1 6510

    When the device command successfully completes, we will have a connection to the NetCFLaunch application.  The NetCFLaunch window will display "Connection SUCCEEDED".
     

  5. Run your application using the run command

    I will use the WebCrawler sample from Visual Studio 2005.

    run "\program files\webcrawler.exe"

    When the run command completes, MDbg will display the current source location (the application entry point).

    STOP: Breakpoint Hit288: {[p#:0, t#:0] mdbg>

    Note: The breakpoint to which MDbg refers is the initial, temporary breakpoint managed by the debugger.  This breakpoint is inserted and cleared when MDbg connects to the application.

You can now debug your application using the other MDbg commands.  For a list of available commands, use the h[elp] or ? commands.

In the coming weeks, I plan on continuing this series and talking about the other commands added by the mdbgnetcf extension and show some examples of how they can be used.

Enjoy!
-- DK

Disclaimer(s): This posting is provided "AS IS" with no warranties, and confers no rights.

Comments

  • Anonymous
    July 13, 2006
    I don't have a device compatible with CF 2.0, so I've tried to use the Emulator instead. Is this possible?

    I ran into a problem, when launching the NetCfLaunch on the emulator. It gives me connection parameters as "-2147479518" - which looks more like an error code and Mdbg certainly does not like it!

    BTW - I copied the ARMV4i binaries to the emulator - is this the correct CPU for an emulator?

  • Anonymous
    July 13, 2006
    You beat me to it! I started writing a post similar to this yesterday. Grr! :)

  • Anonymous
    July 13, 2006
    PingBack from http://blog.opennetcf.org/ncowburn/2006/07/14/UsingMDbgWithNETCompactFrameworkApplications.aspx

  • Anonymous
    July 14, 2006
    Henrik,

    You need to use Visual Studio 2005 to configure the emulator to use the TCP/IP transport.  Once done, you can cradle the emulator using ActiveSync and the Device Emulator Manager (from Visual Studio).

    I will post details on how to do this in my next update.

    --DK

  • Anonymous
    July 14, 2006
    Sorry about that, Neil :)

  • Anonymous
    July 14, 2006
    The Visual Studio 2005 Device Emulator is a very cool tool for developing, testing and debugging Windows...

  • Anonymous
    August 08, 2006
    .NET Compact Framework v2.0 SP1 includes support for Windows CE 4.2 based devices.&amp;nbsp; To date, Visual...

  • Anonymous
    August 11, 2006
    In the previous parts of this series, I talked about getting started with MDbg and using the Device Emulator.&amp;nbsp;...

  • Anonymous
    August 23, 2006
    The comment has been removed

  • Anonymous
    August 25, 2006
    Being able to attach to a running process is a very powerful debugger feature.&amp;nbsp; It is especially...

  • Anonymous
    September 13, 2006
    In the previous installment, I talked about attaching to running processes using MDbg.&amp;nbsp; As part...

  • Anonymous
    September 27, 2006
    Dan Elliott recently posted about the IL OpCodes supported by the .NET Compact Framework.&amp;nbsp; This...

  • Anonymous
    October 07, 2006
    N&iacute;že se nach&aacute;zej&iacute;c&iacute; seznam obsahuje n&aacute;stroje dostupn&eacute; v SDK

  • Anonymous
    December 28, 2006
    I started this series last year and thought I would continue the tradition with my best of 2006 collection.

  • Anonymous
    February 23, 2007
    Esta es una de las preguntas más comunes que me suelen hacer siempre en sesiones de rendimiento y optimización

  • Anonymous
    August 11, 2007
    .NET Compact Framework v2.0 SP1 includes support for Windows CE 4.2 based devices. To date, Visual Studio