1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set sw=4 ts=8 et tw=80 :
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Plugin App.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * The Mozilla Foundation
20 : * Portions created by the Initial Developer are Copyright (C) 2010
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Ted Mielczarek <ted.mielczarek@gmail.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 : #include "CrashReporterParent.h"
40 :
41 : #include "base/process_util.h"
42 :
43 : #include <time.h>
44 :
45 : using namespace base;
46 :
47 : namespace mozilla {
48 : namespace dom {
49 :
50 : void
51 0 : CrashReporterParent::ActorDestroy(ActorDestroyReason why)
52 : {
53 : #if defined(__ANDROID__) && defined(MOZ_CRASHREPORTER)
54 : CrashReporter::RemoveLibraryMappingsForChild(ProcessId(OtherProcess()));
55 : #endif
56 0 : }
57 :
58 : bool
59 0 : CrashReporterParent::RecvAddLibraryMappings(const InfallibleTArray<Mapping>& mappings)
60 : {
61 : #if defined(__ANDROID__) && defined(MOZ_CRASHREPORTER)
62 : for (PRUint32 i = 0; i < mappings.Length(); i++) {
63 : const Mapping& m = mappings[i];
64 : CrashReporter::AddLibraryMappingForChild(ProcessId(OtherProcess()),
65 : m.library_name().get(),
66 : m.file_id().get(),
67 : m.start_address(),
68 : m.mapping_length(),
69 : m.file_offset());
70 : }
71 : #endif
72 0 : return true;
73 : }
74 :
75 : bool
76 0 : CrashReporterParent::RecvAnnotateCrashReport(const nsCString& key,
77 : const nsCString& data)
78 : {
79 : #ifdef MOZ_CRASHREPORTER
80 0 : mNotes.Put(key, data);
81 : #endif
82 0 : return true;
83 : }
84 :
85 : bool
86 0 : CrashReporterParent::RecvAppendAppNotes(const nsCString& data)
87 : {
88 0 : mAppNotes.Append(data);
89 0 : return true;
90 : }
91 :
92 0 : CrashReporterParent::CrashReporterParent()
93 0 : : mStartTime(time(NULL))
94 0 : , mInitialized(false)
95 : {
96 0 : MOZ_COUNT_CTOR(CrashReporterParent);
97 :
98 : #ifdef MOZ_CRASHREPORTER
99 0 : mNotes.Init(4);
100 : #endif
101 0 : }
102 :
103 0 : CrashReporterParent::~CrashReporterParent()
104 : {
105 0 : MOZ_COUNT_DTOR(CrashReporterParent);
106 0 : }
107 :
108 : void
109 0 : CrashReporterParent::SetChildData(const NativeThreadId& tid,
110 : const PRUint32& processType)
111 : {
112 0 : mInitialized = true;
113 0 : mMainThread = tid;
114 0 : mProcessType = processType;
115 0 : }
116 :
117 : #ifdef MOZ_CRASHREPORTER
118 : bool
119 0 : CrashReporterParent::GenerateHangCrashReport(const AnnotationTable* processNotes)
120 : {
121 0 : if (mChildDumpID.IsEmpty())
122 0 : return false;
123 :
124 0 : GenerateChildData(processNotes);
125 :
126 0 : CrashReporter::AnnotationTable notes;
127 0 : if (!notes.Init(4))
128 0 : return false;
129 0 : notes.Put(nsDependentCString("HangID"), NS_ConvertUTF16toUTF8(mHangID));
130 0 : if (!CrashReporter::AppendExtraData(mParentDumpID, notes))
131 0 : NS_WARNING("problem appending parent data to .extra");
132 0 : return true;
133 : }
134 :
135 : bool
136 0 : CrashReporterParent::GenerateChildData(const AnnotationTable* processNotes)
137 : {
138 0 : MOZ_ASSERT(mInitialized);
139 :
140 0 : nsCAutoString type;
141 0 : switch (mProcessType) {
142 : case GeckoProcessType_Content:
143 0 : type = NS_LITERAL_CSTRING("content");
144 0 : break;
145 : case GeckoProcessType_Plugin:
146 0 : type = NS_LITERAL_CSTRING("plugin");
147 0 : break;
148 : default:
149 0 : NS_ERROR("unknown process type");
150 0 : break;
151 : }
152 0 : mNotes.Put(NS_LITERAL_CSTRING("ProcessType"), type);
153 :
154 : char startTime[32];
155 0 : sprintf(startTime, "%lld", static_cast<PRInt64>(mStartTime));
156 0 : mNotes.Put(NS_LITERAL_CSTRING("StartupTime"), nsDependentCString(startTime));
157 :
158 0 : if (!mAppNotes.IsEmpty())
159 0 : mNotes.Put(NS_LITERAL_CSTRING("Notes"), mAppNotes);
160 :
161 0 : bool ret = CrashReporter::AppendExtraData(mChildDumpID, mNotes);
162 0 : if (ret && processNotes)
163 0 : ret = CrashReporter::AppendExtraData(mChildDumpID, *processNotes);
164 0 : if (!ret)
165 0 : NS_WARNING("problem appending child data to .extra");
166 0 : return ret;
167 : }
168 : #endif
169 :
170 : } // namespace dom
171 : } // namespace mozilla
|