LEFT | RIGHT |
1 // Copyright (c) 2009, Google Inc. | 1 // Copyright (c) 2009, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include <list> | 38 #include <list> |
39 #include <utility> | 39 #include <utility> |
40 | 40 |
41 #include "client/linux/minidump_writer/linux_dumper.h" | 41 #include "client/linux/minidump_writer/linux_dumper.h" |
42 #include "google_breakpad/common/minidump_format.h" | 42 #include "google_breakpad/common/minidump_format.h" |
43 | 43 |
44 namespace google_breakpad { | 44 namespace google_breakpad { |
45 | 45 |
46 class ExceptionHandler; | 46 class ExceptionHandler; |
47 | 47 |
48 struct MappingEntry { | |
49 MappingInfo first; | |
50 uint8_t second[sizeof(MDGUID)]; | |
51 }; | |
52 | |
53 // Content flags that control the amount of information written to the Minidump
file | |
54 enum ContentFlags { | |
55 DUMP_CRASH_THREAD = (1 << 0), // Dump the crashing thread | |
56 DUMP_ADDITIONAL_THREADS = (1 << 1), // Dump the other threads | |
57 DUMP_LIMIT_STACK_SIZE = (1 << 2), // Limit the stack size | |
58 DUMP_MAPPINGS = (1 << 3), | |
59 DUMP_APP_MEMORY = (1 << 4), | |
60 DUMP_MEMORY_LIST = (1 << 5), | |
61 DUMP_EXCEPTION = (1 << 6), | |
62 DUMP_SYSTEM_INFO = (1 << 7), | |
63 DUMP_LINUX_CPU_INFO = (1 << 8), | |
64 DUMP_LINUX_PROC_STATUS = (1 << 9), | |
65 DUMP_LINUX_LSB_RELEASE = (1 << 10), | |
66 DUMP_LINUX_CMD_LINE = (1 << 11), | |
67 DUMP_LINUX_ENVIRON = (1 << 12), | |
68 DUMP_LINUX_AUXV = (1 << 13), | |
69 DUMP_LINUX_MAPS = (1 << 14), | |
70 DUMP_LINUX_DSO_DEBUG = (1 << 15), | |
71 | |
72 DUMP_ALL = -1 & ~(DUMP_LIMIT_STACK_SIZE) | |
73 }; | |
74 | |
75 inline ContentFlags operator | (ContentFlags a, ContentFlags b) { | |
76 return static_cast<ContentFlags>(static_cast<int>(a) | static_cast<int>(b)); | |
77 } | |
78 | |
79 inline ContentFlags operator & (ContentFlags a, ContentFlags b) { | |
80 return static_cast<ContentFlags>(static_cast<int>(a) & static_cast<int>(b)); | |
81 } | |
82 | |
83 inline ContentFlags& operator |= (ContentFlags& a, ContentFlags b) { | |
84 return a = a|b; | |
85 } | |
86 | |
87 inline ContentFlags& operator &= (ContentFlags& a, ContentFlags b) { | |
88 return a = a & b; | |
89 } | |
90 | |
91 // A list of <MappingInfo, GUID> | |
92 typedef std::list<MappingEntry> MappingList; | |
93 | |
94 #if defined(__aarch64__) | 48 #if defined(__aarch64__) |
95 typedef struct fpsimd_context fpstate_t; | 49 typedef struct fpsimd_context fpstate_t; |
96 #elif !defined(__ARM_EABI__) && !defined(__mips__) | 50 #elif !defined(__ARM_EABI__) && !defined(__mips__) |
97 typedef struct _libc_fpstate fpstate_t; | 51 typedef struct _libc_fpstate fpstate_t; |
98 #endif | 52 #endif |
99 | 53 |
100 // These entries store a list of memory regions that the client wants included | 54 // These entries store a list of memory regions that the client wants included |
101 // in the minidump. | 55 // in the minidump. |
102 struct AppMemory { | 56 struct AppMemory { |
103 void* ptr; | 57 void* ptr; |
104 size_t length; | 58 size_t length; |
105 | 59 |
106 bool operator==(const struct AppMemory& other) const { | 60 bool operator==(const struct AppMemory& other) const { |
107 return ptr == other.ptr; | 61 return ptr == other.ptr; |
108 } | 62 } |
109 | 63 |
110 bool operator==(const void* other) const { | 64 bool operator==(const void* other) const { |
111 return ptr == other; | 65 return ptr == other; |
112 } | 66 } |
113 }; | 67 }; |
114 typedef std::list<AppMemory> AppMemoryList; | 68 typedef std::list<AppMemory> AppMemoryList; |
| 69 |
| 70 // Content flags that control the amount of information written to the Minidump |
| 71 // file. |
| 72 // When DUMP_LIMIT_STACK_SIZE is set, breakpad's algorithm to save space from |
| 73 // a minidump file (by writing only a limited amount of stack data) is triggered |
| 74 // always, instead of when the resulting minidump file size might exceed the |
| 75 // limit set by the user. |
| 76 // By default, the amount of thread stack data written is the default value of |
| 77 // 2Kb (as defined by the |kLimitMaxExtraThreadStackLen| variable in |
| 78 // minidump_writer.cc. This value can be overriden by the user by setting the |
| 79 // |minidump_stack_limit| parameter, which defaults to -1 (meaning use whatever |
| 80 // default is set in minidump_writer.cc) |
| 81 enum ContentFlags { |
| 82 DUMP_CRASH_THREAD = (1 << 0), // Dump the crashing thread |
| 83 DUMP_ADDITIONAL_THREADS = (1 << 1), // Dump the other threads |
| 84 DUMP_LIMIT_STACK_SIZE = (1 << 2), // Limit the thread stack data written |
| 85 // to save disk space |
| 86 DUMP_MAPPINGS = (1 << 3), // Write information about mappings |
| 87 // in effect |
| 88 DUMP_APP_MEMORY = (1 << 4), // Write application provided |
| 89 // memory regions |
| 90 DUMP_MEMORY_LIST = (1 << 5), // Write the memory list stream |
| 91 DUMP_EXCEPTION = (1 << 6), // Write the exception information |
| 92 // stream |
| 93 DUMP_SYSTEM_INFO = (1 << 7), // Write the system information |
| 94 // (CPU/OS) stream |
| 95 DUMP_LINUX_CPU_INFO = (1 << 8), // Add the contents of the |
| 96 // /proc/cpuinfo file |
| 97 DUMP_LINUX_PROC_STATUS = (1 << 9), // Add the contents of the |
| 98 // /proc/<crashtread>/status file |
| 99 DUMP_LINUX_LSB_RELEASE = (1 << 10), // Add the contents of the |
| 100 // /etc/lsb_release file |
| 101 DUMP_LINUX_CMD_LINE = (1 << 11), // Add the contents of the |
| 102 // /proc/<crashthread>/cmdline file |
| 103 DUMP_LINUX_ENVIRON = (1 << 12), // Add the contents of the |
| 104 // /proc/<crashthread>/environ file |
| 105 DUMP_LINUX_AUXV = (1 << 13), // Add the contents of the |
| 106 // /proc/<crashthread>/auxv file |
| 107 DUMP_LINUX_MAPS = (1 << 14), // Add the contents of the |
| 108 // /proc/<crashthread>/maps file |
| 109 DUMP_LINUX_DSO_DEBUG = (1 << 15), // Write information about loaded DSOs, |
| 110 // if available |
| 111 |
| 112 // Dump all possible information (default behavior) |
| 113 DUMP_ALL = -1 & ~(DUMP_LIMIT_STACK_SIZE), |
| 114 |
| 115 // Predefined crash report sizes. They do not have a stack size limit |
| 116 // (use DUMP_LIMIT_STACK_SIZE for that) |
| 117 |
| 118 // Small size: smallest possible minidump that produces a human readable |
| 119 // stack trace |
| 120 DUMP_SMALL = DUMP_EXCEPTION | DUMP_SYSTEM_INFO | DUMP_MAPPINGS |
| 121 | DUMP_CRASH_THREAD, |
| 122 // Medium size: add also information about all other running threads |
| 123 DUMP_MEDIUM = DUMP_SMALL | DUMP_ADDITIONAL_THREADS, |
| 124 // Large size: add everything else, except for the /proc file dumps |
| 125 DUMP_LARGE = DUMP_MEDIUM | DUMP_APP_MEMORY | DUMP_MEMORY_LIST |
| 126 }; |
| 127 |
| 128 inline ContentFlags operator | (ContentFlags a, ContentFlags b) { |
| 129 return static_cast<ContentFlags>(static_cast<int>(a) | static_cast<int>(b)); |
| 130 } |
| 131 |
| 132 inline ContentFlags operator & (ContentFlags a, ContentFlags b) { |
| 133 return static_cast<ContentFlags>(static_cast<int>(a) & static_cast<int>(b)); |
| 134 } |
| 135 |
| 136 inline ContentFlags& operator |= (ContentFlags& a, ContentFlags b) { |
| 137 return a = a|b; |
| 138 } |
| 139 |
| 140 inline ContentFlags& operator &= (ContentFlags& a, ContentFlags b) { |
| 141 return a = a & b; |
| 142 } |
115 | 143 |
116 // Writes a minidump to the filesystem. These functions do not malloc nor use | 144 // Writes a minidump to the filesystem. These functions do not malloc nor use |
117 // libc functions which may. Thus, it can be used in contexts where the state | 145 // libc functions which may. Thus, it can be used in contexts where the state |
118 // of the heap may be corrupt. | 146 // of the heap may be corrupt. |
119 // minidump_path: the path to the file to write to. This is opened O_EXCL and | 147 // minidump_path: the path to the file to write to. This is opened O_EXCL and |
120 // fails open fails. | 148 // fails open fails. |
121 // crashing_process: the pid of the crashing process. This must be trusted. | 149 // crashing_process: the pid of the crashing process. This must be trusted. |
122 // blob: a blob of data from the crashing process. See exception_handler.h | 150 // blob: a blob of data from the crashing process. See exception_handler.h |
123 // blob_size: the length of |blob|, in bytes | 151 // blob_size: the length of |blob|, in bytes |
124 // | 152 // |
125 // Returns true if successful. | 153 // Returns true iff successful. |
126 bool WriteMinidump(const char* minidump_path, pid_t crashing_process, | 154 bool WriteMinidump(const char* minidump_path, pid_t crashing_process, |
127 const void* blob, size_t blob_size, | 155 const void* blob, size_t blob_size, |
128 ContentFlags flags); | 156 ContentFlags flags, off_t minidump_stack_limit); |
129 // Same as above but takes an open file descriptor instead of a path. | 157 // Same as above but takes an open file descriptor instead of a path. |
130 bool WriteMinidump(int minidump_fd, pid_t crashing_process, | 158 bool WriteMinidump(int minidump_fd, pid_t crashing_process, |
131 const void* blob, size_t blob_size, | 159 const void* blob, size_t blob_size, |
132 ContentFlags flags); | 160 ContentFlags flags, off_t minidump_stack_limit); |
133 | 161 |
134 // Alternate form of WriteMinidump() that works with processes that | 162 // Alternate form of WriteMinidump() that works with processes that |
135 // are not expected to have crashed. If |process_blamed_thread| is | 163 // are not expected to have crashed. If |process_blamed_thread| is |
136 // meaningful, it will be the one from which a crash signature is | 164 // meaningful, it will be the one from which a crash signature is |
137 // extracted. It is not expected that this function will be called | 165 // extracted. It is not expected that this function will be called |
138 // from a compromised context, but it is safe to do so. | 166 // from a compromised context, but it is safe to do so. |
139 bool WriteMinidump(const char* minidump_path, pid_t process, | 167 bool WriteMinidump(const char* minidump_path, pid_t process, |
140 ContentFlags flags, | 168 ContentFlags flags, off_t minidump_stack_limit, |
141 pid_t process_blamed_thread); | 169 pid_t process_blamed_thread); |
142 | 170 |
143 // These overloads also allow passing a list of known mappings and | 171 // These overloads also allow passing a list of known mappings and |
144 // a list of additional memory regions to be included in the minidump. | 172 // a list of additional memory regions to be included in the minidump. |
145 bool WriteMinidump(const char* minidump_path, pid_t crashing_process, | 173 bool WriteMinidump(const char* minidump_path, pid_t crashing_process, |
146 const void* blob, size_t blob_size, | 174 const void* blob, size_t blob_size, |
147 ContentFlags flags, | 175 ContentFlags flags, off_t minidump_stack_limit, |
148 const MappingList& mappings, | 176 const MappingList& mappings, |
149 const AppMemoryList& appdata); | 177 const AppMemoryList& appdata); |
150 bool WriteMinidump(int minidump_fd, pid_t crashing_process, | 178 bool WriteMinidump(int minidump_fd, pid_t crashing_process, |
151 const void* blob, size_t blob_size, | 179 const void* blob, size_t blob_size, |
152 ContentFlags flags, | 180 ContentFlags flags, off_t minidump_stack_limit, |
153 const MappingList& mappings, | 181 const MappingList& mappings, |
154 const AppMemoryList& appdata); | 182 const AppMemoryList& appdata); |
155 | 183 |
156 // These overloads also allow passing a file size limit for the minidump. | 184 // These overloads also allow passing a file size limit for the minidump. |
157 bool WriteMinidump(const char* minidump_path, off_t minidump_size_limit, | 185 bool WriteMinidump(const char* minidump_path, off_t minidump_size_limit, |
158 pid_t crashing_process, | 186 pid_t crashing_process, |
159 const void* blob, size_t blob_size, | 187 const void* blob, size_t blob_size, |
160 ContentFlags flags, | 188 ContentFlags flags, off_t minidump_stack_limit, |
161 const MappingList& mappings, | 189 const MappingList& mappings, |
162 const AppMemoryList& appdata); | 190 const AppMemoryList& appdata); |
163 bool WriteMinidump(int minidump_fd, off_t minidump_size_limit, | 191 bool WriteMinidump(int minidump_fd, off_t minidump_size_limit, |
164 pid_t crashing_process, | 192 pid_t crashing_process, |
165 const void* blob, size_t blob_size, | 193 const void* blob, size_t blob_size, |
166 ContentFlags flags, | 194 ContentFlags flags, off_t minidump_stack_limit, |
167 const MappingList& mappings, | 195 const MappingList& mappings, |
168 const AppMemoryList& appdata); | 196 const AppMemoryList& appdata); |
169 | 197 |
170 bool WriteMinidump(const char* filename, | 198 bool WriteMinidump(const char* filename, |
171 ContentFlags flags, | 199 ContentFlags flags, |
| 200 off_t minidump_stack_limit, |
172 const MappingList& mappings, | 201 const MappingList& mappings, |
173 const AppMemoryList& appdata, | 202 const AppMemoryList& appdata, |
174 LinuxDumper* dumper); | 203 LinuxDumper* dumper); |
175 | 204 |
176 } // namespace google_breakpad | 205 } // namespace google_breakpad |
177 | 206 |
178 #endif // CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_ | 207 #endif // CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_ |
LEFT | RIGHT |