Files
tubestation/toolkit/crashreporter/CrashAnnotations.h.in
Alex Franchuk fe4b975d31 Bug 1920927 - Automatically filter out crash annotations that are only used locally r=gsvelto
This adds a new `scope` field to `CrashAnnotations.yaml`, replacing the
`ping` field. It adds the `StackTraces` and `Comments` annotations
(which were missing), and an `object` annotation type for completeness.

There's a bit of reorganized code for the client UI test interaction
hook as well, and a better panic handler for the logic thread: the new
debug assertion around extra data before submission was failing because
I was missing the `Comments` annotation, however the logic thread
panicking resulted in the test hanging rather than exiting with the
panic message(s). This panic handler fixes that case (and I'm glad I
added the debug assertion!).

Differential Revision: https://phabricator.services.mozilla.com/D239078
2025-03-13 17:39:09 +00:00

144 lines
4.0 KiB
C

/* 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>
#include "mozilla/Maybe.h"
#include "nsStringFwd.h"
namespace CrashReporter {
using mozilla::Maybe;
// 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
Object = 5, // Not able to be read/written from the C++ API.
};
// Type of each annotation
const AnnotationType kAnnotationTypes[] = {
${types}
};
// Allowlist of crash annotations that can be included in a crash ping
const Annotation kCrashPingAllowedList[] = {
${pingallowedlist}
};
// Allowlist of crash annotations that can be included in a crash report
// (excludes those in kCrashPingAllowedList).
const Annotation kCrashReportAllowedList[] = {
${reportallowedlist}
};
// Annotations which should be skipped when they have specific values
struct AnnotationSkipValue {
Annotation annotation;
const char* value;
};
const AnnotationSkipValue kSkipIfList[] = {
${skiplist}
};
/**
* Return the type of a crash annotation.
*
* @param aAnnotation a crash annotation
* @returns The type of this annotation
*/
static inline AnnotationType TypeOfAnnotation(Annotation aAnnotation) {
return kAnnotationTypes[static_cast<uint32_t>(aAnnotation)];
}
/**
* 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 aValue the string to be converted
* @return the annotation corresponding to the string or nothing
*/
Maybe<Annotation> AnnotationFromString(const nsACString& aValue);
/**
* Checks if the given crash annotation is allowed for inclusion in a crash
* ping.
*
* @param aAnnotation the crash annotation to be checked
* @return true if the annotation can be included in a crash ping, false
* otherwise
*/
bool IsAnnotationAllowedForPing(Annotation aAnnotation);
/**
* Checks if the given crash annotation is allowed for inclusion in a crash
* report.
*
* @param aAnnotation the crash annotation to be checked
* @return true if the annotation can be included in a crash report, false
* otherwise
*/
bool IsAnnotationAllowedForReport(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, bool aValue) = 0;
virtual void Write(Annotation aAnnotation, uint64_t aValue) = 0;
};
#ifdef XP_WIN
extern void RecordDllAnnotations(bool* aBlocklistInitFailed,
bool* aUser32BeforeBlocklist);
#endif // XP_WIN
} // namespace CrashReporter
#endif // CrashAnnotations_h