1 // Debugging support -*- C++ -*-
3 // Copyright The GNU Toolchain Authors.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // Under Section 7 of GPL version 3, you are granted additional
16 // permissions described in the GCC Runtime Library Exception, version
17 // 3.1, as published by the Free Software Foundation.
19 // You should have received a copy of the GNU General Public License and
20 // a copy of the GCC Runtime Library Exception along with this program;
21 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 // <http://www.gnu.org/licenses/>.
24 /** @file include/debugging
25 * This is a Standard C++ Library header.
28 #ifndef _GLIBCXX_DEBUGGING
29 #define _GLIBCXX_DEBUGGING 1
31 #define __glibcxx_want_debugging
32 #include <bits/version.h>
34 #if __cpp_lib_debugging // C++ >= 26
35 namespace std _GLIBCXX_VISIBILITY(default)
37 // N.B. _GLIBCXX_BEGIN_NAMESPACE_VERSION is not used here.
39 /** Try to determine if the program is running under control of a debugger.
41 * On GNU/Linux systems this function will only return true if the program
42 * is being traced by another program which is known to be a debugger.
43 * This is determined by checking the command name of the tracing program
44 * against a list of known debuggers, such as "gdb".
46 * On other POSIX-based systems, this function will return true if the
47 * program is being traced by any other process, which means it can return
48 * true for non-debugger utilities that use the ptrace system call.
53 is_debugger_present() noexcept;
55 /** Stop the program with a breakpoint or debug trap.
57 * The details of how a breakpoint is implemented are platform-specific.
58 * Some systems provide a special instruction, such as `int3` in x86.
59 * When no more appropriate mechanism is available, this will stop the
60 * program using `__builtin_trap()`. It might not be possible for the
61 * program to continue after such a breakpoint.
66 breakpoint() noexcept;
68 /** Stop the program if it is running under control of a debugger.
73 breakpoint_if_debugging() noexcept;
77 #endif // _GLIBCXX_DEBUGGING