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

Unified Diff: base/debug/stack_trace_unittest.cc

Issue 1879073002: Add function to trace stack using frame pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Properly exclude Thumb; saner EXPECT_ macro to force frame pointers 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..b68fd589b0960519552b42006fd57bc6bef8cc94 100644
--- a/base/debug/stack_trace_unittest.cc
+++ b/base/debug/stack_trace_unittest.cc
@@ -238,5 +238,47 @@ 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;
+}
+
+TEST_F(StackTraceTest, 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