If you’ve ever needed to hit a breakpoint programmatically in C++, you’ve probably written something like this: 1 2 3 4 5 6 7 8 9 #if defined(_MSC_VER) __debugbreak(); #elif defined(__clang__) __builtin_debugtrap(); #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) __asm__ volatile("int3"); #else raise(SIGTRAP); #endif Every major C++ project reinvents this wheel. Boost.Test has debugger_break(), Catch2 has CATCH_BREAK_INTO_DEBUGGER, Dear ImGui has IM_DEBUG_BREAK() and…
C++26 introduces a standardized <debugging> header with three functions for debugging.
The <debugging> header provides unconditional breakpoints and debugger detection.
Functions are noexcept and freestanding, not constexpr.
Behavior varies when no debugger is attached, often causing termination.
Summarised automatically by AI from the original article by Hacker News. AI can make mistakes, so check the original for details.
Every major C++ project reinvents this wheel. Boost.Test has debugger_break(), Catch2 has CATCH_BREAK_INTO_DEBUGGER, Dear ImGui has IM_DEBUG_BREAK() and Unreal has UE_DEBUG_BREAK. The platform knowledge required is arcane but well-known to tooling implementers — it just wasn’t standardized.
C++26 fixes this with P2546R5 and its companion P2810R4 thanks to Rene Ferdinand Rivera Morell. A new <debugging> header provides three functions.
All three are noexcept and all three are freestanding. None are constexpr — debugging is a runtime concern.
An unconditional breakpoint. When a debugger is attached, execution halts and control is handed to the debugger. On x86, this typically compiles to a single int3 instruction.
Read the full story on Hacker NewsThat's the opening of the story. The full piece is published by Hacker News.