Index: chrome_elf/breakpad.cc |
diff --git a/chrome_elf/breakpad.cc b/chrome_elf/breakpad.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cef0f5508749fac2e5f1ecea45897ac123c35382 |
--- /dev/null |
+++ b/chrome_elf/breakpad.cc |
@@ -0,0 +1,108 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
grt (UTC plus 2)
2014/02/13 03:58:26
(c)
Cait (Slow)
2014/02/14 01:17:02
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// This module contains the necessary code to register the Breakpad exception |
+// handler. This implementation is based on Chrome's crash reporting code. |
+ |
+#include "chrome_elf/breakpad.h" |
+ |
+#include <string> |
+ |
+#include "base/macros.h" |
+#include "breakpad/src/client/windows/handler/exception_handler.h" |
+#include "chrome_elf/chrome_elf_util.h" |
+#include "version.h" // NOLINT |
+ |
+google_breakpad::ExceptionHandler* g_elf_breakpad = NULL; |
+ |
+namespace { |
+ |
+const wchar_t kBreakpadProductName[] = L"ChromeElf"; |
+const wchar_t kBreakpadVersionEntry[] = L"ver"; |
+const wchar_t kBreakpadVersionDefault[] = L"0.1.0.0"; |
+const wchar_t kBreakpadProdEntry[] = L"prod"; |
+const wchar_t kBreakpadPlatformEntry[] = L"plat"; |
+const wchar_t kBreakpadPlatformWin32[] = L"Win32"; |
+ |
+// TODO(caitkp): figure out what these should be. Current pipe works with local |
grt (UTC plus 2)
2014/02/13 03:58:26
32-bit system: \\.\pipe\GoogleCrashServices\S-1-5-
Cait (Slow)
2014/02/14 01:17:02
Done.
|
+// instance of crash_service.exe. |
+// The protocol for connecting to the out-of-process Breakpad crash |
+// reporter is different for x86-32 and x86-64: the message sizes |
+// are different because the message struct contains a pointer. As |
+// a result, there are two different named pipes to connect to. The |
+// 64-bit one is distinguished with an "-x64" suffix. |
+#if defined(_WIN64) |
+const wchar_t kGoogleUpdatePipeName[] = |
+ L"\\\\.\\pipe\\ChromeCrashServices"; |
+ // L"\\\\.\\pipe\\GoogleCrashServices\\S-1-5-18-x64"; |
+#else |
+const wchar_t kGoogleUpdatePipeName[] = |
+ L"\\\\.\\pipe\\ChromeCrashServices"; |
+ // L"\\\\.\\pipe\\GoogleCrashServices\\S-1-5-18"; |
+#endif |
+ |
grt (UTC plus 2)
2014/02/13 03:58:26
nit: remove extra newline
Cait (Slow)
2014/02/14 01:17:02
Done.
|
+ |
+google_breakpad::CustomClientInfo* GetCustomInfo() { |
+ static google_breakpad::CustomInfoEntry ver_entry( |
+ kBreakpadVersionEntry, TEXT(CHROME_VERSION_STRING)); |
+ static google_breakpad::CustomInfoEntry prod_entry( |
+ kBreakpadProdEntry, kBreakpadProductName); |
+ static google_breakpad::CustomInfoEntry plat_entry( |
+ kBreakpadPlatformEntry, kBreakpadPlatformWin32); |
+ static google_breakpad::CustomInfoEntry entries[] = { |
+ ver_entry, prod_entry, plat_entry }; |
+ static google_breakpad::CustomClientInfo custom_info = { |
+ entries, arraysize(entries) }; |
+ return &custom_info; |
+} |
+ |
+} // namespace |
+ |
+int GenerateCrashDump(EXCEPTION_POINTERS* exinfo) { |
+ DWORD code = exinfo->ExceptionRecord->ExceptionCode; |
+ if (code == EXCEPTION_BREAKPOINT || code == EXCEPTION_SINGLE_STEP) |
+ return EXCEPTION_CONTINUE_SEARCH; |
+ |
+ if (g_elf_breakpad != NULL) |
+ g_elf_breakpad->WriteMinidumpForException(exinfo); |
+ return EXCEPTION_CONTINUE_SEARCH; |
+} |
+ |
+void InitializeCrashReporting() { |
+ // Do not set up crash reporting if the user has not consented to it. |
+ if (!AreUsageStatsEnabled()) |
+ return; |
+ |
+ // Disable the message box for assertions. |
+ _CrtSetReportMode(_CRT_ASSERT, 0); |
+ |
+ // Get the alternate dump directory. We use the temp path. |
+ // N.B. We don't use base::GetTempDir() here to avoid running more code then |
+ // necessary before crashes can be properly reported. |
+ wchar_t temp_directory[MAX_PATH + 1] = {}; |
+ DWORD length = GetTempPath(MAX_PATH, temp_directory); |
+ if (length == 0) |
+ return; |
+ |
+ // Minidump with stacks, PEB, TEBs and unloaded module list. |
+ MINIDUMP_TYPE dump_type = static_cast<MINIDUMP_TYPE>( |
+ MiniDumpWithProcessThreadData | // Get PEB and TEB. |
grt (UTC plus 2)
2014/02/13 03:58:26
nit: indent two more spaces
Cait (Slow)
2014/02/14 01:17:02
Done.
|
+ MiniDumpWithUnloadedModules | // Get unloaded modules when available. |
+ MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack. |
+ |
+ g_elf_breakpad = new google_breakpad::ExceptionHandler( |
+ temp_directory, |
+ NULL, |
+ NULL, |
+ NULL, |
+ google_breakpad::ExceptionHandler::HANDLER_ALL, |
+ dump_type, |
+ kGoogleUpdatePipeName, |
+ GetCustomInfo()); |
+ |
+ if (g_elf_breakpad->IsOutOfProcess()) { |
+ // Tells breakpad to handle breakpoint and single step exceptions. |
+ g_elf_breakpad->set_handle_debug_exceptions(true); |
+ } |
+} |