PrevUpHomeNext

debugging - c++26 std


> Start
> std::is_debugger_present()
> std::breakpoint()
> std::breakpoint_if_debugging()
> Link c++ experimental library
> c++ example
> Back: Home

c++26 <debugging> is implemented initially by gnu c++ compiler:

g++

Requires gnu c++ compiler 16.0 at least.

https://gcc.gnu.org

std::is_debugger_present()

bool std::is_debugger_present() noexcept;

Try to determine if the program is running under control of a debugger.

It returns true if the program is running under control of gdb .

std::breakpoint()

void std::breakpoint() noexcept;

Stop the program with a breakpoint or debug trap.

The program will be stopped by std::breakpoint() for either a debugger present or not.

std::breakpoint_if_debugging

void std::breakpoint_if_debugging() noexcept;

Stop the program if it is running under control of a debugger.

Link c++ experimental library

Link if gnu c++ compiler.

-lstdc++exp

c++ Example

c++ Example: dbgprog.cpp

#include <debugging>
#include <iostream>

int main()
{
	std::cout
		<< std::boolalpha
		<< std::is_debugger_present()
		<< std::endl;
	;

	std::cout << "A" << std::endl;

	std::breakpoint_if_debugging();

	std::cout << "B" << std::endl;

	std::breakpoint();

	std::cout << "C" << std::endl;
}

compile:

gpp dbgprog.cpp -lstdc++exp -o dbgprog

( alias gpp=g++ -fmodules-ts -std=c++26 )
( At least g++ 16.0 required )

Run without a debugger

> ./dbgprog
false
A
B
Trace/breakpoint trap

Run in gdb

( Some trivial informations are removed. )

> gdb ./dbgprog
Reading symbols from ./dbgprog...

(gdb) r

true
A

Program received signal SIGTRAP, Trace/breakpoint trap.
0x000000000040257d in std::breakpoint ()
    at ........../gcc/libstdc++-v3/src/c++26/debugging.cc:142

(gdb) n
0x0000000000402471 in main ()
(gdb) n
Single stepping until exit from function main,
which has no line number information.
B

Program received signal SIGTRAP, Trace/breakpoint trap.
0x000000000040257d in std::breakpoint ()

(gdb) n
0x0000000000402492 in main ()
(gdb) n
Single stepping until exit from function main,
which has no line number information.
C

(gdb) n
[Inferior 1 (process 14244) exited normally]
(gdb) n
The program is not being run.
(gdb) q

//////////////////////////////////////////////////////////////////////

Home

//////////////////////////////////////////////////////////////////////

Sun Jan 18 10:06:22 AM UTC 2026

//////////////////////////////////////////////////////////////////////

Role

Powered by - B2 Build | boost quickbook | I2Pd

====

cppfx.i2p

cppfxjjm5bgqx2cepvisfcy4zz4ystzxxh36mtuvqm2jp5g6rb7a.b32.i2p


PrevUpHomeNext