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