[libcxx-commits] [libcxx] Add C++23 stacktrace (P0881R7) (PR #136528)

Steve O'Brien via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 1 13:17:59 PDT 2025


================
@@ -0,0 +1,84 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include <__config>
+#include <__stacktrace/basic_stacktrace.h>
+#include <__stacktrace/stacktrace_entry.h>
+#include <string>
+
+#if _LIBCPP_HAS_LOCALIZATION
+#  include <iomanip>
+#  include <iostream>
+#  include <sstream>
+#endif //_LIBCPP_HAS_LOCALIZATION
+
+#include "stacktrace/images.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace __stacktrace {
+
+#if _LIBCPP_HAS_LOCALIZATION
+
+_LIBCPP_EXPORTED_FROM_ABI ostream& entry_base::write_to(ostream& __os) const {
+  // Although 64-bit addresses are 16 nibbles long, they're often <= 0x7fff_ffff_ffff
+  constexpr static int __k_addr_width = (sizeof(void*) > 4) ? 12 : 8;
+
+  __os << "0x" << std::hex << std::setfill('0') << std::setw(__k_addr_width) << __addr_;
----------------
elsteveogrande wrote:

Ah!  Good call, will avoid this.

I was thinking, maybe I could implement a `formatter` for these -- although perhaps in this PR, not including the [formatting options as prescribed here](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2693r1.pdf) , and have `operator<<` go through that instead?

https://github.com/llvm/llvm-project/pull/136528


More information about the libcxx-commits mailing list