OLD | NEW |
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 struct _CONTEXT; |
21 #endif | 21 #endif |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 namespace debug { | 24 namespace debug { |
25 | 25 |
26 // Enables stack dump to console output on exception and signals. | 26 // Enables stack dump to console output on exception and signals. |
27 // 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 |
28 // 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. |
| 29 // In sandboxed processes, this has to be called before the sandbox is turned |
| 30 // on. |
| 31 // Calling this function on Linux opens /proc/self/maps and caches its |
| 32 // contents. In non-official builds, this function also opens the object files |
| 33 // that are loaded in memory and caches their file descriptors (this cannot be |
| 34 // done in official builds because it has security implications). |
29 BASE_EXPORT bool EnableInProcessStackDumping(); | 35 BASE_EXPORT bool EnableInProcessStackDumping(); |
30 | 36 |
31 // A different version of EnableInProcessStackDumping that also works for | |
32 // sandboxed processes. For more details take a look at the description | |
33 // of EnableInProcessStackDumping. | |
34 // Calling this function on Linux opens /proc/self/maps and caches its | |
35 // contents. In DEBUG builds, this function also opens the object files that | |
36 // are loaded in memory and caches their file descriptors (this cannot be | |
37 // done in official builds because it has security implications). | |
38 BASE_EXPORT bool EnableInProcessStackDumpingForSandbox(); | |
39 | |
40 // A stacktrace can be helpful in debugging. For example, you can include a | 37 // A stacktrace can be helpful in debugging. For example, you can include a |
41 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you | 38 // stacktrace member in a object (probably around #ifndef NDEBUG) so that you |
42 // can later see where the given object was created from. | 39 // can later see where the given object was created from. |
43 class BASE_EXPORT StackTrace { | 40 class BASE_EXPORT StackTrace { |
44 public: | 41 public: |
45 // Creates a stacktrace from the current location. | 42 // Creates a stacktrace from the current location. |
46 StackTrace(); | 43 StackTrace(); |
47 | 44 |
48 // Creates a stacktrace from an existing array of instruction | 45 // Creates a stacktrace from an existing array of instruction |
49 // pointers (such as returned by Addresses()). |count| will be | 46 // pointers (such as returned by Addresses()). |count| will be |
50 // trimmed to |kMaxTraces|. | 47 // trimmed to |kMaxTraces|. |
51 StackTrace(const void* const* trace, size_t count); | 48 StackTrace(const void* const* trace, size_t count); |
52 | 49 |
53 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
54 // Creates a stacktrace for an exception. | 51 // Creates a stacktrace for an exception. |
55 // Note: this function will throw an import not found (StackWalk64) exception | 52 // Note: this function will throw an import not found (StackWalk64) exception |
56 // on system without dbghelp 5.1. | 53 // on system without dbghelp 5.1. |
57 StackTrace(const _EXCEPTION_POINTERS* exception_pointers); | 54 StackTrace(_EXCEPTION_POINTERS* exception_pointers); |
58 StackTrace(const _CONTEXT* context); | 55 StackTrace(_CONTEXT* context); |
59 #endif | 56 #endif |
60 | 57 |
61 // Copying and assignment are allowed with the default functions. | 58 // Copying and assignment are allowed with the default functions. |
62 | 59 |
63 ~StackTrace(); | 60 ~StackTrace(); |
64 | 61 |
65 // Gets an array of instruction pointer values. |*count| will be set to the | 62 // Gets an array of instruction pointer values. |*count| will be set to the |
66 // number of elements in the returned array. | 63 // number of elements in the returned array. |
67 const void* const* Addresses(size_t* count) const; | 64 const void* const* Addresses(size_t* count) const; |
68 | 65 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 int base, | 106 int base, |
110 size_t padding); | 107 size_t padding); |
111 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) | 108 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) |
112 | 109 |
113 } // namespace internal | 110 } // namespace internal |
114 | 111 |
115 } // namespace debug | 112 } // namespace debug |
116 } // namespace base | 113 } // namespace base |
117 | 114 |
118 #endif // BASE_DEBUG_STACK_TRACE_H_ | 115 #endif // BASE_DEBUG_STACK_TRACE_H_ |
OLD | NEW |