If std::stacktrace is available (currently only GCC (opt-in feature) and
MSVC), use it for printing stack traces.
If both Abseil and std::stacktrace are available, prefer
std::stacktrace.
Advantages of std::stacktrace over Abseil:
* Includes file and line information
* Includes DLL information
* Better stack trace quality on Windows
Disadvantages of std::stacktrace compared to Abseil:
* Runs more slowly on Windows
* Includes information which might not be relevant such as byte offsets
* Printed lines are longer thus harder to skim
Before (Windows using Abseil):
[ RUN ] FooTest.Xyz
[snip]\googletest-filter-unittest_.cc(49): error: Failed
Expected failure.
Stack trace:
00007FF69EF90E8D: testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test,void>
00007FF69EF90AC3: testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,void>
00007FF69EF5C01B: testing::Test::Run
00007FF69EF5CCC5: testing::TestInfo::Run
00007FF69EF5D6EC: testing::TestSuite::Run
... Google Test internal frames ...
[ FAILED ] FooTest.Xyz (21 ms)
After (Windows using MSVC STL's std::stacktrace):
[ RUN ] FooTest.Xyz
[snip]\googletest-filter-unittest_.cc(49): error: Failed
Expected failure.
Stack trace:
00007FF6770283A9: googletest_filter_unittest_!`anonymous namespace'::FooTest_Xyz_Test::TestBody+0x89 [snip]\googletest-filter-unittest_.cc:49
00007FF677080E8D: googletest_filter_unittest_!testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test,void>+0x1D [snip]\gtest.cc:2609
00007FF677080AC3: googletest_filter_unittest_!testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,void>+0x73 [snip]\gtest.cc:2652
00007FF67704C01B: googletest_filter_unittest_!testing::Test::Run+0xAB [snip]\gtest.cc:2698
... Google Test internal frames ...
[ FAILED ] FooTest.Xyz (127 ms)
The OsStackTraceGetter class does different things depending on whether
GTEST_HAS_ABSL is set. I want to add another implementation of
OsStackTraceGetter, and I think it's ugly if my new implementation
litters OsStackTraceGetter with more #if-s.
Split OsStackTraceGetter into two different classes:
* AbslStackTraceGetter, which is only defined if GTEST_HAS_ABSL is set.
This class behaves the same as OsStackTraceGetter currently behaves.
* NoopStackTraceGetter, which is always defined. This class behaves the
same as OsStackTraceGetter currently behaves if GTEST_HAS_ABSL is not
set.
After this refactor, it is easier to add new OsStackTraceGetter
backend classes.
This commit removes `<iomanip>` from public GoogleTest header files.
As `<iomanip>` is not a common included file, its content is unlikely
to be included in translation units other than through GoogleTest
includes.
By reducing the number of include directives public headers in
GoogleTest, this may reduce the time taken to compile tests as it would
reduce the amount of work that the preprocessor and compiler front-end
need to do.
This allows types that provide an AbslStringify definition to be streamed into GoogleTest macros.
PiperOrigin-RevId: 552914482
Change-Id: I5fb386980d4d24873f95f0a8ef83067a6a3c86ac
This was shown to work for C++14, C++17, and C++20 after patched into googletest for the protobuf repo's CI.
Closes#3659
PiperOrigin-RevId: 544795507
Change-Id: I3e0a94f675e78a6ee9aeccae86c23d940efed8eb
This ensure the erroring stack frame is visible and accessible when the handler is invoked.
Fixes#4298
PiperOrigin-RevId: 544692549
Change-Id: Ia165a8c293e8edc820da5f5ad4416546fffe2493
Also tidies up a couple of things:
- Prevent handling of stack overflows, which cannot be done safely
- `exception_code` is a macro, so we rename it
- The `std::string` heap allocation was unnecessary
Fixes#4298
PiperOrigin-RevId: 544117790
Change-Id: I8ba61f87119d5fbdb1f653700d9867ca6f8c28ce
From the CMake 3.27 release notes:
Compatibility with versions of CMake older than 3.5 is now
deprecated and will be removed from a future version. Calls to
cmake_minimum_required() or cmake_policy() that set the policy
version to an older value now issue a deprecation diagnostic.
This PR also removes manually setting policy CMP0048. This is
redundant since the CMake min is already 3.X