Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio - can be a breakpoint called from code?

I have a unit test project based on UnitTest++. I usually put a breakpoint to the last line of the code so that the I can inspect the console when one of the tests fails:

  n = UnitTest::RunAllTests();   if ( n != 0 )   {   // place breakpoint here         return n;   }   return n; 

But I have to reinsert it each time I check-out the code anew from SVN. Is it possible to somewhat place the breakpoint by the compiler?:

      n = UnitTest::RunAllTests();       if ( n != 0 )       {       // place breakpoint here     #ifdef __MSVC__         @!!!$$$??___BREAKPOINT; #endif         return n;       }       return n; 
like image 312
danatel Avatar asked Mar 05 '10 19:03

danatel


People also ask

What is breakpoint in Visual Studio code?

Breakpoints are one of the most important debugging techniques in your developer's toolbox. You set breakpoints wherever you want to pause debugger execution. For example, you may want to see the state of code variables or look at the call stack at a certain breakpoint.

How do breakpoints work in code?

Software Breakpoint They work by patching the code you are trying to execute with an instruction that triggers a debug event in some fashion. This is accomplished by injecting a breakpoint instruction or when that is not supported by inserting an instruction that causes a fault that halts the core.

How do I Debug a code in Visual Studio?

Navigate code using Run to Click The tooltip for the button shows "Run execution to here". The Run to Click button is new in Visual Studio 2017. (If you don't see the green arrow button, use F11 in this example instead to advance the debugger to the right place.) Click the Run to Click button .

Why is my breakpoint not working in Visual Studio code?

If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.


1 Answers

Use the __debugbreak() intrinsic(requires the inclusion of <intrin.h>).

Using __debugbreak() is preferable to directly writing __asm { int 3 } since inline assembly is not permitted when compiling code for the x64 architecture.

And for the record, on Linux and Mac, with GCC, I'm using __builtin_trap().

like image 127
Gregory Pakosz Avatar answered Oct 12 '22 22:10

Gregory Pakosz