[libcxx-commits] [libcxx] Add C++23 stacktrace (P0881R7) (PR #136528)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Sep 1 01:29:57 PDT 2025
================
@@ -0,0 +1,108 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __LIBCPP_STACKTRACE_UNWIND_ADDRS_H
+#define __LIBCPP_STACKTRACE_UNWIND_ADDRS_H
+
+#include <__stacktrace/basic_stacktrace.h>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+namespace __stacktrace {
+void unwind_addrs(std::__stacktrace::base& base, size_t skip, size_t depth);
+} // namespace __stacktrace
+_LIBCPP_END_NAMESPACE_STD
+
+#ifndef _WIN32
+
+# if __has_include(<libunwind.h>)
+# include <libunwind.h>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+namespace __stacktrace {
+
+_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE inline void unwind_addrs(base& base, size_t skip, size_t depth) {
+ if (!depth) {
+ return;
+ }
+ unw_context_t cx;
+ unw_getcontext(&cx);
+ unw_cursor_t cur;
+ unw_init_local(&cur, &cx);
+ while (unw_step(&cur) > 0) {
+ if (skip && skip--) {
+ continue;
+ }
+ if (!depth--) {
+ break;
+ }
+ auto& entry = base.__entry_append_();
+ auto& eb = (__stacktrace::entry_base&)entry;
----------------
philnik777 wrote:
Please avoid the C-style casts all over the place.
https://github.com/llvm/llvm-project/pull/136528
More information about the libcxx-commits
mailing list