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

Side by Side Diff: base/debug/stack_trace.h

Issue 1907373002: Revert of Add function to trace stack using frame pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « no previous file | base/debug/stack_trace.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_DEBUG_STACK_TRACE_H_ 5 #ifndef BASE_DEBUG_STACK_TRACE_H_
6 #define BASE_DEBUG_STACK_TRACE_H_ 6 #define BASE_DEBUG_STACK_TRACE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <iosfwd> 10 #include <iosfwd>
11 #include <string> 11 #include <string>
12 12
13 #include "base/base_export.h" 13 #include "base/base_export.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 15
16 #if defined(OS_POSIX) 16 #if defined(OS_POSIX)
17 #include <unistd.h> 17 #include <unistd.h>
18 #endif 18 #endif
19 19
20 #if defined(OS_WIN) 20 #if defined(OS_WIN)
21 struct _EXCEPTION_POINTERS; 21 struct _EXCEPTION_POINTERS;
22 struct _CONTEXT; 22 struct _CONTEXT;
23 #endif 23 #endif
24 24
25 #if defined(OS_POSIX) && ( \
26 defined(__i386__) || defined(__x86_64__) || \
27 (defined(__arm__) && !defined(__thumb__)))
28 #define HAVE_TRACE_STACK_FRAME_POINTERS 1
29 #else
30 #define HAVE_TRACE_STACK_FRAME_POINTERS 0
31 #endif
32
33 namespace base { 25 namespace base {
34 namespace debug { 26 namespace debug {
35 27
36 // Enables stack dump to console output on exception and signals. 28 // Enables stack dump to console output on exception and signals.
37 // When enabled, the process will quit immediately. This is meant to be used in 29 // When enabled, the process will quit immediately. This is meant to be used in
38 // unit_tests only! This is not thread-safe: only call from main thread. 30 // unit_tests only! This is not thread-safe: only call from main thread.
39 // In sandboxed processes, this has to be called before the sandbox is turned 31 // In sandboxed processes, this has to be called before the sandbox is turned
40 // on. 32 // on.
41 // Calling this function on Linux opens /proc/self/maps and caches its 33 // Calling this function on Linux opens /proc/self/maps and caches its
42 // contents. In non-official builds, this function also opens the object files 34 // contents. In non-official builds, this function also opens the object files
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // so set it to 62. Even if on POSIX it could be a larger value, it usually 86 // so set it to 62. Even if on POSIX it could be a larger value, it usually
95 // doesn't give much more information. 87 // doesn't give much more information.
96 static const int kMaxTraces = 62; 88 static const int kMaxTraces = 62;
97 89
98 void* trace_[kMaxTraces]; 90 void* trace_[kMaxTraces];
99 91
100 // The number of valid frames in |trace_|. 92 // The number of valid frames in |trace_|.
101 size_t count_; 93 size_t count_;
102 }; 94 };
103 95
104 #if HAVE_TRACE_STACK_FRAME_POINTERS
105 // Traces the stack by using frame pointers. This function is faster but less
106 // reliable than StackTrace. It should work for debug and profiling builds,
107 // but not for release builds (although there are some exceptions).
108 //
109 // Writes at most |max_depth| frames (instruction pointers) into |out_trace|
110 // after skipping |skip_initial| frames. Note that the function itself is not
111 // added to the trace so |skip_initial| should be 0 in most cases.
112 // Returns number of frames written.
113 BASE_EXPORT size_t TraceStackFramePointers(const void** out_trace,
114 size_t max_depth,
115 size_t skip_initial);
116 #endif // HAVE_TRACE_STACK_FRAME_POINTERS
117
118 namespace internal { 96 namespace internal {
119 97
120 #if defined(OS_POSIX) && !defined(OS_ANDROID) 98 #if defined(OS_POSIX) && !defined(OS_ANDROID)
121 // POSIX doesn't define any async-signal safe function for converting 99 // POSIX doesn't define any async-signal safe function for converting
122 // an integer to ASCII. We'll have to define our own version. 100 // an integer to ASCII. We'll have to define our own version.
123 // itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the 101 // itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the
124 // conversion was successful or NULL otherwise. It never writes more than "sz" 102 // conversion was successful or NULL otherwise. It never writes more than "sz"
125 // bytes. Output will be truncated as needed, and a NUL character is always 103 // bytes. Output will be truncated as needed, and a NUL character is always
126 // appended. 104 // appended.
127 BASE_EXPORT char *itoa_r(intptr_t i, 105 BASE_EXPORT char *itoa_r(intptr_t i,
128 char *buf, 106 char *buf,
129 size_t sz, 107 size_t sz,
130 int base, 108 int base,
131 size_t padding); 109 size_t padding);
132 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) 110 #endif // defined(OS_POSIX) && !defined(OS_ANDROID)
133 111
134 } // namespace internal 112 } // namespace internal
135 113
136 } // namespace debug 114 } // namespace debug
137 } // namespace base 115 } // namespace base
138 116
139 #endif // BASE_DEBUG_STACK_TRACE_H_ 117 #endif // BASE_DEBUG_STACK_TRACE_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/stack_trace.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698