OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // This module contains the necessary code to register the Breakpad exception |
| 6 // handler. This implementation is based on Chrome crash reporting code. |
| 7 |
| 8 #include "chrome_elf/breakpad.h" |
| 9 |
| 10 #include <string> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "chrome_elf/chrome_elf_util.h" |
| 14 #include "version.h" // NOLINT |
| 15 |
| 16 google_breakpad::ExceptionHandler* g_elf_breakpad; |
| 17 |
| 18 namespace { |
| 19 |
| 20 const wchar_t kBreakpadProductName[] = L"ChromeElf"; |
| 21 const wchar_t kBreakpadVersionEntry[] = L"ver"; |
| 22 const wchar_t kBreakpadVersionDefault[] = L"0.1.0.0"; |
| 23 const wchar_t kBreakpadProdEntry[] = L"prod"; |
| 24 const wchar_t kBreakpadPlatformEntry[] = L"plat"; |
| 25 const wchar_t kBreakpadPlatformWin32[] = L"Win32"; |
| 26 |
| 27 // TODO(caitkp): figure out what these should be. Current pipe works with local |
| 28 // instance of crash_service.exe. |
| 29 // The protocol for connecting to the out-of-process Breakpad crash |
| 30 // reporter is different for x86-32 and x86-64: the message sizes |
| 31 // are different because the message struct contains a pointer. As |
| 32 // a result, there are two different named pipes to connect to. The |
| 33 // 64-bit one is distinguished with an "-x64" suffix. |
| 34 #if defined(_WIN64) |
| 35 const wchar_t kGoogleUpdatePipeName[] = |
| 36 L"\\\\.\\pipe\\ChromeCrashServices"; |
| 37 // L"\\\\.\\pipe\\GoogleCrashServices\\S-1-5-18-x64"; |
| 38 #else |
| 39 const wchar_t kGoogleUpdatePipeName[] = |
| 40 L"\\\\.\\pipe\\ChromeCrashServices"; |
| 41 // L"\\\\.\\pipe\\GoogleCrashServices\\S-1-5-18"; |
| 42 #endif |
| 43 |
| 44 |
| 45 google_breakpad::CustomClientInfo* GetCustomInfo() { |
| 46 static google_breakpad::CustomInfoEntry ver_entry( |
| 47 kBreakpadVersionEntry, TEXT(CHROME_VERSION_STRING)); |
| 48 static google_breakpad::CustomInfoEntry prod_entry( |
| 49 kBreakpadProdEntry, kBreakpadProductName); |
| 50 static google_breakpad::CustomInfoEntry plat_entry( |
| 51 kBreakpadPlatformEntry, kBreakpadPlatformWin32); |
| 52 static google_breakpad::CustomInfoEntry entries[] = { |
| 53 ver_entry, prod_entry, plat_entry }; |
| 54 static google_breakpad::CustomClientInfo custom_info = { |
| 55 entries, arraysize(entries) }; |
| 56 return &custom_info; |
| 57 } |
| 58 |
| 59 } // namespace |
| 60 |
| 61 int GenerateCrashDump(EXCEPTION_POINTERS* exinfo) { |
| 62 DWORD code = exinfo->ExceptionRecord->ExceptionCode; |
| 63 if (code == EXCEPTION_BREAKPOINT || code == EXCEPTION_SINGLE_STEP) |
| 64 return EXCEPTION_CONTINUE_SEARCH; |
| 65 |
| 66 if (g_elf_breakpad != NULL) |
| 67 g_elf_breakpad->WriteMinidumpForException(exinfo); |
| 68 return EXCEPTION_CONTINUE_SEARCH; |
| 69 } |
| 70 |
| 71 void InitializeCrashReporting() { |
| 72 // Do not set up crash reporting if the user has not consented to it. |
| 73 if (!AreUsageStatsEnabled()) |
| 74 return; |
| 75 |
| 76 // Disable the message box for assertions. |
| 77 _CrtSetReportMode(_CRT_ASSERT, 0); |
| 78 |
| 79 // Get the alternate dump directory. We use the temp path. |
| 80 // N.B. We don't use base::GetTempDir() here to avoid running more code then |
| 81 // necessary before crashes can be properly reported. |
| 82 wchar_t temp_directory[MAX_PATH + 1] = {}; |
| 83 DWORD length = GetTempPath(MAX_PATH, temp_directory); |
| 84 if (length == 0) |
| 85 return; |
| 86 |
| 87 // Minidump with stacks, PEB, TEBs and unloaded module list. |
| 88 MINIDUMP_TYPE dump_type = static_cast<MINIDUMP_TYPE>( |
| 89 MiniDumpWithProcessThreadData | // Get PEB and TEB. |
| 90 MiniDumpWithUnloadedModules | // Get unloaded modules when available. |
| 91 MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack. |
| 92 |
| 93 g_elf_breakpad = new google_breakpad::ExceptionHandler( |
| 94 temp_directory, |
| 95 NULL, |
| 96 NULL, |
| 97 NULL, |
| 98 google_breakpad::ExceptionHandler::HANDLER_ALL, |
| 99 dump_type, |
| 100 kGoogleUpdatePipeName, |
| 101 GetCustomInfo()); |
| 102 |
| 103 if (g_elf_breakpad->IsOutOfProcess()) { |
| 104 // Tells breakpad to handle breakpoint and single step exceptions. |
| 105 g_elf_breakpad->set_handle_debug_exceptions(true); |
| 106 } |
| 107 } |
OLD | NEW |