Partager via


How to build Mdbg apps

I often publish little samples in this blog based off MDbg (which generally show off the debugging services in some way; such as app to convert Pdb-->XML, or this harness to print all exceptions in an app). I generally call these apps "harnesses" because they run on another app (the debuggee). I've gotten some questions about how to build them, so here are some more details.

The big picture is that these samples just need a reference to the Mdbg dlls and then all else is good. We ship Mdbg as a source sample and also in the .NET 2.0 SDK. See here for a comparison. The key details are that:
- the sample has full source for Mdbg. The sdk version does not.
- the sample has 4 dlls to link against: Corapi, CorApi2, MdbgEng, MdbgExt.  The sdk just has 1 dll, MdbgCore.
The 2 versions are very close and most test apps could be compiled against either one.

Note MDbg requires .NET 2.0. So V1.1 users are some what out of luck.

Here are more details:

The easy way: Do it all in VS 2005
If you have VS2005 installed (even the C# Express edition, which is free), then you can:

  1. Just install the Mdbg sample (details here).
  2. Build it for a sanity check.
  3. Create a new project for your test app. My samples are mostly C# console applications
  4. My samples are usually a single file; so you can just copy the sample off the web page and then paste it into the newly created project file.
  5. For the new project, add a reference to the Mdbg dlls from the other projects (Corapi, CorApi2, MdbgEng, MdbgExt.)
  6. Make sure it all builds.
  7. Set the test app as your startup project and go. In some cases, you may need to supply command line args to the test app.

This is nice because then everything is in VS. You get intellisense for all of Mdbg, you can step between the new app and mdbg core, and you get Edit-and-continue support.

The harder way: Do it all on the Command line (no VS)

If you don't have VS, you can still build an Mdbg app on the command line.

  1. Download both .NET 2.0 and the .Net 2.0 sdk. (X86 links are here and here).
  2. Copy the sample from the web page to some source file (eg, T.cs).
  3. Copy mdbgcore.dll from the sdk into the same directory as T.cs
  4. Compile it:
        csc t.cs /debug+ /r:mdbgcore.dll
  5. Run t.exe.  It may need some command line args.

Other alternatives:
You could also download the mdbg sample and build that without VS, and then build the test app against that; all on the command line.
Or you could build just your harness in VS, and then add a reference to mdbgcore.dll from the sdk.

Comments