views:

1308

answers:

2

I am using Visual Studio, developing a native application, I have a programmatical breakpoint (assert) in my code placed using __asm int 3 or __debugbreak. Sometimes when I hit it, I would like to disable it so that successive hits in the same debugging session no longer break into the debugger. How can I do this?

+6  A: 

x86 / x64

Assuming you are writing x86/x64 application, write following in your watch window:

*(char *)eip,x

You should see a value 0xcc, which is opcode for INT 3. Replace it with 0x90, which is opcode for NOP. You can also use the memory window with eip as an address.

PPC

Assuming you are writing PPC application (e.g. Xbox 360), write following in your watch window:

*(int *)iar,x

You should see a value 0xfeNNNNNN, which is opcode for trap (most often 0x0fe00016 = unconditional trap). Replace it with 0x60000000, which is opcode for NOP.

Suma
on win32 you may have to make your code-segment writable. Great answer nevertheless!
Nils Pipenbrinck
I am doing this on Win32 and I have never seen any code-segment writeability issues. Can you elaborate some more? I will be glad to incorporate any more details into the answer to make it better.
Suma
0x90 is NOP in x64 as well
Nathan Fellman
It seems my ignorance on x64 has been revealed. :) I will remember now many opcodes are the same for x86/x64. Thanks.
Suma
A: 

The debugger can write to the code even if it is "otherwise" read only. Presumably it does a VirtualProtect(make it writable), write, VirtualProtect(restore). And the underlying mechanism is solid -- "writable" is really "copy on write" so if other instances of your program are running, they will NOT also get the change, just the one in the debugger.

Jay