diff options
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r-- | libstdc++-v3/src/c++20/Makefile.am | 2 | ||||
-rw-r--r-- | libstdc++-v3/src/c++20/Makefile.in | 4 | ||||
-rw-r--r-- | libstdc++-v3/src/c++20/clock.cc | 52 | ||||
-rw-r--r-- | libstdc++-v3/src/c++23/std.cc.in | 83 | ||||
-rw-r--r-- | libstdc++-v3/src/c++26/Makefile.am | 4 | ||||
-rw-r--r-- | libstdc++-v3/src/c++26/Makefile.in | 7 | ||||
-rw-r--r-- | libstdc++-v3/src/c++26/debugging.cc | 176 |
7 files changed, 314 insertions, 14 deletions
diff --git a/libstdc++-v3/src/c++20/Makefile.am b/libstdc++-v3/src/c++20/Makefile.am index 15e6f34..736558f 100644 --- a/libstdc++-v3/src/c++20/Makefile.am +++ b/libstdc++-v3/src/c++20/Makefile.am @@ -36,7 +36,7 @@ else inst_sources = endif -sources = tzdb.cc format.cc atomic.cc +sources = tzdb.cc format.cc atomic.cc clock.cc vpath % $(top_srcdir)/src/c++20 diff --git a/libstdc++-v3/src/c++20/Makefile.in b/libstdc++-v3/src/c++20/Makefile.in index d9e1615..3cb6d6f 100644 --- a/libstdc++-v3/src/c++20/Makefile.in +++ b/libstdc++-v3/src/c++20/Makefile.in @@ -121,7 +121,7 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libc__20convenience_la_LIBADD = -am__objects_1 = tzdb.lo format.lo atomic.lo +am__objects_1 = tzdb.lo format.lo atomic.lo clock.lo @ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_2 = sstream-inst.lo @GLIBCXX_HOSTED_TRUE@am_libc__20convenience_la_OBJECTS = \ @GLIBCXX_HOSTED_TRUE@ $(am__objects_1) $(am__objects_2) @@ -432,7 +432,7 @@ headers = @ENABLE_EXTERN_TEMPLATE_TRUE@inst_sources = \ @ENABLE_EXTERN_TEMPLATE_TRUE@ sstream-inst.cc -sources = tzdb.cc format.cc atomic.cc +sources = tzdb.cc format.cc atomic.cc clock.cc @GLIBCXX_HOSTED_FALSE@libc__20convenience_la_SOURCES = @GLIBCXX_HOSTED_TRUE@libc__20convenience_la_SOURCES = $(sources) $(inst_sources) diff --git a/libstdc++-v3/src/c++20/clock.cc b/libstdc++-v3/src/c++20/clock.cc new file mode 100644 index 0000000..9d674b0 --- /dev/null +++ b/libstdc++-v3/src/c++20/clock.cc @@ -0,0 +1,52 @@ +// std::chrono::tai_clock, gps_clock + +// Copyright (C) 2021-2025 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// +// ISO C++ 14882:2020 +// 27.7.4 [time.clock.tai], 27.7.5 [time.clock.gps] +// P0355R7 + +#include <chrono> + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +namespace chrono +{ +#if __cpp_lib_chrono >= 201803L && _GLIBCXX_HOSTED + // TODO use CLOCK_TAI on linux, add extension point. + time_point<tai_clock> + tai_clock::now() + { return from_utc(utc_clock::now()); } + + // TODO add extension point. + time_point<gps_clock> + gps_clock::now() + { return from_utc(utc_clock::now()); } +#endif +} + +_GLIBCXX_END_NAMESPACE_VERSION +} diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in index 9301ed9..4888b8b 100644 --- a/libstdc++-v3/src/c++23/std.cc.in +++ b/libstdc++-v3/src/c++23/std.cc.in @@ -277,15 +277,14 @@ export namespace std using std::ranges::shuffle; } using std::shift_left; - namespace ranges - { - using std::ranges::shift_left; - } using std::shift_right; +#if __cpp_lib_shift >= 202202L // >= C++23 namespace ranges { + using std::ranges::shift_left; using std::ranges::shift_right; } +#endif using std::sort; namespace ranges { @@ -500,7 +499,9 @@ export namespace std using ranges::fold_left; using ranges::fold_left_first; using ranges::fold_left_first_with_iter; + using ranges::fold_left_first_with_iter_result; using ranges::fold_left_with_iter; + using ranges::fold_left_with_iter_result; using ranges::fold_right; using ranges::fold_right_last; using ranges::in_value_result; @@ -672,6 +673,9 @@ export namespace std using std::popcount; using std::rotl; using std::rotr; +#if __cpp_lib_byteswap // >= C++23 + using std::byteswap; +#endif } // 22.9 <bitset> @@ -1747,6 +1751,9 @@ export namespace std using std::make_const_iterator; using std::make_const_sentinel; #endif +#if __glibcxx_algorithm_default_value_type // >= C++26 + using std::projected_value_t; +#endif } // <latch> @@ -1851,14 +1858,20 @@ export namespace std { using std::extents; using std::dextents; +#if __glibcxx_mdspan >= 202406L + using std::dims; +#endif using std::layout_left; using std::layout_right; using std::layout_stride; using std::default_accessor; +#if __glibcxx_aligned_accessor + using std::aligned_accessor; +#endif using std::mdspan; - // FIXME layout_left_padded, layout_right_padded, aligned_accessor, - // strided_slice, submdspan_mapping_result, full_extent_t, full_extent, - // submdspan_extents, mdsubspan + // FIXME layout_left_padded, layout_right_padded, strided_slice, + // submdspan_mapping_result, full_extent_t, full_extent, submdspan_extents, + // mdsubspan } #endif @@ -1871,6 +1884,9 @@ export namespace std using std::allocator_arg_t; using std::allocator_traits; using std::assume_aligned; +#if __glibcxx_is_sufficiently_aligned + using std::is_sufficiently_aligned; +#endif using std::make_obj_using_allocator; using std::pointer_traits; using std::to_address; @@ -1973,6 +1989,8 @@ export namespace std #if __cpp_lib_out_ptr using std::out_ptr; using std::inout_ptr; + using std::out_ptr_t; + using std::inout_ptr_t; #endif #if __cpp_lib_indirect using std::indirect; @@ -1982,6 +2000,10 @@ export namespace std using std::polymorphic; namespace pmr { using std::pmr::polymorphic; } #endif +#if __cpp_lib_smart_ptr_owner_equality + using std::owner_equal; + using std::owner_hash; +#endif } // 20.4 <memory_resource> @@ -2097,7 +2119,11 @@ export namespace std using std::lcm; using std::midpoint; #if __cpp_lib_ranges_iota - namespace ranges { using ranges::iota; } + namespace ranges + { + using ranges::iota; + using ranges::iota_result; + } #endif #if __cpp_lib_saturation_arithmetic using std::add_sat; @@ -2508,6 +2534,43 @@ export namespace std using std::regex_constants::operator|; using std::regex_constants::operator|=; using std::regex_constants::operator~; + using std::regex_constants::awk; + using std::regex_constants::basic; + using std::regex_constants::collate; + using std::regex_constants::ECMAScript; + using std::regex_constants::egrep; + using std::regex_constants::extended; + using std::regex_constants::grep; + using std::regex_constants::icase; + using std::regex_constants::multiline; + using std::regex_constants::nosubs; + using std::regex_constants::optimize; + using std::regex_constants::format_default; + using std::regex_constants::format_first_only; + using std::regex_constants::format_no_copy; + using std::regex_constants::format_sed; + using std::regex_constants::match_any; + using std::regex_constants::match_continuous; + using std::regex_constants::match_default; + using std::regex_constants::match_not_bol; + using std::regex_constants::match_not_bow; + using std::regex_constants::match_not_eol; + using std::regex_constants::match_not_eow; + using std::regex_constants::match_not_null; + using std::regex_constants::match_prev_avail; + using std::regex_constants::error_backref; + using std::regex_constants::error_badbrace; + using std::regex_constants::error_badrepeat; + using std::regex_constants::error_brace; + using std::regex_constants::error_brack; + using std::regex_constants::error_collate; + using std::regex_constants::error_complexity; + using std::regex_constants::error_ctype; + using std::regex_constants::error_escape; + using std::regex_constants::error_paren; + using std::regex_constants::error_range; + using std::regex_constants::error_space; + using std::regex_constants::error_stack; } using std::basic_regex; using std::csub_match; @@ -3149,6 +3212,10 @@ export namespace std using std::is_pointer_interconvertible_base_of_v; using std::is_pointer_interconvertible_with_class; #endif +#if __cpp_lib_is_scoped_enum + using std::is_scoped_enum; + using std::is_scoped_enum_v; +#endif } // <typeindex> diff --git a/libstdc++-v3/src/c++26/Makefile.am b/libstdc++-v3/src/c++26/Makefile.am index 5defa4a..4123b7d 100644 --- a/libstdc++-v3/src/c++26/Makefile.am +++ b/libstdc++-v3/src/c++26/Makefile.am @@ -35,7 +35,9 @@ else inst_sources = endif -sources = text_encoding.cc +sources = \ + debugging.cc \ + text_encoding.cc vpath % $(top_srcdir)/src/c++26 diff --git a/libstdc++-v3/src/c++26/Makefile.in b/libstdc++-v3/src/c++26/Makefile.in index 77e73b2..1c317d6 100644 --- a/libstdc++-v3/src/c++26/Makefile.in +++ b/libstdc++-v3/src/c++26/Makefile.in @@ -121,7 +121,7 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libc__26convenience_la_LIBADD = -am__objects_1 = text_encoding.lo +am__objects_1 = debugging.lo text_encoding.lo am__objects_2 = @GLIBCXX_HOSTED_TRUE@am_libc__26convenience_la_OBJECTS = \ @GLIBCXX_HOSTED_TRUE@ $(am__objects_1) $(am__objects_2) @@ -430,7 +430,10 @@ headers = # XTEMPLATE_FLAGS = -fno-implicit-templates @ENABLE_EXTERN_TEMPLATE_TRUE@inst_sources = -sources = text_encoding.cc +sources = \ + debugging.cc \ + text_encoding.cc + @GLIBCXX_HOSTED_FALSE@libc__26convenience_la_SOURCES = @GLIBCXX_HOSTED_TRUE@libc__26convenience_la_SOURCES = $(sources) $(inst_sources) diff --git a/libstdc++-v3/src/c++26/debugging.cc b/libstdc++-v3/src/c++26/debugging.cc new file mode 100644 index 0000000..c6262db --- /dev/null +++ b/libstdc++-v3/src/c++26/debugging.cc @@ -0,0 +1,176 @@ +// Implementation of <debugging> -*- C++ -*- + +// Copyright The GNU Toolchain Authors. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +#include <debugging> + +#if __cpp_lib_debugging + +#include <csignal> // std::raise + +#if _GLIBCXX_USE_PROC_SELF_STATUS +# include <fstream> +# include <string> +#endif + +#if _GLIBCXX_HAVE_SYS_PTRACE_H +# include <sys/types.h> // for darwin ptrace +# include <sys/ptrace.h> +# include <errno.h> +#endif + +#if _GLIBCXX_HAVE_DEBUGAPI_H +# include <debugapi.h> +#endif + +#ifdef _GLIBCXX_HAVE_SYS_SDT_H +# include <sys/sdt.h> +/* We only want to use stap probes starting with v3. Earlier versions + added too much startup cost. */ +# if defined (STAP_PROBE) && _SDT_NOTE_TYPE >= 3 +# define PROBE(name) STAP_PROBE(libstdcxx, name) +# endif +#endif + +#ifndef PROBE +# define PROBE(name) +#endif + +namespace __gnu_cxx +{ + // This should be changed to non-zero by debuggers when they attach + // and back to zero when they detach. + // If the value is positive, std::breakpoint() will use it as the argument + // to std::raise, so it should be a valid signal number, e.g. SIGABRT or + // SIGTRAP. + // If the value is negative, std::breakpoint() will use a target-specific + // trap, e.g. asm("int3") or __builtin_trap(). + volatile int debugger_signal_for_breakpoint = 0; +} + +_GLIBCXX_WEAK_DEFINITION +bool +std::is_debugger_present() noexcept +{ + PROBE(std::is_debugger_present); + + if (__gnu_cxx::debugger_signal_for_breakpoint != 0) + return true; + +#if _GLIBCXX_HOSTED +# if _GLIBCXX_USE_PROC_SELF_STATUS + const string_view prefix = "TracerPid:\t"; // populated since Linux 2.6.0 + ifstream in("/proc/self/status"); + string line; + while (std::getline(in, line)) + { + if (!line.starts_with(prefix)) + continue; + + string_view tracer = line; + tracer.remove_prefix(prefix.size()); + if (tracer.size() == 1 && tracer[0] == '0') [[likely]] + return false; // Not being traced. + + in.close(); + string_view cmd; + string proc_dir = "/proc/" + string(tracer) + '/'; + in.open(proc_dir + "comm"); // since Linux 2.6.33 + if (std::getline(in, line)) [[likely]] + cmd = line; + else + { + in.close(); + in.open(proc_dir + "cmdline"); + if (std::getline(in, line)) + cmd = line.c_str(); // Only up to first '\0' + else + return false; + } + + for (auto i : {"gdb", "gdbserver", "lldb-server"}) // known debuggers + if (cmd.ends_with(i)) + return true; + + // We found the TracerPid line, no need to do any more work. + return false; + } +# elif _GLIBCXX_USE_PTRACE + if (::ptrace(PTRACE_TRACEME, 0, 1, 0) == -1) + return errno == EPERM; +# endif +# if _GLIBCXX_HAVE_DEBUGAPI_H && defined(_WIN32) && !defined(__CYGWIN__) + return IsDebuggerPresent(); +# endif +#endif // HOSTED + return false; +} + +void +std::breakpoint() noexcept +{ + PROBE(std::breakpoint); + + if (__gnu_cxx::debugger_signal_for_breakpoint > 0) + std::raise(__gnu_cxx::debugger_signal_for_breakpoint); + +#if _GLIBCXX_HAVE_DEBUGAPI_H && defined(_WIN32) && !defined(__CYGWIN__) + DebugBreak(); +#elif __has_builtin(__builtin_debugtrap) + __builtin_debugtrap(); // Clang +#elif defined(__i386__) || defined(__x86_64__) + // nop is for GDB, see https://sourceware.org/bugzilla/show_bug.cgi?id=31194 + __asm__ volatile ("int $0x3\n\tnop"); +#elifdef __thumb__ + __asm__ volatile (".inst 0xde01"); +#elifdef __aarch64__ + __asm__ volatile (".inst 0xd4200000"); +#elifdef __arm__ + __asm__ volatile (".inst 0xe7f001f0"); +#elifdef __riscv + /* section 2.8 in the RISC-V unprivileged ISA manual says for semi-hosted + * environments we want the sequence: + * slli x0, x0, 0x1f # Entry NOP + * ebreak # Break to debugger + * srai x0, x0, 7 # NOP encoding the semihosting call number 7 + */ + __asm__ volatile (".4byte 0x00100073"); +#elif defined __powerpc__ && ! defined _AIX + __asm__ volatile(".4byte 0x7d821008"); +#else + __builtin_trap(); +#endif +} // If the debugger stops here, std::breakpoint() was called. + +// This is intentionally not defined inline. A non-inline definition allows +// debuggers to insert a breakpoint on calls to the function, avoiding the +// overhead of calling `is_debugger_present()`. +void +std::breakpoint_if_debugging() noexcept +{ + PROBE(std::breakpoint_if_debugging); + + if (std::is_debugger_present()) [[unlikely]] + std::breakpoint(); +} + +#endif // __cpp_lib_debugging |