bug 380541 - build time logic to extract debug symbols on Linux - first cut at integrating Breakpad on Linux. r=mento

This commit is contained in:
ted.mielczarek@gmail.com 2007-07-24 18:06:04 -07:00
Родитель 9f90de0509
Коммит 5c7218ef68
9 изменённых файлов: 378 добавлений и 82 удалений

Просмотреть файл

@ -70,6 +70,18 @@ DIRS += \
$(NULL)
endif
ifeq ($(OS_ARCH),Linux)
# there's no define for this normally
DEFINES += -DXP_LINUX
DIRS += \
airbag/src/common \
airbag/src/common/linux \
airbag/src/client \
airbag/src/client/linux/handler \
airbag/src/tools/linux/dump_syms \
$(NULL)
endif
DIRS += client
LOCAL_INCLUDES = -I$(srcdir)/airbag/src

Просмотреть файл

@ -79,6 +79,14 @@ LIBS += \
LOCAL_INCLUDES += -I$(srcdir) -I$(srcdir)/../airbag/src/common/mac/
endif
ifeq ($(OS_ARCH),Linux)
CPPSRCS += crashreporter_linux.cpp
LIBS += \
$(DEPTH)/toolkit/airbag/airbag/src/common/linux/$(LIB_PREFIX)breakpad_linux_common_s.$(LIB_SUFFIX) \
$(NULL)
LOCAL_INCLUDES += -I$(srcdir)
endif
include $(topsrcdir)/config/rules.mk
ifeq ($(OS_ARCH),Darwin)

Просмотреть файл

@ -0,0 +1,136 @@
/* -*- 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.
*
* The Original Code is Mozilla Toolkit Crash Reporter
*
* 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):
*
* 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 ***** */
#include "crashreporter.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <algorithm>
#include <cctype>
using std::string;
bool UIInit()
{
//XXX: implement me
return true;
}
void UIShutdown()
{
//XXX: implement me
}
void UIShowDefaultUI()
{
//XXX: implement me
}
void UIShowCrashUI(const string& dumpfile,
const StringTable& queryParameters,
const string& sendURL)
{
//XXX: implement me
}
void UIError(const string& message)
{
//XXX: implement me
printf("Error: %s\n", message.c_str());
}
bool UIGetIniPath(string& path)
{
path = gArgv[0];
path.append(".ini");
return true;
}
/*
* Settings are stored in ~/.vendor/product, or
* ~/.product if vendor is empty.
*/
bool UIGetSettingsPath(const string& vendor,
const string& product,
string& settingsPath)
{
char* home = getenv("HOME");
if (!home)
return false;
settingsPath = home;
settingsPath += "/.";
if (!vendor.empty()) {
string lc_vendor;
std::transform(vendor.begin(), vendor.end(), back_inserter(lc_vendor),
(int(*)(int)) std::tolower);
settingsPath += lc_vendor + "/";
}
string lc_product;
std::transform(product.begin(), product.end(), back_inserter(lc_product),
(int(*)(int)) std::tolower);
settingsPath += lc_product + "/Crash Reports";
printf("settingsPath: %s\n", settingsPath.c_str());
return UIEnsurePathExists(settingsPath);
}
bool UIEnsurePathExists(const string& path)
{
int ret = mkdir(path.c_str(), S_IRWXU);
int e = errno;
if (ret == -1 && e != EEXIST)
return false;
return true;
}
bool UIMoveFile(const string& file, const string& newfile)
{
return (rename(file.c_str(), newfile.c_str()) != -1);
}
bool UIDeleteFile(const string& file)
{
return (unlink(file.c_str()) != -1);
}

Просмотреть файл

