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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/debug/stack_trace.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include <limits> 7 #include <limits>
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 EXPECT_EQ("00001", itoa_r_wrapper(1, 128, 10, 5)); 231 EXPECT_EQ("00001", itoa_r_wrapper(1, 128, 10, 5));
232 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 0)); 232 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 0));
233 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 1)); 233 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 1));
234 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 2)); 234 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 2));
235 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 3)); 235 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 3));
236 EXPECT_EQ("0688", itoa_r_wrapper(0x688, 128, 16, 4)); 236 EXPECT_EQ("0688", itoa_r_wrapper(0x688, 128, 16, 4));
237 EXPECT_EQ("00688", itoa_r_wrapper(0x688, 128, 16, 5)); 237 EXPECT_EQ("00688", itoa_r_wrapper(0x688, 128, 16, 5));
238 } 238 }
239 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) 239 #endif // defined(OS_POSIX) && !defined(OS_ANDROID)
240 240
241 #if HAVE_TRACE_STACK_FRAME_POINTERS
242
243 template <size_t Depth>
244 void NOINLINE ExpectStackFramePointers(const void** frames,
245 size_t max_depth) {
246 code_start:
247 // Calling __builtin_frame_address() forces compiler to emit
248 // frame pointers, even if they are not enabled.
249 EXPECT_NE(nullptr, __builtin_frame_address(0));
250 ExpectStackFramePointers<Depth - 1>(frames, max_depth);
251
252 constexpr size_t frame_index = Depth - 1;
253 const void* frame = frames[frame_index];
254 EXPECT_GE(frame, &&code_start) << "For frame at index " << frame_index;
255 EXPECT_LE(frame, &&code_end) << "For frame at index " << frame_index;
256 code_end: return;
257 }
258
259 template <>
260 void NOINLINE ExpectStackFramePointers<1>(const void** frames,
261 size_t max_depth) {
262 code_start:
263 // Calling __builtin_frame_address() forces compiler to emit
264 // frame pointers, even if they are not enabled.
265 EXPECT_NE(nullptr, __builtin_frame_address(0));
266 size_t count = TraceStackFramePointers(frames, max_depth, 0);
267 ASSERT_EQ(max_depth, count);
268
269 const void* frame = frames[0];
270 EXPECT_GE(frame, &&code_start) << "For the top frame";
271 EXPECT_LE(frame, &&code_end) << "For the top frame";
272 code_end: return;
273 }
274
275 TEST_F(StackTraceTest, TraceStackFramePointers) {
276 constexpr size_t kDepth = 5;
277 const void* frames[kDepth];
278 ExpectStackFramePointers<kDepth>(frames, kDepth);
279 }
280
281 #endif // HAVE_TRACE_STACK_FRAME_POINTERS
282
241 } // namespace debug 283 } // namespace debug
242 } // namespace base 284 } // namespace base
OLDNEW
« 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