Skip to content

Commit

Permalink
Move DumpProcessWithoutCrash to base, so we can use it from net and c…
Browse files Browse the repository at this point in the history
…ontent

BUG=none
R=mark@chromium.org
TBR=wez@chromium.org

Review URL: https://codereview.chromium.org/99523009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241589 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jochen@chromium.org committed Dec 18, 2013
1 parent b8b2dbe commit 5a8d4ce
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 124 deletions.
2 changes: 2 additions & 0 deletions base/base.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
'debug/debugger.h',
'debug/debugger_posix.cc',
'debug/debugger_win.cc',
'debug/dump_without_crashing.cc',
'debug/dump_without_crashing.h',
# This file depends on files from the 'allocator' target,
# but this target does not depend on 'allocator' (see
# allocator.gyp for details).
Expand Down
9 changes: 9 additions & 0 deletions base/compiler_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,13 @@ void __msan_unpoison(const void *p, unsigned long s);
#define MSAN_UNPOISON(p, s)
#endif // MEMORY_SANITIZER

// Macro useful for writing cross-platform function pointers.
#if !defined(CDECL)
#if defined(OS_WIN)
#define CDECL __cdecl
#else // defined(OS_WIN)
#define CDECL
#endif // defined(OS_WIN)
#endif // !defined(CDECL)

#endif // BASE_COMPILER_SPECIFIC_H_
32 changes: 32 additions & 0 deletions base/debug/dump_without_crashing.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/debug/dump_without_crashing.h"

#include "base/logging.h"

namespace {

// Pointer to the function that's called by DumpWithoutCrashing() to dump the
// process's memory.
void (CDECL *dump_without_crashing_function_)() = NULL;

} // namespace

namespace base {

namespace debug {

void DumpWithoutCrashing() {
if (dump_without_crashing_function_)
(*dump_without_crashing_function_)();
}

void SetDumpWithoutCrashingFunction(void (CDECL *function)()) {
dump_without_crashing_function_ = function;
}

} // namespace debug

} // namespace base
27 changes: 27 additions & 0 deletions base/debug/dump_without_crashing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_DEBUG_DUMP_WITHOUT_CRASHING_H_
#define BASE_DEBUG_DUMP_WITHOUT_CRASHING_H_

#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "build/build_config.h"

namespace base {

namespace debug {

// Handler to silently dump the current process without crashing.
BASE_EXPORT void DumpWithoutCrashing();

// Sets a function that'll be invoked to dump the current process when
// DumpWithoutCrashing() is called.
BASE_EXPORT void SetDumpWithoutCrashingFunction(void (CDECL *function)());

} // namespace debug

} // namespace base

#endif // BASE_DEBUG_DUMP_WITHOUT_CRASHING_H_
8 changes: 1 addition & 7 deletions base/native_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// a loadable module.

#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "build/build_config.h"

#if defined(OS_WIN)
Expand All @@ -19,13 +20,6 @@

#include "base/strings/string16.h"

// Macro useful for writing cross-platform function pointers.
#if defined(OS_WIN) && !defined(CDECL)
#define CDECL __cdecl
#else
#define CDECL
#endif