@ -0,0 +1,59 @@
# ***** 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.
#
# The Original Code is Mozilla Breakpad integration
#
# The Initial Developer of the Original Code is
# Ted Mielczarek <ted.mielczarek@gmail.com>
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# 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 *****
DEPTH = ../../../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = handler
LIBRARY_NAME = exception_handler_s
XPI_NAME = crashreporter
LOCAL_INCLUDES = -I$(srcdir)/../../..
CPPSRCS = \
exception_handler.cc \
minidump_generator.cc \
linux_thread.cc \
$(NULL)
# need static lib
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,75 @@
# ***** 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.
#
# The Original Code is Mozilla Breakpad integration
#
# The Initial Developer of the Original Code is
# Ted Mielczarek <ted.mielczarek@gmail.com>
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# 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 *****
DEPTH = ../../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = breakpad_linux_common
LIBRARY_NAME = breakpad_linux_common_s
HOST_LIBRARY_NAME = host_breakpad_linux_common_s
LOCAL_INCLUDES = -I$(srcdir)/../..
CXXFLAGS := $(filter-out -pedantic,$(CXXFLAGS))
# not compiling http_upload.cc currently
# since it depends on libcurl
CPPSRCS = \
dump_symbols.cc \
file_id.cc \
guid_creator.cc \
$(NULL)
CSRCS = \
md5.c \
$(NULL)
HOST_CPPSRCS = \
dump_symbols.cc \
file_id.cc \
guid_creator.cc \
$(NULL)
HOST_CSRCS = $(CSRCS)
# need static lib
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,63 @@
# ***** 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.
#
# The Original Code is Mozilla Breakpad integration
#
# The Initial Developer of the Original Code is
# Ted Mielczarek <ted.mielczarek@gmail.com>
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# 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 *****
DEPTH = ../../../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
HOST_PROGRAM = dump_syms
LOCAL_INCLUDES = \
-I$(srcdir)/../../.. \
-I$(srcdir)/../../../common/linux \
$(NULL)
HOST_CPPSRCS = \
dump_syms.cc \
$(NULL)
HOST_LIBS += \
$(DEPTH)/toolkit/airbag/airbag/src/common/linux/$(LIB_PREFIX)host_breakpad_linux_common_s.$(LIB_SUFFIX) \
$(DEPTH)/toolkit/airbag/airbag/src/common/$(LIB_PREFIX)host_breakpad_common_s.$(LIB_SUFFIX) \
$(NULL)
# force C++ linking
CPP_PROG_LINK = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -49,6 +49,9 @@
#include <string>
#include <Carbon/Carbon.h>
#include <fcntl.h>
#elif defined(XP_LINUX)
#include "client/linux/handler/exception_handler.h"
#include <fcntl.h>
#else
#error "Not yet implemented for this platform"
#endif // defined(XP_WIN32)
@ -216,78 +219,6 @@ bool MinidumpCallback(const XP_CHAR* dump_path,
return succeeded;
}
static nsresult GetExecutablePath(nsString& exePath)
{
#if !defined(XP_MACOSX)
#ifdef XP_WIN32
exePath.SetLength(XP_PATH_MAX);
if (!GetModuleFileName(NULL, (LPWSTR)exePath.BeginWriting(), XP_PATH_MAX))
return NS_ERROR_FAILURE;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif
NS_NAMED_LITERAL_STRING(pathSep, PATH_SEPARATOR);
PRInt32 lastSlash = exePath.RFind(pathSep);
if (lastSlash < 0)
return NS_ERROR_FAILURE;
exePath.Truncate(lastSlash + 1);
return NS_OK;
#else // !defined(XP_MACOSX)
CFBundleRef appBundle = CFBundleGetMainBundle();
if (!appBundle)
return NS_ERROR_FAILURE;
CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle);
if (!executableURL)
return NS_ERROR_FAILURE;
CFURLRef bundleURL = CFURLCreateCopyDeletingLastPathComponent(NULL,
executableURL);
CFRelease(executableURL);
if (!bundleURL)
return NS_ERROR_FAILURE;
CFURLRef reporterURL = CFURLCreateCopyAppendingPathComponent(
NULL,
bundleURL,
CFSTR("crashreporter.app/Contents/MacOS/"),
false);
CFRelease(bundleURL);
if (!reporterURL)
return NS_ERROR_FAILURE;
FSRef fsRef;
if (!CFURLGetFSRef(reporterURL, &fsRef)) {
CFRelease(reporterURL);
return NS_ERROR_FAILURE;
}
CFRelease(reporterURL);
char path[PATH_MAX + 1];
OSStatus status = FSRefMakePath(&fsRef, (UInt8*)path, PATH_MAX);
if (status != noErr)
return NS_ERROR_FAILURE;
int len = strlen(path);
path[len] = '/';
path[len + 1] = '\0';
exePath = NS_ConvertUTF8toUTF16(path);
return NS_OK;
#endif
}
nsresult SetExceptionHandler(nsILocalFile* aXREDirectory,
const char* aServerURL)
{
@ -316,21 +247,14 @@ nsresult SetExceptionHandler(nsILocalFile* aXREDirectory,
// locate crashreporter executable
nsString exePath;
if (aXREDirectory) {
aXREDirectory->GetPath(exePath);
}
else {
rv = GetExecutablePath(exePath);
NS_ENSURE_SUCCESS(rv, rv);
}
NS_NAMED_LITERAL_STRING(crashReporterFilename, CRASH_REPORTER_FILENAME);
crashReporterPath = TO_NEW_XP_CHAR(exePath + crashReporterFilename);
// get temp path to use for minidump path
nsString tempPath;
#ifdef XP_WIN32
#if defined(XP_WIN32)
// first figure out buffer size
int pathLen = GetTempPath(0, NULL);
if (pathLen == 0)
@ -351,6 +275,9 @@ nsresult SetExceptionHandler(nsILocalFile* aXREDirectory,
return NS_ERROR_FAILURE;
tempPath = NS_ConvertUTF8toUTF16(path);
#elif defined(XP_UNIX)
// we assume it's always /tmp on unix systems
tempPath = NS_LITERAL_STRING("/tmp/");
#else
//XXX: implement get temp path on other platforms
return NS_ERROR_NOT_IMPLEMENTED;

Просмотреть файл

@ -85,6 +85,15 @@ LIBS += \
LOCAL_INCLUDES += -I$(srcdir) -I$(srcdir)/../airbag/src/common/mac/
endif
ifeq ($(OS_ARCH),Linux)
LIBS += \
$(DEPTH)/toolkit/airbag/airbag/src/client/linux/handler/$(LIB_PREFIX)exception_handler_s.$(LIB_SUFFIX) \
$(DEPTH)/toolkit/airbag/airbag/src/client/$(LIB_PREFIX)minidump_file_writer_s.$(LIB_SUFFIX) \
$(DEPTH)/toolkit/airbag/airbag/src/common/$(LIB_PREFIX)breakpad_common_s.$(LIB_SUFFIX) \
$(DEPTH)/toolkit/airbag/airbag/src/common/linux/$(LIB_PREFIX)breakpad_linux_common_s.$(LIB_SUFFIX) \
$(NULL)
endif
ifndef MOZ_ENABLE_LIBXUL
check:: $(PROGRAM)
$(RUN_TEST_PROGRAM) $(DIST)/bin/TestCrashReporterAPI

Просмотреть файл

@ -62,8 +62,15 @@ int tests_run;
char *
test_init_exception_handler()
{
nsCOMPtr<nsILocalFile> lf;
// we don't plan on launching the crash reporter in this app anyway,
// so it's ok to pass a bogus nsILocalFile
mu_assert("NS_NewNativeLocalFile", NS_NewNativeLocalFile(EmptyCString(),
PR_TRUE,
getter_AddRefs(lf)));
mu_assert("CrashReporter::SetExceptionHandler",
CrashReporter::SetExceptionHandler(nsnull, nsnull));
CrashReporter::SetExceptionHandler(lf, nsnull));
return 0;
}