2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef CRASH_REPORTER_KERNEL_COLLECTOR_H_
18 #define CRASH_REPORTER_KERNEL_COLLECTOR_H_
24 #include <base/files/file_path.h>
25 #include <base/macros.h>
26 #include <gtest/gtest_prod.h> // for FRIEND_TEST
28 #include "crash_collector.h"
30 // Kernel crash collector.
31 class KernelCollector : public CrashCollector {
33 // Enumeration to specify architecture type.
41 kArchCount // Number of architectures.
46 ~KernelCollector() override;
48 void OverridePreservedDumpPath(const base::FilePath &file_path);
53 // Returns true if the kernel collection currently enabled.
54 bool is_enabled() const { return is_enabled_; }
56 // Collect any preserved kernel crash dump. Returns true if there was
57 // a dump (even if there were problems storing the dump), false otherwise.
60 // Compute a stack signature string from a kernel dump.
61 bool ComputeKernelStackSignature(const std::string &kernel_dump,
62 std::string *kernel_signature,
63 bool print_diagnostics);
65 // Set the architecture of the crash dumps we are looking at.
66 void set_arch(ArchKind arch) { arch_ = arch; }
67 ArchKind arch() const { return arch_; }
70 friend class KernelCollectorTest;
71 FRIEND_TEST(KernelCollectorTest, LoadPreservedDump);
72 FRIEND_TEST(KernelCollectorTest, StripSensitiveDataBasic);
73 FRIEND_TEST(KernelCollectorTest, StripSensitiveDataBulk);
74 FRIEND_TEST(KernelCollectorTest, StripSensitiveDataSample);
75 FRIEND_TEST(KernelCollectorTest, CollectOK);
77 virtual bool DumpDirMounted();
79 bool LoadPreservedDump(std::string *contents);
80 void StripSensitiveData(std::string *kernel_dump);
82 void GetRamoopsRecordPath(base::FilePath *path, size_t record);
83 bool LoadParameters();
84 bool HasMoreRecords();
86 // Read a record to string, modified from file_utils since that didn't
87 // provide a way to restrict the read length.
88 // Return value indicates (only) error state:
89 // * false when we get an error (can't read from dump location).
90 // * true if no error occured.
91 // Not finding a valid record is not an error state and is signaled by the
92 // record_found output parameter.
93 bool ReadRecordToString(std::string *contents,
94 size_t current_record,
97 void ProcessStackTrace(pcrecpp::StringPiece kernel_dump,
98 bool print_diagnostics,
100 float *last_stack_timestamp,
101 bool *is_watchdog_crash);
102 bool FindCrashingFunction(pcrecpp::StringPiece kernel_dump,
103 bool print_diagnostics,
104 float stack_trace_timestamp,
105 std::string *crashing_function);
106 bool FindPanicMessage(pcrecpp::StringPiece kernel_dump,
107 bool print_diagnostics,
108 std::string *panic_message);
110 // Returns the architecture kind for which we are built.
111 static ArchKind GetCompilerArch();
114 base::FilePath ramoops_dump_path_;
117 // The architecture of kernel dump strings we are working with.
120 DISALLOW_COPY_AND_ASSIGN(KernelCollector);
123 #endif // CRASH_REPORTER_KERNEL_COLLECTOR_H_