-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
51
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
51 commits
Select commit
Hold shift + click to select a range
d313e19
Add C++23 stacktrace
elsteveogrande 13b6b4f
Remove unrelated change
elsteveogrande 2d69584
fix cflag option
elsteveogrande ed263ce
Move stacktrace headers out of experimental
elsteveogrande 213017e
Move stacktrace srcs out of experimental
elsteveogrande 99e6db1
simplify layout of stacktrace files: condense, collapse
elsteveogrande 67567cf
Reference papers and issues
elsteveogrande d7f2629
Updates per PR feedback
elsteveogrande 008ea69
Remove newline at end of file: std.compat.cppm.in
elsteveogrande 4c7c9f4
Committing regenerated files
17699d9
Address lints for system headers
elsteveogrande b12cd7f
Add generated 'stacktrace.version.compile.pass.cpp' test
elsteveogrande f203dc9
Address some errors from gcc regarding inlining
elsteveogrande 8fac222
Feature macros + regenerate
elsteveogrande 41ac845
Break up tests
elsteveogrande b89fa7a
Minor: formatting
elsteveogrande 83ee2e3
Remove changes not related to this (probably a previous bad merge)
elsteveogrande 2d20c4b
Correcting doc for LIBCXX_STACKTRACE_ALLOW_TOOLS_AT_RUNTIME
elsteveogrande b4d97e5
Add C++23 stacktrace
elsteveogrande 823f0ba
Remove unrelated change
elsteveogrande 2fd143b
Move stacktrace headers out of experimental
elsteveogrande f511de2
Move stacktrace srcs out of experimental
elsteveogrande d9c7698
simplify layout of stacktrace files: condense, collapse
elsteveogrande 140d36a
Updates per PR feedback
elsteveogrande 2428ac5
Remove newline at end of file: std.compat.cppm.in
elsteveogrande 2e6632c
Committing regenerated files
e0d2b60
Address some errors from gcc regarding inlining
elsteveogrande 7724b01
Feature macros + regenerate
elsteveogrande f65f5a8
Break up tests
elsteveogrande ce9bc35
Remove changes not related to this (probably a previous bad merge)
elsteveogrande 0d8ebc6
Mention URL 'format' task (105257) for TODO's
elsteveogrande bff8a08
commit new generated files
elsteveogrande 587951b
formatting
elsteveogrande 9c5986c
refactor; rework alloc/dealloc, strings; don't use pmr
elsteveogrande 5b5c49e
regenerated files
elsteveogrande 408e900
formatting
elsteveogrande fdc6b09
formatting
elsteveogrande 71c4fbc
clean up non-ASCII chars from pasted content
elsteveogrande c6b4f19
minor: rename a .cpp
elsteveogrande 3ea41c6
split up confusing 'utils.h'
elsteveogrande 2df8911
fix windows macros
elsteveogrande ed89357
break up win impl
elsteveogrande d5b7e0f
break up other impl's
elsteveogrande 3f8c40c
cleanup impl's
elsteveogrande 8499f93
remove placeholder header for formatter
elsteveogrande 35bc431
end-of-file newline?
elsteveogrande 524373c
rebase, and push small whitespace-only change on generated file
elsteveogrande 42cb643
update build_stacktrace
elsteveogrande 06fe49f
fix build, needed an instantiation of allocator
elsteveogrande d9040e9
formatting
elsteveogrande 24dcdfc
formatting
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.