1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef CrashAnnotations_h
#define CrashAnnotations_h
#include <cstddef>
#include <cstdint>
namespace CrashReporter {
// Typed enum representing all crash annotations
enum class Annotation : uint32_t {
${enum}
};
// Stringified crash annotation names
const char* const kAnnotationStrings[] = {
${strings}
};
// Type of each annotation
enum class AnnotationType : uint8_t {
String = 0, // Any type of string, const char*, nsCString, etc...
Boolean = 1, // Stored as a byte
U32 = 2, // C/C++'s uint32_t or Rust's u32
U64 = 3, // C/C++'s uint64_t or Rust's u64
USize = 4, // C/C++'s size_t or Rust's usize
};
// Type of each annotation
const AnnotationType kAnnotationTypes[] = {
${types}
};
// Allowlist of crash annotations that can be included in a crash ping
const Annotation kCrashPingAllowedList[] = {
${allowedlist}
};
// Annotations which should be skipped when they have specific values
struct AnnotationSkipValue {
Annotation annotation;
const char* value;
};
const AnnotationSkipValue kSkipIfList[] = {
${skiplist}
};
/**
* Return the string representation of a crash annotation.
*
* @param aAnnotation a crash annotation
* @returns A constant string holding the annotation name
*/
static inline const char* AnnotationToString(Annotation aAnnotation) {
return kAnnotationStrings[static_cast<uint32_t>(aAnnotation)];
}
/**
* Converts a string to its corresponding crash annotation.
*
* @param aResult a reference where the annotation will be stored
* @param aValue the string to be converted
* @return true if the string was successfully converted, false if it did not
* correspond to any known annotation
*/
bool AnnotationFromString(Annotation& aResult, const char* aValue);
/**
* Checks if the given crash annotation is allowed for inclusion in the crash
* ping.
*
* @param aAnnotation the crash annotation to be checked
* @return true if the annotation can be included in the crash ping, false
* otherwise
*/
bool IsAnnotationAllowedForPing(Annotation aAnnotation);
/**
* Checks if the annotation should be included. Some annotations are skipped if
* their value matches a specific one (like the value 0).
*
* @param aAnnotation the crash annotation to be checked
* @param aValue the contents of the annotation as a string
* @return true if the annotation should be included, false otherwise
*/
bool ShouldIncludeAnnotation(Annotation aAnnotation, const char* aValue);
/**
* Abstract annotation writer, this is needed only for code that writes out
* annotations in the exception handler.
*/
class AnnotationWriter {
public:
virtual void Write(Annotation aAnnotation, const char* aValue,
size_t aLen = 0) = 0;
virtual void Write(Annotation aAnnotation, uint64_t aValue) = 0;
};
} // namespace CrashReporter
#endif // CrashAnnotations_h
|