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

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

Issue 888923004: Temporary commit to evaluate perf impact of prototype CPU profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: . Created 5 years, 10 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
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 <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 10
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 13
14 #if defined(OS_POSIX) 14 #if defined(OS_POSIX)
15 #include <unistd.h> 15 #include <unistd.h>
16 #endif 16 #endif
17 17
18 #if defined(OS_WIN) 18 #if defined(OS_WIN)
19 struct _EXCEPTION_POINTERS; 19 struct _EXCEPTION_POINTERS;
20 struct _CONTEXT;
20 #endif 21 #endif
21 22
22 namespace base { 23 namespace base {
23 namespace debug { 24 namespace debug {
24 25
25 // Enables stack dump to console output on exception and signals. 26 // Enables stack dump to console output on exception and signals.
26 // When enabled, the process will quit immediately. This is meant to be used in 27 // When enabled, the process will quit immediately. This is meant to be used in
27 // unit_tests only! This is not thread-safe: only call from main thread. 28 // unit_tests only! This is not thread-safe: only call from main thread.
28 BASE_EXPORT bool EnableInProcessStackDumping(); 29 BASE_EXPORT bool EnableInProcessStackDumping();
29 30
(...skipping 17 matching lines...) Expand all
47 // Creates a stacktrace from an existing array of instruction 48 // Creates a stacktrace from an existing array of instruction
48 // pointers (such as returned by Addresses()). |count| will be 49 // pointers (such as returned by Addresses()). |count| will be
49 // trimmed to |kMaxTraces|. 50 // trimmed to |kMaxTraces|.
50 StackTrace(const void* const* trace, size_t count); 51 StackTrace(const void* const* trace, size_t count);
51 52
52 #if defined(OS_WIN) 53 #if defined(OS_WIN)
53 // Creates a stacktrace for an exception. 54 // Creates a stacktrace for an exception.
54 // Note: this function will throw an import not found (StackWalk64) exception 55 // Note: this function will throw an import not found (StackWalk64) exception
55 // on system without dbghelp 5.1. 56 // on system without dbghelp 5.1.
56 StackTrace(const _EXCEPTION_POINTERS* exception_pointers); 57 StackTrace(const _EXCEPTION_POINTERS* exception_pointers);
58 StackTrace(const _CONTEXT* context);
57 #endif 59 #endif
58 60
59 // Copying and assignment are allowed with the default functions. 61 // Copying and assignment are allowed with the default functions.
60 62
61 ~StackTrace(); 63 ~StackTrace();
62 64
63 // Gets an array of instruction pointer values. |*count| will be set to the 65 // Gets an array of instruction pointer values. |*count| will be set to the
64 // number of elements in the returned array. 66 // number of elements in the returned array.
65 const void* const* Addresses(size_t* count) const; 67 const void* const* Addresses(size_t* count) const;
66 68
67 // Prints the stack trace to stderr. 69 // Prints the stack trace to stderr.
68 void Print() const; 70 void Print() const;
69 71
70 #if !defined(__UCLIBC__) 72 #if !defined(__UCLIBC__)
71 // Resolves backtrace to symbols and write to stream. 73 // Resolves backtrace to symbols and write to stream.
72 void OutputToStream(std::ostream* os) const; 74 void OutputToStream(std::ostream* os) const;
73 #endif 75 #endif
74 76
75 // Resolves backtrace to symbols and returns as string. 77 // Resolves backtrace to symbols and returns as string.
76 std::string ToString() const; 78 std::string ToString() const;
77 79
78 private: 80 private:
81 #if defined(OS_WIN)
82 void InitTrace(_CONTEXT* context_record);
83 #endif
84
79 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, 85 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx,
80 // the sum of FramesToSkip and FramesToCapture must be less than 63, 86 // the sum of FramesToSkip and FramesToCapture must be less than 63,
81 // so set it to 62. Even if on POSIX it could be a larger value, it usually 87 // so set it to 62. Even if on POSIX it could be a larger value, it usually
82 // doesn't give much more information. 88 // doesn't give much more information.
83 static const int kMaxTraces = 62; 89 static const int kMaxTraces = 62;
84 90
85 void* trace_[kMaxTraces]; 91 void* trace_[kMaxTraces];
86 92
87 // The number of valid frames in |trace_|. 93 // The number of valid frames in |trace_|.
88 size_t count_; 94 size_t count_;
(...skipping 14 matching lines...) Expand all
103 int base, 109 int base,
104 size_t padding); 110 size_t padding);
105 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) 111 #endif // defined(OS_POSIX) && !defined(OS_ANDROID)
106 112
107 } // namespace internal 113 } // namespace internal
108 114
109 } // namespace debug 115 } // namespace debug
110 } // namespace base 116 } // namespace base
111 117
112 #endif // BASE_DEBUG_STACK_TRACE_H_ 118 #endif // BASE_DEBUG_STACK_TRACE_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/debug/stack_trace_win.cc » ('j') | base/profiler/cpu_profiler.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698