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, "", |
| 22 "Generate signature from given kcrash file"); |
21 DEFINE_bool(crash_test, false, "Crash test"); | 23 DEFINE_bool(crash_test, false, "Crash test"); |
22 DEFINE_int32(pid, -1, "Crashing PID"); | 24 DEFINE_int32(pid, -1, "Crashing PID"); |
23 DEFINE_int32(signal, -1, "Signal causing crash"); | 25 DEFINE_int32(signal, -1, "Signal causing crash"); |
24 DEFINE_bool(unclean_check, true, "Check for unclean shutdown"); | 26 DEFINE_bool(unclean_check, true, "Check for unclean shutdown"); |
25 #pragma GCC diagnostic error "-Wstrict-aliasing" | 27 #pragma GCC diagnostic error "-Wstrict-aliasing" |
26 | 28 |
27 static const char kCrashCounterHistogram[] = "Logging.CrashCounter"; | 29 static const char kCrashCounterHistogram[] = "Logging.CrashCounter"; |
28 static const char kUserCrashSignal[] = | 30 static const char kUserCrashSignal[] = |
29 "org.chromium.CrashReporter.UserCrash"; | 31 "org.chromium.CrashReporter.UserCrash"; |
30 static const char kUncleanShutdownFile[] = | 32 static const char kUncleanShutdownFile[] = |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return 0; | 141 return 0; |
140 } | 142 } |
141 | 143 |
142 // Handle the crash, get the name of the process from procfs. | 144 // Handle the crash, get the name of the process from procfs. |
143 if (!user_collector->HandleCrash(FLAGS_signal, FLAGS_pid, NULL)) { | 145 if (!user_collector->HandleCrash(FLAGS_signal, FLAGS_pid, NULL)) { |
144 return 1; | 146 return 1; |
145 } | 147 } |
146 return 0; | 148 return 0; |
147 } | 149 } |
148 | 150 |
| 151 // Interactive/diagnostics mode for generating kernel crash signatures. |
| 152 static int GenerateKernelSignature(KernelCollector *kernel_collector) { |
| 153 std::string kcrash_contents; |
| 154 std::string signature; |
| 155 if (!file_util::ReadFileToString(FilePath(FLAGS_generate_kernel_signature), |
| 156 &kcrash_contents)) { |
| 157 fprintf(stderr, "Could not read file.\n"); |
| 158 return 1; |
| 159 } |
| 160 if (!kernel_collector->ComputeKernelStackSignature( |
| 161 kcrash_contents, |
| 162 &signature, |
| 163 true)) { |
| 164 fprintf(stderr, "Signature could not be generated.\n"); |
| 165 return 1; |
| 166 } |
| 167 printf("Kernel crash signature is \"%s\".\n", signature.c_str()); |
| 168 return 0; |
| 169 } |
149 | 170 |
150 int main(int argc, char *argv[]) { | 171 int main(int argc, char *argv[]) { |
151 google::ParseCommandLineFlags(&argc, &argv, true); | 172 google::ParseCommandLineFlags(&argc, &argv, true); |
152 FilePath my_path(argv[0]); | 173 FilePath my_path(argv[0]); |
153 file_util::AbsolutePath(&my_path); | 174 file_util::AbsolutePath(&my_path); |
154 s_metrics_lib.Init(); | 175 s_metrics_lib.Init(); |
155 CommandLine::Init(argc, argv); | 176 CommandLine::Init(argc, argv); |
156 logging::InitLogging(NULL, | 177 logging::InitLogging(NULL, |
157 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | 178 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, |
158 logging::DONT_LOCK_LOG_FILE, | 179 logging::DONT_LOCK_LOG_FILE, |
(...skipping 19 matching lines...) Expand all Loading... |
178 &user_collector, | 199 &user_collector, |
179 &unclean_shutdown_collector); | 200 &unclean_shutdown_collector); |
180 } | 201 } |
181 | 202 |
182 if (FLAGS_clean_shutdown) { | 203 if (FLAGS_clean_shutdown) { |
183 unclean_shutdown_collector.Disable(); | 204 unclean_shutdown_collector.Disable(); |
184 user_collector.Disable(); | 205 user_collector.Disable(); |
185 return 0; | 206 return 0; |
186 } | 207 } |
187 | 208 |
| 209 if (!FLAGS_generate_kernel_signature.empty()) { |
| 210 return GenerateKernelSignature(&kernel_collector); |
| 211 } |
| 212 |
188 return HandleUserCrash(&user_collector); | 213 return HandleUserCrash(&user_collector); |
189 } | 214 } |
OLD | NEW |