namespace base {

class FilePath;
Expand Down
8 changes: 1 addition & 7 deletions chrome/app/chrome_breakpad_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#endif

#if defined(OS_POSIX)
#include "chrome/common/dump_without_crashing.h"
#include "base/debug/dump_without_crashing.h"
#endif

#if defined(OS_ANDROID)
Expand Down Expand Up @@ -326,12 +326,6 @@ bool ChromeBreakpadClient::GetCrashDumpLocation(base::FilePath* crash_dir) {
return PathService::Get(chrome::DIR_CRASH_DUMPS, crash_dir);
}

#if defined(OS_POSIX)
void ChromeBreakpadClient::SetDumpWithoutCrashingFunction(void (*function)()) {
logging::SetDumpWithoutCrashingFunction(function);
}
#endif

size_t ChromeBreakpadClient::RegisterCrashKeys() {
// Note: This is not called on Windows because Breakpad is initialized in the
// EXE module, but code that uses crash keys is in the DLL module.
Expand Down
4 changes: 0 additions & 4 deletions chrome/app/chrome_breakpad_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ class ChromeBreakpadClient : public breakpad::BreakpadClient {

virtual bool GetCrashDumpLocation(base::FilePath* crash_dir) OVERRIDE;

#if defined(OS_POSIX)
virtual void SetDumpWithoutCrashingFunction(void (*function)()) OVERRIDE;
#endif

virtual size_t RegisterCrashKeys() OVERRIDE;

virtual bool IsRunningUnattended() OVERRIDE;
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/history/thumbnail_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/bind.h"
#include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h"
#include "base/file_util.h"
#include "base/format_macros.h"
#include "base/memory/ref_counted_memory.h"
Expand All @@ -19,7 +20,6 @@
#include "base/time/time.h"
#include "chrome/browser/history/url_database.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/dump_without_crashing.h"
#include "sql/recovery.h"
#include "sql/statement.h"
#include "sql/transaction.h"
Expand Down Expand Up @@ -121,7 +121,7 @@ void DumpWithoutCrashing2000(const std::string& debug_info) {
base::strlcpy(debug_buf, debug_info.c_str(), arraysize(debug_buf));
base::debug::Alias(&debug_buf);

logging::DumpWithoutCrashing();
base::debug::DumpWithoutCrashing();
}

void ReportCorrupt(sql::Connection* db, size_t startup_kb) {
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/metrics/thread_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h"
#include "base/lazy_instance.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
Expand All @@ -19,7 +20,6 @@
#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/dump_without_crashing.h"
#include "chrome/common/logging_chrome.h"

#if defined(OS_WIN)
Expand Down Expand Up @@ -49,7 +49,7 @@ void NullPointerCrash(int line_number) {
#ifndef NDEBUG
*NullPointer() = line_number; // Crash.
#else
logging::DumpWithoutCrashing();
base::debug::DumpWithoutCrashing();
#endif
}

Expand Down Expand Up @@ -861,7 +861,7 @@ class StartupWatchDogThread : public base::Watchdog {
#ifndef NDEBUG
DCHECK(false);
#else
logging::DumpWithoutCrashing();
base::debug::DumpWithoutCrashing();
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/sync/glue/chrome_report_unrecoverable_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"

#include "base/debug/dump_without_crashing.h"
#include "base/rand_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/dump_without_crashing.h"

namespace browser_sync {

Expand All @@ -27,7 +27,7 @@ void ChromeReportUnrecoverableError() {
if (random_number > kErrorUploadRatio)
return;

logging::DumpWithoutCrashing();
base::debug::DumpWithoutCrashing();
}

} // namespace browser_sync
2 changes: 0 additions & 2 deletions chrome/chrome_common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@
'common/custom_handlers/protocol_handler.cc',
'common/custom_handlers/protocol_handler.h',
'common/descriptors_android.h',
'common/dump_without_crashing.cc',
'common/dump_without_crashing.h',
'common/encrypted_media_messages_android.h',
'common/extensions/api/commands/commands_handler.cc',
'common/extensions/api/commands/commands_handler.h',
Expand Down
51 changes: 0 additions & 51 deletions chrome/common/dump_without_crashing.cc

This file was deleted.

23 changes: 0 additions & 23 deletions chrome/common/dump_without_crashing.h

This file was deleted.

4 changes: 2 additions & 2 deletions chrome/common/logging_chrome.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug/debugger.h"
#include "base/debug/dump_without_crashing.h"
#include "base/environment.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
Expand All @@ -47,7 +48,6 @@
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/dump_without_crashing.h"
#include "chrome/common/env_vars.h"
#include "ipc/ipc_logging.h"

Expand Down Expand Up @@ -96,7 +96,7 @@ void SilentRuntimeReportHandler(const std::string& str) {
// Handler to silently dump the current process when there is an assert in
// chrome.
void DumpProcessAssertHandler(const std::string& str) {
logging::DumpWithoutCrashing();
base::debug::DumpWithoutCrashing();
}
#endif // OS_WIN
MSVC_ENABLE_OPTIMIZE();
Expand Down
5 changes: 0 additions & 5 deletions components/breakpad/app/breakpad_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ bool BreakpadClient::GetCrashDumpLocation(base::FilePath* crash_dir) {
return false;
}

#if defined(OS_POSIX)
void BreakpadClient::SetDumpWithoutCrashingFunction(void (*function)()) {
}
#endif

size_t BreakpadClient::RegisterCrashKeys() {
return 0;
}
Expand Down
6 changes: 0 additions & 6 deletions components/breakpad/app/breakpad_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ class BreakpadClient {
// |crash_dir| was set.
virtual bool GetCrashDumpLocation(base::FilePath* crash_dir);

#if defined(OS_POSIX)
// Sets a function that'll be invoked to dump the current process when
// without crashing.
virtual void SetDumpWithoutCrashingFunction(void (*function)());
#endif

// Register all of the potential crash keys that can be sent to the crash
// reporting server. Returns the size of the union of all keys.
virtual size_t RegisterCrashKeys();
Expand Down
3 changes: 2 additions & 1 deletion components/breakpad/app/breakpad_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/debug/crash_logging.h"
#include "base/debug/dump_without_crashing.h"
#include "base/files/file_path.h"
#include "base/linux_util.h"
#include "base/path_service.h"
Expand Down Expand Up @@ -1486,7 +1487,7 @@ void InitCrashReporter(const std::string& process_type) {
SetProcessStartTime();
g_pid = getpid();

GetBreakpadClient()->SetDumpWithoutCrashingFunction(&DumpProcess);
base::debug::SetDumpWithoutCrashingFunction(&DumpProcess);
#if defined(ADDRESS_SANITIZER)
// Register the callback for AddressSanitizer error reporting.
__asan_set_error_report_callback(AsanLinuxBreakpadCallback);
Expand Down
4 changes: 2 additions & 2 deletions components/breakpad/app/breakpad_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "base/basictypes.h"
#include "base/command_line.h"
#include "base/debug/crash_logging.h"
#include "base/debug/dump_without_crashing.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#import "base/logging.h"
Expand Down Expand Up @@ -243,8 +244,7 @@ void InitCrashReporter(const std::string& process_type) {
}

logging::SetLogMessageHandler(&FatalMessageHandler);
GetBreakpadClient()->SetDumpWithoutCrashingFunction(
&DumpHelper::DumpWithoutCrashing);
base::debug::SetDumpWithoutCrashingFunction(&DumpHelper::DumpWithoutCrashing);

// abort() sends SIGABRT, which breakpad does not intercept.
// Register a signal handler to crash in a way breakpad will
Expand Down
Loading

0 comments on commit 5a8d4ce

Please sign in to comment.