Breaking changes in ICorDebug from 1.1 to 2.0.

Here are some random notes about specific ICorDebug breaking changes between .NET v1.1 (Everett) and .NET 2.0 (Whidbey). (I came across these as I was cleaning out old documents in preparation for my upcoming move). This would have been more timely 2 years ago, but better late than never. This can be viewed as the…

0

Things that what work in Native-debugging that don’t work in Interop-debugging.

Interop-debugging (mixed-mode) is managed + native debugging combined. Well, sort of. Native and managed debugging have very different paradigms. Native debugging tends to own the whole process, while managed debugging tends to require control of the whole process while only exposing a managed  view to the user. So some functionality restrictions were needed to get…

1

How to tell if a function is managed code?

This is a moot point for pure C# apps, but what if you’re writing in MC++ (or some other ‘mixed’ language) and you want to know if a function is getting compiled as managed or native code?   You can try and inspect the source and infer from the language rules. Eg, in MC++, look…

1

Interop-debugging fails when using more than 63 TLS slots

Here’s a Public Service Announcement: Interop-debugging may hang if the debuggee uses more than 63 native Thread Local-Storage slots and then loads the CLR. KB939969 has more details, including three workarounds. This is fixed in Orcas, so only applies to pre-Orcas runtimes (like .NET 2.0). You really shouldn’t be using a lot of TLS slots in the first place,…

3

Tips for writing an Interop Debugger

I’ve had a growing number of people inquire about how to write an interop-debugger with ICorDebug. I strongly advise anybody considering writing an interop-debugger to reconsider for reasons listed here. However, for those who can not be dissuaded, and promise to do something really really cool, here are some key tips: Interop-debugging means both the managed…

4

You don’t want to write an interop debugger.

I’ve had a growing number of people inquire about how to write an interop-debugger with ICorDebug.  My goal here is to discourage you from doing that. (This reminds me of one of my college classes. On day one, the acting-Prof launched into a great sermon “Why you should drop this class now”. It turned out…

3

Beware of the Vectored Exception Handler and managed code

A vectored exception handler (see kernel32!AddVectoredExceptionHandler) lets you add to a global list of filters that get executed by the OS when a native exception is thrown. More specifically, this list is executed by the OS before the filters in the FS:0 chain are executed. This means you can get your exception handler to run…

6

Why can’t you detach in interop-debugging?

Matt Pietrek noticed you can’t detach while interop-debugging (aka “mixed-mode”) in VS. Short answer: this is a limitation of the CLR / ICorDebug. Longer answer follows… Some history:Interop-debugging is managed + native debugging simultaneously in a single debugger. This means it’s the lowest common denominator of managed and native debugging. Managed-debugging supports detach (ICorDebugProcess::Detach), but…

8

You can’t do Edit-and-Continue with Interop-debugging on.

Somebody asked on the forums about Edit-and-Continue (EnC) in mixed mode. You can’t use managed EnC with mixed-mode (interop) debugging enabled. This is a limitation of the CLR Debugging Services. Both Interop-debugging and EnC are complicated features; combining them would be a huge test-matrix and very costly. So if you have a C# and native…

6

F5 vs. Ctrl-F5

In VS, F5 will launch your application under the debugger. Under the debugger, you’ll hit breakpoints, be able to edit-and-continue, and do all the debugger things you know and love. Ctrl+F5 will launch your application outside of the debugger. This is like launching your app from the "start | run" menu, except VS becomes the…

5