blob: e1e05b29223002fdf2e36825ce9639a1009bc2f8 [file] [log] [blame]
Kansho Nishida630cc7a2019-10-23 17:37:41 +09001// 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
18namespace arc_util {
19
20using CrashLogHeaderMap = std::unordered_map<std::string, std::string>;
21
22extern const char kArcProduct[];
23
24// Metadata fields included in reports.
25extern const char kAndroidVersionField[];
26extern const char kArcVersionField[];
27extern const char kBoardField[];
28extern const char kChromeOsVersionField[];
29extern const char kCpuAbiField[];
30extern const char kCrashTypeField[];
31extern const char kDeviceField[];
32extern const char kProcessField[];
33extern const char kProductField[];
34extern const char kUptimeField[];
35
36// For Java Crash
37extern const char kExceptionInfoField[];
38extern const char kSignatureField[];
39
40// If this metadata key is set to "true", the report is uploaded silently, i.e.
41// it does not appear in chrome://crashes.
42extern const char kSilentKey[];
43
44// Keys for crash log headers.
Kansho Nishida630cc7a2019-10-23 17:37:41 +090045extern const char kProcessKey[];
46extern const char kSubjectKey[];
47
48extern const std::vector<std::pair<const char*, const char*>>
49 kHeaderToFieldMapping;
50
Kimiyuki Onakada90c602020-09-03 10:58:06 +090051// The property about ARC build. These values comes from a Mojo method,
52// SetBuildProperties.
53struct BuildProperty {
54 std::string device;
55 std::string board;
56 std::string cpu_abi;
57 std::string fingerprint;
58};
59
Kansho Nishida630cc7a2019-10-23 17:37:41 +090060// Returns the Android version (eg: 7.1.1) from the fingerprint.
61base::Optional<std::string> GetVersionFromFingerprint(
62 const std::string& fingerprint);
63
64bool ParseCrashLog(const std::string& type,
65 std::stringstream* stream,
66 CrashLogHeaderMap* map,
67 std::string* exception_info,
68 std::string* log);
69
70const char* GetSubjectTag(const std::string& type);
71
72bool IsSilentReport(const std::string& type);
73
74std::string GetCrashLogHeader(const CrashLogHeaderMap& map, const char* key);
75
76// Return Random PID.
77// FormatDumpBasename relies on the assumption that the combination of process
78// name, timestamp, and PID is unique. This does not hold if a process crashes
79// more than once in the span of a second. While this is improbable for native
80// crashes, Java crashes are not always fatal and may happen in bursts. Hence,
81// ensure uniqueness by replacing the PID with the number of microseconds
82// since the current second.
83pid_t CreateRandomPID();
84
85} // namespace arc_util
86
87#endif // CRASH_REPORTER_ARC_UTIL_H_