1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef CrashAnnotations_h
6 #define CrashAnnotations_h
11 namespace CrashReporter
{
13 // Typed enum representing all crash annotations
14 enum class Annotation
: uint32_t {
18 // Stringified crash annotation names
19 const char* const kAnnotationStrings
[] = {
23 // Allowlist of crash annotations that can be included in a crash ping
24 const Annotation kCrashPingAllowlist
[] = {
29 * Return the string representation of a crash annotation.
31 * @param aAnnotation a crash annotation
32 * @returns A constant string holding the annotation name
34 static inline const char* AnnotationToString(Annotation aAnnotation
) {
35 return kAnnotationStrings
[static_cast<uint32_t>(aAnnotation
)];
39 * Converts a string to its corresponding crash annotation.
41 * @param aResult a reference where the annotation will be stored
42 * @param aValue the string to be converted
43 * @return true if the string was successfully converted, false if it did not
44 * correspond to any known annotation
46 bool AnnotationFromString(Annotation
& aResult
, const char* aValue
);
49 * Checks if the given crash annotation is allowlisted for inclusion in the
52 * @param aAnnotation the crash annotation to be checked
53 * @return true if the annotation can be included in the crash ping, false
56 bool IsAnnotationAllowlistedForPing(Annotation aAnnotation
);
59 * Abstract annotation writer, this is needed only for code that writes out
60 * annotations in the exception handler.
62 class AnnotationWriter
{
64 virtual void Write(Annotation aAnnotation
, const char* aValue
,
66 virtual void Write(Annotation aAnnotation
, uint64_t aValue
) = 0;
69 } // namespace CrashReporter
71 #endif // CrashAnnotations_h