Since C++26, std::breakpoint
and std::breakpoint_if_debugging
is provided. The std::breakpoint
is an "unconditional breakpoint", it breaks program whatever debugging mode or not.
From my understanding, breakpoints should only work when the program is running in debug mode. Otherwise, it will never recover since the debugger does not be present.
Does this mean the code below will hang forever without debug mode?
int main()
{
// Not in debug mode
std::breakpoint();
std::cout << "hello, world" << std::endl;
return 0;
}
Moreover, the revision history shows that the earlier design was indeed a conditional breakpoint.
I found similar designs in LLVM and boost.test. It seems that this design is the mainstream.
So, under what scenarios would std::breakpoint
be used instead of std::breakpoint_if_debugging
?
In other words, under what scenarios would these breakpoints be used unconditionally instead of checking debug mode? Or am I missing something?
std::breakpoint()
, then the implementation load the debugger, and finally resume the program execution by the debugger? – Cerebellum