John Lam 1997 — 2026

WinDBG Rocks

While researching how P/Invoke works, I found out a nasty limitation in the Visual Studio .NET debugger. Here’s the scenario: you’re stepping through some unmanaged code in the debugger. This code was originally called from some managed code. When I step over the x86 ret instruction, it jumps directly back into managed code. You don’t see any of the P/Invoke goo that makes the unmanaged call possible. Now, for most developers this isn’t an issue. In fact the P/Invoke goo just gets in the way. BUT, if you’re trying to figure out how the P/Invoke goo works, it becomes a blocking issue. It would be really nice if the debugger folks could give us a switch that lets us turn this behavior on and off.

I checked with my friend Matt Pietrek, and he confirmed that this was an issue that annoyed him to no end as well. When I asked him what I could do about it, he gave me a typical NuMega response: use SoftICE. My old copy of SoftICE wouldn’t run on Windows XP, so I went on over to NuMega’s web site. I was shocked to find out that the only way that I could get SoftICE was to purchase a copy of their SoftICE Driver Suite product ($999!!!!). Here’s a hint for NuMega: maybe someone just wants the debugger and NOT all of that other stuff. Why not break it out as a separate SKU and get an extra sale? I’d be more than happy to pay $300-$400 for SoftICE, but $999 is going to make me go elsewhere.

So, where did I go? Back to Microsoft, of course. I’ve never really spent much time reverse-engineering Windows OS code, so I haven’t really needed to use a kernel-mode debugger. As it turns out Microsoft gives away a very nice kernel-mode debugger: WinDBG. I went and downloaded the latest release version of WinDBG (3.0.20.0) and cranked it up. Lo and behold, I could step through everything and see the P/Invoke code in action. What a great tool, and what a great price.