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

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: Tidied up architecture variations Created 9 years, 9 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
« no previous file with comments | « kernel_collector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 not be gesignature of the kcrash.
Michael Krebs 2011/03/29 02:20:18 Was this an intentional comment change?
sjg 2011/04/01 20:04:15 Nope. It seems to be gone now so must have been a
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 * For ARM we see:
29 * "<5>[ 39.458982] PC is at write_breakme+0xd0/0x1b4"
30 * For x86:
31 * "<0>[ 37.474699] EIP: [<790ed488>] write_breakme+0x80/0x108 \
32 * SS:ESP 0068:e9dd3efc
33 */
34 static const std::string pcRegex[KernelCollector::archCount] = {
Michael Krebs 2011/03/29 02:20:18 I believe using std::string is not normally allowe
35 " PC is at ([^\\+ ]+).*",
36 " EIP: \\[<.*>\\] ([^\\+ ]+).*", // X86 uses EIP for the program counter
37 " Unsupported architecture"
Michael Krebs 2011/03/29 02:20:18 If it's an unknown architecture, it might be bette
sjg 2011/04/01 20:04:15 Have added a warning in the constructor and a test
38 };
39
27 KernelCollector::KernelCollector() 40 KernelCollector::KernelCollector()
28 : is_enabled_(false), 41 : is_enabled_(false),
29 preserved_dump_path_(kPreservedDumpPath) { 42 preserved_dump_path_(kPreservedDumpPath) {
30 } 43 }
31 44
32 KernelCollector::~KernelCollector() { 45 KernelCollector::~KernelCollector() {
33 } 46 }
34 47
35 void KernelCollector::OverridePreservedDumpPath(const FilePath &file_path) { 48 void KernelCollector::OverridePreservedDumpPath(const FilePath &file_path) {
36 preserved_dump_path_ = file_path; 49 preserved_dump_path_ = file_path;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 hash = hash * 16127 + input[i]; 96 hash = hash * 16127 + input[i];
84 return hash; 97 return hash;
85 } 98 }
86 99
87 void KernelCollector::ProcessStackTrace( 100 void KernelCollector::ProcessStackTrace(
88 pcrecpp::StringPiece kernel_dump, 101 pcrecpp::StringPiece kernel_dump,
89 bool print_diagnostics, 102 bool print_diagnostics,
90 unsigned *hash, 103 unsigned *hash,
91 float *last_stack_timestamp) { 104 float *last_stack_timestamp) {
92 pcrecpp::RE line_re("(.+)", pcrecpp::MULTILINE()); 105 pcrecpp::RE line_re("(.+)", pcrecpp::MULTILINE());
93 pcrecpp::RE stack_trace_start_re(kTimestampRegex + " Call Trace:$"); 106 pcrecpp::RE stack_trace_start_re(kTimestampRegex +
107 " (Call Trace|Backtrace):$");
94 // Match lines such as the following and grab out "error_code". 108 // Match lines such as the following and grab out "error_code".
95 // <4>[ 6066.849504] [<7937bcee>] error_code+0x66/0x6c 109 // <4>[ 6066.849504] [<7937bcee>] ? error_code+0x66/0x6c
110 // The ? may or may not be present
111
112 // For ARM:
113 // <4>[ 3498.731164] [<c0057220>] (__bug+0x20/0x2c) from [<c018062c>]
114 // (write_breakme+0xdc/0x1bc)
96 pcrecpp::RE stack_entry_re(kTimestampRegex + 115 pcrecpp::RE stack_entry_re(kTimestampRegex +
97 " \\[<.*>\\]([\\s\\?]+)([^\\+ ]+)"); 116 "\\s+\\[<[[:xdigit:]]+>\\]" // Matches " [<7937bcee>]"
117 "([\\s\\?(]+)" // Matches " ? ("
118 "([^\\+ )]+)"); // Matches until \ + space )
98 std::string line; 119 std::string line;
99 std::string hashable; 120 std::string hashable;
100 121
101 *hash = 0; 122 *hash = 0;
102 *last_stack_timestamp = 0; 123 *last_stack_timestamp = 0;
103 124
104 while (line_re.FindAndConsume(&kernel_dump, &line)) { 125 while (line_re.FindAndConsume(&kernel_dump, &line)) {
105 std::string certainty; 126 std::string certainty;
106 std::string function_name; 127 std::string function_name;
107 if (stack_trace_start_re.PartialMatch(line, last_stack_timestamp)) { 128 if (stack_trace_start_re.PartialMatch(line, last_stack_timestamp)) {
(...skipping 22 matching lines...) Expand all
130 } 151 }
131 152
132 *hash = HashString(hashable); 153 *hash = HashString(hashable);
133 154
134 if (print_diagnostics) { 155 if (print_diagnostics) {
135 printf("Hash based on stack trace: \"%s\" at %f.\n", 156 printf("Hash based on stack trace: \"%s\" at %f.\n",
136 hashable.c_str(), *last_stack_timestamp); 157 hashable.c_str(), *last_stack_timestamp);
137 } 158 }
138 } 159 }
139 160
161 enum KernelCollector::ArchKind KernelCollector::GetArch(void)
162 {
163 #if defined(COMPILER_GCC) && defined(ARCH_CPU_ARM_FAMILY)
164 return archArm;
165 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_X86_FAMILY)
166 return archX86;
167 #else
168 return archUnknown;
169 #endif
170 }
171
140 bool KernelCollector::FindCrashingFunction( 172 bool KernelCollector::FindCrashingFunction(
141 pcrecpp::StringPiece kernel_dump, 173 pcrecpp::StringPiece kernel_dump,
142 bool print_diagnostics, 174 bool print_diagnostics,
143 float stack_trace_timestamp, 175 float stack_trace_timestamp,
144 std::string *crashing_function) { 176 std::string *crashing_function) {
145 pcrecpp::RE eip_re(kTimestampRegex + " EIP: \\[<.*>\\] ([^\\+ ]+).*", 177 float timestamp = 0;
178
179 // Use the correct regex for this architecture.
180 pcrecpp::RE eip_re(kTimestampRegex + pcRegex[GetArch()],
Michael Krebs 2011/03/29 02:20:18 This very well may be okay (I'm new to what the st
sjg 2011/04/01 20:04:15 I would hope that the compiler will complain if yo
Michael Krebs 2011/04/05 00:43:56 My concern was more like what Ken just mentioned..
146 pcrecpp::MULTILINE()); 181 pcrecpp::MULTILINE());
147 float timestamp = 0; 182
148 while (eip_re.FindAndConsume(&kernel_dump, &timestamp, crashing_function)) { 183 while (eip_re.FindAndConsume(&kernel_dump, &timestamp, crashing_function)) {
149 if (print_diagnostics) { 184 if (print_diagnostics) {
150 printf("@%f: found crashing function %s\n", 185 printf("@%f: found crashing function %s\n",
151 timestamp, 186 timestamp,
152 crashing_function->c_str()); 187 crashing_function->c_str());
153 } 188 }
154 } 189 }
155 if (timestamp == 0) { 190 if (timestamp == 0) {
156 if (print_diagnostics) { 191 if (print_diagnostics) {
157 printf("Found no crashing function.\n"); 192 printf("Found no crashing function.\n");
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 kernel_crash_path.value()); 329 kernel_crash_path.value());
295 330
296 LOG(INFO) << "Stored kcrash to " << kernel_crash_path.value(); 331 LOG(INFO) << "Stored kcrash to " << kernel_crash_path.value();
297 } 332 }
298 if (!ClearPreservedDump()) { 333 if (!ClearPreservedDump()) {
299 return false; 334 return false;
300 } 335 }
301 336
302 return true; 337 return true;
303 } 338 }
OLDNEW
« no previous file with comments | « kernel_collector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698