- Document number:
-
ISO/IEC/JTC1/SC22/WG21/P2515R0
- Date:
-
2021-12-29
- Audience:
-
SG15, LEWG
- Reply-to:
-
René Ferdinand Rivera Morell, grafikrobot@gmail.com
- Project:
-
ISO/IEC JTC1/SC22/WG21 14882: Programming Language — C++
1. Abstract
This paper proposes a new function, std::is_debugger_present
, that checks if
a program is being debugged to aid in software development.
3. Motivation
There are many scenarios where doing something special when your program is running in a debugger is important. That can take the form of:
-
allowing printing out extra output to help diagnose problems,
-
executing extra test code,
-
displaying an extra user interface to help in debugging,
-
and more.
This is something that appears in many development environments but is hard to do as it requires intimate platform knowledge. Making this facility available would improve the program debugging experience of the average user. And spare them the burden of acquiring arcane platform knowledge to implement, over and over, this functionality.
4. Design Decisions
The goal of the std::is_debugger_present
function is to inform when a program
is executing under the control of a debugger monitoring program. The interface
is minimally simple to avoid having to reduce the user from having to know the
intricacies of debugger operation. This is a feature that requires arcane
platform knowledge for most platforms. But it is knowledge that is readily
available to the platform tooling implementors.
The std::is_debugger_present
function is intended to go into a <debugging>
header.
5. Implementation Experience
In addition to the prototype implementation [1] there are the following, full or partial, equivalent implementations:
6. Wording
6.1. Library
Add a new entry to General utilities library summary [utilities.summary] table.
[debugging] |
Debugging |
|
Add section to General utilities library [utilities].
6.1.1. Debugging [debugging]
6.1.1.1. In general [debugging.general]
Subclause [debugging] describes the debugging library that provides functionality to introspect and interact with a debugger that is executing and monitoring the running program.
6.1.1.2. Header <debugging>
synopsis [debugging.syn]
namespace std {
// [debugging.utility], utility
bool is_debugger_present() noexcept;
}
6.1.1.3. Utility [debugging.utility]
bool is_debugger_present() noexcept;
Returns: If the program is currently running under a debugger it returns
true
, otherwise false
.
Remarks: If not supported by the implementation it returns false
.