1. Revision History
1.1. Revision 0
Initial Release 🎉
2. Motivation
Setting breakpoints inside of a debugger can be difficult and confusing for newcomers to C++. Rather than having to learn C++, they have to learn a special syntax just to place a breakpoint in the exact spot they want, or rely on the interface of an IDE. At the end of the day, a simple programmer just wants to place a breakpoint so that their program stops when under the watchful eye of a debugger.
This paper proposes a new function,
, that causes a program to
stop or "break" execution when it is being debugged.
3. Design
The goal of the
function is to "break" when being debugged
but to act as though it is a no-op when it is executing normally. This might
seem difficult in practice, but nearly every platform and various debuggers
supports something to this effect. However, some platforms have caveats that
make implementing this "break when being debugged" behavior hard to implement
correctly.
The
function is intended to go into the
header.
4. FAQ
4.1. Couldn’t this be implemented via contracts?
Possibly. However, a
function gives more fine grained control
than "break on all contract violations".
4.2. How does this work with the upcoming stacktrace API?
It is not intended to interoperate with the stacktrace API at this time. Both
the stacktrace API and
are essentially orthogonal in their
focus and use. Whereas the former is for getting more information in the event
of an error,
is intended to help programmers inspect the
current state of a program at a breakpoint.
5. Wording
Wording is relative to [N4762]
namespace std { void breakpoint () noexcept ; }
-
Remarks
When this function is executed, it first must perform an implementation defined check to see if the program is currently running under a debugger. If it is, the program’s execution is temporarily halted and execution is handed to the debugger until such a time as:
-
the program is terminated by the debugger or,
-
the debugger hands execution back to the program.
-