Skip to content

Commit 2f19f45

Browse files
Add C++23 stacktrace
1 parent c2d6c7c commit 2f19f45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+5348
-4
lines changed

libcxx/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
131131
the shared library they shipped should turn this on and see `include/__configuration/availability.h`
132132
for more details." OFF)
133133

134+
option(LIBCPP_STACKTRACE_ALLOW_TOOLS_AT_RUNTIME
135+
"For C++23 <stacktrace>: whether to allow invocation of `addr2line`, `llvm-addr2line` or `atos`
136+
at runtime (if it's available in PATH) to resolve call-chain addresses in the stacktrace
137+
into source locations, if other methods are not available." ON)
138+
134139
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
135140
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
136141
elseif(MINGW)
@@ -757,6 +762,7 @@ config_define(${LIBCXX_ENABLE_UNICODE} _LIBCPP_HAS_UNICODE)
757762
config_define(${LIBCXX_ENABLE_WIDE_CHARACTERS} _LIBCPP_HAS_WIDE_CHARACTERS)
758763
config_define(${LIBCXX_ENABLE_TIME_ZONE_DATABASE} _LIBCPP_HAS_TIME_ZONE_DATABASE)
759764
config_define(${LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS} _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS)
765+
config_define(${LIBCPP_STACKTRACE_ALLOW_TOOLS_AT_RUNTIME} _LIBCPP_STACKTRACE_ALLOW_TOOLS_AT_RUNTIME)
760766

761767
# TODO: Remove in LLVM 21. We're leaving an error to make this fail explicitly.
762768
if (LIBCXX_ENABLE_ASSERTIONS)

libcxx/docs/UserDocumentation.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ when ``-fexperimental-library`` is passed:
7070

7171
* The parallel algorithms library (``<execution>`` and the associated algorithms)
7272
* ``std::chrono::tzdb`` and related time zone functionality
73+
* ``<stacktrace>``
7374
* ``<syncstream>``
7475

7576
.. note::

libcxx/docs/VendorDocumentation.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ General purpose options
185185
ship the IANA time zone database. When time zones are not supported,
186186
time zone support in <chrono> will be disabled.
187187

188+
.. option:: LIBCPP_STACKTRACE_ALLOW_TOOLS_AT_RUNTIME:BOOL
189+
190+
**Default**: ``OFF``
191+
192+
For C++23 <stacktrace>: whether to allow invocation of ``addr2line`` or ``llvm-addr2line``
193+
at runtime (if it's available in PATH) to resolve call-chain addresses in the stacktrace
194+
into source locations, if other methods are not available.
195+
188196
.. option:: LIBCXX_INSTALL_LIBRARY_DIR:PATH
189197

190198
**Default**: ``lib${LIBCXX_LIBDIR_SUFFIX}``

libcxx/include/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,10 +991,17 @@ set(files
991991
experimental/__simd/traits.h
992992
experimental/__simd/utility.h
993993
experimental/__simd/vec_ext.h
994+
experimental/__stacktrace/basic_stacktrace.h
995+
experimental/__stacktrace/detail/alloc.h
996+
experimental/__stacktrace/detail/context.h
997+
experimental/__stacktrace/detail/entry.h
998+
experimental/__stacktrace/detail/to_string.h
999+
experimental/__stacktrace/stacktrace_entry.h
9941000
experimental/iterator
9951001
experimental/memory
9961002
experimental/propagate_const
9971003
experimental/simd
1004+
experimental/stacktrace
9981005
experimental/type_traits
9991006
experimental/utility
10001007
ext/__hash

libcxx/include/__config

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,33 @@ typedef __char32_t char32_t;
977977
# define _LIBCPP_NOINLINE
978978
# endif
979979

980+
// Some functions, e.g. std::stacktrace::current, need to avoid being
981+
// tail-called by (and tail-calling other) functions, for proper enumeration of
982+
// call-stack frames.
983+
// clang-format off
984+
985+
// Disables tail-call optimization for "outbound" calls
986+
// performed in the function annotated with this attribute.
987+
# if __has_cpp_attribute(_Clang::__disable_tail_calls__)
988+
# define _LIBCPP_NO_TAIL_CALLS_OUT [[_Clang::__disable_tail_calls__]]
989+
# elif __has_cpp_attribute(__gnu__::__optimize__)
990+
# define _LIBCPP_NO_TAIL_CALLS_OUT [[__gnu__::__optimize__("no-optimize-sibling-calls")]]
991+
# else
992+
# define _LIBCPP_NO_TAIL_CALLS_OUT
993+
# endif
994+
995+
// Disables tail-call optimization for "inbound" calls -- that is,
996+
// calls from some other function calling the one having this attribute.
997+
# if __has_cpp_attribute(_Clang::__not_tail_called__)
998+
# define _LIBCPP_NO_TAIL_CALLS_IN [[_Clang::__not_tail_called__]]
999+
# else
1000+
# define _LIBCPP_NO_TAIL_CALLS_IN
1001+
# endif
1002+
1003+
// Disable TCO for calls into, and out from, the annotated function.
1004+
# define _LIBCPP_NO_TAIL_CALLS _LIBCPP_NO_TAIL_CALLS_IN _LIBCPP_NO_TAIL_CALLS_OUT
1005+
// clang-format on
1006+
9801007
// We often repeat things just for handling wide characters in the library.
9811008
// When wide characters are disabled, it can be useful to have a quick way of
9821009
// disabling it without having to resort to #if-#endif, which has a larger

libcxx/include/__config_site.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#cmakedefine _LIBCPP_HAS_NO_STD_MODULES
3434
#cmakedefine01 _LIBCPP_HAS_TIME_ZONE_DATABASE
3535
#cmakedefine01 _LIBCPP_INSTRUMENTED_WITH_ASAN
36+
#cmakedefine01 _LIBCPP_STACKTRACE_ALLOW_TOOLS_AT_RUNTIME
3637

3738
// PSTL backends
3839
#cmakedefine _LIBCPP_PSTL_BACKEND_SERIAL

libcxx/include/__ostream/basic_ostream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ _LIBCPP_HIDE_FROM_ABI _Stream&& operator<<(_Stream&& __os, const _Tp& __x) {
570570
}
571571

572572
template <class _CharT, class _Traits, class _Allocator>
573-
basic_ostream<_CharT, _Traits>&
573+
_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
574574
operator<<(basic_ostream<_CharT, _Traits>& __os, const basic_string<_CharT, _Traits, _Allocator>& __str) {
575575
return std::__put_character_sequence(__os, __str.data(), __str.size());
576576
}

0 commit comments

Comments
 (0)