diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-04-11 10:20:40 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-04-11 17:59:08 +0100 |
commit | bdb9639ee99b68a8c7541e78057e96fe6a2c62ed (patch) | |
tree | ac012f710ff6d4f7bc6dec67892fa61c0d9bfebc /libstdc++-v3/testsuite/19_diagnostics | |
parent | ab0f04e4df1b7b312a4c9fa9b4d675778a0bae86 (diff) | |
download | gcc-bdb9639ee99b68a8c7541e78057e96fe6a2c62ed.tar.gz |
libstdc++: Improve behaviour of std::stacktrace::current
This prevents inlining the current() function to guarantee that it is
present in the stacktrace, then tells libbacktrace to skip that frame.
To avoid overflow in the int argument to __glibcxx_backtrace_simple, we
need to check if the skip parameter exceeds INT_MAX (which is possible
for 16-bit targets where short and int have the same width). We also
need to limit the size of the returned value to the max_depth parameter,
which was missing previously.
This also fixes basic_stacktrace::max_size() to not exceed the maximum
size supported by the allocator, which might be smaller than the maximum
value of size_type.
libstdc++-v3/ChangeLog:
* include/std/stacktrace (basic_stacktrace::current): Duplicate
implementation into each overload. Add noinline attribute and
skip current frame.
(basic_stacktrace::max_size()): Call _Impl::_S_max_size.
(basic_stacktrace::_S_curr_cb()): New function defining lambda.
(basic_stacktrace::_Impl::_S_max_size): New function defining
maximum size in terms of allocator and size_type.
(basic_stacktrace::_Impl::_M_allocate): Check against
max_size().
* testsuite/19_diagnostics/stacktrace/entry.cc: Call function
for non-constexpr checks. Check line number is correct.
Diffstat (limited to 'libstdc++-v3/testsuite/19_diagnostics')
-rw-r--r-- | libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc index 0bbcabd8fae..a222c425b20 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc @@ -36,7 +36,8 @@ test_members() VERIFY( e1 != e2 ); VERIFY( e1.description() == e2.description() ); VERIFY( e1.source_file() == e2.source_file() ); - VERIFY( e1.source_line() != e2.source_line() ); + VERIFY( e1.source_line() == (__LINE__ - 5) ); + VERIFY( e2.source_line() == (__LINE__ - 5) ); std::stacktrace_entry e3 = []{ return std::stacktrace::current().at(0); @@ -44,10 +45,10 @@ test_members() VERIFY( e1 != e3 ); VERIFY( e1.description() != e3.description() ); VERIFY( e1.source_file() == e3.source_file() ); - VERIFY( e1.source_line() != e3.source_line() ); + VERIFY( e3.source_line() == (__LINE__ - 5) ); } int main() { - test_constexpr(); + test_members(); } |