Conventions for passing the arguments to a process

A process’s main() function gets an array of strings for the command line args. This is string[]  in C#, or {int argc, char** argv} in C/C++.  But there are some different conventions for how the parent app passes those strings in. If you execute a program on the command line like:    myapp.exe myfile.txt second.txt The…

4

Managed vs. Native debugging APIs

FxCop has a great rule (UseManagedEquivalentsOfWin32Api) to tell you about managed APIs that exist instead of trying to pinvoke out.  I’m writing a native debugger in managed code (more on this later), and FxCop was telling me to use the managed debugging APIs instead of pinvoke out to the native ones. This came up in…

6

Debugger won’t properly evaluate C#s base keyword

Public Service Announcement: You may have noticed that trying to evaluate members using C#’s ‘base’ keyword in the debugger still calls the derived members. (The ‘base’ keyword lets you access base class member implementations from within  a derived class, which is very useful when the members are polymorphic and so just calling the member directly…

9

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…

1

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

Enc APIs aren’t exposed through reflection

David  Srbecky asked: Can a EnC capable compiler work on top of System.Refletion.Emit? (ie. If an existing compiler is to be extended to support EnC, does it have to be rewritten to use the unmanaged emitting interface?) Unfortuantely, No. Details:1. You can indeed write a compiler in C# which emits using reflection-emit (here’s a sample…

2

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

PSA: Pinvokes may be 100x slower under the debugger.

I need to make an embarrassing public service announcement (PSA): Pinvokes are 100x slower under the debugger in VS2005 / Whidbey.  For example, this is the issue that came up here. It may also manifest as your app “hanging” under the debugger w/ 100% CPU usage. How did this happen?I’ll explain why, but I first…

12

Using MC++ to wrap ICorDebug for .NET 1.1

MDbg and the managed wrappers around ICorDebug only work on .NET 2.0 (VS2005). I previously discussed why they won’t work on 1.1. One workaround to access ICorDebug from managed code in .NET 1.1 is to use MC++. In general, MC++ can be extremely useful for gluing managed and unmanaged code together. Using MC++:MC++ will let…

1

Evil trick to render UI when stopped at a breakpoint.

Here’s an EVIL trick to render your UI in a winforms app when you’re stopped at a breakpoint. When managed-debugging, when you hit a breakpoint, all the managed threads stop. With a winforms app, the UI thread is managed and so it stops too. However, that same UI thread that’s pumping WM_Paint messages is also…

2