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

Side by Side Diff: kernel_collector.cc

Issue 6599022: Add ARM support (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crash-reporter.git@master
Patch Set: Refactored tests a little, var change, comments, nits Created 9 years, 8 months 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 | Annotate | Revision Log
OLDNEW
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 "crash-reporter/kernel_collector.h" 5 #include "crash-reporter/kernel_collector.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 10
11 const char KernelCollector::kClearingSequence[] = " "; 11 const char KernelCollector::kClearingSequence[] = " ";
12 static const char kDefaultKernelStackSignature[] = 12 static const char kDefaultKernelStackSignature[] =
13 "kernel-UnspecifiedStackSignature"; 13 "kernel-UnspecifiedStackSignature";
14 static const char kKernelExecName[] = "kernel"; 14 static const char kKernelExecName[] = "kernel";
15 const pid_t kKernelPid = 0; 15 const pid_t kKernelPid = 0;
16 static const char kKernelSignatureKey[] = "sig"; 16 static const char kKernelSignatureKey[] = "sig";
17 // Byte length of maximum human readable portion of a kernel crash signature. 17 // Byte length of maximum human readable portion of a kernel crash signature.
18 static const int kMaxHumanStringLength = 40; 18 static const int kMaxHumanStringLength = 40;
19 static const char kPreservedDumpPath[] = "/sys/kernel/debug/preserved/kcrash"; 19 static const char kPreservedDumpPath[] = "/sys/kernel/debug/preserved/kcrash";
20 const uid_t kRootUid = 0; 20 const uid_t kRootUid = 0;
21 // Time in seconds from the final kernel log message for a call stack 21 // Time in seconds from the final kernel log message for a call stack
22 // to count towards the signature of the kcrash. 22 // to count towards the signature of the kcrash.
23 static const int kSignatureTimestampWindow = 2; 23 static const int kSignatureTimestampWindow = 2;
24 // Kernel log timestamp regular expression. 24 // Kernel log timestamp regular expression.
25 static const std::string kTimestampRegex("^<.*>\\[\\s*(\\d+\\.\\d+)\\]"); 25 static const std::string kTimestampRegex("^<.*>\\[\\s*(\\d+\\.\\d+)\\]");
26 26
27 /*
28 * These regular expressions enable to us capture the PC in a backtrace.
29 * The backtrace is obtained through dmesg or the kernel's preserved/kcrashmem
30 * feature.
31 *
32 * For ARM we see:
33 * "<5>[ 39.458982] PC is at write_breakme+0xd0/0x1b4"
34 * For x86:
35 * "<0>[ 37.474699] EIP: [<790ed488>] write_breakme+0x80/0x108 \
36 * SS:ESP 0068:e9dd3efc
37 */
38 static const char *s_pc_regex[KernelCollector::archCount] = {
39 0,
40 " PC is at ([^\\+ ]+).*",
41 " EIP: \\[<.*>\\] ([^\\+ ]+).*", // X86 uses EIP for the program counter
42 };
43
27 KernelCollector::KernelCollector() 44 KernelCollector::KernelCollector()
28 : is_enabled_(false), 45 : is_enabled_(false),
29 preserved_dump_path_(kPreservedDumpPath) { 46 preserved_dump_path_(kPreservedDumpPath) {
47 // We expect crash dumps in the format of the architecture we are built for.
48 arch_ = GetCompilerArch();
49 if (arch_ == archUnknown || !s_pc_regex[arch_])
kmixter1 2011/04/05 17:56:52 Shouldn't there be a check of: if (sizeof(s_pc_re
sjg 2011/04/05 18:25:54 done. We are putting on the belts and braces now.
Michael Krebs 2011/04/05 21:02:15 Re: The first archCount check: given the current d
kmixter1 2011/04/05 21:23:56 Agreed - segv is not a good diagnostic. Can we ju
50 LOG(WARNING) << "KernelCollector does not understand this architecture";
30 } 51 }
31 52
32 KernelCollector::~KernelCollector() { 53 KernelCollector::~KernelCollector() {
33 } 54 }
34 55
35 void KernelCollector::OverridePreservedDumpPath(const FilePath &file_path) { 56 void KernelCollector::OverridePreservedDumpPath(const FilePath &file_path) {
36 preserved_dump_path_ = file_path; 57 preserved_dump_path_ = file_path;
37 } 58 }
38 59
39 bool KernelCollector::LoadPreservedDump(std::string *contents) { 60 bool KernelCollector::LoadPreservedDump(std::string *contents) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 hash = hash * 16127 + input[i]; 104 hash = hash * 16127 + input[i];
84 return hash; 105 return hash;
85 } 106 }
86 107
87 void KernelCollector::ProcessStackTrace( 108 void KernelCollector::ProcessStackTrace(
88 pcrecpp::StringPiece kernel_dump, 109 pcrecpp::StringPiece kernel_dump,
89 bool print_diagnostics, 110 bool print_diagnostics,
90 unsigned *hash, 111 unsigned *hash,
91 float *last_stack_timestamp) { 112 float *last_stack_timestamp) {
92 pcrecpp::RE line_re("(.+)", pcrecpp::MULTILINE()); 113 pcrecpp::RE line_re("(.+)", pcrecpp::MULTILINE());
93 pcrecpp::RE stack_trace_start_re(kTimestampRegex + " Call Trace:$"); 114 pcrecpp::RE stack_trace_start_re(kTimestampRegex +
115 " (Call Trace|Backtrace):$");
116
117 // For ARM:
118 // <4>[ 3498.731164] [<c0057220>] (__bug+0x20/0x2c) from [<c018062c>]
119 // (write_breakme+0xdc/0x1bc)
120 //
121 // For X86:
94 // Match lines such as the following and grab out "error_code". 122 // Match lines such as the following and grab out "error_code".
95 // <4>[ 6066.849504] [<7937bcee>] error_code+0x66/0x6c 123 // <4>[ 6066.849504] [<7937bcee>] ? error_code+0x66/0x6c
124 // The ? may or may not be present
96 pcrecpp::RE stack_entry_re(kTimestampRegex + 125 pcrecpp::RE stack_entry_re(kTimestampRegex +
97 " \\[<.*>\\]([\\s\\?]+)([^\\+ ]+)"); 126 "\\s+\\[<[[:xdigit:]]+>\\]" // Matches " [<7937bcee>]"
127 "([\\s\\?(]+)" // Matches " ? (" (ARM) or " ? " (X86)
128 "([^\\+ )]+)"); // Matches until delimiter reached
98 std::string line; 129 std::string line;
99 std::string hashable; 130 std::string hashable;
100 131
101 *hash = 0; 132 *hash = 0;
102 *last_stack_timestamp = 0; 133 *last_stack_timestamp = 0;
103 134
104 while (line_re.FindAndConsume(&kernel_dump, &line)) { 135 while (line_re.FindAndConsume(&kernel_dump, &line)) {
105 std::string certainty; 136 std::string certainty;
106 std::string function_name; 137 std::string function_name;
107 if (stack_trace_start_re.PartialMatch(line, last_stack_timestamp)) { 138 if (stack_trace_start_re.PartialMatch(line, last_stack_timestamp)) {
(...skipping 22 matching lines...) Expand all
130 } 161 }
131 162
132 *hash = HashString(hashable); 163 *hash = HashString(hashable);
133 164
134 if (print_diagnostics) { 165 if (print_diagnostics) {
135 printf("Hash based on stack trace: \"%s\" at %f.\n", 166 printf("Hash based on stack trace: \"%s\" at %f.\n",
136 hashable.c_str(), *last_stack_timestamp); 167 hashable.c_str(), *last_stack_timestamp);
137 } 168 }
138 } 169 }
139 170
171 enum KernelCollector::ArchKind KernelCollector::GetCompilerArch(void)
172 {
173 #if defined(COMPILER_GCC) && defined(ARCH_CPU_ARM_FAMILY)
174 return archArm;
175 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_X86_FAMILY)
176 return archX86;
177 #else
178 return archUnknown;
179 #endif
180 }
181
182 void KernelCollector::SetArch(enum ArchKind arch)
183 {
184 arch_ = arch;
185 }
186
140 bool KernelCollector::FindCrashingFunction( 187 bool KernelCollector::FindCrashingFunction(
141 pcrecpp::StringPiece kernel_dump, 188 pcrecpp::StringPiece kernel_dump,
142 bool print_diagnostics, 189 bool print_diagnostics,
143 float stack_trace_timestamp, 190 float stack_trace_timestamp,
144 std::string *crashing_function) { 191 std::string *crashing_function) {
145 pcrecpp::RE eip_re(kTimestampRegex + " EIP: \\[<.*>\\] ([^\\+ ]+).*", 192 float timestamp = 0;
193
194 // Use the correct regex for this architecture.
195 pcrecpp::RE eip_re(kTimestampRegex + s_pc_regex[arch_],
146 pcrecpp::MULTILINE()); 196 pcrecpp::MULTILINE());
147 float timestamp = 0; 197
148 while (eip_re.FindAndConsume(&kernel_dump, &timestamp, crashing_function)) { 198 while (eip_re.FindAndConsume(&kernel_dump, &timestamp, crashing_function)) {
149 if (print_diagnostics) { 199 if (print_diagnostics) {
150 printf("@%f: found crashing function %s\n", 200 printf("@%f: found crashing function %s\n",
151 timestamp, 201 timestamp,
152 crashing_function->c_str()); 202 crashing_function->c_str());
153 } 203 }
154 } 204 }
155 if (timestamp == 0) { 205 if (timestamp == 0) {
156 if (print_diagnostics) { 206 if (print_diagnostics) {
157 printf("Found no crashing function.\n"); 207 printf("Found no crashing function.\n");
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 kernel_crash_path.value()); 344 kernel_crash_path.value());
295 345
296 LOG(INFO) << "Stored kcrash to " << kernel_crash_path.value(); 346 LOG(INFO) << "Stored kcrash to " << kernel_crash_path.value();
297 } 347 }
298 if (!ClearPreservedDump()) { 348 if (!ClearPreservedDump()) {
299 return false; 349 return false;
300 } 350 }
301 351
302 return true; 352 return true;
303 } 353 }
OLDNEW
« no previous file with comments | « kernel_collector.h ('k') | kernel_collector_test.cc » ('j') | kernel_collector_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698