Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: chrome_elf/breakpad/breakpad.cc

Issue 2123073002: Switch chrome_elf exception handling from breakpad to crashpad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to tip and git cl format Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome_elf/breakpad/breakpad.h ('k') | chrome_elf/chrome_elf.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 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's crash reporting code.
7
8 #include "chrome_elf/breakpad/breakpad.h"
9
10 #include "breakpad/src/client/windows/handler/exception_handler.h"
11 #include "chrome/common/chrome_version.h"
12 #include "chrome/install_static/install_util.h"
13 #include "chrome_elf/nt_registry/nt_registry.h"
14
15 google_breakpad::ExceptionHandler* g_elf_breakpad = NULL;
16
17 namespace {
18
19 const wchar_t kBreakpadProductName[] = L"Chrome";
20 const wchar_t kBreakpadVersionEntry[] = L"ver";
21 const wchar_t kBreakpadProdEntry[] = L"prod";
22 const wchar_t kBreakpadPlatformEntry[] = L"plat";
23 const wchar_t kBreakpadPlatformWin32[] = L"Win32";
24 const wchar_t kBreakpadProcessEntry[] = L"ptype";
25 const wchar_t kBreakpadChannelEntry[] = L"channel";
26
27 // The protocol for connecting to the out-of-process Breakpad crash
28 // reporter is different for x86-32 and x86-64: the message sizes
29 // are different because the message struct contains a pointer. As
30 // a result, there are two different named pipes to connect to. The
31 // 64-bit one is distinguished with an "-x64" suffix.
32 const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices\\";
33 const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\";
34 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18";
35
36 const wchar_t kNoErrorDialogs[] = L"noerrdialogs";
37
38 google_breakpad::CustomClientInfo* GetCustomInfo() {
39 std::wstring process =
40 install_static::IsNonBrowserProcess() ? L"renderer" : L"browser";
41
42 wchar_t exe_path[MAX_PATH] = {};
43 std::wstring channel;
44 if (GetModuleFileName(NULL, exe_path, MAX_PATH) &&
45 install_static::IsSxSChrome(exe_path)) {
46 channel = L"canary";
47 }
48
49 static google_breakpad::CustomInfoEntry ver_entry(
50 kBreakpadVersionEntry, TEXT(CHROME_VERSION_STRING));
51 static google_breakpad::CustomInfoEntry prod_entry(kBreakpadProdEntry,
52 kBreakpadProductName);
53 static google_breakpad::CustomInfoEntry plat_entry(kBreakpadPlatformEntry,
54 kBreakpadPlatformWin32);
55 static google_breakpad::CustomInfoEntry proc_entry(kBreakpadProcessEntry,
56 process.c_str());
57 static google_breakpad::CustomInfoEntry channel_entry(kBreakpadChannelEntry,
58 channel.c_str());
59 static google_breakpad::CustomInfoEntry entries[] = {
60 ver_entry, prod_entry, plat_entry, proc_entry, channel_entry};
61 static google_breakpad::CustomClientInfo custom_info = {
62 entries, (sizeof(entries) / sizeof(google_breakpad::CustomInfoEntry))};
63 return &custom_info;
64 }
65
66 bool IsHeadless() {
67 DWORD ret = ::GetEnvironmentVariable(L"CHROME_HEADLESS", NULL, 0);
68 if (ret != 0)
69 return true;
70
71 wchar_t* command_line = ::GetCommandLine();
72
73 // Note: Since this is a pure substring search rather than a check for a
74 // switch, there is a small chance that this code will match things that the
75 // Chrome code (which executes a similar check) does not. However, as long as
76 // no other switches contain the string "noerrdialogs", it should not be an
77 // issue.
78 return (command_line && wcsstr(command_line, kNoErrorDialogs));
79 }
80
81 } // namespace
82
83 int GenerateCrashDump(EXCEPTION_POINTERS* exinfo) {
84 DWORD code = exinfo->ExceptionRecord->ExceptionCode;
85 if (code == EXCEPTION_BREAKPOINT || code == EXCEPTION_SINGLE_STEP)
86 return EXCEPTION_CONTINUE_SEARCH;
87
88 if (g_elf_breakpad != NULL)
89 g_elf_breakpad->WriteMinidumpForException(exinfo);
90 return EXCEPTION_CONTINUE_SEARCH;
91 }
92
93 void InitializeCrashReporting() {
94 wchar_t exe_path[MAX_PATH] = {};
95 if (!::GetModuleFileName(NULL, exe_path, MAX_PATH))
96 return;
97
98 // Disable the message box for assertions.
99 _CrtSetReportMode(_CRT_ASSERT, 0);
100
101 // Get the alternate dump directory. We use the temp path.
102 // N.B. We don't use base::GetTempDir() here to avoid running more code then
103 // necessary before crashes can be properly reported.
104 wchar_t temp_directory[MAX_PATH + 1] = {};
105 DWORD length = GetTempPath(MAX_PATH, temp_directory);
106 if (length == 0)
107 return;
108
109 // Minidump with stacks, PEB, TEBs and unloaded module list.
110 MINIDUMP_TYPE dump_type = static_cast<MINIDUMP_TYPE>(
111 MiniDumpWithProcessThreadData | // Get PEB and TEB.
112 MiniDumpWithUnloadedModules | // Get unloaded modules when available.
113 MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by
114 // stack.
115
116 #if defined(GOOGLE_CHROME_BUILD) && defined(OFFICIAL_BUILD)
117 bool is_official_chrome_build = true;
118 #else
119 bool is_official_chrome_build = false;
120 #endif
121
122 std::wstring pipe_name;
123
124 bool enabled_by_policy = false;
125 bool use_policy =
126 install_static::ReportingIsEnforcedByPolicy(&enabled_by_policy);
127
128 if (!use_policy && IsHeadless()) {
129 pipe_name = kChromePipeName;
130 } else if (use_policy ? enabled_by_policy
131 : (is_official_chrome_build &&
132 install_static::GetCollectStatsConsent())) {
133 // Build the pipe name. It can be one of:
134 // 32-bit system: \\.\pipe\GoogleCrashServices\S-1-5-18
135 // 32-bit user: \\.\pipe\GoogleCrashServices\<user SID>
136 // 64-bit system: \\.\pipe\GoogleCrashServices\S-1-5-18-x64
137 // 64-bit user: \\.\pipe\GoogleCrashServices\<user SID>-x64
138 std::wstring user_sid = install_static::IsSystemInstall(exe_path)
139 ? kSystemPrincipalSid
140 : nt::GetCurrentUserSidString();
141 if (user_sid.empty())
142 return;
143
144 pipe_name = kGoogleUpdatePipeName;
145 pipe_name += user_sid;
146
147 #if defined(_WIN64)
148 pipe_name += L"-x64";
149 #endif
150 } else {
151 // Either this is a Chromium build, reporting is disabled by policy or the
152 // user has not given consent.
153 return;
154 }
155
156 g_elf_breakpad = new google_breakpad::ExceptionHandler(
157 temp_directory, NULL, NULL, NULL,
158 google_breakpad::ExceptionHandler::HANDLER_ALL, dump_type,
159 pipe_name.c_str(), GetCustomInfo());
160
161 if (g_elf_breakpad->IsOutOfProcess()) {
162 // Tells breakpad to handle breakpoint and single step exceptions.
163 g_elf_breakpad->set_handle_debug_exceptions(true);
164 }
165 }
OLDNEW
« no previous file with comments | « chrome_elf/breakpad/breakpad.h ('k') | chrome_elf/chrome_elf.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698