Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Unified Diff: base/debug/stack_trace_unittest.cc

Issue 1915593003: Reland of Add function to trace stack using frame pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ARM unwinding on GCC Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/debug/stack_trace.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/stack_trace_unittest.cc
diff --git a/base/debug/stack_trace_unittest.cc b/base/debug/stack_trace_unittest.cc
index 9abedba6bafd91160989fb718cebc78b4fafbdf6..e716bf740d81cbd795e4b879eaf1096e0acd91e3 100644
--- a/base/debug/stack_trace_unittest.cc
+++ b/base/debug/stack_trace_unittest.cc
@@ -238,5 +238,56 @@ TEST_F(StackTraceTest, itoa_r) {
}
#endif // defined(OS_POSIX) && !defined(OS_ANDROID)
+#if HAVE_TRACE_STACK_FRAME_POINTERS
+
+template <size_t Depth>
+void NOINLINE ExpectStackFramePointers(const void** frames,
+ size_t max_depth) {
+ code_start:
+ // Calling __builtin_frame_address() forces compiler to emit
+ // frame pointers, even if they are not enabled.
+ EXPECT_NE(nullptr, __builtin_frame_address(0));
+ ExpectStackFramePointers<Depth - 1>(frames, max_depth);
+
+ constexpr size_t frame_index = Depth - 1;
+ const void* frame = frames[frame_index];
+ EXPECT_GE(frame, &&code_start) << "For frame at index " << frame_index;
+ EXPECT_LE(frame, &&code_end) << "For frame at index " << frame_index;
+ code_end: return;
+}
+
+template <>
+void NOINLINE ExpectStackFramePointers<1>(const void** frames,
+ size_t max_depth) {
+ code_start:
+ // Calling __builtin_frame_address() forces compiler to emit
+ // frame pointers, even if they are not enabled.
+ EXPECT_NE(nullptr, __builtin_frame_address(0));
+ size_t count = TraceStackFramePointers(frames, max_depth, 0);
+ ASSERT_EQ(max_depth, count);
+
+ const void* frame = frames[0];
+ EXPECT_GE(frame, &&code_start) << "For the top frame";
+ EXPECT_LE(frame, &&code_end) << "For the top frame";
+ code_end: return;
+}
+
+#if defined(MEMORY_SANITIZER)
+// The test triggers use-of-uninitialized-value errors on MSan bots.
+// This is expected because we're walking and reading the stack, and
+// sometimes we read fp / pc from the place that previously held
+// uninitialized value.
+#define MAYBE_TraceStackFramePointers DISABLED_TraceStackFramePointers
+#else
+#define MAYBE_TraceStackFramePointers TraceStackFramePointers
+#endif
+TEST_F(StackTraceTest, MAYBE_TraceStackFramePointers) {
+ constexpr size_t kDepth = 5;
+ const void* frames[kDepth];
+ ExpectStackFramePointers<kDepth>(frames, kDepth);
+}
+
+#endif // HAVE_TRACE_STACK_FRAME_POINTERS
+
} // namespace debug
} // namespace base
« no previous file with comments | « base/debug/stack_trace.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698