Welcome to MSDN Blogs Sign in | Join | Help

Managed Debugger Sample

We have a pure C#/IL managed debugger sample, called MDbg. It's available on MSDN at  http://www.microsoft.com/downloads/details.aspx?familyid=38449a42-6b7a-4e28-80ce-c55645ab1310&displaylang=en . For a variety of reasons, this sample only runs on v2.0 CLR (you can download beta 1 here).  

[Update]: We also have a winforms gui sample for Mdbg.
[Update]: The Mdbg binaries are now included in Whidbey beta2. See here for details.
[Update: 11/8/05] Here's a set of a bunch of MDbg links.

ICorDebug is an unmanaged COM-classic API. Cordbg.exe is a simple command line debugger that our team produces that consumes this API. We view Cordbg primarily as a testing tool, and I personally cringe at the thought of people using it for production debugging needs. Cordbg ships in the SDK and is actually available as a sample, though admittedly not a very good one. The code should also be public via the CLR shared source efforts. Cordbg is written in unmanaged C++ and suffers all the problems of unmanaged code: clunky api, painful to use strings, reference counting, poor extensibility, etc...

At the time Cordbg was being written, Com-interop didn't exist (at least not in a usable state). That aside, there's no technical reason that Cordbg couldn't be managed code.  And since we all know that managed code is much cooler than unmanaged code (shameless plug..), it made a lot of sense to try and make a managed version of Cordbg in C#.

Jan Stranik, a tester on our debugger team, used COM-interop to wrap the unmanaged ICorDebug API. This was very painful as ICorDebug was designed by folks (including myself) who were not very familiar with COM (for eg, I don't think any of us knew what "apartment state" was at the time). Jan worked these kinks out and then wrote a pretty managed wrapper on top of the com-interop layer which does things like exposes string properties as System.String instead. He then wrote a managed shell on top of that. The finished product is called MDbg (for Managed Debugger), and is exclusively in C# and IL.  It's extra impressive that he did most of it as a hobby. Most other folks on our team have since jumped on the Mdbg bandwagon. Nick Hertl, another tester, has done a lot of great work to make Mdbg into a sample. I personally think Mdbg is the greatest thing since sliced bread.

Mdbg's not perfect, but here are some reasons why Mdbg is so much better than Cordbg:

  1. It's managed. Enough said :)
  2. Great extensibility model. You can easily write C# plugs-ins for Mdbg. A lot of our managed-debugger testing is done with Mdbg now.
  3. Great object model. Mdbg lets you write small simple apps that can do cool things. For eg, Jan wrote a tiny app (< 100 lines) that's a sniffs a running app to print out when modules get loaded. You could write a similar app to attach to a random app and collect a managed stack trace.
  4. Better portability story - because it's pure-managed, you can drop the exact same bits onto other CLR-supported platforms (ia64,amd64) and run them as is. Cordbg had to be manually ported to these platforms.

There's a readme in the download with more info. We have an alias for further questions about Mdbg: clrmdbg AT microsoft.com

Who knows what the future holds? I personally would like to see us ship Mdbg in the SDK and kill off Cordbg.  I'd also love to see Mdbg become an open-source project (it's currently not, although it's freely available as a sample). I can't promise anything, but we'll see what happens.

 

Published Thursday, September 30, 2004 3:20 PM by jmstall
Filed under: , ,

Comments

# re: Managed Debugger Sample

Thursday, September 30, 2004 10:11 PM by Woo Seok Seo
Thank you for good information!

# re: An update

Friday, October 01, 2004 7:35 PM by Jon Shute's Blog

# re: Managed Debugger Sample

Monday, October 04, 2004 10:35 AM by Andrew Stopford
Hi, might be worth mentioning that this sample is for .NET 2.0 SDK beta due the inclusion of features such as edit and continue.

# re: Managed Debugger Sample

Monday, October 04, 2004 11:36 AM by Mike Stall
Whoops! Thanks Andrew, I forgot to mention that. I updated the original post with that addition. It's likely not possible to write a managed client of ICorDebug on pre-v2.0 ICorDebug.

# Mike Stall's (Relatively)New Debugger Blog

Tuesday, October 05, 2004 5:11 PM by .Net Security Blog

# Mike Stall's (Relatively)New Debugger Blog

Tuesday, October 05, 2004 5:12 PM by .Net Security Blog

# re: We need your feedback on the fate of Cordbg.exe

Wednesday, October 06, 2004 3:12 AM by Mike Stall's .NET Debugging Blog

# re: Why is managed debugging different than native-debugging?

Sunday, October 10, 2004 10:56 PM by Mike Stall's .NET Debugging Blog

# re: We need your feedback on the fate of Cordbg.exe

Thursday, October 14, 2004 1:33 AM by Mike Stall's .NET Debugging Blog

# re: ICorDebug, Edit-and-Continue, and C#

Sunday, October 17, 2004 12:47 PM by Mike Stall's .NET Debugging Blog

# re: Managed Debugger Sample

Wednesday, October 20, 2004 11:33 PM by Chua Wen Ching
Can MDbg supports .Net Framework 1.1? I want debug for exe or dll created in .net framework 1.1.

Any idea?

# re: Managed Debugger Sample

Wednesday, October 20, 2004 11:33 PM by Mike Stall's .NET Debugging Blog

# re: Managed Debugger Sample

Thursday, October 21, 2004 12:31 AM by Mike Stall
Chua Wen Ching -
1) The current MDbg sample can only debug v2.0 apps (eg, the version of the CLR in the debuggee's process is v2.0). We're actively revising MDbg to add support for debugging v1.1 and v2.0 apps. One snag is that there are bugs in the V1.1 ICorDebug impl that prevent it from being consumed by managed wrappers (eg, embarrassing bugs in our QueryInterface impls that break com-interop).

2) MDbg requires the v2.0 CLR to run. In other words, the version of the CLR in the debugger's (Mdbg's) process is v2.0.
This is because:
- The actual MDbg implementation uses v2.0 functionality (like generics)
- there are limitations with calling metadata from managed code that require the latest CLR to work around.

