diff --git a/source/common/common/assert.h b/source/common/common/assert.h index 6fa4d8d388d0..148a69091f59 100644 --- a/source/common/common/assert.h +++ b/source/common/common/assert.h @@ -135,6 +135,9 @@ void resetEnvoyBugCountersForTest(); ENVOY_LOG_TO_LOGGER(Envoy::Logger::Registry::getLog(Envoy::Logger::Id::assert), critical, \ "assert failure: {}.{}{}", CONDITION_STR, \ details.empty() ? "" : " Details: ", details); \ + Envoy::Assert::EnvoyBugStackTrace st; \ + st.capture(); \ + st.logStackTrace(); \ ACTION; \ } \ } while (false) diff --git a/test/common/common/assert_test.cc b/test/common/common/assert_test.cc index 68587688f696..82a43825be91 100644 --- a/test/common/common/assert_test.cc +++ b/test/common/common/assert_test.cc @@ -7,6 +7,8 @@ namespace Envoy { +static void releaseAssertInAFunction() { RELEASE_ASSERT(0, ""); } + TEST(ReleaseAssertDeathTest, VariousLogs) { EXPECT_DEATH({ RELEASE_ASSERT(0, ""); }, ".*assert failure: 0.*"); EXPECT_DEATH({ RELEASE_ASSERT(0, "With some logs"); }, @@ -15,6 +17,18 @@ TEST(ReleaseAssertDeathTest, VariousLogs) { ".*assert failure: 0 == EAGAIN. Details: using fmt.*"); } +TEST(ReleaseAssertDeathTest, AssertIncludesStackTrace) { +#ifdef NDEBUG + GTEST_SKIP() << "optimized build inlines functions so the stack trace won't be reliable"; +#endif +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) + GTEST_SKIP() << "memory sanitizer build inlines functions so the stack trace won't be reliable"; +#endif +#endif + EXPECT_DEATH({ releaseAssertInAFunction(); }, "releaseAssertInAFunction"); +} + TEST(AssertDeathTest, VariousLogs) { int expected_counted_failures; // Use 2 assert action registrations to verify that action chaining is working correctly.