[FR]: std::stacktrace support
- Dominant language
- C++
- Stars
- 39.6k
- Forks
- 10.9k
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
### Does the feature exist in the most recent commit?
no
### Why do we need this feature?
I want to get pretty stack traces in my tests without depending on Abseil.
In addition, Microsoft STL's implementation of std::stacktrace provides more information than Abseil, such as file and line numbers.
I think this feature would be generally useful, thus I think this feature should be built into googletest instead of users leveraging the (currently broken #1020) `OsStackTraceGetterInterface` extension point.
### Describe the proposal.
Approach A:
Change the existing `OsStackTraceGetter` class to use std::stacktrace if available, falling back to Absel or a no-op implementation if std::stacktrace unavailable.
Problem with approach A:
This would involve adding `#if`s in header files which might lead to ODR problems.
Approach B:
1. Split `OsStackTraceGetter` into two classes: `AbslStackTraceGetter` (which uses Abseil; conditionally defined) and `NoopStackTraceGetter` (always defined).
2. Add `StdStackTraceGetter` (which uses std::stacktrace; conditionally defined).
3. Make `UnitTestImpl::os_stack_trace_getter` choos `StdStackTraceGetter` if available, falling back to `AbslStackTraceGetter` or `NoopStackTraceGetter` if std::stacktrace is unavailable.
(This seems to be how `OsStackTraceGetterInterface` was meant to be used.)
### Is the feature specific to an operating system, compiler, or build system version?
Currently, std::stacktrace is available on recent MSVC versions for Windows. It might be available with effort on GCC/libstdc++. libc++ does not have an implementation.
Boost has a somewhat-portable implementation which looks similar to std::stacktrace. I don't propose using Boost's version.
Contributor guide
Assessment
This issue has not been assessed yet.