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

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: Address comments 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
« base/debug/stack_trace_posix.cc ('K') | « base/debug/stack_trace_posix.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..af53a147766cad1969b0ac8cf52b8ec3dc621e17 100644
--- a/base/debug/stack_trace_unittest.cc
+++ b/base/debug/stack_trace_unittest.cc
@@ -238,5 +238,61 @@ TEST_F(StackTraceTest, itoa_r) {
}
#endif // defined(OS_POSIX) && !defined(OS_ANDROID)
+#if HAVE_TRACE_STACK_FRAME_POINTERS
+
+TEST_F(StackTraceTest, TraceStackFramePointers) {
Primiano Tucci (use gerrit) 2016/04/18 20:18:08 I wouldn't base this test on comparing unwinding
Dmitry Skiba 2016/04/20 16:32:56 Done.
+ const void* fp_frames[10];
+ size_t fp_frame_count =
+ TraceStackFramePointers(fp_frames, arraysize(fp_frames), 0);
+
+ // We expect to fill the whole frame array
+ ASSERT_EQ(arraysize(fp_frames), fp_frame_count);
+
+ // Compare against StackTrace
+
+ StackTrace stack_trace;
+ size_t frame_count = 0;
+ const void* const* frames = stack_trace.Addresses(&frame_count);
+
+ // Find offsets into both frame arrays that have matching frames
+ size_t fp_frames_offset = 0;
+ size_t frames_offset = 0;
+ bool found_matching_frame = false;
+ for (;fp_frames_offset != fp_frame_count; ++fp_frames_offset) {
+ const void* frame = fp_frames[fp_frames_offset];
+ for (frames_offset = 0; frames_offset != frame_count; ++frames_offset) {
+ if (frames[frames_offset] == frame) {
+ found_matching_frame = true;
+ break;
+ }
+ }
+ if (found_matching_frame) {
+ break;
+ }
+ }
+
+ ASSERT_TRUE(found_matching_frame) <<
+ "StackTrace class and TraceStackFramePointers function produced " <<
+ "completely different traces.";
+
+ // fp_frames[0] points somewhere inside this function and differs from
+ // location reported by StackFrame (since invocations are on different
+ // lines). However fp_frames[1] points to the caller function, and should
+ // be in both frame arrays.
+ ASSERT_EQ(fp_frames_offset, 1u);
+
+ size_t check_depth = std::min(fp_frame_count - fp_frames_offset,
+ frame_count - frames_offset);
+ for (size_t i = 0; i != check_depth; ++i) {
+ size_t fp_frame_index = i + fp_frames_offset;
+ size_t frame_index = i + frames_offset;
+ EXPECT_EQ(frames[frame_index], fp_frames[fp_frame_index]) <<
+ "Where frame_index = " << frame_index << ", " <<
+ "fp_frame_index = " << fp_frame_index;
+ }
+}
+
+#endif // HAVE_TRACE_STACK_FRAME_POINTERS
+
} // namespace debug
} // namespace base
« base/debug/stack_trace_posix.cc ('K') | « base/debug/stack_trace_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698