diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-06-01 12:13:01 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-06-01 12:13:01 +0000 |
commit | 3de3834cd05b2f70147ef74794602b435130c42c (patch) | |
tree | f23c929b90668718286671ab324034c9e2f5fe0d /vespalib | |
parent | b8854385c6cb338defea6dee194d8217c61f349b (diff) |
Ensure names are visible in backtrace by moving functions to a shared library
Name resolving does not necessarily work for static functions.
Diffstat (limited to 'vespalib')
4 files changed, 35 insertions, 15 deletions
diff --git a/vespalib/src/tests/signalhandler/CMakeLists.txt b/vespalib/src/tests/signalhandler/CMakeLists.txt index c33cdcf10cd..4f78eb2e82d 100644 --- a/vespalib/src/tests/signalhandler/CMakeLists.txt +++ b/vespalib/src/tests/signalhandler/CMakeLists.txt @@ -1,9 +1,16 @@ # Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_library(vespalib_signalhandler_test_my_shared_library TEST + SOURCES + my_shared_library.cpp + DEPENDS + vespalib +) vespa_add_executable(vespalib_signalhandler_test_app TEST SOURCES signalhandler_test.cpp DEPENDS vespalib + vespalib_signalhandler_test_my_shared_library GTest::GTest ) vespa_add_test(NAME vespalib_signalhandler_test_app NO_VALGRIND COMMAND vespalib_signalhandler_test_app) diff --git a/vespalib/src/tests/signalhandler/my_shared_library.cpp b/vespalib/src/tests/signalhandler/my_shared_library.cpp new file mode 100644 index 00000000000..5663f6c4ba0 --- /dev/null +++ b/vespalib/src/tests/signalhandler/my_shared_library.cpp @@ -0,0 +1,19 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "my_shared_library.h" +#include <vespa/vespalib/util/signalhandler.h> + +// This tiny library exists solely as a way to ensure we get visible function names in our backtrace, +// as that is not necessarily the case for statically linked functions. + +// Could have used a single std::barrier<no op functor> here, but when using explicit +// phase latches it sort of feels like the semantics are more immediately obvious. +void my_cool_function(std::latch& arrival_latch, std::latch& departure_latch) { + arrival_latch.arrive_and_wait(); + // Twiddle thumbs in departure latch until main test thread has dumped our stack + departure_latch.arrive_and_wait(); +} + +vespalib::string my_totally_tubular_and_groovy_function() { + return vespalib::SignalHandler::get_cross_thread_stack_trace(pthread_self()); +} diff --git a/vespalib/src/tests/signalhandler/my_shared_library.h b/vespalib/src/tests/signalhandler/my_shared_library.h new file mode 100644 index 00000000000..e48a6d91a4f --- /dev/null +++ b/vespalib/src/tests/signalhandler/my_shared_library.h @@ -0,0 +1,8 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/vespalib/stllike/string.h> +#include <latch> + +void my_cool_function(std::latch&, std::latch&) __attribute__((noinline)); + +vespalib::string my_totally_tubular_and_groovy_function() __attribute__((noinline)); diff --git a/vespalib/src/tests/signalhandler/signalhandler_test.cpp b/vespalib/src/tests/signalhandler/signalhandler_test.cpp index f15233e78a3..9e1052bb588 100644 --- a/vespalib/src/tests/signalhandler/signalhandler_test.cpp +++ b/vespalib/src/tests/signalhandler/signalhandler_test.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "my_shared_library.h" #include <vespa/vespalib/util/signalhandler.h> #include <vespa/vespalib/gtest/gtest.h> #include <gmock/gmock.h> @@ -35,16 +36,6 @@ TEST(SignalHandlerTest, signal_handler_can_intercept_hooked_signals) EXPECT_EQ(0, system("res=`./vespalib_victim_app`; test \"$res\" = \"GOT TERM\"")); } -void my_cool_function(std::latch&, std::latch&) __attribute__((noinline)); - -// Could have used a single std::barrier<no op functor> here, but when using explicit -// phase latches it sort of feels like the semantics are more immediately obvious. -void my_cool_function(std::latch& arrival_latch, std::latch& departure_latch) { - arrival_latch.arrive_and_wait(); - // Twiddle thumbs in departure latch until main test thread has dumped our stack - departure_latch.arrive_and_wait(); -} - TEST(SignalHandlerTest, can_dump_stack_of_another_thread) { std::latch arrival_latch(2); @@ -73,11 +64,6 @@ TEST(SignalHandlerTest, dumping_stack_of_an_ex_thread_does_not_crash) EXPECT_EQ(trace, "(pthread_kill() failed; could not get backtrace)"); } -string my_totally_tubular_and_groovy_function() __attribute__((noinline)); -string my_totally_tubular_and_groovy_function() { - return SignalHandler::get_cross_thread_stack_trace(pthread_self()); -} - TEST(SignalHandlerTest, can_get_stack_trace_of_own_thread) { auto trace = my_totally_tubular_and_groovy_function(); |