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

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

Issue 7766013: [Mac] Capture -dealloc backtrace to log with CrZombie messages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use sizeof(trace_) workaround. Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/debug/stack_trace.cc » ('j') | base/debug/stack_trace.cc » ('J')
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 #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 #pragma once 7 #pragma once
8 8
9 #include <iosfwd> 9 #include <iosfwd>
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_WIN) 14 #if defined(OS_WIN)
15 struct _EXCEPTION_POINTERS; 15 struct _EXCEPTION_POINTERS;
16 #endif 16 #endif
17 17
18 namespace base { 18 namespace base {
19 namespace debug { 19 namespace debug {
20 20
21 // A stacktrace can be helpful in debugging. For example, you can include a 21 // A stacktrace can be helpful in debugging. For example, you can include a
22 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you 22 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you
23 // can later see where the given object was created from. 23 // can later see where the given object was created from.
24 class BASE_EXPORT StackTrace { 24 class BASE_EXPORT StackTrace {
25 public: 25 public:
26 // Creates a stacktrace from the current location. 26 // Creates a stacktrace from the current location.
27 StackTrace(); 27 StackTrace();
28 28
29 // Creates a stacktrace from an existing array of instruction
30 // pointers (such as returned by Addresses()). |count| will be
31 // trimmed to |kMaxTraces|.
32 StackTrace(const void* const* trace, int count);
33
29 #if defined(OS_WIN) 34 #if defined(OS_WIN)
30 // Creates a stacktrace for an exception. 35 // Creates a stacktrace for an exception.
31 // Note: this function will throw an import not found (StackWalk64) exception 36 // Note: this function will throw an import not found (StackWalk64) exception
32 // on system without dbghelp 5.1. 37 // on system without dbghelp 5.1.
33 StackTrace(_EXCEPTION_POINTERS* exception_pointers); 38 StackTrace(_EXCEPTION_POINTERS* exception_pointers);
34 #endif 39 #endif
35 40
36 // Copying and assignment are allowed with the default functions. 41 // Copying and assignment are allowed with the default functions.
37 42
38 ~StackTrace(); 43 ~StackTrace();
39 44
40 // Gets an array of instruction pointer values. |*count| will be set to the 45 // Gets an array of instruction pointer values. |*count| will be set to the
41 // number of elements in the returned array. 46 // number of elements in the returned array.
42 const void* const* Addresses(size_t* count) const; 47 const void* const* Addresses(size_t* count) const;
43 48
44 // Prints a backtrace to stderr 49 // Prints a backtrace to stderr
45 void PrintBacktrace() const; 50 void PrintBacktrace() const;
46 51
47 // Resolves backtrace to symbols and write to stream. 52 // Resolves backtrace to symbols and write to stream.
48 void OutputToStream(std::ostream* os) const; 53 void OutputToStream(std::ostream* os) const;
49 54
50 private: 55 private:
51 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx, 56 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx,
52 // the sum of FramesToSkip and FramesToCapture must be less than 63, 57 // the sum of FramesToSkip and FramesToCapture must be less than 63,
53 // so set it to 62. Even if on POSIX it could be a larger value, it usually 58 // so set it to 62. Even if on POSIX it could be a larger value, it usually
54 // doesn't give much more information. 59 // doesn't give much more information.
55 static const int kMaxTraces = 62; 60 static const int kMaxTraces = 62;
56 61
57 void* trace_[kMaxTraces]; 62 void* trace_[kMaxTraces];
58 int count_; 63 int count_;
Scott Hess - ex-Googler 2011/08/29 20:13:36 Having this and kMaxTraces be int seems wrong, wou
59 }; 64 };
60 65
61 } // namespace debug 66 } // namespace debug
62 } // namespace base 67 } // namespace base
63 68
64 #endif // BASE_DEBUG_STACK_TRACE_H_ 69 #endif // BASE_DEBUG_STACK_TRACE_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/stack_trace.cc » ('j') | base/debug/stack_trace.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698