-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add C++23 stacktrace (P0881R7) #136528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
elsteveogrande
wants to merge
46
commits into
llvm:main
Choose a base branch
from
elsteveogrande:stacktrace23
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add C++23 stacktrace (P0881R7) #136528
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
b287a16
Add C++23 stacktrace
elsteveogrande 52da939
Remove unrelated change
elsteveogrande c92d736
fix cflag option
elsteveogrande ffe3cdb
Move stacktrace headers out of experimental
elsteveogrande a440a46
Move stacktrace srcs out of experimental
elsteveogrande dab7e01
simplify layout of stacktrace files: condense, collapse
elsteveogrande 0f93c02
Reference papers and issues
elsteveogrande 15992ea
Updates per PR feedback
elsteveogrande 39162cf
Remove newline at end of file: std.compat.cppm.in
elsteveogrande f9c412d
Committing regenerated files
1a35918
Address lints for system headers
elsteveogrande 02d2480
Add generated 'stacktrace.version.compile.pass.cpp' test
elsteveogrande aab978a
Address some errors from gcc regarding inlining
elsteveogrande 658060f
Feature macros + regenerate
elsteveogrande b2b15f8
Break up tests
elsteveogrande 2a11c50
Minor: formatting
elsteveogrande 4ddfbae
Remove changes not related to this (probably a previous bad merge)
elsteveogrande 6c98f6b
Correcting doc for LIBCXX_STACKTRACE_ALLOW_TOOLS_AT_RUNTIME
elsteveogrande 01faf65
Add C++23 stacktrace
elsteveogrande f6ee162
Remove unrelated change
elsteveogrande 4b45777
Move stacktrace headers out of experimental
elsteveogrande 8fef91f
Move stacktrace srcs out of experimental
elsteveogrande 65389c1
simplify layout of stacktrace files: condense, collapse
elsteveogrande 2f12acb
Updates per PR feedback
elsteveogrande c26efd9
Remove newline at end of file: std.compat.cppm.in
elsteveogrande 63bfca9
Committing regenerated files
7fb17ca
Address some errors from gcc regarding inlining
elsteveogrande 4560726
Feature macros + regenerate
elsteveogrande 4950562
Break up tests
elsteveogrande f486936
Remove changes not related to this (probably a previous bad merge)
elsteveogrande 11b74de
Mention URL 'format' task (105257) for TODO's
elsteveogrande b651a47
commit new generated files
elsteveogrande 6680809
formatting
elsteveogrande 85e36c4
refactor; rework alloc/dealloc, strings; don't use pmr
elsteveogrande 94b7e2f
regenerated files
elsteveogrande eae8d87
formatting
elsteveogrande e332628
formatting
elsteveogrande f3aab1b
clean up non-ASCII chars from pasted content
elsteveogrande e130395
minor: rename a .cpp
elsteveogrande 27cf220
split up confusing 'utils.h'
elsteveogrande c179647
fix windows macros
elsteveogrande ac43b8c
break up win impl
elsteveogrande c7ca34f
break up other impl's
elsteveogrande 786afd1
cleanup impl's
elsteveogrande b1f6f70
remove placeholder header for formatter
elsteveogrande b36616a
end-of-file newline?
elsteveogrande File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// -*- C++ -*- | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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_BUILDER | ||
#define _LIBCPP_STACKTRACE_BUILDER | ||
|
||
#include <__config> | ||
#include <__cstddef/byte.h> | ||
#include <__cstddef/size_t.h> | ||
#include <__functional/function.h> | ||
#include <__fwd/format.h> | ||
#include <__fwd/ostream.h> | ||
#include <__memory/allocator_traits.h> | ||
#include <__vector/vector.h> | ||
#include <cstddef> | ||
#include <cstdint> | ||
#include <list> | ||
#include <optional> | ||
#include <string> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_PUSH_MACROS | ||
#include <__undef_macros> | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
class stacktrace_entry; | ||
|
||
namespace __stacktrace { | ||
|
||
struct _LIBCPP_HIDE_FROM_ABI alloc final { | ||
function<byte*(size_t)> __alloc_bytes_; | ||
function<void(byte*, size_t)> __dealloc_bytes_; | ||
|
||
template <class _Allocator> | ||
alloc(_Allocator __alloc) { | ||
using _AT = allocator_traits<_Allocator>; | ||
using _BA = typename _AT::template rebind_alloc<byte>; | ||
auto __ba = _BA(__alloc); | ||
__alloc_bytes_ = [__ba](size_t __sz) mutable { return __ba.allocate(__sz); }; | ||
__dealloc_bytes_ = [__ba](void* __ptr, size_t __sz) mutable { __ba.deallocate((byte*)__ptr, __sz); }; | ||
} | ||
|
||
template <typename _Tp> | ||
struct Alloc { | ||
function<byte*(size_t)> __alloc_bytes_; | ||
function<void(byte*, size_t)> __dealloc_bytes_; | ||
|
||
Alloc(function<byte*(size_t)> __alloc_bytes, function<void(byte*, size_t)> __dealloc_bytes) | ||
: __alloc_bytes_(__alloc_bytes), __dealloc_bytes_(__dealloc_bytes) {} | ||
|
||
template <typename _T2 = _Tp> | ||
Alloc(Alloc<_T2> const& __rhs) : Alloc(__rhs.__alloc_bytes_, __rhs.__dealloc_bytes_) {} | ||
|
||
using value_type = _Tp; | ||
[[nodiscard]] _Tp* allocate(size_t __sz) { return (_Tp*)__alloc_bytes_(__sz * sizeof(_Tp)); } | ||
void deallocate(_Tp* __ptr, size_t __sz) { __dealloc_bytes_((byte*)__ptr, __sz * sizeof(_Tp)); } | ||
|
||
template <typename _A2> | ||
bool operator==(_A2 const& __rhs) const { | ||
return &__rhs == this; | ||
} | ||
}; | ||
|
||
template <typename _Tp> | ||
Alloc<_Tp> make_alloc() { | ||
return {__alloc_bytes_, __dealloc_bytes_}; | ||
} | ||
|
||
using str = basic_string<char, char_traits<char>, Alloc<char>>; | ||
|
||
template <typename... _Args> | ||
str make_str(_Args... __args) { | ||
return str(std::forward<_Args>(__args)..., make_alloc<char>()); | ||
} | ||
|
||
template <typename _Tp> | ||
using vec = vector<_Tp, Alloc<_Tp>>; | ||
|
||
template <typename _Tp, typename... _Args> | ||
vec<_Tp> make_vec(_Args... __args) { | ||
return vec(std::forward<_Args>(__args)..., make_alloc<_Tp>()); | ||
} | ||
|
||
template <typename _Tp> | ||
using list = ::std::list<_Tp, Alloc<_Tp>>; | ||
|
||
template <typename _Tp, typename... _Args> | ||
list<_Tp> make_list(_Args... __args) { | ||
return list(std::forward<_Args>(__args)..., make_alloc<_Tp>()); | ||
} | ||
}; | ||
|
||
struct _LIBCPP_HIDE_FROM_ABI entry_base { | ||
uintptr_t __addr_actual_{}; // this address, as observed in this current process | ||
uintptr_t __addr_unslid_{}; // address adjusted for ASLR | ||
optional<__stacktrace::alloc::str> __desc_{}; // uses wrapped _Allocator from caller | ||
optional<__stacktrace::alloc::str> __file_{}; // uses wrapped _Allocator from caller | ||
uint_least32_t __line_{}; | ||
|
||
stacktrace_entry to_stacktrace_entry() const; | ||
}; | ||
|
||
struct _LIBCPP_HIDE_FROM_ABI builder final { | ||
alloc __alloc_; // wraps the caller-provided allocator | ||
alloc::vec<entry_base> __entries_; | ||
alloc::str __main_prog_path_; | ||
|
||
template <class _Allocator> | ||
explicit builder(_Allocator __alloc) | ||
: __alloc_(__alloc), __entries_(__alloc_.make_vec<entry_base>()), __main_prog_path_(__alloc_.make_str()) {} | ||
|
||
_LIBCPP_NO_TAIL_CALLS _LIBCPP_NOINLINE _LIBCPP_EXPORTED_FROM_ABI void | ||
build_stacktrace(size_t __skip, size_t __max_depth); | ||
}; | ||
|
||
} // namespace __stacktrace | ||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
_LIBCPP_POP_MACROS | ||
|
||
#endif // _LIBCPP_STACKTRACE_BUILDER |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only had a quick look but I think the status should be
|Complete|
and you also need to addCloses #104998
.#104998
We don't add an entry to Release Notes for LWG issues.