2007-07-24 18:05:54 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2007-08-08 08:19:57 -07:00
|
|
|
* The Original Code is Mozilla Breakpad integration
|
2007-07-24 18:05:54 -07:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Ted Mielczarek <ted.mielczarek@gmail.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2008-08-27 21:41:38 -07:00
|
|
|
* Josh Aas <josh@mozilla.com>
|
2010-02-09 17:05:31 -08:00
|
|
|
* Justin Dolske <dolske@mozilla.com>
|
2007-07-24 18:05:54 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2007-08-08 08:19:57 -07:00
|
|
|
#include "nsExceptionHandler.h"
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
#if defined(XP_WIN32)
|
2007-07-24 18:05:54 -07:00
|
|
|
#ifdef WIN32_LEAN_AND_MEAN
|
|
|
|
#undef WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
2010-02-09 17:05:31 -08:00
|
|
|
#include "nsIWindowsRegKey.h"
|
2010-01-12 14:00:48 -08:00
|
|
|
#if defined(MOZ_IPC)
|
|
|
|
# include "client/windows/crash_generation/crash_generation_server.h"
|
|
|
|
#endif
|
2007-07-24 18:05:54 -07:00
|
|
|
#include "client/windows/handler/exception_handler.h"
|
2010-01-12 13:14:38 -08:00
|
|
|
#include <DbgHelp.h>
|
2007-07-24 18:05:54 -07:00
|
|
|
#include <string.h>
|
2007-07-24 18:06:00 -07:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
#include "client/mac/handler/exception_handler.h"
|
|
|
|
#include <string>
|
|
|
|
#include <Carbon/Carbon.h>
|
2010-06-20 19:07:59 -07:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
2007-07-24 18:06:00 -07:00
|
|
|
#include <fcntl.h>
|
2007-07-24 18:06:11 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2007-07-24 18:06:09 -07:00
|
|
|
#include "mac_utils.h"
|
2007-07-24 18:06:04 -07:00
|
|
|
#elif defined(XP_LINUX)
|
2010-02-09 17:05:31 -08:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsIINIParser.h"
|
2010-01-12 14:00:48 -08:00
|
|
|
#if defined(MOZ_IPC)
|
2010-03-30 17:24:45 -07:00
|
|
|
# include "common/linux/linux_syscall_support.h"
|
2010-01-14 14:38:00 -08:00
|
|
|
# include "client/linux/crash_generation/client_info.h"
|
2010-01-12 14:00:48 -08:00
|
|
|
# include "client/linux/crash_generation/crash_generation_server.h"
|
|
|
|
#endif
|
2007-07-24 18:06:04 -07:00
|
|
|
#include "client/linux/handler/exception_handler.h"
|
|
|
|
#include <fcntl.h>
|
2007-07-24 18:06:11 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2008-03-19 18:13:36 -07:00
|
|
|
#elif defined(XP_SOLARIS)
|
|
|
|
#include "client/solaris/handler/exception_handler.h"
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2007-07-24 18:05:55 -07:00
|
|
|
#else
|
|
|
|
#error "Not yet implemented for this platform"
|
2007-07-24 18:06:00 -07:00
|
|
|
#endif // defined(XP_WIN32)
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
#include <stdlib.h>
|
2007-07-24 18:06:15 -07:00
|
|
|
#include <time.h>
|
2007-07-24 18:05:54 -07:00
|
|
|
#include <prenv.h>
|
2007-07-24 18:06:14 -07:00
|
|
|
#include <prio.h>
|
2007-11-12 10:53:52 -08:00
|
|
|
#include <prmem.h>
|
2010-01-14 14:38:00 -08:00
|
|
|
#include "mozilla/Mutex.h"
|
2007-07-24 18:05:54 -07:00
|
|
|
#include "nsDebug.h"
|
2007-07-24 18:05:55 -07:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsILocalFile.h"
|
2010-01-14 14:38:00 -08:00
|
|
|
#include "nsIFileStreams.h"
|
|
|
|
#include "nsInterfaceHashtable.h"
|
2010-01-13 07:44:10 -08:00
|
|
|
#include "prprf.h"
|
2010-02-09 17:05:31 -08:00
|
|
|
#include "nsIXULAppInfo.h"
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2010-06-20 19:07:59 -07:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
CFStringRef reporterClientAppID = CFSTR("org.mozilla.crashreporter");
|
|
|
|
#endif
|
|
|
|
|
2010-06-20 20:04:31 -07:00
|
|
|
#if defined(MOZ_IPC)
|
|
|
|
#include "nsIUUIDGenerator.h"
|
|
|
|
|
2010-03-30 10:32:53 -07:00
|
|
|
#if !defined(XP_MACOSX)
|
2010-01-12 13:14:38 -08:00
|
|
|
using google_breakpad::CrashGenerationServer;
|
|
|
|
using google_breakpad::ClientInfo;
|
2010-03-30 10:32:53 -07:00
|
|
|
#endif
|
2010-01-11 12:13:12 -08:00
|
|
|
|
2010-01-14 14:38:00 -08:00
|
|
|
using mozilla::Mutex;
|
|
|
|
using mozilla::MutexAutoLock;
|
2010-06-20 20:04:31 -07:00
|
|
|
#endif // MOZ_IPC
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
namespace CrashReporter {
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
#ifdef XP_WIN32
|
|
|
|
typedef wchar_t XP_CHAR;
|
2010-03-24 14:22:00 -07:00
|
|
|
typedef std::wstring xpstring;
|
2007-07-24 18:06:00 -07:00
|
|
|
#define CONVERT_UTF16_TO_XP_CHAR(x) x
|
2009-04-02 08:41:12 -07:00
|
|
|
#define CONVERT_XP_CHAR_TO_UTF16(x) x
|
2007-07-24 18:06:00 -07:00
|
|
|
#define XP_STRLEN(x) wcslen(x)
|
|
|
|
#define CRASH_REPORTER_FILENAME "crashreporter.exe"
|
|
|
|
#define PATH_SEPARATOR "\\"
|
|
|
|
#define XP_PATH_SEPARATOR L"\\"
|
|
|
|
// sort of arbitrary, but MAX_PATH is kinda small
|
|
|
|
#define XP_PATH_MAX 4096
|
|
|
|
// "<reporter path>" "<minidump path>"
|
|
|
|
#define CMDLINE_SIZE ((XP_PATH_MAX * 2) + 6)
|
2007-08-29 12:46:00 -07:00
|
|
|
#ifdef _USE_32BIT_TIME_T
|
|
|
|
#define XP_TTOA(time, buffer, base) ltoa(time, buffer, base)
|
|
|
|
#else
|
|
|
|
#define XP_TTOA(time, buffer, base) _i64toa(time, buffer, base)
|
|
|
|
#endif
|
2007-07-24 18:06:00 -07:00
|
|
|
#else
|
|
|
|
typedef char XP_CHAR;
|
2010-03-24 14:22:00 -07:00
|
|
|
typedef std::string xpstring;
|
2007-07-24 18:06:00 -07:00
|
|
|
#define CONVERT_UTF16_TO_XP_CHAR(x) NS_ConvertUTF16toUTF8(x)
|
2009-04-02 08:41:12 -07:00
|
|
|
#define CONVERT_XP_CHAR_TO_UTF16(x) NS_ConvertUTF8toUTF16(x)
|
2007-07-24 18:06:00 -07:00
|
|
|
#define XP_STRLEN(x) strlen(x)
|
|
|
|
#define CRASH_REPORTER_FILENAME "crashreporter"
|
|
|
|
#define PATH_SEPARATOR "/"
|
|
|
|
#define XP_PATH_SEPARATOR "/"
|
|
|
|
#define XP_PATH_MAX PATH_MAX
|
2007-08-29 12:46:00 -07:00
|
|
|
#define XP_TTOA(time, buffer, base) sprintf(buffer, "%ld", time)
|
2007-07-24 18:06:00 -07:00
|
|
|
#endif // XP_WIN32
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
static const XP_CHAR dumpFileExtension[] = {'.', 'd', 'm', 'p',
|
|
|
|
'\0'}; // .dmp
|
|
|
|
static const XP_CHAR extraFileExtension[] = {'.', 'e', 'x', 't',
|
|
|
|
'r', 'a', '\0'}; // .extra
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:05:56 -07:00
|
|
|
static google_breakpad::ExceptionHandler* gExceptionHandler = nsnull;
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
static XP_CHAR* crashReporterPath;
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:02 -07:00
|
|
|
// if this is false, we don't launch the crash reporter
|
|
|
|
static bool doReport = true;
|
|
|
|
|
2007-07-24 18:06:09 -07:00
|
|
|
// if this is true, we pass the exception on to the OS crash reporter
|
|
|
|
static bool showOSCrashReporter = false;
|
|
|
|
|
2007-08-29 12:46:00 -07:00
|
|
|
// The time of the last recorded crash, as a time_t value.
|
|
|
|
static time_t lastCrashTime = 0;
|
|
|
|
// The pathname of a file to store the crash time in
|
|
|
|
static XP_CHAR lastCrashTimeFilename[XP_PATH_MAX] = {0};
|
|
|
|
|
|
|
|
// these are just here for readability
|
|
|
|
static const char kCrashTimeParameter[] = "CrashTime=";
|
|
|
|
static const int kCrashTimeParameterLen = sizeof(kCrashTimeParameter)-1;
|
|
|
|
|
|
|
|
static const char kTimeSinceLastCrashParameter[] = "SecondsSinceLastCrash=";
|
|
|
|
static const int kTimeSinceLastCrashParameterLen =
|
|
|
|
sizeof(kTimeSinceLastCrashParameter)-1;
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
// this holds additional data sent via the API
|
2010-03-24 14:22:01 -07:00
|
|
|
static AnnotationTable* crashReporterAPIData_Hash;
|
2007-07-24 18:05:58 -07:00
|
|
|
static nsCString* crashReporterAPIData = nsnull;
|
2008-07-27 10:08:03 -07:00
|
|
|
static nsCString* notesField = nsnull;
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2010-01-12 14:00:48 -08:00
|
|
|
#if defined(MOZ_IPC)
|
2010-03-30 10:32:53 -07:00
|
|
|
#if !defined(XP_MACOSX)
|
2010-01-12 13:14:38 -08:00
|
|
|
// OOP crash reporting
|
|
|
|
static CrashGenerationServer* crashServer; // chrome process has this
|
2010-03-30 10:32:53 -07:00
|
|
|
#endif
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2010-01-12 14:00:48 -08:00
|
|
|
# if defined(XP_WIN)
|
2010-01-12 13:14:38 -08:00
|
|
|
// If crash reporting is disabled, we hand out this "null" pipe to the
|
|
|
|
// child process and don't attempt to connect to a parent server.
|
|
|
|
static const char kNullNotifyPipe[] = "-";
|
2010-01-13 07:44:10 -08:00
|
|
|
static char* childCrashNotifyPipe;
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2010-01-12 14:00:48 -08:00
|
|
|
# elif defined(XP_LINUX)
|
2010-01-12 13:14:38 -08:00
|
|
|
static int serverSocketFd = -1;
|
|
|
|
static int clientSocketFd = -1;
|
|
|
|
static const int kMagicChildCrashReportFd = 42;
|
2010-01-12 14:00:48 -08:00
|
|
|
# endif
|
2010-01-14 14:38:00 -08:00
|
|
|
|
|
|
|
// |dumpMapLock| must protect all access to |pidToMinidump|.
|
|
|
|
static Mutex* dumpMapLock;
|
2010-03-24 14:22:01 -07:00
|
|
|
typedef nsInterfaceHashtable<nsUint32HashKey, nsILocalFile> ChildMinidumpMap;
|
2010-01-14 14:38:00 -08:00
|
|
|
static ChildMinidumpMap* pidToMinidump;
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
// Crashreporter annotations that we don't send along in subprocess
|
|
|
|
// reports
|
|
|
|
static const char* kSubprocessBlacklist[] = {
|
|
|
|
"FramePoisonBase",
|
|
|
|
"FramePoisonSize",
|
|
|
|
"StartupTime",
|
|
|
|
"URL"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-01-12 14:00:48 -08:00
|
|
|
#endif // MOZ_IPC
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
static void
|
|
|
|
CreateFileFromPath(const xpstring& path, nsILocalFile** file)
|
|
|
|
{
|
|
|
|
NS_NewLocalFile(nsDependentString(path.c_str()), PR_FALSE, file);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void
|
|
|
|
CreateFileFromPath(const xpstring& path, nsILocalFile** file)
|
|
|
|
{
|
|
|
|
NS_NewNativeLocalFile(nsDependentCString(path.c_str()), PR_FALSE, file);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
static XP_CHAR*
|
|
|
|
Concat(XP_CHAR* str, const XP_CHAR* toAppend, int* size)
|
|
|
|
{
|
|
|
|
int appendLen = XP_STRLEN(toAppend);
|
|
|
|
if (appendLen >= *size) appendLen = *size - 1;
|
|
|
|
|
|
|
|
memcpy(str, toAppend, appendLen * sizeof(XP_CHAR));
|
|
|
|
str += appendLen;
|
|
|
|
*str = '\0';
|
|
|
|
*size -= appendLen;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MinidumpCallback(const XP_CHAR* dump_path,
|
|
|
|
const XP_CHAR* minidump_id,
|
|
|
|
void* context,
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion,
|
|
|
|
#endif
|
2007-07-24 18:05:56 -07:00
|
|
|
bool succeeded)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:06:09 -07:00
|
|
|
bool returnValue = showOSCrashReporter ? false : succeeded;
|
2007-07-24 18:06:06 -07:00
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
XP_CHAR minidumpPath[XP_PATH_MAX];
|
|
|
|
int size = XP_PATH_MAX;
|
|
|
|
XP_CHAR* p = Concat(minidumpPath, dump_path, &size);
|
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
p = Concat(p, minidump_id, &size);
|
|
|
|
Concat(p, dumpFileExtension, &size);
|
|
|
|
|
|
|
|
XP_CHAR extraDataPath[XP_PATH_MAX];
|
|
|
|
size = XP_PATH_MAX;
|
|
|
|
p = Concat(extraDataPath, dump_path, &size);
|
|
|
|
p = Concat(p, XP_PATH_SEPARATOR, &size);
|
|
|
|
p = Concat(p, minidump_id, &size);
|
|
|
|
Concat(p, extraFileExtension, &size);
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-08-29 12:46:00 -07:00
|
|
|
// calculate time since last crash (if possible), and store
|
|
|
|
// the time of this crash.
|
|
|
|
time_t crashTime = time(NULL);
|
|
|
|
time_t timeSinceLastCrash = 0;
|
|
|
|
// stringified versions of the above
|
|
|
|
char crashTimeString[32];
|
|
|
|
int crashTimeStringLen = 0;
|
|
|
|
char timeSinceLastCrashString[32];
|
|
|
|
int timeSinceLastCrashStringLen = 0;
|
|
|
|
|
|
|
|
XP_TTOA(crashTime, crashTimeString, 10);
|
|
|
|
crashTimeStringLen = strlen(crashTimeString);
|
|
|
|
if (lastCrashTime != 0) {
|
|
|
|
timeSinceLastCrash = crashTime - lastCrashTime;
|
|
|
|
XP_TTOA(timeSinceLastCrash, timeSinceLastCrashString, 10);
|
|
|
|
timeSinceLastCrashStringLen = strlen(timeSinceLastCrashString);
|
|
|
|
}
|
|
|
|
// write crash time to file
|
|
|
|
if (lastCrashTimeFilename[0] != 0) {
|
|
|
|
#if defined(XP_WIN32)
|
|
|
|
HANDLE hFile = CreateFile(lastCrashTimeFilename, GENERIC_WRITE, 0,
|
|
|
|
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
|
|
|
if(hFile != INVALID_HANDLE_VALUE) {
|
|
|
|
DWORD nBytes;
|
|
|
|
WriteFile(hFile, crashTimeString, crashTimeStringLen, &nBytes, NULL);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
int fd = open(lastCrashTimeFilename,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC,
|
|
|
|
0600);
|
|
|
|
if (fd != -1) {
|
2010-01-14 14:38:00 -08:00
|
|
|
ssize_t ignored = write(fd, crashTimeString, crashTimeStringLen);
|
|
|
|
(void)ignored;
|
2007-08-29 12:46:00 -07:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2007-08-29 12:46:00 -07:00
|
|
|
#if defined(XP_WIN32)
|
2007-07-24 18:06:00 -07:00
|
|
|
XP_CHAR cmdLine[CMDLINE_SIZE];
|
|
|
|
size = CMDLINE_SIZE;
|
|
|
|
p = Concat(cmdLine, L"\"", &size);
|
|
|
|
p = Concat(p, crashReporterPath, &size);
|
|
|
|
p = Concat(p, L"\" \"", &size);
|
|
|
|
p = Concat(p, minidumpPath, &size);
|
|
|
|
Concat(p, L"\"", &size);
|
|
|
|
|
2007-07-24 18:05:58 -07:00
|
|
|
if (!crashReporterAPIData->IsEmpty()) {
|
2007-07-24 18:05:55 -07:00
|
|
|
// write out API data
|
2007-07-24 18:06:00 -07:00
|
|
|
HANDLE hFile = CreateFile(extraDataPath, GENERIC_WRITE, 0,
|
2007-07-24 18:05:55 -07:00
|
|
|
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
|
|
|
if(hFile != INVALID_HANDLE_VALUE) {
|
|
|
|
DWORD nBytes;
|
2007-07-24 18:05:58 -07:00
|
|
|
WriteFile(hFile, crashReporterAPIData->get(),
|
|
|
|
crashReporterAPIData->Length(), &nBytes, NULL);
|
2007-08-29 12:46:00 -07:00
|
|
|
WriteFile(hFile, kCrashTimeParameter, kCrashTimeParameterLen,
|
|
|
|
&nBytes, NULL);
|
|
|
|
WriteFile(hFile, crashTimeString, crashTimeStringLen, &nBytes, NULL);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, NULL);
|
|
|
|
if (timeSinceLastCrash != 0) {
|
|
|
|
WriteFile(hFile, kTimeSinceLastCrashParameter,
|
|
|
|
kTimeSinceLastCrashParameterLen, &nBytes, NULL);
|
|
|
|
WriteFile(hFile, timeSinceLastCrashString, timeSinceLastCrashStringLen,
|
|
|
|
&nBytes, NULL);
|
|
|
|
WriteFile(hFile, "\n", 1, &nBytes, NULL);
|
|
|
|
}
|
2007-07-24 18:05:55 -07:00
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:02 -07:00
|
|
|
if (!doReport) {
|
2007-07-24 18:06:09 -07:00
|
|
|
return returnValue;
|
2007-07-24 18:06:02 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
STARTUPINFO si;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
|
|
|
ZeroMemory(&si, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
ZeroMemory(&pi, sizeof(pi));
|
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
if (CreateProcess(NULL, (LPWSTR)cmdLine, NULL, NULL, FALSE, 0,
|
2007-07-24 18:05:55 -07:00
|
|
|
NULL, NULL, &si, &pi)) {
|
2007-07-24 18:05:54 -07:00
|
|
|
CloseHandle( pi.hProcess );
|
|
|
|
CloseHandle( pi.hThread );
|
|
|
|
}
|
|
|
|
// we're not really in a position to do anything if the CreateProcess fails
|
|
|
|
TerminateProcess(GetCurrentProcess(), 1);
|
2007-07-24 18:06:00 -07:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
if (!crashReporterAPIData->IsEmpty()) {
|
|
|
|
// write out API data
|
|
|
|
int fd = open(extraDataPath,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC,
|
|
|
|
0666);
|
|
|
|
|
|
|
|
if (fd != -1) {
|
|
|
|
// not much we can do in case of error
|
2010-01-14 14:38:00 -08:00
|
|
|
ssize_t ignored = write(fd, crashReporterAPIData->get(),
|
|
|
|
crashReporterAPIData->Length());
|
|
|
|
ignored = write(fd, kCrashTimeParameter, kCrashTimeParameterLen);
|
|
|
|
ignored = write(fd, crashTimeString, crashTimeStringLen);
|
|
|
|
ignored = write(fd, "\n", 1);
|
2007-08-29 12:46:00 -07:00
|
|
|
if (timeSinceLastCrash != 0) {
|
2010-01-14 14:38:00 -08:00
|
|
|
ignored = write(fd, kTimeSinceLastCrashParameter,
|
|
|
|
kTimeSinceLastCrashParameterLen);
|
|
|
|
ignored = write(fd, timeSinceLastCrashString,
|
|
|
|
timeSinceLastCrashStringLen);
|
|
|
|
ignored = write(fd, "\n", 1);
|
2007-08-29 12:46:00 -07:00
|
|
|
}
|
2007-07-24 18:06:00 -07:00
|
|
|
close (fd);
|
|
|
|
}
|
2007-07-24 18:05:55 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:02 -07:00
|
|
|
if (!doReport) {
|
2007-07-24 18:06:09 -07:00
|
|
|
return returnValue;
|
2007-07-24 18:06:02 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
pid_t pid = fork();
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
if (pid == -1)
|
|
|
|
return false;
|
|
|
|
else if (pid == 0) {
|
2007-12-10 10:47:29 -08:00
|
|
|
// need to clobber this, as libcurl might load NSS,
|
|
|
|
// and we want it to load the system NSS.
|
|
|
|
unsetenv("LD_LIBRARY_PATH");
|
2007-07-24 18:06:00 -07:00
|
|
|
(void) execl(crashReporterPath,
|
|
|
|
crashReporterPath, minidumpPath, (char*)0);
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:06:09 -07:00
|
|
|
return returnValue;
|
2007-07-24 18:05:55 -07:00
|
|
|
}
|
|
|
|
|
2010-01-11 10:16:20 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
/**
|
|
|
|
* Filters out floating point exceptions which are handled by nsSigHandlers.cpp
|
|
|
|
* and should not be handled as crashes.
|
|
|
|
*/
|
|
|
|
static bool FPEFilter(void* context, EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion)
|
|
|
|
{
|
2010-05-04 12:34:55 -07:00
|
|
|
if (!exinfo)
|
|
|
|
return true;
|
|
|
|
|
2010-01-11 10:16:20 -08:00
|
|
|
PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)exinfo->ExceptionRecord;
|
|
|
|
switch (e->ExceptionCode) {
|
|
|
|
case STATUS_FLOAT_DENORMAL_OPERAND:
|
|
|
|
case STATUS_FLOAT_DIVIDE_BY_ZERO:
|
|
|
|
case STATUS_FLOAT_INEXACT_RESULT:
|
|
|
|
case STATUS_FLOAT_INVALID_OPERATION:
|
|
|
|
case STATUS_FLOAT_OVERFLOW:
|
|
|
|
case STATUS_FLOAT_STACK_CHECK:
|
|
|
|
case STATUS_FLOAT_UNDERFLOW:
|
|
|
|
case STATUS_FLOAT_MULTIPLE_FAULTS:
|
|
|
|
case STATUS_FLOAT_MULTIPLE_TRAPS:
|
|
|
|
return false; // Don't write minidump, continue exception search
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // XP_WIN
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
static bool ShouldReport()
|
|
|
|
{
|
|
|
|
// this environment variable prevents us from launching
|
|
|
|
// the crash reporter client
|
|
|
|
const char *envvar = PR_GetEnv("MOZ_CRASHREPORTER_NO_REPORT");
|
|
|
|
return !(envvar && *envvar);
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
nsresult SetExceptionHandler(nsILocalFile* aXREDirectory,
|
2009-04-02 08:41:12 -07:00
|
|
|
bool force/*=false*/)
|
2007-07-24 18:05:55 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (gExceptionHandler)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
2007-07-24 18:06:10 -07:00
|
|
|
const char *envvar = PR_GetEnv("MOZ_CRASHREPORTER_DISABLE");
|
2009-04-02 08:41:12 -07:00
|
|
|
if (envvar && *envvar && !force)
|
2007-07-24 18:06:10 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-24 18:06:02 -07:00
|
|
|
// this environment variable prevents us from launching
|
|
|
|
// the crash reporter client
|
2010-03-24 14:22:00 -07:00
|
|
|
doReport = ShouldReport();
|
2007-07-24 18:06:02 -07:00
|
|
|
|
2007-07-24 18:05:58 -07:00
|
|
|
// allocate our strings
|
|
|
|
crashReporterAPIData = new nsCString();
|
|
|
|
NS_ENSURE_TRUE(crashReporterAPIData, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2007-07-24 18:05:59 -07:00
|
|
|
crashReporterAPIData_Hash =
|
|
|
|
new nsDataHashtable<nsCStringHashKey,nsCString>();
|
|
|
|
NS_ENSURE_TRUE(crashReporterAPIData_Hash, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
rv = crashReporterAPIData_Hash->Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-07-27 10:08:03 -07:00
|
|
|
notesField = new nsCString();
|
|
|
|
NS_ENSURE_TRUE(notesField, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
// locate crashreporter executable
|
2007-07-24 18:06:05 -07:00
|
|
|
nsCOMPtr<nsIFile> exePath;
|
|
|
|
rv = aXREDirectory->Clone(getter_AddRefs(exePath));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-07-24 18:06:06 -07:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
exePath->Append(NS_LITERAL_STRING("crashreporter.app"));
|
|
|
|
exePath->Append(NS_LITERAL_STRING("Contents"));
|
|
|
|
exePath->Append(NS_LITERAL_STRING("MacOS"));
|
|
|
|
#endif
|
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
exePath->AppendNative(NS_LITERAL_CSTRING(CRASH_REPORTER_FILENAME));
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
#ifdef XP_WIN32
|
2007-07-24 18:06:05 -07:00
|
|
|
nsString crashReporterPath_temp;
|
|
|
|
exePath->GetPath(crashReporterPath_temp);
|
2007-07-24 18:05:58 -07:00
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
crashReporterPath = ToNewUnicode(crashReporterPath_temp);
|
|
|
|
#else
|
|
|
|
nsCString crashReporterPath_temp;
|
|
|
|
exePath->GetNativePath(crashReporterPath_temp);
|
|
|
|
|
|
|
|
crashReporterPath = ToNewCString(crashReporterPath_temp);
|
|
|
|
#endif
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
// get temp path to use for minidump path
|
2007-07-24 18:06:04 -07:00
|
|
|
#if defined(XP_WIN32)
|
2007-09-15 06:39:05 -07:00
|
|
|
nsString tempPath;
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
// first figure out buffer size
|
|
|
|
int pathLen = GetTempPath(0, NULL);
|
|
|
|
if (pathLen == 0)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
tempPath.SetLength(pathLen);
|
|
|
|
GetTempPath(pathLen, (LPWSTR)tempPath.BeginWriting());
|
2007-07-24 18:06:00 -07:00
|
|
|
#elif defined(XP_MACOSX)
|
2007-09-15 06:39:05 -07:00
|
|
|
nsCString tempPath;
|
2007-07-24 18:06:00 -07:00
|
|
|
FSRef fsRef;
|
|
|
|
OSErr err = FSFindFolder(kUserDomain, kTemporaryFolderType,
|
|
|
|
kCreateFolder, &fsRef);
|
|
|
|
if (err != noErr)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:01 -07:00
|
|
|
char path[PATH_MAX];
|
|
|
|
OSStatus status = FSRefMakePath(&fsRef, (UInt8*)path, PATH_MAX);
|
2007-07-24 18:06:00 -07:00
|
|
|
if (status != noErr)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-09-15 06:39:05 -07:00
|
|
|
|
|
|
|
tempPath = path;
|
2007-07-24 18:06:01 -07:00
|
|
|
|
2007-07-24 18:06:04 -07:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
// we assume it's always /tmp on unix systems
|
2007-09-15 06:39:05 -07:00
|
|
|
nsCString tempPath = NS_LITERAL_CSTRING("/tmp/");
|
2007-07-24 18:06:00 -07:00
|
|
|
#else
|
2007-09-15 06:39:05 -07:00
|
|
|
#error "Implement this for your platform"
|
2007-07-24 18:06:00 -07:00
|
|
|
#endif
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2010-06-29 10:19:09 -07:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
// During a crash we must not enter the dynamic loader for symbol
|
|
|
|
// resolution. The symbols used from within the exception handler
|
|
|
|
// which might not be called by the application during normal run
|
|
|
|
// should be early-resolved by calling them from here. See bug 573290.
|
|
|
|
int fd = open("/dev/null", O_RDONLY);
|
|
|
|
close(fd);
|
|
|
|
write(-1, NULL, 0);
|
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
// now set the exception handler
|
2007-07-24 18:06:00 -07:00
|
|
|
gExceptionHandler = new google_breakpad::
|
2007-09-15 06:39:05 -07:00
|
|
|
ExceptionHandler(tempPath.get(),
|
2010-01-11 10:16:20 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
FPEFilter,
|
|
|
|
#else
|
2007-07-24 18:06:00 -07:00
|
|
|
nsnull,
|
2010-01-11 10:16:20 -08:00
|
|
|
#endif
|
2007-07-24 18:06:00 -07:00
|
|
|
MinidumpCallback,
|
|
|
|
nsnull,
|
2007-07-24 18:06:13 -07:00
|
|
|
#if defined(XP_WIN32)
|
|
|
|
google_breakpad::ExceptionHandler::HANDLER_ALL);
|
|
|
|
#else
|
2007-07-24 18:06:00 -07:00
|
|
|
true);
|
2007-07-24 18:06:13 -07:00
|
|
|
#endif
|
2007-07-24 18:05:55 -07:00
|
|
|
|
|
|
|
if (!gExceptionHandler)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-12-21 13:49:32 -08:00
|
|
|
// store application start time
|
|
|
|
char timeString[32];
|
|
|
|
XP_TTOA(time(NULL), timeString, 10);
|
|
|
|
AnnotateCrashReport(NS_LITERAL_CSTRING("StartupTime"),
|
|
|
|
nsDependentCString(timeString));
|
|
|
|
|
2007-07-24 18:06:09 -07:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// On OS X, many testers like to see the OS crash reporting dialog
|
|
|
|
// since it offers immediate stack traces. We allow them to set
|
|
|
|
// a default to pass exceptions to the OS handler.
|
2010-06-20 19:07:59 -07:00
|
|
|
Boolean keyExistsAndHasValidFormat = false;
|
|
|
|
Boolean prefValue = ::CFPreferencesGetAppBooleanValue(CFSTR("OSCrashReporter"),
|
|
|
|
kCFPreferencesCurrentApplication,
|
|
|
|
&keyExistsAndHasValidFormat);
|
|
|
|
if (keyExistsAndHasValidFormat)
|
|
|
|
showOSCrashReporter = prefValue;
|
2007-07-24 18:06:09 -07:00
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-02 08:41:12 -07:00
|
|
|
bool GetEnabled()
|
|
|
|
{
|
2010-07-23 08:24:52 -07:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
return gExceptionHandler != nsnull;
|
|
|
|
#else
|
2010-07-22 23:28:55 -07:00
|
|
|
return gExceptionHandler != nsnull && !gExceptionHandler->IsOutOfProcess();
|
2010-07-23 08:24:52 -07:00
|
|
|
#endif
|
2009-04-02 08:41:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GetMinidumpPath(nsAString& aPath)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aPath = CONVERT_XP_CHAR_TO_UTF16(gExceptionHandler->dump_path().c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
nsresult SetMinidumpPath(const nsAString& aPath)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:05:55 -07:00
|
|
|
if (!gExceptionHandler)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
gExceptionHandler->set_dump_path(CONVERT_UTF16_TO_XP_CHAR(aPath).BeginReading());
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:14 -07:00
|
|
|
static nsresult
|
|
|
|
WriteDataToFile(nsIFile* aFile, const nsACString& data)
|
|
|
|
{
|
2007-09-15 06:39:05 -07:00
|
|
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile);
|
|
|
|
NS_ENSURE_TRUE(localFile, NS_ERROR_FAILURE);
|
2007-07-24 18:06:14 -07:00
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
PRFileDesc* fd;
|
|
|
|
nsresult rv = localFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 00600,
|
|
|
|
&fd);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-24 18:06:14 -07:00
|
|
|
|
|
|
|
rv = NS_OK;
|
|
|
|
if (PR_Write(fd, data.Data(), data.Length()) == -1) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
PR_Close(fd);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
GetFileContents(nsIFile* aFile, nsACString& data)
|
|
|
|
{
|
2007-09-15 06:39:05 -07:00
|
|
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile);
|
|
|
|
NS_ENSURE_TRUE(localFile, NS_ERROR_FAILURE);
|
2007-07-24 18:06:14 -07:00
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
PRFileDesc* fd;
|
|
|
|
nsresult rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-24 18:06:14 -07:00
|
|
|
|
|
|
|
rv = NS_OK;
|
|
|
|
PRInt32 filesize = PR_Available(fd);
|
|
|
|
if (filesize <= 0) {
|
|
|
|
rv = NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.SetLength(filesize);
|
|
|
|
if (PR_Read(fd, data.BeginWriting(), filesize) == -1) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PR_Close(fd);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function typedef for initializing a piece of data that we
|
|
|
|
// don't already have.
|
|
|
|
typedef nsresult (*InitDataFunc)(nsACString&);
|
|
|
|
|
|
|
|
// Attempt to read aFile's contents into aContents, if aFile
|
|
|
|
// does not exist, create it and initialize its contents
|
|
|
|
// by calling aInitFunc for the data.
|
2007-09-26 11:35:21 -07:00
|
|
|
static nsresult
|
2007-09-15 06:39:05 -07:00
|
|
|
GetOrInit(nsIFile* aDir, const nsACString& filename,
|
2007-07-24 18:06:15 -07:00
|
|
|
nsACString& aContents, InitDataFunc aInitFunc)
|
2007-07-24 18:06:14 -07:00
|
|
|
{
|
|
|
|
PRBool exists;
|
2007-07-24 18:06:15 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> dataFile;
|
|
|
|
nsresult rv = aDir->Clone(getter_AddRefs(dataFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
rv = dataFile->AppendNative(filename);
|
2007-07-24 18:06:15 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = dataFile->Exists(&exists);
|
2007-07-24 18:06:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!exists) {
|
2007-08-29 12:46:00 -07:00
|
|
|
if (aInitFunc) {
|
|
|
|
// get the initial value and write it to the file
|
|
|
|
rv = aInitFunc(aContents);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = WriteDataToFile(dataFile, aContents);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// didn't pass in an init func
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-07-24 18:06:15 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// just get the file's contents
|
|
|
|
rv = GetFileContents(dataFile, aContents);
|
2007-07-24 18:06:14 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:15 -07:00
|
|
|
return rv;
|
2007-07-24 18:06:14 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:15 -07:00
|
|
|
// Init the "install time" data. We're taking an easy way out here
|
|
|
|
// and just setting this to "the time when this version was first run".
|
|
|
|
static nsresult
|
|
|
|
InitInstallTime(nsACString& aInstallTime)
|
|
|
|
{
|
|
|
|
time_t t = time(NULL);
|
|
|
|
char buf[16];
|
|
|
|
sprintf(buf, "%ld", t);
|
|
|
|
aInstallTime = buf;
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2007-07-24 18:06:15 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-29 12:46:00 -07:00
|
|
|
// Annotate the crash report with a Unique User ID and time
|
|
|
|
// since install. Also do some prep work for recording
|
|
|
|
// time since last crash, which must be calculated at
|
|
|
|
// crash time.
|
2007-07-24 18:06:14 -07:00
|
|
|
// If any piece of data doesn't exist, initialize it first.
|
2007-07-24 18:06:15 -07:00
|
|
|
nsresult SetupExtraData(nsILocalFile* aAppDataDirectory,
|
|
|
|
const nsACString& aBuildID)
|
2007-07-24 18:06:14 -07:00
|
|
|
{
|
2007-08-29 12:46:00 -07:00
|
|
|
nsCOMPtr<nsIFile> dataDirectory;
|
|
|
|
nsresult rv = aAppDataDirectory->Clone(getter_AddRefs(dataDirectory));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
rv = dataDirectory->AppendNative(NS_LITERAL_CSTRING("Crash Reports"));
|
2007-07-24 18:06:14 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-04 13:38:38 -07:00
|
|
|
PRBool exists;
|
|
|
|
rv = dataDirectory->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!exists) {
|
2007-09-04 16:03:53 -07:00
|
|
|
rv = dataDirectory->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
2007-09-04 13:38:38 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2007-09-26 11:35:21 -07:00
|
|
|
#if defined(XP_WIN32)
|
2008-06-24 13:15:35 -07:00
|
|
|
nsAutoString dataDirEnv(NS_LITERAL_STRING("MOZ_CRASHREPORTER_DATA_DIRECTORY="));
|
|
|
|
|
2007-09-26 11:35:21 -07:00
|
|
|
nsAutoString dataDirectoryPath;
|
|
|
|
rv = dataDirectory->GetPath(dataDirectoryPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-06-24 13:15:35 -07:00
|
|
|
dataDirEnv.Append(dataDirectoryPath);
|
|
|
|
|
|
|
|
_wputenv(dataDirEnv.get());
|
2007-09-26 11:35:21 -07:00
|
|
|
#else
|
2008-06-24 13:15:35 -07:00
|
|
|
// Save this path in the environment for the crash reporter application.
|
|
|
|
nsCAutoString dataDirEnv("MOZ_CRASHREPORTER_DATA_DIRECTORY=");
|
|
|
|
|
2007-09-26 11:35:21 -07:00
|
|
|
nsCAutoString dataDirectoryPath;
|
|
|
|
rv = dataDirectory->GetNativePath(dataDirectoryPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
dataDirEnv.Append(dataDirectoryPath);
|
|
|
|
|
|
|
|
char* env = ToNewCString(dataDirEnv);
|
|
|
|
NS_ENSURE_TRUE(env, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
PR_SetEnv(env);
|
2008-06-24 13:15:35 -07:00
|
|
|
#endif
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2007-07-24 18:06:15 -07:00
|
|
|
nsCAutoString data;
|
2007-08-29 12:46:00 -07:00
|
|
|
if(NS_SUCCEEDED(GetOrInit(dataDirectory,
|
2007-09-15 06:39:05 -07:00
|
|
|
NS_LITERAL_CSTRING("InstallTime") + aBuildID,
|
2007-07-24 18:06:15 -07:00
|
|
|
data, InitInstallTime)))
|
|
|
|
AnnotateCrashReport(NS_LITERAL_CSTRING("InstallTime"), data);
|
|
|
|
|
2007-08-29 12:46:00 -07:00
|
|
|
// this is a little different, since we can't init it with anything,
|
|
|
|
// since it's stored at crash time, and we can't annotate the
|
|
|
|
// crash report with the stored value, since we really want
|
|
|
|
// (now - LastCrash), so we just get a value if it exists,
|
|
|
|
// and store it in a time_t value.
|
2007-09-15 06:39:05 -07:00
|
|
|
if(NS_SUCCEEDED(GetOrInit(dataDirectory, NS_LITERAL_CSTRING("LastCrash"),
|
2007-08-29 12:46:00 -07:00
|
|
|
data, NULL))) {
|
|
|
|
lastCrashTime = (time_t)atol(data.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
// not really the best place to init this, but I have the path I need here
|
|
|
|
nsCOMPtr<nsIFile> lastCrashFile;
|
|
|
|
rv = dataDirectory->Clone(getter_AddRefs(lastCrashFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-15 06:39:05 -07:00
|
|
|
rv = lastCrashFile->AppendNative(NS_LITERAL_CSTRING("LastCrash"));
|
2007-08-29 12:46:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
memset(lastCrashTimeFilename, 0, sizeof(lastCrashTimeFilename));
|
|
|
|
|
|
|
|
#if defined(XP_WIN32)
|
|
|
|
nsAutoString filename;
|
|
|
|
rv = lastCrashFile->GetPath(filename);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (filename.Length() < XP_PATH_MAX)
|
|
|
|
wcsncpy(lastCrashTimeFilename, filename.get(), filename.Length());
|
|
|
|
#else
|
|
|
|
nsCAutoString filename;
|
|
|
|
rv = lastCrashFile->GetNativePath(filename);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (filename.Length() < XP_PATH_MAX)
|
|
|
|
strncpy(lastCrashTimeFilename, filename.get(), filename.Length());
|
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:06:14 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-20 18:17:40 -08:00
|
|
|
static void OOPDeinit();
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
nsresult UnsetExceptionHandler()
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2009-07-23 08:23:19 -07:00
|
|
|
delete gExceptionHandler;
|
|
|
|
|
2007-07-24 18:05:58 -07:00
|
|
|
// do this here in the unlikely case that we succeeded in allocating
|
|
|
|
// our strings but failed to allocate gExceptionHandler.
|
2007-07-24 18:05:59 -07:00
|
|
|
if (crashReporterAPIData_Hash) {
|
|
|
|
delete crashReporterAPIData_Hash;
|
|
|
|
crashReporterAPIData_Hash = nsnull;
|
|
|
|
}
|
2007-10-24 17:37:18 -07:00
|
|
|
|
|
|
|
if (crashReporterAPIData) {
|
|
|
|
delete crashReporterAPIData;
|
|
|
|
crashReporterAPIData = nsnull;
|
|
|
|
}
|
|
|
|
|
2008-07-27 10:08:03 -07:00
|
|
|
if (notesField) {
|
|
|
|
delete notesField;
|
|
|
|
notesField = nsnull;
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:00 -07:00
|
|
|
if (crashReporterPath) {
|
|
|
|
NS_Free(crashReporterPath);
|
|
|
|
crashReporterPath = nsnull;
|
|
|
|
}
|
2007-07-24 18:05:58 -07:00
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
if (!gExceptionHandler)
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
gExceptionHandler = nsnull;
|
|
|
|
|
2010-01-20 18:17:40 -08:00
|
|
|
#ifdef MOZ_IPC
|
|
|
|
OOPDeinit();
|
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReplaceChar(nsCString& str, const nsACString& character,
|
|
|
|
const nsACString& replacement)
|
|
|
|
{
|
|
|
|
nsCString::const_iterator start, end;
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
str.BeginReading(start);
|
|
|
|
str.EndReading(end);
|
|
|
|
|
|
|
|
while (FindInReadable(character, start, end)) {
|
|
|
|
PRInt32 pos = end.size_backward();
|
|
|
|
str.Replace(pos - 1, 1, replacement);
|
|
|
|
|
|
|
|
str.BeginReading(start);
|
|
|
|
start.advance(pos + replacement.Length() - 1);
|
|
|
|
str.EndReading(end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool DoFindInReadable(const nsACString& str, const nsACString& value)
|
|
|
|
{
|
|
|
|
nsACString::const_iterator start, end;
|
|
|
|
str.BeginReading(start);
|
|
|
|
str.EndReading(end);
|
|
|
|
|
|
|
|
return FindInReadable(value, start, end);
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator EnumerateEntries(const nsACString& key,
|
|
|
|
nsCString entry,
|
|
|
|
void* userData)
|
2007-07-24 18:05:59 -07:00
|
|
|
{
|
|
|
|
crashReporterAPIData->Append(key + NS_LITERAL_CSTRING("=") + entry +
|
|
|
|
NS_LITERAL_CSTRING("\n"));
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2008-07-27 10:08:03 -07:00
|
|
|
nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data)
|
2007-07-24 18:05:55 -07:00
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
if (DoFindInReadable(key, NS_LITERAL_CSTRING("=")) ||
|
|
|
|
DoFindInReadable(key, NS_LITERAL_CSTRING("\n")))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2007-07-24 18:05:57 -07:00
|
|
|
if (DoFindInReadable(data, NS_LITERAL_CSTRING("\0")))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
nsCString escapedData(data);
|
2007-09-26 11:35:21 -07:00
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
// escape backslashes
|
|
|
|
ReplaceChar(escapedData, NS_LITERAL_CSTRING("\\"),
|
|
|
|
NS_LITERAL_CSTRING("\\\\"));
|
|
|
|
// escape newlines
|
|
|
|
ReplaceChar(escapedData, NS_LITERAL_CSTRING("\n"),
|
|
|
|
NS_LITERAL_CSTRING("\\n"));
|
|
|
|
|
2007-07-24 18:05:59 -07:00
|
|
|
nsresult rv = crashReporterAPIData_Hash->Put(key, escapedData);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// now rebuild the file contents
|
|
|
|
crashReporterAPIData->Truncate(0);
|
|
|
|
crashReporterAPIData_Hash->EnumerateRead(EnumerateEntries,
|
|
|
|
crashReporterAPIData);
|
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2008-07-27 10:08:03 -07:00
|
|
|
nsresult AppendAppNotesToCrashReport(const nsACString& data)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
if (DoFindInReadable(data, NS_LITERAL_CSTRING("\0")))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
notesField->Append(data);
|
|
|
|
return AnnotateCrashReport(NS_LITERAL_CSTRING("Notes"), *notesField);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if found, false if not found.
|
|
|
|
bool GetAnnotation(const nsACString& key, nsACString& data)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
2009-04-02 08:41:12 -07:00
|
|
|
return false;
|
2008-07-27 10:08:03 -07:00
|
|
|
|
|
|
|
nsCAutoString entry;
|
|
|
|
if (!crashReporterAPIData_Hash->Get(key, &entry))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
data = entry;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-04-02 08:41:12 -07:00
|
|
|
bool GetServerURL(nsACString& aServerURL)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return GetAnnotation(NS_LITERAL_CSTRING("ServerURL"), aServerURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult SetServerURL(const nsACString& aServerURL)
|
|
|
|
{
|
|
|
|
// store server URL with the API data
|
|
|
|
// the client knows to handle this specially
|
|
|
|
return AnnotateCrashReport(NS_LITERAL_CSTRING("ServerURL"),
|
|
|
|
aServerURL);
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
nsresult
|
2008-07-27 10:08:03 -07:00
|
|
|
SetRestartArgs(int argc, char** argv)
|
2007-07-24 18:06:05 -07:00
|
|
|
{
|
2007-07-24 18:06:10 -07:00
|
|
|
if (!gExceptionHandler)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
int i;
|
|
|
|
nsCAutoString envVar;
|
2007-07-24 18:06:06 -07:00
|
|
|
char *env;
|
2007-07-24 18:06:05 -07:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_ARG_";
|
|
|
|
envVar.AppendInt(i);
|
|
|
|
envVar += "=";
|
2007-12-21 11:40:39 -08:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
// we'd like to run the script around the binary
|
|
|
|
// instead of the binary itself, so remove the -bin
|
|
|
|
// if it exists on the first argument
|
|
|
|
int arg_len = 0;
|
|
|
|
if (i == 0 &&
|
|
|
|
(arg_len = strlen(argv[i])) > 4 &&
|
|
|
|
strcmp(argv[i] + arg_len - 4, "-bin") == 0) {
|
|
|
|
envVar.Append(argv[i], arg_len - 4);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
envVar += argv[i];
|
|
|
|
}
|
2007-07-24 18:06:06 -07:00
|
|
|
|
|
|
|
// PR_SetEnv() wants the string to be available for the lifetime
|
|
|
|
// of the app, so dup it here
|
|
|
|
env = ToNewCString(envVar);
|
|
|
|
if (!env)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PR_SetEnv(env);
|
2007-07-24 18:06:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure the arg list is terminated
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_ARG_";
|
|
|
|
envVar.AppendInt(i);
|
|
|
|
envVar += "=";
|
|
|
|
|
2007-07-24 18:06:06 -07:00
|
|
|
// PR_SetEnv() wants the string to be available for the lifetime
|
|
|
|
// of the app, so dup it here
|
|
|
|
env = ToNewCString(envVar);
|
|
|
|
if (!env)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
PR_SetEnv(env);
|
2007-07-24 18:06:05 -07:00
|
|
|
|
2007-07-24 18:06:12 -07:00
|
|
|
// make sure we save the info in XUL_APP_FILE for the reporter
|
|
|
|
const char *appfile = PR_GetEnv("XUL_APP_FILE");
|
|
|
|
if (appfile && *appfile) {
|
|
|
|
envVar = "MOZ_CRASHREPORTER_RESTART_XUL_APP_FILE=";
|
|
|
|
envVar += appfile;
|
|
|
|
env = ToNewCString(envVar);
|
|
|
|
PR_SetEnv(env);
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-02-08 18:40:47 -08:00
|
|
|
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
nsresult WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo)
|
|
|
|
{
|
|
|
|
if (!gExceptionHandler)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
return gExceptionHandler->WriteMinidumpForException(aExceptionInfo) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-27 21:41:38 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
nsresult AppendObjCExceptionInfoToAppNotes(void *inException)
|
|
|
|
{
|
|
|
|
nsCAutoString excString;
|
|
|
|
GetObjCExceptionInfo(inException, excString);
|
|
|
|
AppendAppNotesToCrashReport(excString);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-09 17:05:31 -08:00
|
|
|
/*
|
|
|
|
* Combined code to get/set the crash reporter submission pref on
|
|
|
|
* different platforms.
|
|
|
|
*/
|
|
|
|
static nsresult PrefSubmitReports(PRBool* aSubmitReports, bool writePref)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
#if defined(XP_WIN32)
|
|
|
|
/*
|
|
|
|
* NOTE! This needs to stay in sync with the preference checking code
|
|
|
|
* in toolkit/crashreporter/client/crashreporter_win.cpp
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIXULAppInfo> appinfo =
|
|
|
|
do_GetService("@mozilla.org/xre/app-info;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCAutoString appVendor, appName;
|
|
|
|
rv = appinfo->GetVendor(appVendor);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = appinfo->GetName(appName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWindowsRegKey> regKey
|
|
|
|
(do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCAutoString regPath;
|
|
|
|
|
|
|
|
regPath.AppendLiteral("Software\\");
|
|
|
|
if(!appVendor.IsEmpty()) {
|
|
|
|
regPath.Append(appVendor);
|
|
|
|
regPath.AppendLiteral("\\");
|
|
|
|
}
|
|
|
|
regPath.Append(appName);
|
|
|
|
regPath.AppendLiteral("\\Crash Reporter");
|
|
|
|
|
|
|
|
// If we're saving the pref value, just write it to ROOT_KEY_CURRENT_USER
|
|
|
|
// and we're done.
|
|
|
|
if (writePref) {
|
|
|
|
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRUint32 value = *aSubmitReports ? 1 : 0;
|
|
|
|
rv = regKey->WriteIntValue(NS_LITERAL_STRING("SubmitCrashReport"), value);
|
|
|
|
regKey->Close();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're reading the pref value, so we need to first look under
|
|
|
|
// ROOT_KEY_LOCAL_MACHINE to see if it's set there, and then fall back to
|
|
|
|
// ROOT_KEY_CURRENT_USER. If it's not set in either place, the pref defaults
|
|
|
|
// to "true".
|
|
|
|
PRUint32 value;
|
|
|
|
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = regKey->ReadIntValue(NS_LITERAL_STRING("SubmitCrashReport"), &value);
|
|
|
|
regKey->Close();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aSubmitReports = !!value;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_ConvertUTF8toUTF16(regPath),
|
|
|
|
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*aSubmitReports = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = regKey->ReadIntValue(NS_LITERAL_STRING("SubmitCrashReport"), &value);
|
|
|
|
// default to true on failure
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
value = 1;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
regKey->Close();
|
|
|
|
|
|
|
|
*aSubmitReports = !!value;
|
|
|
|
return NS_OK;
|
2010-02-09 18:11:08 -08:00
|
|
|
#elif defined(XP_MACOSX)
|
2010-06-20 19:07:59 -07:00
|
|
|
rv = NS_OK;
|
|
|
|
if (writePref) {
|
|
|
|
CFPropertyListRef cfValue = (CFPropertyListRef)(*aSubmitReports ? kCFBooleanTrue : kCFBooleanFalse);
|
|
|
|
::CFPreferencesSetAppValue(CFSTR("submitReport"),
|
|
|
|
cfValue,
|
|
|
|
reporterClientAppID);
|
|
|
|
if (!::CFPreferencesAppSynchronize(reporterClientAppID))
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aSubmitReports = PR_TRUE;
|
|
|
|
Boolean keyExistsAndHasValidFormat = false;
|
|
|
|
Boolean prefValue = ::CFPreferencesGetAppBooleanValue(CFSTR("submitReport"),
|
|
|
|
reporterClientAppID,
|
|
|
|
&keyExistsAndHasValidFormat);
|
|
|
|
if (keyExistsAndHasValidFormat)
|
|
|
|
*aSubmitReports = !!prefValue;
|
|
|
|
}
|
|
|
|
return rv;
|
2010-02-09 17:05:31 -08:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
/*
|
|
|
|
* NOTE! This needs to stay in sync with the preference checking code
|
|
|
|
* in toolkit/crashreporter/client/crashreporter_linux.cpp
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIFile> reporterINI;
|
|
|
|
rv = NS_GetSpecialDirectory("UAppData", getter_AddRefs(reporterINI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
reporterINI->AppendNative(NS_LITERAL_CSTRING("Crash Reports"));
|
|
|
|
reporterINI->AppendNative(NS_LITERAL_CSTRING("crashreporter.ini"));
|
|
|
|
|
|
|
|
PRBool exists;
|
|
|
|
rv = reporterINI->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!exists) {
|
|
|
|
if (!writePref) {
|
|
|
|
// If reading the pref, default to true if .ini doesn't exist.
|
|
|
|
*aSubmitReports = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// Create the file so the INI processor can write to it.
|
|
|
|
rv = reporterINI->Create(nsIFile::NORMAL_FILE_TYPE, 0600);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIINIParserFactory> iniFactory =
|
|
|
|
do_GetService("@mozilla.org/xpcom/ini-processor-factory;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(reporterINI);
|
|
|
|
NS_ENSURE_TRUE(localFile, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIINIParser> iniParser;
|
|
|
|
rv = iniFactory->CreateINIParser(localFile,
|
|
|
|
getter_AddRefs(iniParser));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If we're writing the pref, just set and we're done.
|
|
|
|
if (writePref) {
|
|
|
|
nsCOMPtr<nsIINIParserWriter> iniWriter = do_QueryInterface(iniParser);
|
|
|
|
NS_ENSURE_TRUE(iniWriter, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = iniWriter->SetString(NS_LITERAL_CSTRING("Crash Reporter"),
|
|
|
|
NS_LITERAL_CSTRING("SubmitReport"),
|
|
|
|
*aSubmitReports ? NS_LITERAL_CSTRING("1") :
|
|
|
|
NS_LITERAL_CSTRING("0"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = iniWriter->WriteFile(NULL);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString submitReportValue;
|
|
|
|
rv = iniParser->GetString(NS_LITERAL_CSTRING("Crash Reporter"),
|
|
|
|
NS_LITERAL_CSTRING("SubmitReport"),
|
|
|
|
submitReportValue);
|
|
|
|
|
|
|
|
// Default to "true" if the pref can't be found.
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
*aSubmitReports = PR_TRUE;
|
|
|
|
else if (submitReportValue.EqualsASCII("0"))
|
|
|
|
*aSubmitReports = PR_FALSE;
|
|
|
|
else
|
|
|
|
*aSubmitReports = PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult GetSubmitReports(PRBool* aSubmitReports)
|
|
|
|
{
|
|
|
|
return PrefSubmitReports(aSubmitReports, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult SetSubmitReports(PRBool aSubmitReports)
|
|
|
|
{
|
|
|
|
return PrefSubmitReports(&aSubmitReports, true);
|
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
// The "pending" dir is Crash Reports/pending, from which minidumps
|
|
|
|
// can be submitted
|
|
|
|
static bool
|
|
|
|
GetPendingDir(nsILocalFile** dir)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIProperties> dirSvc =
|
|
|
|
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
|
|
|
|
if (!dirSvc)
|
|
|
|
return false;
|
|
|
|
nsCOMPtr<nsILocalFile> pendingDir;
|
|
|
|
if (NS_FAILED(dirSvc->Get("UAppData",
|
|
|
|
NS_GET_IID(nsILocalFile),
|
|
|
|
getter_AddRefs(pendingDir))) ||
|
|
|
|
NS_FAILED(pendingDir->Append(NS_LITERAL_STRING("Crash Reports"))) ||
|
|
|
|
NS_FAILED(pendingDir->Append(NS_LITERAL_STRING("pending"))))
|
|
|
|
return false;
|
|
|
|
*dir = NULL;
|
|
|
|
pendingDir.swap(*dir);
|
|
|
|
return true;
|
|
|
|
}
|
2010-02-09 17:05:31 -08:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
// The "limbo" dir is where minidumps go to wait for something else to
|
|
|
|
// use them. If we're |ShouldReport()|, then the "something else" is
|
|
|
|
// a minidump submitter, and they're coming from the
|
|
|
|
// Crash Reports/pending/ dir. Otherwise, we don't know what the
|
|
|
|
// "somthing else" is, but the minidumps stay in [profile]/minidumps/
|
|
|
|
// limbo.
|
|
|
|
static bool
|
|
|
|
GetMinidumpLimboDir(nsILocalFile** dir)
|
|
|
|
{
|
|
|
|
if (ShouldReport()) {
|
|
|
|
return GetPendingDir(dir);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CreateFileFromPath(gExceptionHandler->dump_path(), dir);
|
|
|
|
return NULL != *dir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetMinidumpForID(const nsAString& id, nsILocalFile** minidump)
|
|
|
|
{
|
|
|
|
if (!GetMinidumpLimboDir(minidump))
|
|
|
|
return false;
|
|
|
|
(*minidump)->Append(id + NS_LITERAL_STRING(".dmp"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetIDFromMinidump(nsILocalFile* minidump, nsAString& id)
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(minidump->GetLeafName(id))) {
|
|
|
|
id.Replace(id.Length() - 4, 4, NS_LITERAL_STRING(""));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetExtraFileForID(const nsAString& id, nsILocalFile** extraFile)
|
|
|
|
{
|
|
|
|
if (!GetMinidumpLimboDir(extraFile))
|
|
|
|
return false;
|
|
|
|
(*extraFile)->Append(id + NS_LITERAL_STRING(".extra"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetExtraFileForMinidump(nsILocalFile* minidump, nsILocalFile** extraFile)
|
|
|
|
{
|
|
|
|
nsAutoString leafName;
|
|
|
|
nsresult rv = minidump->GetLeafName(leafName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> extraF;
|
|
|
|
rv = minidump->Clone(getter_AddRefs(extraF));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> extra = do_QueryInterface(extraF);
|
|
|
|
if (!extra)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
leafName.Replace(leafName.Length() - 3, 3,
|
|
|
|
NS_LITERAL_STRING("extra"));
|
|
|
|
rv = extra->SetLeafName(leafName);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*extraFile = NULL;
|
|
|
|
extra.swap(*extraFile);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AppendExtraData(const nsAString& id, const AnnotationTable& data)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsILocalFile> extraFile;
|
|
|
|
if (!GetExtraFileForID(id, getter_AddRefs(extraFile)))
|
|
|
|
return false;
|
|
|
|
return AppendExtraData(extraFile, data);
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Helpers for AppendExtraData()
|
|
|
|
//
|
2010-03-24 14:22:00 -07:00
|
|
|
struct Blacklist {
|
|
|
|
Blacklist() : mItems(NULL), mLen(0) { }
|
|
|
|
Blacklist(const char** items, int len) : mItems(items), mLen(len) { }
|
|
|
|
|
|
|
|
bool Contains(const nsACString& key) const {
|
|
|
|
for (int i = 0; i < mLen; ++i)
|
|
|
|
if (key.EqualsASCII(mItems[i]))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char** mItems;
|
|
|
|
const int mLen;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnumerateAnnotationsContext {
|
|
|
|
const Blacklist& blacklist;
|
|
|
|
PRFileDesc* fd;
|
|
|
|
};
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
static void
|
|
|
|
WriteAnnotation(PRFileDesc* fd, const nsACString& key, const nsACString& value)
|
|
|
|
{
|
|
|
|
PR_Write(fd, key.BeginReading(), key.Length());
|
|
|
|
PR_Write(fd, "=", 1);
|
|
|
|
PR_Write(fd, value.BeginReading(), value.Length());
|
|
|
|
PR_Write(fd, "\n", 1);
|
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
static PLDHashOperator
|
|
|
|
EnumerateAnnotations(const nsACString& key,
|
|
|
|
nsCString entry,
|
|
|
|
void* userData)
|
2010-01-14 14:38:00 -08:00
|
|
|
{
|
2010-03-24 14:22:00 -07:00
|
|
|
EnumerateAnnotationsContext* ctx =
|
|
|
|
static_cast<EnumerateAnnotationsContext*>(userData);
|
|
|
|
const Blacklist& blacklist = ctx->blacklist;
|
2010-01-14 14:38:00 -08:00
|
|
|
|
|
|
|
// skip entries in the blacklist
|
2010-03-24 14:22:00 -07:00
|
|
|
if (blacklist.Contains(key))
|
2010-01-14 14:38:00 -08:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
WriteAnnotation(ctx->fd, key, entry);
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-01-14 14:38:00 -08:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
static bool
|
2010-03-24 14:22:01 -07:00
|
|
|
WriteExtraData(nsILocalFile* extraFile,
|
|
|
|
const AnnotationTable& data,
|
|
|
|
const Blacklist& blacklist,
|
|
|
|
bool writeCrashTime=false,
|
|
|
|
bool truncate=false)
|
2010-03-24 14:22:00 -07:00
|
|
|
{
|
2010-03-24 14:22:01 -07:00
|
|
|
PRFileDesc* fd;
|
|
|
|
PRIntn truncOrAppend = truncate ? PR_TRUNCATE : PR_APPEND;
|
|
|
|
nsresult rv =
|
|
|
|
extraFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | truncOrAppend,
|
|
|
|
0600, &fd);
|
2010-03-24 14:22:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
EnumerateAnnotationsContext ctx = { blacklist, fd };
|
|
|
|
data.EnumerateRead(EnumerateAnnotations, &ctx);
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
if (writeCrashTime) {
|
|
|
|
time_t crashTime = time(NULL);
|
|
|
|
char crashTimeString[32];
|
|
|
|
XP_TTOA(crashTime, crashTimeString, 10);
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
WriteAnnotation(fd,
|
|
|
|
nsDependentCString("CrashTime"),
|
|
|
|
nsDependentCString(crashTimeString));
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
PR_Close(fd);
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
bool
|
|
|
|
AppendExtraData(nsILocalFile* extraFile, const AnnotationTable& data)
|
|
|
|
{
|
|
|
|
return WriteExtraData(extraFile, data, Blacklist());
|
|
|
|
}
|
2010-03-24 14:22:00 -07:00
|
|
|
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
#if defined(MOZ_IPC)
|
|
|
|
|
|
|
|
static bool
|
|
|
|
WriteExtraForMinidump(nsILocalFile* minidump,
|
|
|
|
const Blacklist& blacklist,
|
|
|
|
nsILocalFile** extraFile)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsILocalFile> extra;
|
|
|
|
if (!GetExtraFileForMinidump(minidump, getter_AddRefs(extra)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!WriteExtraData(extra, *crashReporterAPIData_Hash,
|
|
|
|
blacklist,
|
|
|
|
true /*write crash time*/,
|
|
|
|
true /*truncate*/))
|
|
|
|
return false;
|
2010-03-24 14:22:00 -07:00
|
|
|
|
|
|
|
*extraFile = NULL;
|
|
|
|
extra.swap(*extraFile);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
// It really only makes sense to call this function when
|
|
|
|
// ShouldReport() is true.
|
2010-02-09 17:05:31 -08:00
|
|
|
static bool
|
|
|
|
MoveToPending(nsIFile* dumpFile, nsIFile* extraFile)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsILocalFile> pendingDir;
|
2010-03-24 14:22:01 -07:00
|
|
|
if (!GetPendingDir(getter_AddRefs(pendingDir)))
|
|
|
|
return false;
|
2010-02-09 17:05:31 -08:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
return NS_SUCCEEDED(dumpFile->MoveTo(pendingDir, EmptyString())) &&
|
|
|
|
NS_SUCCEEDED(extraFile->MoveTo(pendingDir, EmptyString()));
|
2010-02-09 17:05:31 -08:00
|
|
|
}
|
|
|
|
|
2010-03-30 10:32:53 -07:00
|
|
|
#if !defined(XP_MACOSX)
|
2010-01-12 13:14:38 -08:00
|
|
|
static void
|
|
|
|
OnChildProcessDumpRequested(void* aContext,
|
|
|
|
const ClientInfo* aClientInfo,
|
2010-03-24 14:22:00 -07:00
|
|
|
const xpstring* aFilePath)
|
2010-01-12 13:14:38 -08:00
|
|
|
{
|
2010-03-24 14:22:00 -07:00
|
|
|
nsCOMPtr<nsILocalFile> minidump;
|
|
|
|
nsCOMPtr<nsILocalFile> extraFile;
|
2010-01-14 14:38:00 -08:00
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
CreateFileFromPath(*aFilePath, getter_AddRefs(minidump));
|
2010-01-14 14:38:00 -08:00
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
if (!WriteExtraForMinidump(minidump,
|
|
|
|
Blacklist(kSubprocessBlacklist,
|
|
|
|
NS_ARRAY_LENGTH(kSubprocessBlacklist)),
|
|
|
|
getter_AddRefs(extraFile)))
|
2010-01-14 14:38:00 -08:00
|
|
|
return;
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
if (ShouldReport())
|
|
|
|
MoveToPending(minidump, extraFile);
|
2010-02-09 17:05:31 -08:00
|
|
|
|
2010-01-14 14:38:00 -08:00
|
|
|
{
|
2010-03-24 14:22:00 -07:00
|
|
|
PRUint32 pid = aClientInfo->pid();
|
|
|
|
|
2010-01-14 14:38:00 -08:00
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
2010-03-24 14:22:00 -07:00
|
|
|
pidToMinidump->Put(pid, minidump);
|
2010-01-14 14:38:00 -08:00
|
|
|
}
|
2010-01-12 13:14:38 -08:00
|
|
|
}
|
2010-03-30 10:32:53 -07:00
|
|
|
#endif // XP_MACOSX
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
static bool
|
|
|
|
OOPInitialized()
|
|
|
|
{
|
2010-04-12 13:47:47 -07:00
|
|
|
return pidToMinidump != NULL;
|
2010-01-12 13:14:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
OOPInit()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!OOPInitialized(),
|
|
|
|
"OOP crash reporter initialized more than once!");
|
|
|
|
NS_ABORT_IF_FALSE(gExceptionHandler != NULL,
|
|
|
|
"attempt to initialize OOP crash reporter before in-process crashreporter!");
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
2010-01-13 07:44:10 -08:00
|
|
|
childCrashNotifyPipe =
|
|
|
|
PR_smprintf("\\\\.\\pipe\\gecko-crash-server-pipe.%i",
|
|
|
|
static_cast<int>(::GetCurrentProcessId()));
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
const std::wstring dumpPath = gExceptionHandler->dump_path();
|
|
|
|
crashServer = new CrashGenerationServer(
|
2010-01-13 07:44:10 -08:00
|
|
|
NS_ConvertASCIItoUTF16(childCrashNotifyPipe).get(),
|
2010-01-12 13:14:38 -08:00
|
|
|
NULL, // default security attributes
|
|
|
|
NULL, NULL, // we don't care about process connect here
|
|
|
|
OnChildProcessDumpRequested, NULL,
|
|
|
|
NULL, NULL, // we don't care about process exit here
|
|
|
|
true, // automatically generate dumps
|
|
|
|
&dumpPath);
|
|
|
|
|
|
|
|
#elif defined(XP_LINUX)
|
|
|
|
if (!CrashGenerationServer::CreateReportChannel(&serverSocketFd,
|
|
|
|
&clientSocketFd))
|
|
|
|
NS_RUNTIMEABORT("can't create crash reporter socketpair()");
|
|
|
|
|
|
|
|
const std::string dumpPath = gExceptionHandler->dump_path();
|
|
|
|
crashServer = new CrashGenerationServer(
|
|
|
|
serverSocketFd,
|
|
|
|
OnChildProcessDumpRequested, NULL,
|
|
|
|
NULL, NULL, // we don't care about process exit here
|
|
|
|
true, // automatically generate dumps
|
|
|
|
&dumpPath);
|
|
|
|
#endif
|
|
|
|
|
2010-03-30 10:32:53 -07:00
|
|
|
#if !defined(XP_MACOSX)
|
2010-01-12 13:14:38 -08:00
|
|
|
if (!crashServer->Start())
|
|
|
|
NS_RUNTIMEABORT("can't start crash reporter server()");
|
2010-03-30 10:32:53 -07:00
|
|
|
#endif
|
2010-01-14 14:38:00 -08:00
|
|
|
|
|
|
|
pidToMinidump = new ChildMinidumpMap();
|
|
|
|
pidToMinidump->Init();
|
|
|
|
|
|
|
|
dumpMapLock = new Mutex("CrashReporter::dumpMapLock");
|
2010-01-12 13:14:38 -08:00
|
|
|
}
|
|
|
|
|
2010-01-20 18:17:40 -08:00
|
|
|
static void
|
|
|
|
OOPDeinit()
|
|
|
|
{
|
|
|
|
if (!OOPInitialized()) {
|
|
|
|
NS_WARNING("OOPDeinit() without successful OOPInit()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-30 10:32:53 -07:00
|
|
|
#if !defined(XP_MACOSX)
|
2010-01-20 18:17:40 -08:00
|
|
|
delete crashServer;
|
|
|
|
crashServer = NULL;
|
2010-03-30 10:32:53 -07:00
|
|
|
#endif
|
2010-01-20 18:17:40 -08:00
|
|
|
|
|
|
|
delete dumpMapLock;
|
|
|
|
dumpMapLock = NULL;
|
|
|
|
|
|
|
|
delete pidToMinidump;
|
|
|
|
pidToMinidump = NULL;
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
PR_Free(childCrashNotifyPipe);
|
|
|
|
childCrashNotifyPipe = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-01-12 13:14:38 -08:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// Parent-side API for children
|
2010-01-13 07:44:10 -08:00
|
|
|
const char*
|
2010-01-12 13:14:38 -08:00
|
|
|
GetChildNotificationPipe()
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
2010-01-13 07:44:10 -08:00
|
|
|
return kNullNotifyPipe;
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
if (!OOPInitialized())
|
|
|
|
OOPInit();
|
|
|
|
|
2010-01-13 07:44:10 -08:00
|
|
|
return childCrashNotifyPipe;
|
2010-01-12 13:14:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Child-side API
|
|
|
|
bool
|
|
|
|
SetRemoteExceptionHandler(const nsACString& crashPipe)
|
|
|
|
{
|
|
|
|
// crash reporting is disabled
|
|
|
|
if (crashPipe.Equals(kNullNotifyPipe))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(!gExceptionHandler, "crash client already init'd");
|
|
|
|
|
|
|
|
gExceptionHandler = new google_breakpad::
|
|
|
|
ExceptionHandler(L"",
|
|
|
|
NULL, // no filter callback
|
|
|
|
NULL, // no minidump callback
|
|
|
|
NULL, // no callback context
|
|
|
|
google_breakpad::ExceptionHandler::HANDLER_ALL,
|
|
|
|
MiniDumpNormal,
|
|
|
|
NS_ConvertASCIItoUTF16(crashPipe).BeginReading(),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
// we either do remote or nothing, no fallback to regular crash reporting
|
|
|
|
return gExceptionHandler->IsOutOfProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------
|
2010-03-30 10:32:53 -07:00
|
|
|
#elif defined(XP_LINUX)
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
// Parent-side API for children
|
|
|
|
bool
|
|
|
|
CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd)
|
|
|
|
{
|
|
|
|
if (!GetEnabled()) {
|
|
|
|
*childCrashFd = -1;
|
|
|
|
*childCrashRemapFd = -1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!OOPInitialized())
|
|
|
|
OOPInit();
|
|
|
|
|
|
|
|
*childCrashFd = clientSocketFd;
|
|
|
|
*childCrashRemapFd = kMagicChildCrashReportFd;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Child-side API
|
|
|
|
bool
|
|
|
|
SetRemoteExceptionHandler()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!gExceptionHandler, "crash client already init'd");
|
|
|
|
|
|
|
|
gExceptionHandler = new google_breakpad::
|
|
|
|
ExceptionHandler("",
|
|
|
|
NULL, // no filter callback
|
|
|
|
NULL, // no minidump callback
|
|
|
|
NULL, // no callback context
|
|
|
|
true, // install signal handlers
|
|
|
|
kMagicChildCrashReportFd);
|
|
|
|
|
|
|
|
// we either do remote or nothing, no fallback to regular crash reporting
|
|
|
|
return gExceptionHandler->IsOutOfProcess();
|
|
|
|
}
|
|
|
|
|
2010-04-12 13:47:47 -07:00
|
|
|
//--------------------------------------------------
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
void
|
|
|
|
CreateNotificationPipeForChild()
|
|
|
|
{
|
|
|
|
if (GetEnabled() && !OOPInitialized())
|
|
|
|
OOPInit();
|
|
|
|
}
|
2010-01-12 14:00:48 -08:00
|
|
|
#endif // XP_WIN
|
2010-01-12 13:14:38 -08:00
|
|
|
|
|
|
|
|
2010-01-14 14:38:00 -08:00
|
|
|
bool
|
2010-03-24 14:22:01 -07:00
|
|
|
TakeMinidumpForChild(PRUint32 childPid, nsILocalFile** dump)
|
2010-01-14 14:38:00 -08:00
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MutexAutoLock lock(*dumpMapLock);
|
2010-03-18 15:52:36 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
nsCOMPtr<nsILocalFile> d;
|
2010-03-18 19:01:10 -07:00
|
|
|
bool found = pidToMinidump->Get(childPid, getter_AddRefs(d));
|
2010-03-18 15:52:36 -07:00
|
|
|
if (found)
|
2010-03-18 19:01:10 -07:00
|
|
|
pidToMinidump->Remove(childPid);
|
2010-03-18 15:52:36 -07:00
|
|
|
|
|
|
|
*dump = NULL;
|
|
|
|
d.swap(*dump);
|
|
|
|
|
|
|
|
return found;
|
2010-01-14 14:38:00 -08:00
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// CreatePairedMinidumps() and helpers
|
|
|
|
//
|
|
|
|
struct PairedDumpContext {
|
|
|
|
nsCOMPtr<nsILocalFile>* minidump;
|
|
|
|
nsCOMPtr<nsILocalFile>* extra;
|
|
|
|
const Blacklist& blacklist;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
PairedDumpCallback(const XP_CHAR* dump_path,
|
|
|
|
const XP_CHAR* minidump_id,
|
|
|
|
void* context,
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
EXCEPTION_POINTERS* /*unused*/,
|
|
|
|
MDRawAssertionInfo* /*unused*/,
|
|
|
|
#endif
|
|
|
|
bool succeeded)
|
|
|
|
{
|
|
|
|
PairedDumpContext* ctx = static_cast<PairedDumpContext*>(context);
|
|
|
|
nsCOMPtr<nsILocalFile>& minidump = *ctx->minidump;
|
|
|
|
nsCOMPtr<nsILocalFile>& extra = *ctx->extra;
|
|
|
|
const Blacklist& blacklist = ctx->blacklist;
|
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
xpstring dump(dump_path);
|
|
|
|
dump += XP_PATH_SEPARATOR;
|
|
|
|
dump += minidump_id;
|
|
|
|
dump += dumpFileExtension;
|
2010-03-24 14:22:00 -07:00
|
|
|
|
2010-03-24 14:22:01 -07:00
|
|
|
CreateFileFromPath(dump, getter_AddRefs(minidump));
|
2010-03-24 14:22:00 -07:00
|
|
|
return WriteExtraForMinidump(minidump, blacklist, getter_AddRefs(extra));
|
|
|
|
}
|
|
|
|
|
2010-03-30 17:24:45 -07:00
|
|
|
ThreadId
|
|
|
|
CurrentThreadId()
|
|
|
|
{
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
return ::GetCurrentThreadId();
|
|
|
|
#elif defined(XP_LINUX)
|
|
|
|
return sys_gettid();
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
return -1;
|
|
|
|
#else
|
|
|
|
# error "Unsupported platform"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
bool
|
|
|
|
CreatePairedMinidumps(ProcessHandle childPid,
|
2010-03-30 17:24:46 -07:00
|
|
|
ThreadId childBlamedThread,
|
2010-03-24 14:22:00 -07:00
|
|
|
nsAString* pairGUID,
|
|
|
|
nsILocalFile** childDump,
|
|
|
|
nsILocalFile** parentDump)
|
|
|
|
{
|
|
|
|
if (!GetEnabled())
|
|
|
|
return false;
|
|
|
|
|
2010-03-30 10:32:53 -07:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
|
2010-03-24 14:22:00 -07:00
|
|
|
// create the UUID for the hang dump as a pair
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
|
|
|
do_GetService("@mozilla.org/uuid-generator;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
nsID id;
|
|
|
|
rv = uuidgen->GenerateUUIDInPlace(&id);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
char chars[NSID_LENGTH];
|
|
|
|
id.ToProvidedString(chars);
|
|
|
|
CopyASCIItoUTF16(chars, *pairGUID);
|
|
|
|
|
|
|
|
// trim off braces
|
|
|
|
pairGUID->Cut(0, 1);
|
|
|
|
pairGUID->Cut(pairGUID->Length()-1, 1);
|
|
|
|
|
|
|
|
// dump the child
|
|
|
|
nsCOMPtr<nsILocalFile> childMinidump;
|
|
|
|
nsCOMPtr<nsILocalFile> childExtra;
|
|
|
|
Blacklist childBlacklist(kSubprocessBlacklist,
|
|
|
|
NS_ARRAY_LENGTH(kSubprocessBlacklist));
|
|
|
|
PairedDumpContext childCtx =
|
|
|
|
{ &childMinidump, &childExtra, childBlacklist };
|
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidumpForChild(
|
|
|
|
childPid,
|
2010-03-30 17:24:46 -07:00
|
|
|
childBlamedThread,
|
2010-03-24 14:22:00 -07:00
|
|
|
gExceptionHandler->dump_path(),
|
|
|
|
PairedDumpCallback,
|
|
|
|
&childCtx))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// dump the parent
|
|
|
|
nsCOMPtr<nsILocalFile> parentMinidump;
|
|
|
|
nsCOMPtr<nsILocalFile> parentExtra;
|
|
|
|
// nothing's blacklisted for this process
|
|
|
|
Blacklist parentBlacklist;
|
|
|
|
PairedDumpContext parentCtx =
|
|
|
|
{ &parentMinidump, &parentExtra, parentBlacklist };
|
|
|
|
if (!google_breakpad::ExceptionHandler::WriteMinidump(
|
|
|
|
gExceptionHandler->dump_path(),
|
2010-03-30 17:24:48 -07:00
|
|
|
true, // write exception stream
|
2010-03-24 14:22:00 -07:00
|
|
|
PairedDumpCallback,
|
|
|
|
&parentCtx))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// success
|
|
|
|
if (ShouldReport()) {
|
|
|
|
MoveToPending(childMinidump, childExtra);
|
|
|
|
MoveToPending(parentMinidump, parentExtra);
|
|
|
|
}
|
|
|
|
|
|
|
|
*childDump = NULL;
|
|
|
|
*parentDump = NULL;
|
|
|
|
childMinidump.swap(*childDump);
|
|
|
|
parentMinidump.swap(*parentDump);
|
|
|
|
|
|
|
|
return true;
|
2010-03-30 10:32:53 -07:00
|
|
|
#endif // XP_MACOSX
|
2010-03-24 14:22:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-30 10:32:53 -07:00
|
|
|
#if !defined(XP_MACOSX)
|
2010-01-12 13:14:38 -08:00
|
|
|
bool
|
|
|
|
UnsetRemoteExceptionHandler()
|
|
|
|
{
|
|
|
|
delete gExceptionHandler;
|
|
|
|
gExceptionHandler = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-30 10:32:53 -07:00
|
|
|
#endif // XP_MACOSX
|
2010-01-12 13:14:38 -08:00
|
|
|
|
2010-01-12 14:00:48 -08:00
|
|
|
#endif // MOZ_IPC
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
} // namespace CrashReporter
|