|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsExceptionHandler_h__ |
|
7 #define nsExceptionHandler_h__ |
|
8 |
|
9 #include <stddef.h> |
|
10 #include <stdint.h> |
|
11 #include "nsError.h" |
|
12 #include "nsStringGlue.h" |
|
13 |
|
14 #if defined(XP_WIN32) |
|
15 #ifdef WIN32_LEAN_AND_MEAN |
|
16 #undef WIN32_LEAN_AND_MEAN |
|
17 #endif |
|
18 #include <windows.h> |
|
19 #endif |
|
20 |
|
21 #if defined(XP_MACOSX) |
|
22 #include <mach/mach.h> |
|
23 #endif |
|
24 |
|
25 #if defined(XP_LINUX) |
|
26 #include <signal.h> |
|
27 #endif |
|
28 |
|
29 class nsIFile; |
|
30 template<class KeyClass, class DataType> class nsDataHashtable; |
|
31 class nsCStringHashKey; |
|
32 |
|
33 namespace CrashReporter { |
|
34 nsresult SetExceptionHandler(nsIFile* aXREDirectory, bool force=false); |
|
35 nsresult UnsetExceptionHandler(); |
|
36 |
|
37 /** |
|
38 * Tell the crash reporter to recalculate where crash events files should go. |
|
39 * |
|
40 * This should be called during crash reporter initialization and when a |
|
41 * profile is activated or deactivated. |
|
42 */ |
|
43 void UpdateCrashEventsDir(); |
|
44 |
|
45 /** |
|
46 * Get the path where crash event files should be written. |
|
47 */ |
|
48 bool GetCrashEventsDir(nsAString& aPath); |
|
49 |
|
50 bool GetEnabled(); |
|
51 bool GetServerURL(nsACString& aServerURL); |
|
52 nsresult SetServerURL(const nsACString& aServerURL); |
|
53 bool GetMinidumpPath(nsAString& aPath); |
|
54 nsresult SetMinidumpPath(const nsAString& aPath); |
|
55 |
|
56 |
|
57 // AnnotateCrashReport and AppendAppNotesToCrashReport may be called from any |
|
58 // thread in a chrome process, but may only be called from the main thread in |
|
59 // a content process. |
|
60 nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data); |
|
61 nsresult AppendAppNotesToCrashReport(const nsACString& data); |
|
62 |
|
63 void AnnotateOOMAllocationSize(size_t size); |
|
64 nsresult SetGarbageCollecting(bool collecting); |
|
65 void SetEventloopNestingLevel(uint32_t level); |
|
66 |
|
67 nsresult SetRestartArgs(int argc, char** argv); |
|
68 nsresult SetupExtraData(nsIFile* aAppDataDirectory, |
|
69 const nsACString& aBuildID); |
|
70 bool GetLastRunCrashID(nsAString& id); |
|
71 |
|
72 // Registers an additional memory region to be included in the minidump |
|
73 nsresult RegisterAppMemory(void* ptr, size_t length); |
|
74 nsresult UnregisterAppMemory(void* ptr); |
|
75 |
|
76 // Functions for working with minidumps and .extras |
|
77 typedef nsDataHashtable<nsCStringHashKey, nsCString> AnnotationTable; |
|
78 |
|
79 bool GetMinidumpForID(const nsAString& id, nsIFile** minidump); |
|
80 bool GetIDFromMinidump(nsIFile* minidump, nsAString& id); |
|
81 bool GetExtraFileForID(const nsAString& id, nsIFile** extraFile); |
|
82 bool GetExtraFileForMinidump(nsIFile* minidump, nsIFile** extraFile); |
|
83 bool AppendExtraData(const nsAString& id, const AnnotationTable& data); |
|
84 bool AppendExtraData(nsIFile* extraFile, const AnnotationTable& data); |
|
85 void RenameAdditionalHangMinidump(nsIFile* minidump, nsIFile* childMinidump, |
|
86 const nsACString& name); |
|
87 |
|
88 #ifdef XP_WIN32 |
|
89 nsresult WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo); |
|
90 #endif |
|
91 #ifdef XP_LINUX |
|
92 bool WriteMinidumpForSigInfo(int signo, siginfo_t* info, void* uc); |
|
93 #endif |
|
94 #ifdef XP_MACOSX |
|
95 nsresult AppendObjCExceptionInfoToAppNotes(void *inException); |
|
96 #endif |
|
97 nsresult GetSubmitReports(bool* aSubmitReport); |
|
98 nsresult SetSubmitReports(bool aSubmitReport); |
|
99 |
|
100 // Out-of-process crash reporter API. |
|
101 |
|
102 // Initializes out-of-process crash reporting. This method must be called |
|
103 // before the platform-specifi notificationpipe APIs are called. |
|
104 void OOPInit(); |
|
105 |
|
106 // Return true if a dump was found for |childPid|, and return the |
|
107 // path in |dump|. The caller owns the last reference to |dump| if it |
|
108 // is non-nullptr. The sequence parameter will be filled with an ordinal |
|
109 // indicating which remote process crashed first. |
|
110 bool TakeMinidumpForChild(uint32_t childPid, |
|
111 nsIFile** dump, |
|
112 uint32_t* aSequence = nullptr); |
|
113 |
|
114 #if defined(XP_WIN) |
|
115 typedef HANDLE ProcessHandle; |
|
116 typedef DWORD ThreadId; |
|
117 #elif defined(XP_MACOSX) |
|
118 typedef task_t ProcessHandle; |
|
119 typedef mach_port_t ThreadId; |
|
120 #else |
|
121 typedef int ProcessHandle; |
|
122 typedef int ThreadId; |
|
123 #endif |
|
124 |
|
125 // Return the current thread's ID. |
|
126 // |
|
127 // XXX: this is a somewhat out-of-place interface to expose through |
|
128 // crashreporter, but it takes significant work to call sys_gettid() |
|
129 // correctly on Linux and breakpad has already jumped through those |
|
130 // hoops for us. |
|
131 ThreadId CurrentThreadId(); |
|
132 |
|
133 // Create a hang report with two minidumps that are snapshots of the state |
|
134 // of this parent process and |childPid|. The "main" minidump will be the |
|
135 // child process, and this parent process will have the -browser extension. |
|
136 // |
|
137 // Returns true on success. If this function fails, it will attempt to delete |
|
138 // any files that were created. |
|
139 // |
|
140 // The .extra information created will not include an additional_minidumps |
|
141 // annotation: the caller should annotate additional_minidumps with |
|
142 // at least "browser" and perhaps other minidumps attached to this report. |
|
143 bool CreatePairedMinidumps(ProcessHandle childPid, |
|
144 ThreadId childBlamedThread, |
|
145 nsIFile** childDump); |
|
146 |
|
147 // Create an additional minidump for a child of a process which already has |
|
148 // a minidump (|parentMinidump|). |
|
149 // The resulting dump will get the id of the parent and use the |name| as |
|
150 // an extension. |
|
151 bool CreateAdditionalChildMinidump(ProcessHandle childPid, |
|
152 ThreadId childBlamedThread, |
|
153 nsIFile* parentMinidump, |
|
154 const nsACString& name); |
|
155 |
|
156 # if defined(XP_WIN32) || defined(XP_MACOSX) |
|
157 // Parent-side API for children |
|
158 const char* GetChildNotificationPipe(); |
|
159 |
|
160 #ifdef MOZ_CRASHREPORTER_INJECTOR |
|
161 // Inject a crash report client into an arbitrary process, and inform the |
|
162 // callback object when it crashes. Parent process only. |
|
163 |
|
164 class InjectorCrashCallback |
|
165 { |
|
166 public: |
|
167 InjectorCrashCallback() { } |
|
168 |
|
169 /** |
|
170 * Inform the callback of a crash. The client code should call |
|
171 * TakeMinidumpForChild to remove it from the PID mapping table. |
|
172 * |
|
173 * The callback will not be fired if the client has already called |
|
174 * TakeMinidumpForChild for this process ID. |
|
175 */ |
|
176 virtual void OnCrash(DWORD processID) = 0; |
|
177 }; |
|
178 |
|
179 // This method implies OOPInit |
|
180 void InjectCrashReporterIntoProcess(DWORD processID, InjectorCrashCallback* cb); |
|
181 void UnregisterInjectorCallback(DWORD processID); |
|
182 #endif |
|
183 |
|
184 // Child-side API |
|
185 bool SetRemoteExceptionHandler(const nsACString& crashPipe); |
|
186 |
|
187 # elif defined(XP_LINUX) |
|
188 // Parent-side API for children |
|
189 |
|
190 // Set the outparams for crash reporter server's fd (|childCrashFd|) |
|
191 // and the magic fd number it should be remapped to |
|
192 // (|childCrashRemapFd|) before exec() in the child process. |
|
193 // |SetRemoteExceptionHandler()| in the child process expects to find |
|
194 // the server at |childCrashRemapFd|. Return true iff successful. |
|
195 // |
|
196 // If crash reporting is disabled, both outparams will be set to -1 |
|
197 // and |true| will be returned. |
|
198 bool CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd); |
|
199 |
|
200 // Child-side API |
|
201 bool SetRemoteExceptionHandler(); |
|
202 |
|
203 #endif // XP_WIN32 |
|
204 |
|
205 bool UnsetRemoteExceptionHandler(); |
|
206 |
|
207 #if defined(MOZ_WIDGET_ANDROID) |
|
208 // Android builds use a custom library loader, so /proc/<pid>/maps |
|
209 // will just show anonymous mappings for all the non-system |
|
210 // shared libraries. This API is to work around that by providing |
|
211 // info about the shared libraries that are mapped into these anonymous |
|
212 // mappings. |
|
213 void AddLibraryMapping(const char* library_name, |
|
214 uintptr_t start_address, |
|
215 size_t mapping_length, |
|
216 size_t file_offset); |
|
217 |
|
218 #endif |
|
219 } |
|
220 |
|
221 #endif /* nsExceptionHandler_h__ */ |