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

Side by Side Diff: components/crash/content/app/crashpad_win.cc

Issue 2053953002: Add chrome_crash_reporter_client_win.cc to the source file list for chrome_elf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix kasko annotations Created 4 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/crash/content/app/crashpad.h" 5 #include "components/crash/content/app/crashpad.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/path_service.h"
13 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
14 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
16 #include "build/build_config.h" 15 #include "build/build_config.h"
17 #include "components/crash/content/app/crash_reporter_client.h" 16 #include "components/crash/content/app/crash_reporter_client.h"
18 #include "components/crash/content/app/crash_switches.h" 17 #include "components/crash/content/app/crash_switches.h"
19 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win. h" 18 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win. h"
20 #include "third_party/crashpad/crashpad/client/crashpad_client.h" 19 #include "third_party/crashpad/crashpad/client/crashpad_client.h"
21 #include "third_party/crashpad/crashpad/client/crashpad_info.h" 20 #include "third_party/crashpad/crashpad/client/crashpad_info.h"
22 #include "third_party/crashpad/crashpad/client/simulate_crash_win.h" 21 #include "third_party/crashpad/crashpad/client/simulate_crash_win.h"
23 22
24 namespace crash_reporter { 23 namespace crash_reporter {
25 namespace internal { 24 namespace internal {
26 25
27 namespace { 26 namespace {
28 27
29 base::LazyInstance<crashpad::CrashpadClient>::Leaky g_crashpad_client = 28 base::LazyInstance<crashpad::CrashpadClient>::Leaky g_crashpad_client =
30 LAZY_INSTANCE_INITIALIZER; 29 LAZY_INSTANCE_INITIALIZER;
31 30
32 } // namespace 31 } // namespace
33 32
34 void GetPlatformCrashpadAnnotations( 33 void GetPlatformCrashpadAnnotations(
35 std::map<std::string, std::string>* annotations) { 34 std::map<std::string, std::string>* annotations) {
36 CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); 35 CrashReporterClient* crash_reporter_client = GetCrashReporterClient();
37 base::FilePath exe_file; 36 wchar_t exe_file[MAX_PATH] = {};
38 CHECK(PathService::Get(base::FILE_EXE, &exe_file)); 37 CHECK(::GetModuleFileName(NULL, exe_file, arraysize(exe_file)));
39 base::string16 product_name, version, special_build, channel_name; 38 base::string16 product_name, version, special_build, channel_name;
40 crash_reporter_client->GetProductNameAndVersion( 39 crash_reporter_client->GetProductNameAndVersion(
41 exe_file.value(), &product_name, &version, &special_build, 40 exe_file, &product_name, &version, &special_build, &channel_name);
42 &channel_name);
43 (*annotations)["prod"] = base::UTF16ToUTF8(product_name); 41 (*annotations)["prod"] = base::UTF16ToUTF8(product_name);
44 (*annotations)["ver"] = base::UTF16ToUTF8(version); 42 (*annotations)["ver"] = base::UTF16ToUTF8(version);
45 (*annotations)["channel"] = base::UTF16ToUTF8(channel_name); 43 (*annotations)["channel"] = base::UTF16ToUTF8(channel_name);
46 if (!special_build.empty()) 44 if (!special_build.empty())
47 (*annotations)["special"] = base::UTF16ToUTF8(special_build); 45 (*annotations)["special"] = base::UTF16ToUTF8(special_build);
48 #if defined(ARCH_CPU_X86) 46 #if defined(ARCH_CPU_X86)
49 (*annotations)["plat"] = std::string("Win32"); 47 (*annotations)["plat"] = std::string("Win32");
50 #elif defined(ARCH_CPU_X86_64) 48 #elif defined(ARCH_CPU_X86_64)
51 (*annotations)["plat"] = std::string("Win64"); 49 (*annotations)["plat"] = std::string("Win64");
52 #endif 50 #endif
53 } 51 }
54 52
55 base::FilePath PlatformCrashpadInitialization(bool initial_client, 53 base::FilePath PlatformCrashpadInitialization(bool initial_client,
56 bool browser_process, 54 bool browser_process,
57 bool embedded_handler) { 55 bool embedded_handler) {
58 base::FilePath database_path; // Only valid in the browser process. 56 base::FilePath database_path; // Only valid in the browser process.
59 bool result; 57 bool result = false;
60 58
61 const char kPipeNameVar[] = "CHROME_CRASHPAD_PIPE_NAME"; 59 const char kPipeNameVar[] = "CHROME_CRASHPAD_PIPE_NAME";
62 const char kServerUrlVar[] = "CHROME_CRASHPAD_SERVER_URL"; 60 const char kServerUrlVar[] = "CHROME_CRASHPAD_SERVER_URL";
63 std::unique_ptr<base::Environment> env(base::Environment::Create()); 61 std::unique_ptr<base::Environment> env(base::Environment::Create());
64
65 if (initial_client) { 62 if (initial_client) {
66 CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); 63 CrashReporterClient* crash_reporter_client = GetCrashReporterClient();
67 64
68 base::string16 database_path_str; 65 base::string16 database_path_str;
69 if (crash_reporter_client->GetCrashDumpLocation(&database_path_str)) 66 if (crash_reporter_client->GetCrashDumpLocation(&database_path_str))
70 database_path = base::FilePath(database_path_str); 67 database_path = base::FilePath(database_path_str);
71 68
72 std::map<std::string, std::string> process_annotations; 69 std::map<std::string, std::string> process_annotations;
73 GetPlatformCrashpadAnnotations(&process_annotations); 70 GetPlatformCrashpadAnnotations(&process_annotations);
74 71
75 #if defined(GOOGLE_CHROME_BUILD) 72 #if defined(GOOGLE_CHROME_BUILD)
76 std::string url = "https://clients2.google.com/cr/report"; 73 std::string url = "https://clients2.google.com/cr/report";
77 #else 74 #else
78 std::string url; 75 std::string url;
79 #endif 76 #endif
80 77
81 // Allow the crash server to be overridden for testing. If the variable 78 // Allow the crash server to be overridden for testing. If the variable
82 // isn't present in the environment then the default URL will remain. 79 // isn't present in the environment then the default URL will remain.
83 env->GetVar(kServerUrlVar, &url); 80 env->GetVar(kServerUrlVar, &url);
84 81
85 base::FilePath exe_file; 82 wchar_t exe_file_path[MAX_PATH] = {};
86 CHECK(PathService::Get(base::FILE_EXE, &exe_file)); 83 CHECK(::GetModuleFileName(NULL, exe_file_path, arraysize(exe_file_path)));
84
85 base::FilePath exe_file(exe_file_path);
87 86
88 bool is_per_user_install = 87 bool is_per_user_install =
89 crash_reporter_client->GetIsPerUserInstall(exe_file.value()); 88 crash_reporter_client->GetIsPerUserInstall(exe_file.value());
90 if (crash_reporter_client->GetShouldDumpLargerDumps(is_per_user_install)) { 89 if (crash_reporter_client->GetShouldDumpLargerDumps(is_per_user_install)) {
91 const uint32_t kIndirectMemoryLimit = 4 * 1024 * 1024; 90 const uint32_t kIndirectMemoryLimit = 4 * 1024 * 1024;
92 crashpad::CrashpadInfo::GetCrashpadInfo() 91 crashpad::CrashpadInfo::GetCrashpadInfo()
93 ->set_gather_indirectly_referenced_memory( 92 ->set_gather_indirectly_referenced_memory(
94 crashpad::TriState::kEnabled, kIndirectMemoryLimit); 93 crashpad::TriState::kEnabled, kIndirectMemoryLimit);
95 } 94 }
96 95
97 // If the handler is embedded in the binary (e.g. chrome, setup), we 96 // If the handler is embedded in the binary (e.g. chrome, setup), we
98 // reinvoke it with --type=crashpad-handler. Otherwise, we use the 97 // reinvoke it with --type=crashpad-handler. Otherwise, we use the
99 // standalone crashpad_handler.exe (for tests, etc.). 98 // standalone crashpad_handler.exe (for tests, etc.).
100 std::vector<std::string> arguments; 99 std::vector<std::string> arguments;
101 if (embedded_handler) { 100 if (embedded_handler) {
102 arguments.push_back(std::string("--type=") + switches::kCrashpadHandler); 101 arguments.push_back(std::string("--type=") + switches::kCrashpadHandler);
103 102 // The prefetch argument added here has to be documented in
104 if (startup_metric_utils::GetPreReadOptions().use_prefetch_argument) { 103 // chrome_switches.cc, below the kPrefetchArgument* constants. A
grt (UTC plus 2) 2016/06/10 14:20:01 fdoray: PTAL
fdoray 2016/06/10 17:37:42 The pre-read experiment is completed. Removing thi
105 // The prefetch argument added here has to be documented in 104 // constant can't be used here because crashpad can't depend on Chrome.
106 // chrome_switches.cc, below the kPrefetchArgument* constants. A 105 arguments.push_back("/prefetch:7");
107 // constant can't be used here because crashpad can't depend on Chrome.
108 arguments.push_back("/prefetch:7");
109 }
110 } else { 106 } else {
111 base::FilePath exe_dir = exe_file.DirName(); 107 base::FilePath exe_dir = exe_file.DirName();
112 exe_file = exe_dir.Append(FILE_PATH_LITERAL("crashpad_handler.exe")); 108 exe_file = exe_dir.Append(FILE_PATH_LITERAL("crashpad_handler.exe"));
113 } 109 }
114
115 // TODO(scottmg): See https://crashpad.chromium.org/bug/23. 110 // TODO(scottmg): See https://crashpad.chromium.org/bug/23.
116 arguments.push_back("--no-rate-limit"); 111 arguments.push_back("--no-rate-limit");
117 112
118 result = g_crashpad_client.Get().StartHandler( 113 result = g_crashpad_client.Get().StartHandler(
119 exe_file, database_path, url, process_annotations, arguments, false); 114 exe_file, database_path, url, process_annotations, arguments, false);
120 115
121 // If we're the browser, push the pipe name into the environment so child 116 // If we're the browser, push the pipe name into the environment so child
122 // processes can connect to it. If we inherited another crashpad_handler's 117 // processes can connect to it. If we inherited another crashpad_handler's
123 // pipe name, we'll overwrite it here. 118 // pipe name, we'll overwrite it here.
124 env->SetVar(kPipeNameVar, 119 env->SetVar(kPipeNameVar,
125 base::UTF16ToUTF8(g_crashpad_client.Get().GetHandlerIPCPipe())); 120 base::UTF16ToUTF8(g_crashpad_client.Get().GetHandlerIPCPipe()));
126 } else { 121 } else {
127 std::string pipe_name_utf8; 122 std::string pipe_name_utf8;
128 result = env->GetVar(kPipeNameVar, &pipe_name_utf8); 123 result = env->GetVar(kPipeNameVar, &pipe_name_utf8);
129 if (result) { 124 if (result) {
130 result = g_crashpad_client.Get().SetHandlerIPCPipe( 125 result = g_crashpad_client.Get().SetHandlerIPCPipe(
131 base::UTF8ToUTF16(pipe_name_utf8)); 126 base::UTF8ToUTF16(pipe_name_utf8));
132 } 127 }
133 } 128 }
134 129
135 if (result) { 130 if (result) {
136 result = g_crashpad_client.Get().UseHandler(); 131 result = g_crashpad_client.Get().UseHandler();
137 } 132 }
138
139 return database_path; 133 return database_path;
140 } 134 }
141 135
142 // TODO(scottmg): http://crbug.com/546288 These exported functions are for 136 // TODO(scottmg): http://crbug.com/546288 These exported functions are for
143 // compatibility with how Breakpad worked, but it seems like there's no need to 137 // compatibility with how Breakpad worked, but it seems like there's no need to
144 // do the CreateRemoteThread() dance with a minor extension of the Crashpad API 138 // do the CreateRemoteThread() dance with a minor extension of the Crashpad API
145 // (to just pass the pid we want a dump for). We should add that and then modify 139 // (to just pass the pid we want a dump for). We should add that and then modify
146 // hang_crash_dump_win.cc to work in a more direct manner. 140 // hang_crash_dump_win.cc to work in a more direct manner.
147 141
148 // Used for dumping a process state when there is no crash. 142 // Used for dumping a process state when there is no crash.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 void __declspec(dllexport) __cdecl UnregisterNonABICompliantCodeRange( 285 void __declspec(dllexport) __cdecl UnregisterNonABICompliantCodeRange(
292 void* start) { 286 void* start) {
293 ExceptionHandlerRecord* record = 287 ExceptionHandlerRecord* record =
294 reinterpret_cast<ExceptionHandlerRecord*>(start); 288 reinterpret_cast<ExceptionHandlerRecord*>(start);
295 289
296 CHECK(RtlDeleteFunctionTable(&record->runtime_function)); 290 CHECK(RtlDeleteFunctionTable(&record->runtime_function));
297 } 291 }
298 #endif // ARCH_CPU_X86_64 292 #endif // ARCH_CPU_X86_64
299 293
300 } // extern "C" 294 } // extern "C"
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698