Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CRASH_REPORTER_ARC_UTIL_H_ |
| 6 | #define CRASH_REPORTER_ARC_UTIL_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <unordered_map> |
| 10 | #include <unordered_set> |
| 11 | #include <utility> |
| 12 | #include <vector> |
| 13 | |
| 14 | #include <base/optional.h> |
| 15 | |
| 16 | #include "crash-reporter/crash_collector.h" |
| 17 | |
| 18 | namespace arc_util { |
| 19 | |
| 20 | using CrashLogHeaderMap = std::unordered_map<std::string, std::string>; |
| 21 | |
| 22 | extern const char kArcProduct[]; |
| 23 | |
| 24 | // Metadata fields included in reports. |
Long Cheng | 6b72d28 | 2020-11-05 18:40:30 -0800 | [diff] [blame^] | 25 | extern const char kAbiMigrationField[]; |
Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 26 | extern const char kAndroidVersionField[]; |
| 27 | extern const char kArcVersionField[]; |
| 28 | extern const char kBoardField[]; |
| 29 | extern const char kChromeOsVersionField[]; |
| 30 | extern const char kCpuAbiField[]; |
| 31 | extern const char kCrashTypeField[]; |
| 32 | extern const char kDeviceField[]; |
| 33 | extern const char kProcessField[]; |
| 34 | extern const char kProductField[]; |
| 35 | extern const char kUptimeField[]; |
| 36 | |
| 37 | // For Java Crash |
| 38 | extern const char kExceptionInfoField[]; |
| 39 | extern const char kSignatureField[]; |
| 40 | |
| 41 | // If this metadata key is set to "true", the report is uploaded silently, i.e. |
| 42 | // it does not appear in chrome://crashes. |
| 43 | extern const char kSilentKey[]; |
| 44 | |
| 45 | // Keys for crash log headers. |
Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 46 | extern const char kProcessKey[]; |
| 47 | extern const char kSubjectKey[]; |
| 48 | |
| 49 | extern const std::vector<std::pair<const char*, const char*>> |
| 50 | kHeaderToFieldMapping; |
| 51 | |
Kimiyuki Onaka | da90c60 | 2020-09-03 10:58:06 +0900 | [diff] [blame] | 52 | // The property about ARC build. These values comes from a Mojo method, |
| 53 | // SetBuildProperties. |
| 54 | struct BuildProperty { |
| 55 | std::string device; |
| 56 | std::string board; |
| 57 | std::string cpu_abi; |
| 58 | std::string fingerprint; |
| 59 | }; |
| 60 | |
Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 61 | // Returns the Android version (eg: 7.1.1) from the fingerprint. |
| 62 | base::Optional<std::string> GetVersionFromFingerprint( |
| 63 | const std::string& fingerprint); |
| 64 | |
| 65 | bool ParseCrashLog(const std::string& type, |
| 66 | std::stringstream* stream, |
| 67 | CrashLogHeaderMap* map, |
| 68 | std::string* exception_info, |
| 69 | std::string* log); |
| 70 | |
| 71 | const char* GetSubjectTag(const std::string& type); |
| 72 | |
| 73 | bool IsSilentReport(const std::string& type); |
| 74 | |
| 75 | std::string GetCrashLogHeader(const CrashLogHeaderMap& map, const char* key); |
| 76 | |
| 77 | // Return Random PID. |
| 78 | // FormatDumpBasename relies on the assumption that the combination of process |
| 79 | // name, timestamp, and PID is unique. This does not hold if a process crashes |
| 80 | // more than once in the span of a second. While this is improbable for native |
| 81 | // crashes, Java crashes are not always fatal and may happen in bursts. Hence, |
| 82 | // ensure uniqueness by replacing the PID with the number of microseconds |
| 83 | // since the current second. |
| 84 | pid_t CreateRandomPID(); |
| 85 | |
| 86 | } // namespace arc_util |
| 87 | |
| 88 | #endif // CRASH_REPORTER_ARC_UTIL_H_ |