Document number:







ISO/IEC JTC1/SC22/WG21 14882: Programming Language — C++


René Ferdinand Rivera Morell - grafikrobot at gmail dot com
Ben Craig - ben dot craig at gmail dot com

1. Abstract

This proposes to add std::is_debugger_present, proposed in P2546 [1], to the set of replacement functions to allow users the flexibility to control the result of the function when otherwise it would not be possible to determine the platform specific result.

2. Revision History

2.1. Revision 0 (February 2023)


3. Motivation

The debugging support proposed in P2546 [1] defines its functions as available in both hosted and freestanding realms. In it the std::is_debugger_present function poses some challenges for embedded platforms where determining the circumstances of debuggers in a freestanding environment is most times impossible. Hence it is reasonable to allow the user to control what the function returns by some means. While some options are possible, like environment variables, platform configuration files, alternate runtime implementations, they are not ideal. As even those options may not be implementable for the platform. It is also ideal to not remove the function from freestanding as that will complicate the use of the functions with macro checks and alternative implementations. Placing the C++ ecosystem in yet more reliance on the preprocessor.

The option we propose is to allow users to replace the function in their programs, i.e. a replaceable function. This has the benefits of giving users the ability to overcome any deficiencies in the default platform implementation and to have fine control over the result even on hosted platforms. Possible user implementations could:

  • Wire it to return true in special verifying builds of their application.

  • Wire it to return true from external input like: a key press or other external mechanical signal, a software signal as might be caught by a process signal handler, and so on.

4. Impact on the Standard

This proposal marks the one function as an allowed replacement function.

5. Wording

Wording is relative to P2546R3. [1]

5.1. Library

Insert the following paragraph between [replacement.functions] par. 2 and par. 3.

A C++ program may provide the definition of the following function signature declared in header <debugging> ([debugging.syn]):

bool std::is_debugger_present() noexcept

Add the following clause after the "Returns" clause of is_debugger_present in [debugging.utility]:

Replaceable: A C++ program may define a function with the function signature, and thereby displace the default version defined by the C++ standard library.

6. Acknowledgements

Thank you Ben Craig for the idea of using a replaceable function.

1. P2546R3 Debugging Support, René Ferdinand Rivera Morell 2022-11-15 (