The most effective debugging tool is still careful thought, coupled with judiciously placed print statements. - Brian Kernighan, "Unix for Beginners" (1979)

the brown-dragon blog

Disabling instructions while debugging using WinDbg

2009-04-29

A quick way of disabling instructions you don't want to execute during a WinDbg session is to nop (no-op) the code in memory. WinDbg takes care of changing the protection over the code segment pages and hopefully it also flushes the instruction cache. In any case, it seems to work fine. Let's look at an example.

In the session below, I want to disable the "return BAD" statement under the breakpoint (the breakpoint is highlighted in red).
I want to disable the BAD return

The first thing to do is to see which instructions have to be disabled. In the assembly window ensure that "Highlight instructions from current source line" is selected. This allows us to see which instructions correspond to the source line we want disabled.
Ensure we can see which instructions need to be disabled

Next, in the disassembly view, move to the line of interest (here I am using "Source Line Syntax" (`recfile.cpp:116`) but any addressing mode will work).
Move to correct line in disassembly view

Finally, fill the range with the NOP(=0x90) instruction ("f <start> <end> 90" will work).
Fill with NOP

Done! Now, in my example, the "return BAD;" will be ignored and the loop will continue.
Fill with NOP

Easy enough. Of course you can also do this with a jmp instructions if you like but this is simpler and cleaner.

Other Posts

(ordered by Tags then Date)