| 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_string(exec_name, "", "Crashing executable name"); |
| 24 DEFINE_int32(pid, -1, "Crashing PID"); | 25 DEFINE_int32(pid, -1, "Crashing PID"); |
| 25 DEFINE_int32(signal, -1, "Signal causing crash"); | 26 DEFINE_int32(signal, -1, "Signal causing crash"); |
| 26 DEFINE_bool(unclean_check, true, "Check for unclean shutdown"); | 27 DEFINE_bool(unclean_check, true, "Check for unclean shutdown"); |
| 27 #pragma GCC diagnostic error "-Wstrict-aliasing" | 28 #pragma GCC diagnostic error "-Wstrict-aliasing" |
| 28 | 29 |
| 29 static const char kCrashCounterHistogram[] = "Logging.CrashCounter"; | 30 static const char kCrashCounterHistogram[] = "Logging.CrashCounter"; |
| 30 static const char kUserCrashSignal[] = | 31 static const char kUserCrashSignal[] = |
| 31 "org.chromium.CrashReporter.UserCrash"; | 32 "org.chromium.CrashReporter.UserCrash"; |
| 32 static const char kUncleanShutdownFile[] = | 33 static const char kUncleanShutdownFile[] = |
| 33 "/var/lib/crash_reporter/pending_clean_shutdown"; | 34 "/var/lib/crash_reporter/pending_clean_shutdown"; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 CHECK(FLAGS_pid != -1) << "PID must be set"; | 136 CHECK(FLAGS_pid != -1) << "PID must be set"; |
| 136 | 137 |
| 137 // Make it possible to test what happens when we crash while | 138 // Make it possible to test what happens when we crash while |
| 138 // handling a crash. | 139 // handling a crash. |
| 139 if (FLAGS_crash_test) { | 140 if (FLAGS_crash_test) { |
| 140 *(char *)0 = 0; | 141 *(char *)0 = 0; |
| 141 return 0; | 142 return 0; |
| 142 } | 143 } |
| 143 | 144 |
| 144 // Handle the crash, get the name of the process from procfs. | 145 // Handle the crash, get the name of the process from procfs. |
| 145 if (!user_collector->HandleCrash(FLAGS_signal, FLAGS_pid, NULL)) { | 146 if (!user_collector->HandleCrash(FLAGS_signal, FLAGS_pid, |
| 147 FLAGS_exec_name.c_str(), NULL)) { |
| 146 return 1; | 148 return 1; |
| 147 } | 149 } |
| 148 return 0; | 150 return 0; |
| 149 } | 151 } |
| 150 | 152 |
| 151 // Interactive/diagnostics mode for generating kernel crash signatures. | 153 // Interactive/diagnostics mode for generating kernel crash signatures. |
| 152 static int GenerateKernelSignature(KernelCollector *kernel_collector) { | 154 static int GenerateKernelSignature(KernelCollector *kernel_collector) { |
| 153 std::string kcrash_contents; | 155 std::string kcrash_contents; |
| 154 std::string signature; | 156 std::string signature; |
| 155 if (!file_util::ReadFileToString(FilePath(FLAGS_generate_kernel_signature), | 157 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(); | 207 user_collector.Disable(); |
| 206 return 0; | 208 return 0; |
| 207 } | 209 } |
| 208 | 210 |
| 209 if (!FLAGS_generate_kernel_signature.empty()) { | 211 if (!FLAGS_generate_kernel_signature.empty()) { |
| 210 return GenerateKernelSignature(&kernel_collector); | 212 return GenerateKernelSignature(&kernel_collector); |
| 211 } | 213 } |
| 212 | 214 |
| 213 return HandleUserCrash(&user_collector); | 215 return HandleUserCrash(&user_collector); |
| 214 } | 216 } |
| OLD | NEW |