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

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

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 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
« no previous file with comments | « base/debug/profiler.cc ('k') | 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_DEBUG_STACK_TRACE_H_
6 #define BASE_DEBUG_STACK_TRACE_H_
7
8 #include <iosfwd>
9 #include <string>
10
11 #include "base/base_export.h"
12 #include "build/build_config.h"
13
14 #if defined(OS_POSIX)
15 #include <unistd.h>
16 #endif
17
18 namespace base {
19 namespace debug {
20
21 // Enables stack dump to console output on exception and signals.
22 // When enabled, the process will quit immediately. This is meant to be used in
23 // unit_tests only! This is not thread-safe: only call from main thread.
24 BASE_EXPORT bool EnableInProcessStackDumping();
25
26 // A different version of EnableInProcessStackDumping that also works for
27 // sandboxed processes. For more details take a look at the description
28 // of EnableInProcessStackDumping.
29 // Calling this function on Linux opens /proc/self/maps and caches its
30 // contents. In DEBUG builds, this function also opens the object files that
31 // are loaded in memory and caches their file descriptors (this cannot be
32 // done in official builds because it has security implications).
33 BASE_EXPORT bool EnableInProcessStackDumpingForSandbox();
34
35 // A stacktrace can be helpful in debugging. For example, you can include a
36 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you
37 // can later see where the given object was created from.
38 class BASE_EXPORT StackTrace {
39 public:
40 // Creates a stacktrace from the current location.
41 StackTrace();
42
43 // Creates a stacktrace from an existing array of instruction
44 // pointers (such as returned by Addresses()). |count| will be
45 // trimmed to |kMaxTraces|.
46 StackTrace(const void* const* trace, size_t count);
47
48 // Copying and assignment are allowed with the default functions.
49
50 ~StackTrace();
51
52 // Gets an array of instruction pointer values. |*count| will be set to the
53 // number of elements in the returned array.
54 const void* const* Addresses(size_t* count) const;
55
56 // Prints the stack trace to stderr.
57 void Print() const;
58
59 // Resolves backtrace to symbols and write to stream (if supported).
60 void OutputToStream(std::ostream* os) const;
61
62 // Resolves backtrace to symbols and returns as string.
63 std::string ToString() const;
64
65 private:
66 // From http://msdn.microsoft.com/en-us/library/bb204633.aspx,
67 // the sum of FramesToSkip and FramesToCapture must be less than 63,
68 // so set it to 62. Even if on POSIX it could be a larger value, it usually
69 // doesn't give much more information.
70 static const int kMaxTraces = 62;
71
72 void* trace_[kMaxTraces];
73
74 // The number of valid frames in |trace_|.
75 size_t count_;
76 };
77
78 namespace internal {
79
80 #if defined(OS_POSIX) && !defined(OS_ANDROID)
81 // POSIX doesn't define any async-signal safe function for converting
82 // an integer to ASCII. We'll have to define our own version.
83 // itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the
84 // conversion was successful or NULL otherwise. It never writes more than "sz"
85 // bytes. Output will be truncated as needed, and a NUL character is always
86 // appended.
87 BASE_EXPORT char *itoa_r(intptr_t i,
88 char *buf,
89 size_t sz,
90 int base,
91 size_t padding);
92 #endif // defined(OS_POSIX) && !defined(OS_ANDROID)
93
94 } // namespace internal
95
96 } // namespace debug
97 } // namespace base
98
99 #endif // BASE_DEBUG_STACK_TRACE_H_
OLDNEW
« no previous file with comments | « base/debug/profiler.cc ('k') | base/debug/stack_trace.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698