summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/base/SConscript17
-rw-r--r--src/mongo/util/SConscript17
-rw-r--r--src/mongo/util/stacktrace_libunwind_test.cpp (renamed from src/mongo/base/unwind_test.cpp)16
-rw-r--r--src/mongo/util/stacktrace_libunwind_test_functions.cpp (renamed from src/mongo/base/backtrace_visibility_test.cpp)34
-rw-r--r--src/mongo/util/stacktrace_libunwind_test_functions.h (renamed from src/mongo/base/backtrace_visibility_test.h)15
-rw-r--r--src/mongo/util/stacktrace_test.cpp1
6 files changed, 46 insertions, 54 deletions
diff --git a/src/mongo/base/SConscript b/src/mongo/base/SConscript
index ee394b80761..e2edc4bc554 100644
--- a/src/mongo/base/SConscript
+++ b/src/mongo/base/SConscript
@@ -1,7 +1,6 @@
# -*- mode: python -*-
Import("env")
-Import("use_libunwind")
env = env.Clone()
@@ -105,19 +104,3 @@ env.CppUnitTest(
'system_error',
],
)
-
-if use_libunwind:
- unwindTestEnv = env.Clone()
- unwindTestEnv.InjectThirdParty(libraries=['unwind'])
- unwindTestEnv.CppUnitTest(
- target=[
- 'unwind_test',
- ],
- source=[
- 'backtrace_visibility_test.cpp',
- 'unwind_test.cpp',
- ],
- LIBDEPS=[
- '$BUILD_DIR/third_party/shim_unwind',
- ],
- )
diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript
index 034fcf96d27..4d98e0b3e9d 100644
--- a/src/mongo/util/SConscript
+++ b/src/mongo/util/SConscript
@@ -4,6 +4,7 @@ Import("endian")
Import("env")
Import("get_option")
Import("has_option")
+Import("use_libunwind")
Import("use_system_version_of_library")
env = env.Clone()
@@ -636,3 +637,19 @@ env.CppUnitTest(
LIBDEPS=[
],
)
+
+if use_libunwind:
+ unwindTestEnv = env.Clone()
+ unwindTestEnv.InjectThirdParty(libraries=['unwind'])
+ unwindTestEnv.CppUnitTest(
+ target=[
+ 'stacktrace_libunwind_test',
+ ],
+ source=[
+ 'stacktrace_libunwind_test_functions.cpp',
+ 'stacktrace_libunwind_test.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/third_party/shim_unwind',
+ ],
+ )
diff --git a/src/mongo/base/unwind_test.cpp b/src/mongo/util/stacktrace_libunwind_test.cpp
index e0f67946484..363b0414600 100644
--- a/src/mongo/base/unwind_test.cpp
+++ b/src/mongo/util/stacktrace_libunwind_test.cpp
@@ -40,9 +40,9 @@
#include <libunwind.h>
-#include "mongo/base/backtrace_visibility_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/stacktrace.h"
+#include "mongo/util/stacktrace_libunwind_test_functions.h"
namespace mongo {
@@ -146,11 +146,11 @@ TEST(Unwind, Demangled) {
}
TEST(Unwind, Linkage) {
- std::string stacktrace;
-
// From backtrace_visibility_test.h. Calls a chain of functions and stores the backtrace at the
// bottom in the "stacktrace" argument.
- normal_function(stacktrace);
+ std::ostringstream os;
+ normalFunction(os);
+ std::string stacktrace = os.str();
std::string_view view = stacktrace;
@@ -170,10 +170,10 @@ TEST(Unwind, Linkage) {
// preceded our libunwind integration could *not* symbolize hidden/static_function.
std::string frames[] = {
"printStackTrace",
- "static_function",
- "anonymous_namespace_function",
- "hidden_function",
- "normal_function",
+ "staticFunction",
+ "anonymousNamespaceFunction",
+ "hiddenFunction",
+ "normalFunction",
};
for (const auto& name : frames) {
diff --git a/src/mongo/base/backtrace_visibility_test.cpp b/src/mongo/util/stacktrace_libunwind_test_functions.cpp
index 1984829e93c..bcef679ba7e 100644
--- a/src/mongo/base/backtrace_visibility_test.cpp
+++ b/src/mongo/util/stacktrace_libunwind_test_functions.cpp
@@ -32,43 +32,39 @@
* functions appear in backtraces, see unwind_test.cpp.
*/
-#include "backtrace_visibility_test.h"
+#include "stacktrace_libunwind_test_functions.h"
#include "mongo/platform/compiler.h"
#include "mongo/util/stacktrace.h"
#include <sstream>
+#define PREVENT_TAIL_CALL asm volatile("") // NOLINT
+
// "static" means internal linkage only for functions at namespace scope.
-MONGO_COMPILER_NOINLINE static void static_function(std::string& s) {
- std::ostringstream ostream;
- mongo::printStackTrace(ostream);
- s = ostream.str();
- // Prevent tail-call optimization.
- asm volatile(""); // NOLINT
+MONGO_COMPILER_NOINLINE static void staticFunction(std::ostream& s) {
+ mongo::printStackTrace(s);
+ PREVENT_TAIL_CALL;
}
namespace {
-MONGO_COMPILER_NOINLINE void anonymous_namespace_function(std::string& s) {
- static_function(s);
- // Prevent tail-call optimization.
- asm volatile(""); // NOLINT
+MONGO_COMPILER_NOINLINE void anonymousNamespaceFunction(std::ostream& s) {
+ staticFunction(s);
+ PREVENT_TAIL_CALL;
}
} // namespace
-MONGO_COMPILER_NOINLINE MONGO_COMPILER_API_HIDDEN_FUNCTION void hidden_function(std::string& s) {
- anonymous_namespace_function(s);
- // Prevent tail-call optimization.
- asm volatile(""); // NOLINT
+MONGO_COMPILER_NOINLINE MONGO_COMPILER_API_HIDDEN_FUNCTION void hiddenFunction(std::ostream& s) {
+ anonymousNamespaceFunction(s);
+ PREVENT_TAIL_CALL;
}
namespace mongo {
namespace unwind_test_detail {
-MONGO_COMPILER_NOINLINE void normal_function(std::string& s) {
- hidden_function(s);
- // Prevent tail-call optimization.
- asm volatile(""); // NOLINT
+MONGO_COMPILER_NOINLINE void normalFunction(std::ostream& s) {
+ hiddenFunction(s);
+ PREVENT_TAIL_CALL;
}
} // namespace unwind_test_detail
} // namespace mongo
diff --git a/src/mongo/base/backtrace_visibility_test.h b/src/mongo/util/stacktrace_libunwind_test_functions.h
index cb60120af9c..168f52fb5c9 100644
--- a/src/mongo/base/backtrace_visibility_test.h
+++ b/src/mongo/util/stacktrace_libunwind_test_functions.h
@@ -32,15 +32,12 @@
* functions appear in backtraces, see unwind_test.cpp.
*/
-#include <string>
+#include <ostream>
-namespace mongo {
+namespace mongo::unwind_test_detail {
-namespace unwind_test_detail {
+// Generates a stack trace by calling functions of various visibility and linkage
+// Writes a stack trace to `s` from the deep call stack.
+void normalFunction(std::ostream& s);
-// Store a stack trace in s.
-void normal_function(std::string& s);
-
-} // namespace unwind_test_detail
-
-} // namespace mongo
+} // namespace mongo::unwind_test_detail
diff --git a/src/mongo/util/stacktrace_test.cpp b/src/mongo/util/stacktrace_test.cpp
index 95e2c785283..b2ba29b045d 100644
--- a/src/mongo/util/stacktrace_test.cpp
+++ b/src/mongo/util/stacktrace_test.cpp
@@ -38,7 +38,6 @@
#include <sstream>
#include <vector>
-#include "mongo/base/backtrace_visibility_test.h"
#include "mongo/bson/json.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/stacktrace.h"