| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "crash-reporter/kernel_collector.h" | 11 #include "crash-reporter/kernel_collector.h" |
| 12 #include "crash-reporter/system_logging.h" | 12 #include "crash-reporter/system_logging.h" |
| 13 #include "crash-reporter/unclean_shutdown_collector.h" | 13 #include "crash-reporter/unclean_shutdown_collector.h" |
| 14 #include "crash-reporter/user_collector.h" | 14 #include "crash-reporter/user_collector.h" |
| 15 #include "gflags/gflags.h" | 15 #include "gflags/gflags.h" |
| 16 #include "metrics/metrics_library.h" | 16 #include "metrics/metrics_library.h" |
| 17 | 17 |
| 18 #pragma GCC diagnostic ignored "-Wstrict-aliasing" | 18 #pragma GCC diagnostic ignored "-Wstrict-aliasing" |
| 19 DEFINE_bool(init, false, "Initialize crash logging"); | 19 DEFINE_bool(init, false, "Initialize crash logging"); |
| 20 DEFINE_bool(clean_shutdown, false, "Signal clean shutdown"); | 20 DEFINE_bool(clean_shutdown, false, "Signal clean shutdown"); |
| 21 DEFINE_string(generate_kernel_signature, "", | 21 DEFINE_string(generate_kernel_signature, "", |
| 22 "Generate signature from given kcrash file"); | 22 "Generate signature from given kcrash file"); |
| 23 DEFINE_bool(crash_test, false, "Crash test"); | 23 DEFINE_bool(crash_test, false, "Crash test"); |
| 24 DEFINE_int32(pid, -1, "Crashing PID"); | 24 DEFINE_string(user, "", "User crash info (pid:signal:exec_name)"); |
| 25 DEFINE_int32(signal, -1, "Signal causing crash"); | |
| 26 DEFINE_bool(unclean_check, true, "Check for unclean shutdown"); | 25 DEFINE_bool(unclean_check, true, "Check for unclean shutdown"); |
| 27 #pragma GCC diagnostic error "-Wstrict-aliasing" | 26 #pragma GCC diagnostic error "-Wstrict-aliasing" |
| 28 | 27 |
| 29 static const char kCrashCounterHistogram[] = "Logging.CrashCounter"; | 28 static const char kCrashCounterHistogram[] = "Logging.CrashCounter"; |
| 30 static const char kUserCrashSignal[] = | 29 static const char kUserCrashSignal[] = |
| 31 "org.chromium.CrashReporter.UserCrash"; | 30 "org.chromium.CrashReporter.UserCrash"; |
| 32 static const char kUncleanShutdownFile[] = | 31 static const char kUncleanShutdownFile[] = |
| 33 "/var/lib/crash_reporter/pending_clean_shutdown"; | 32 "/var/lib/crash_reporter/pending_clean_shutdown"; |
| 34 | 33 |
| 35 | 34 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 123 |
| 125 // Must enable the unclean shutdown collector *after* collecting. | 124 // Must enable the unclean shutdown collector *after* collecting. |
| 126 unclean_shutdown_collector->Enable(); | 125 unclean_shutdown_collector->Enable(); |
| 127 user_collector->Enable(); | 126 user_collector->Enable(); |
| 128 | 127 |
| 129 return 0; | 128 return 0; |
| 130 } | 129 } |
| 131 | 130 |
| 132 static int HandleUserCrash(UserCollector *user_collector) { | 131 static int HandleUserCrash(UserCollector *user_collector) { |
| 133 // Handle a specific user space crash. | 132 // Handle a specific user space crash. |
| 134 CHECK(FLAGS_signal != -1) << "Signal must be set"; | 133 CHECK(!FLAGS_user.empty()) << "--user= must be set"; |
| 135 CHECK(FLAGS_pid != -1) << "PID must be set"; | |
| 136 | 134 |
| 137 // Make it possible to test what happens when we crash while | 135 // Make it possible to test what happens when we crash while |
| 138 // handling a crash. | 136 // handling a crash. |
| 139 if (FLAGS_crash_test) { | 137 if (FLAGS_crash_test) { |
| 140 *(char *)0 = 0; | 138 *(char *)0 = 0; |
| 141 return 0; | 139 return 0; |
| 142 } | 140 } |
| 143 | 141 |
| 144 // Handle the crash, get the name of the process from procfs. | 142 // Handle the crash, get the name of the process from procfs. |
| 145 if (!user_collector->HandleCrash(FLAGS_signal, FLAGS_pid, NULL)) { | 143 if (!user_collector->HandleCrash(FLAGS_user, NULL)) { |
| 146 return 1; | 144 return 1; |
| 147 } | 145 } |
| 148 return 0; | 146 return 0; |
| 149 } | 147 } |
| 150 | 148 |
| 151 // Interactive/diagnostics mode for generating kernel crash signatures. | 149 // Interactive/diagnostics mode for generating kernel crash signatures. |
| 152 static int GenerateKernelSignature(KernelCollector *kernel_collector) { | 150 static int GenerateKernelSignature(KernelCollector *kernel_collector) { |
| 153 std::string kcrash_contents; | 151 std::string kcrash_contents; |
| 154 std::string signature; | 152 std::string signature; |
| 155 if (!file_util::ReadFileToString(FilePath(FLAGS_generate_kernel_signature), | 153 if (!file_util::ReadFileToString(FilePath(FLAGS_generate_kernel_signature), |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 user_collector.Disable(); | 203 user_collector.Disable(); |
| 206 return 0; | 204 return 0; |
| 207 } | 205 } |
| 208 | 206 |
| 209 if (!FLAGS_generate_kernel_signature.empty()) { | 207 if (!FLAGS_generate_kernel_signature.empty()) { |
| 210 return GenerateKernelSignature(&kernel_collector); | 208 return GenerateKernelSignature(&kernel_collector); |
| 211 } | 209 } |
| 212 | 210 |
| 213 return HandleUserCrash(&user_collector); | 211 return HandleUserCrash(&user_collector); |
| 214 } | 212 } |
| OLD | NEW |