blob: 1ba263da9ba1f0535ab7085220dab8be13b243fd [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.
Long Cheng6b72d282020-11-05 18:40:30 -080025extern const char kAbiMigrationField[];
Kansho Nishida630cc7a2019-10-23 17:37:41 +090026extern const char kAndroidVersionField[];
27extern const char kArcVersionField[];
28extern const char kBoardField[];
29extern const char kChromeOsVersionField[];
30extern const char kCpuAbiField[];
31extern const char kCrashTypeField[];
32extern const char kDeviceField[];
33extern const char kProcessField[];
34extern const char kProductField[];
35extern const char kUptimeField[];
36
37// For Java Crash
38extern const char kExceptionInfoField[];
39extern 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.
43extern const char kSilentKey[];
44
45// Keys for crash log headers.
Kansho Nishida630cc7a2019-10-23 17:37:41 +090046extern const char kProcessKey[];
47extern const char kSubjectKey[];
48
49extern const std::vector<std::pair<const char*, const char*>>
50 kHeaderToFieldMapping;
51
Kimiyuki Onakada90c602020-09-03 10:58:06 +090052// The property about ARC build. These values comes from a Mojo method,
53// SetBuildProperties.
54struct BuildProperty {
55 std::string device;
56 std::string board;
57 std::string cpu_abi;
58 std::string fingerprint;
59};
60
Kansho Nishida630cc7a2019-10-23 17:37:41 +090061// Returns the Android version (eg: 7.1.1) from the fingerprint.
62base::Optional<std::string> GetVersionFromFingerprint(
63 const std::string& fingerprint);
64
65bool ParseCrashLog(const std::string& type,
66 std::stringstream* stream,
67 CrashLogHeaderMap* map,
68 std::string* exception_info,
69 std::string* log);
70
71const char* GetSubjectTag(const std::string& type);
72
73bool IsSilentReport(const std::string& type);
74
75std::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.
84pid_t CreateRandomPID();
85
86} // namespace arc_util
87
88#endif // CRASH_REPORTER_ARC_UTIL_H_