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

Side by Side Diff: handler/win/crashy_test_program.cc

Issue 1428803006: win: Implement CrashpadClient::StartHandler() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback; add a test Created 5 years, 1 month 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 | « handler/main.cc ('k') | snapshot/win/end_to_end_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include <stdlib.h>
15 #include <windows.h> 16 #include <windows.h>
16 #include <winternl.h> 17 #include <winternl.h>
17 18
19 #include <string>
20 #include <map>
21 #include <vector>
22
18 // ntstatus.h conflicts with windows.h so define this locally. 23 // ntstatus.h conflicts with windows.h so define this locally.
19 #ifndef STATUS_NO_SUCH_FILE 24 #ifndef STATUS_NO_SUCH_FILE
20 #define STATUS_NO_SUCH_FILE static_cast<NTSTATUS>(0xC000000F) 25 #define STATUS_NO_SUCH_FILE static_cast<NTSTATUS>(0xC000000F)
21 #endif 26 #endif
22 27
23 #include "base/basictypes.h" 28 #include "base/basictypes.h"
29 #include "base/files/file_path.h"
24 #include "base/logging.h" 30 #include "base/logging.h"
31 #include "base/strings/utf_string_conversions.h"
25 #include "client/crashpad_client.h" 32 #include "client/crashpad_client.h"
26 #include "tools/tool_support.h" 33 #include "tools/tool_support.h"
27 #include "util/win/critical_section_with_debug_info.h" 34 #include "util/win/critical_section_with_debug_info.h"
28 #include "util/win/get_function.h" 35 #include "util/win/get_function.h"
29 36
30 namespace crashpad { 37 namespace crashpad {
31 namespace { 38 namespace {
32 39
33 CRITICAL_SECTION g_test_critical_section; 40 CRITICAL_SECTION g_test_critical_section;
34 41
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // SetLastError and NTSTATUS so that we have something to view in !gle in 88 // SetLastError and NTSTATUS so that we have something to view in !gle in
82 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the 89 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the
83 // LastStatusError of the TEB as a side-effect, and we'll be setting 90 // LastStatusError of the TEB as a side-effect, and we'll be setting
84 // ERROR_FILE_NOT_FOUND for GetLastError(). 91 // ERROR_FILE_NOT_FOUND for GetLastError().
85 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); 92 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE));
86 volatile int* foo = reinterpret_cast<volatile int*>(7); 93 volatile int* foo = reinterpret_cast<volatile int*>(7);
87 *foo = 42; 94 *foo = 42;
88 } 95 }
89 96
90 int CrashyMain(int argc, char* argv[]) { 97 int CrashyMain(int argc, char* argv[]) {
91 if (argc != 2) { 98 CrashpadClient client;
99
100 if (argc == 2) {
101 if (!client.SetHandler(argv[1])) {
102 LOG(ERROR) << "SetHandler";
103 return EXIT_FAILURE;
104 }
105 } else if (argc == 3) {
106 if (!client.StartHandler(base::FilePath(base::UTF8ToUTF16(argv[1])),
107 base::FilePath(base::UTF8ToUTF16(argv[2])),
108 std::string(),
109 std::map<std::string, std::string>(),
110 std::vector<std::string>())) {
111 LOG(ERROR) << "StartHandler";
112 return EXIT_FAILURE;
113 }
114 } else {
92 fprintf(stderr, "Usage: %s <server_pipe_name>\n", argv[0]); 115 fprintf(stderr, "Usage: %s <server_pipe_name>\n", argv[0]);
93 return 1; 116 fprintf(stderr, " %s <handler_path> <database_path>\n", argv[0]);
117 return EXIT_FAILURE;
94 } 118 }
95 119
96 CrashpadClient client;
97 if (!client.SetHandler(argv[1])) {
98 LOG(ERROR) << "SetHandler";
99 return 1;
100 }
101 if (!client.UseHandler()) { 120 if (!client.UseHandler()) {
102 LOG(ERROR) << "UseHandler"; 121 LOG(ERROR) << "UseHandler";
103 return 1; 122 return EXIT_FAILURE;
104 } 123 }
105 124
106 AllocateMemoryOfVariousProtections(); 125 AllocateMemoryOfVariousProtections();
107 126
108 if (InitializeCriticalSectionWithDebugInfoIfPossible( 127 if (InitializeCriticalSectionWithDebugInfoIfPossible(
109 &g_test_critical_section)) { 128 &g_test_critical_section)) {
110 EnterCriticalSection(&g_test_critical_section); 129 EnterCriticalSection(&g_test_critical_section);
111 } 130 }
112 131
113 SomeCrashyFunction(); 132 SomeCrashyFunction();
114 133
115 return 0; 134 return EXIT_SUCCESS;
116 } 135 }
117 136
118 } // namespace 137 } // namespace
119 } // namespace crashpad 138 } // namespace crashpad
120 139
121 int wmain(int argc, wchar_t* argv[]) { 140 int wmain(int argc, wchar_t* argv[]) {
122 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::CrashyMain); 141 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::CrashyMain);
123 } 142 }
OLDNEW
« no previous file with comments | « handler/main.cc ('k') | snapshot/win/end_to_end_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698