# re: Managed Debugger Sample

Thursday, October 21, 2004 12:31 AM by Mike Stall's .NET Debugging Blog

# CLR Debugging vs. CLR Profiling

Friday, October 22, 2004 1:25 AM by Mike Stall's .NET Debugging Blog

# re: We need your feedback on the fate of Cordbg.exe

Wednesday, October 27, 2004 3:19 PM by Mike Stall's .NET Debugging Blog

# Using metadata interfaces from managed code

Saturday, October 30, 2004 11:58 AM by Mike Stall's .NET Debugging Blog

# re: Using metadata interfaces from managed code

Monday, November 01, 2004 3:20 PM by Mike Stall's .NET Debugging Blog

# Problems for a managed debugger for v1.1?

Tuesday, November 02, 2004 2:23 AM by Mike Stall's .NET Debugging Blog

# re: Problems for a managed debugger for v1.1?

Thursday, November 04, 2004 6:13 AM by Mike Stall's .NET Debugging Blog

# re: Problems for a managed debugger for v1.1?

Thursday, November 04, 2004 12:13 PM by Mike Stall's .NET Debugging Blog

# re: Problems for a managed debugger for v1.1?

Sunday, November 07, 2004 1:24 AM by Mike Stall's .NET Debugging Blog

# re: Winforms gui on top of Managed debugger sample.

Monday, November 15, 2004 12:29 PM by Mike Stall's .NET Debugging Blog

# re: Winforms gui on top of Managed debugger sample.

Monday, November 15, 2004 1:24 PM by Mike Stall's .NET Debugging Blog

# Sample app to print loaded modules.

Friday, November 19, 2004 11:04 PM by Mike Stall's .NET Debugging Blog

# How do Managed Breakpoints work?

Tuesday, December 28, 2004 10:26 PM by Mike Stall's .NET Debugging Blog

# How can I debug Just My Code?

Friday, December 31, 2004 11:47 AM by Mike Stall's .NET Debugging Blog

# What's new in v2.0 CLR Debugging (ICorDebug)?

Tuesday, January 04, 2005 8:36 PM by Mike Stall's .NET Debugging Blog

# re: What's new in v2.0 CLR Debugging (ICorDebug)?

Friday, January 07, 2005 6:14 PM by Mike Stall's .NET Debugging Blog

# re: What's new in v2.0 CLR Debugging (ICorDebug)?

Tuesday, January 11, 2005 1:42 AM by Mike Stall's .NET Debugging Blog

# re: Object Identity in Managed Debugging

Tuesday, January 11, 2005 1:52 AM by Mike Stall's .NET Debugging Blog

# How to get a V2.0 ICorDebug object

Saturday, January 15, 2005 5:02 PM by Mike Stall's .NET Debugging Blog

# re: Implementing ICorDebug to reuse existing debuggers?

Tuesday, February 01, 2005 9:14 PM by Mike Stall's .NET Debugging Blog

# re: Implementing ICorDebug to reuse existing debuggers?

Wednesday, February 02, 2005 12:39 AM by Mike Stall's .NET Debugging Blog

# Source is available for MDbg Winforms GUI!

Friday, February 04, 2005 7:50 PM by Mike Stall's .NET Debugging Blog

# Compiler Lab Results

Tuesday, February 08, 2005 11:34 PM by Mike Stall's .NET Debugging Blog

