Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a programmatical breakpoint / assert?

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?

like image 479
Suma Avatar asked Sep 22 '08 14:09

Suma


People also ask

How do I turn off assert?

To disable assert, NDEBUG must be defined. You can choose to define this in your code as #define NDEBUG .

How do I disable assert in Visual Studio?

In Visual Studio, go to Debug / Windows / Exception Settings. In the Exception Settings, go to Win32 Exceptions / 0xc0000420 Assertion Failed. Uncheck the box in front of that entry.

How do I temporarily disable breakpoints in Visual Studio?

In the Query Editor window, right-click the breakpoint, and then click Disable Breakpoint.


2 Answers

x86 / x64

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

x86: *(char *)eip,x

x64: *(char *)rip,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.

like image 81
Suma Avatar answered Oct 11 '22 17:10

Suma


You might try something like this:

#define ASSERT(x) {\
   if (!(x)) \
   { \
      static bool ignore = false; \
      if (!ignore) \
      { \
         ignore = true; \
         __asm int 3 \
      } \
   }\
}

This should hit the debug only once. You might even show a messagebox to the user and ask what to do: continue (nothing happens), break (int 3 is called) or ignore (ignore is set to true, the breakpoint is never hit again)

like image 23
Fili Avatar answered Oct 11 '22 16:10

Fili