OLD | NEW |
---|---|
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, |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include "client/settings.h" | 35 #include "client/settings.h" |
36 #include "tools/tool_support.h" | 36 #include "tools/tool_support.h" |
37 #include "util/file/file_io.h" | 37 #include "util/file/file_io.h" |
38 #include "util/file/file_reader.h" | 38 #include "util/file/file_reader.h" |
39 #include "util/misc/uuid.h" | 39 #include "util/misc/uuid.h" |
40 | 40 |
41 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
42 #include <libgen.h> | 42 #include <libgen.h> |
43 #endif // OS_MACOSX | 43 #endif // OS_MACOSX |
44 | 44 |
45 #if defined(OS_POSIX) | |
46 base::FilePath::StringType UTF8ToFilePathStringType(const char* path) { | |
47 return path; | |
48 } | |
49 #elif defined(OS_WIN) | |
50 base::FilePath::StringType UTF8ToFilePathStringType(const char* path) { | |
51 return base::UTF8ToUTF16(path); | |
52 } | |
53 #endif | |
54 | |
55 namespace crashpad { | 45 namespace crashpad { |
56 namespace { | 46 namespace { |
57 | 47 |
58 void Usage(const base::FilePath& me) { | 48 void Usage(const base::FilePath& me) { |
59 fprintf(stderr, | 49 fprintf(stderr, |
60 "Usage: %" PRFilePath " [OPTION]... PID\n" | 50 "Usage: %" PRFilePath " [OPTION]... PID\n" |
61 "Operate on Crashpad crash report databases.\n" | 51 "Operate on Crashpad crash report databases.\n" |
62 "\n" | 52 "\n" |
63 " -d, --database=PATH operate on the crash report database at PATH\ n" | 53 " -d, --database=PATH operate on the crash report database at PATH\ n" |
64 " --show-client-id show the client ID\n" | 54 " --show-client-id show the client ID\n" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 | 248 |
259 for (const CrashReportDatabase::Report& report : reports) { | 249 for (const CrashReportDatabase::Report& report : reports) { |
260 printf("%s%s%s\n", spaces.c_str(), report.uuid.ToString().c_str(), colon); | 250 printf("%s%s%s\n", spaces.c_str(), report.uuid.ToString().c_str(), colon); |
261 if (options.show_all_report_info) { | 251 if (options.show_all_report_info) { |
262 ShowReport(report, space_count + 2, options.utc); | 252 ShowReport(report, space_count + 2, options.utc); |
263 } | 253 } |
264 } | 254 } |
265 } | 255 } |
266 | 256 |
267 int DatabaseUtilMain(int argc, char* argv[]) { | 257 int DatabaseUtilMain(int argc, char* argv[]) { |
268 const base::FilePath me( | 258 const base::FilePath me(base::FilePath(ToolSupport::UTF8ToFilePathStringType( |
269 base::FilePath(UTF8ToFilePathStringType(argv[0])).BaseName()); | 259 argv[0])).BaseName()); |
270 | 260 |
271 enum OptionFlags { | 261 enum OptionFlags { |
272 // “Short” (single-character) options. | 262 // “Short” (single-character) options. |
273 kOptionDatabase = 'd', | 263 kOptionDatabase = 'd', |
274 | 264 |
275 // Long options without short equivalents. | 265 // Long options without short equivalents. |
276 kOptionLastChar = 255, | 266 kOptionLastChar = 255, |
277 kOptionShowClientID, | 267 kOptionShowClientID, |
278 kOptionShowUploadsEnabled, | 268 kOptionShowUploadsEnabled, |
279 kOptionShowLastUploadAttemptTime, | 269 kOptionShowLastUploadAttemptTime, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 } | 361 } |
372 options.has_set_uploads_enabled = true; | 362 options.has_set_uploads_enabled = true; |
373 break; | 363 break; |
374 } | 364 } |
375 case kOptionSetLastUploadAttemptTime: { | 365 case kOptionSetLastUploadAttemptTime: { |
376 options.set_last_upload_attempt_time_string = optarg; | 366 options.set_last_upload_attempt_time_string = optarg; |
377 break; | 367 break; |
378 } | 368 } |
379 case kOptionNewReport: { | 369 case kOptionNewReport: { |
380 options.new_report_paths.push_back( | 370 options.new_report_paths.push_back( |
381 base::FilePath(UTF8ToFilePathStringType(optarg))); | 371 base::FilePath(ToolSupport::UTF8ToFilePathStringType(optarg))); |
382 break; | 372 break; |
383 } | 373 } |
384 case kOptionUTC: { | 374 case kOptionUTC: { |
385 options.utc = true; | 375 options.utc = true; |
386 break; | 376 break; |
387 } | 377 } |
388 case kOptionHelp: { | 378 case kOptionHelp: { |
389 Usage(me); | 379 Usage(me); |
390 return EXIT_SUCCESS; | 380 return EXIT_SUCCESS; |
391 } | 381 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 const size_t set_operations = | 421 const size_t set_operations = |
432 options.has_set_uploads_enabled + | 422 options.has_set_uploads_enabled + |
433 (options.set_last_upload_attempt_time_string != nullptr); | 423 (options.set_last_upload_attempt_time_string != nullptr); |
434 | 424 |
435 if (show_operations + set_operations == 0) { | 425 if (show_operations + set_operations == 0) { |
436 ToolSupport::UsageHint(me, "nothing to do"); | 426 ToolSupport::UsageHint(me, "nothing to do"); |
437 return EXIT_FAILURE; | 427 return EXIT_FAILURE; |
438 } | 428 } |
439 | 429 |
440 scoped_ptr<CrashReportDatabase> database(CrashReportDatabase::Initialize( | 430 scoped_ptr<CrashReportDatabase> database(CrashReportDatabase::Initialize( |
441 base::FilePath(UTF8ToFilePathStringType(options.database)))); | 431 base::FilePath(ToolSupport::UTF8ToFilePathStringType(options.database)))); |
442 if (!database) { | 432 if (!database) { |
443 return EXIT_FAILURE; | 433 return EXIT_FAILURE; |
444 } | 434 } |
445 | 435 |
446 Settings* settings = database->GetSettings(); | 436 Settings* settings = database->GetSettings(); |
447 | 437 |
448 // Handle the “show” options before the “set” options so that when they’re | 438 // Handle the “show” options before the “set” options so that when they’re |
449 // specified together, the “show” option reflects the initial state. | 439 // specified together, the “show” option reflects the initial state. |
450 | 440 |
451 if (options.show_client_id) { | 441 if (options.show_client_id) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 | 581 |
592 } // namespace | 582 } // namespace |
593 } // namespace crashpad | 583 } // namespace crashpad |
594 | 584 |
595 #if defined(OS_POSIX) | 585 #if defined(OS_POSIX) |
596 int main(int argc, char* argv[]) { | 586 int main(int argc, char* argv[]) { |
597 return crashpad::DatabaseUtilMain(argc, argv); | 587 return crashpad::DatabaseUtilMain(argc, argv); |
598 } | 588 } |
599 #elif defined(OS_WIN) | 589 #elif defined(OS_WIN) |
600 int wmain(int argc, wchar_t* argv[]) { | 590 int wmain(int argc, wchar_t* argv[]) { |
601 scoped_ptr<char*[]> argv_as_utf8(new char*[argc]); | 591 return crashpad::ToolSupport::Wmain(argc, argv, &crashpad::DatabaseUtilMain); |
Mark Mentovai
2015/05/05 22:41:35
Ah, yup, you did it. :) I think you can skip the &
scottmg
2015/05/05 23:23:52
Done.
| |
602 std::vector<std::string> storage; | |
603 storage.reserve(argc); | |
604 for (int i = 0; i < argc; ++i) { | |
605 storage.push_back(base::UTF16ToUTF8(argv[i])); | |
606 argv_as_utf8[i] = &storage[i][0]; | |
607 } | |
608 return crashpad::DatabaseUtilMain(argc, argv_as_utf8.get()); | |
609 } | 592 } |
610 #endif // OS_POSIX | 593 #endif // OS_POSIX |
OLD | NEW |