# Winforms Mdbg threading issue

Saturday, February 12, 2005 12:16 AM by Mike Stall's .NET Debugging Blog

# re: What if you do attach both a managed and native debugger simultaneously?

Wednesday, February 16, 2005 7:04 AM by Mike Stall's .NET Debugging Blog

# re: What if you do attach both a managed and native debugger simultaneously?

Wednesday, February 16, 2005 11:19 AM by Mike Stall's .NET Debugging Blog

# re: Debugging any .Net language

Thursday, February 24, 2005 7:25 PM by Mike Stall's .NET Debugging Blog

# re: Source is available for MDbg Winforms GUI!

Thursday, March 03, 2005 4:06 PM by Mike Stall's .NET Debugging Blog

# re: Source is available for MDbg Winforms GUI!

Thursday, March 03, 2005 5:53 PM by Mike Stall's .NET Debugging Blog

# re: Source is available for MDbg Winforms GUI!

Friday, March 04, 2005 3:31 PM by Mike Stall's .NET Debugging Blog

# re: Source is available for MDbg Winforms GUI!

Friday, March 04, 2005 3:35 PM by Mike Stall's .NET Debugging Blog

# re: Source is available for MDbg Winforms GUI!

Friday, March 04, 2005 4:57 PM by Mike Stall's .NET Debugging Blog

# re: Source is available for MDbg Winforms GUI!

Friday, March 04, 2005 4:58 PM by Mike Stall's .NET Debugging Blog

# Feedback on the ICorDebug API?

Wednesday, April 06, 2005 11:11 AM by Mike Stall's .NET Debugging Blog
Do you write Managed debuggers? Do you use the ICorDebug API?&amp;nbsp;We're designing V3 of ICorDebug and...

# MDbg and Beta 2

Tuesday, April 26, 2005 10:28 AM by Mike Stall's .NET Debugging Blog
VS Beta 2 has shipped. The MDbg binaries are now included in the beta 2 sdk. (Kudos to Rick for this)...

# Mdbgcore.dll and linking IL

Friday, June 03, 2005 1:22 AM by Mike Stall's .NET Debugging Blog
Mdbg is now included in the Whidbey Beta 2 SDK as a tool. The source is not actually included in the...

# A common problem: forgetting to call ICorDebugAppDomain::Attach

Tuesday, July 19, 2005 6:08 PM by Mike Stall's .NET Debugging Blog
I notice one of the most common issues folks hit when they try to write their own managed debugger is...

# Simple harness to print exceptions in an app

Thursday, July 28, 2005 1:30 AM by Mike Stall's .NET Debugging Blog
Several people have asked how to write&amp;nbsp;something that runs some executable under a harness and then...

# MDbg Sample is updated for Beta 2 and RTM

Wednesday, August 10, 2005 4:52 PM by Mike Stall's .NET Debugging Blog

The Mdbg (a managed debugging written in pure C#) sample, which includes full source, has now been...

# MDbg Sample is updated for Beta 2 and RTM

Wednesday, August 10, 2005 4:53 PM by Mike Stall's .NET Debugging Blog

The Mdbg (a managed debugging written in pure C#) sample, which includes full source, has now been...

# ICorDebug, MTA, STA.

Thursday, September 15, 2005 1:18 AM by Mike Stall's .NET Debugging Blog
ICorDebug (ICD) is a com-classic interface. In terms of COM threading models, ICorDebug is technically...

# Solutions that don't actually solve anything

Wednesday, May 10, 2006 10:00 AM by The Old New Thing
You've already lost the game.

# Debugging and Symbols FAQ

Friday, May 19, 2006 10:42 AM by Dan McKinley
This is something I typed up internally, to help resolve the confusion that precipitates when Visual...

# Mike Stall's .NET Debugging Blog : MDbg Linkfest

Wednesday, June 14, 2006 2:34 PM by Mike Stall's .NET Debugging Blog : MDbg Linkfest

# How can I use ICorDebug?

Wednesday, July 26, 2006 11:29 AM by Mike Stall's .NET Debugging Blog
ICorDebug, the managed debugging API, &amp;nbsp;is a public API and anybody can use it to write a managed...

# MDbg Linkfest

Wednesday, November 22, 2006 10:11 PM by Mike Stall's .NET Debugging Blog

MDbg is a debugger for managed code written entirely in C# (and IL), which started shipping in the CLR

# Using Windows live Writer

Saturday, October 27, 2007 12:21 AM by Mike Stall's .NET Debugging Blog

I'm trying out Windows Live Writer. Currently, I do all of my blogging via Frontpage , so this will be

# Reflector + Deblector + x64 = 0&#215;80131C0 | Nic's Blog

New Comments to this post are disabled
 
Page view tracker