C++26 adds a new <debug> header (via P2546R5 and companion P2810R4, credited to René Ferdinand Rivera Morell) that standardizes a tiny, pragmatic debugging API: std::breakpoint() (unconditional), std::is_debugger_present() (query), and std::breakpoint_if_debugging() (convenience). All three are noexcept, freestanding and non-constexpr; breakpoint() typically emits an int3 on x86 and has implementation-defined behavior when no debugger is attached (often delivering SIGTRAP). The intent is to replace the myriad project-specific macros and platform checks that currently reinvent how to programmatically hit a breakpoint.
The standard leaves detection mechanisms implementation-defined - Windows implementations can call ::IsDebuggerPresent(), Linux ones can read /proc/self/status’s TracerPid - and makes std::is_debugger_present() replaceable so bare-metal or custom platforms can supply their own check. breakpoint_if_debugging() is simply if (std::is_debugger_present()) std::breakpoint(). Separating detection from the trap enables other debugger-aware behavior: extra diagnostics, disabling timeouts during stepping, switching to debugger-friendly allocators, or avoiding optimizations that impede debugging. This is a small, practical addition that codifies well-known platform knowledge and saves projects from repeating the same boilerplate.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.