Base class for an annotation, which records a name-value pair of arbitrary data when set. More...
#include "client/annotation.h"
Public Types | |
enum class | Type : uint16_t |
The type of data stored in the annotation. More... | |
enum class | ConcurrentAccessGuardMode : bool |
Mode used to guard concurrent reads from writes. More... | |
using | ValueSizeType = uint32_t |
The type used for SetSize(). | |
Public Member Functions | |
constexpr | Annotation (Type type, const char name[], void *value_ptr) |
Constructs a new annotation. | |
Annotation (const Annotation &)=delete | |
Annotation & | operator= (const Annotation &)=delete |
void | SetSize (ValueSizeType size) |
Specifies the number of bytes in value_ptr_ to include when generating a crash report. | |
void | Clear () |
Marks the annotation as cleared, indicating the value_ptr_ should not be included in a crash report. | |
bool | is_set () const |
Tests whether the annotation has been set. | |
Type | type () const |
ValueSizeType | size () const |
const char * | name () const |
const void * | value () const |
ConcurrentAccessGuardMode | concurrent_access_guard_mode () const |
std::optional< ScopedSpinGuard > | TryCreateScopedSpinGuard (uint64_t timeout_ns) |
If this Annotation guards concurrent access using ScopedSpinGuard, tries to obtain the spin guard and returns the result. | |
Static Public Member Functions | |
static constexpr Type | UserDefinedType (uint16_t value) |
Creates a user-defined Annotation::Type. | |
Static Public Attributes | |
static constexpr size_t | kNameMaxLength = 256 |
The maximum length of an annotation’s name, in bytes. Matches the behavior of Breakpad's SimpleStringDictionary. | |
static constexpr size_t | kValueMaxSize = 5 * 4096 |
The maximum size of an annotation’s value, in bytes. | |
Protected Member Functions | |
constexpr | Annotation (Type type, const char name[], void *value_ptr, ConcurrentAccessGuardMode concurrent_access_guard_mode) |
Constructs a new annotation. | |
std::atomic< Annotation * > & | link_node () |
Annotation * | GetLinkNode (std::memory_order order=std::memory_order_seq_cst) |
const Annotation * | GetLinkNode (std::memory_order order=std::memory_order_seq_cst) const |
Friends | |
class | AnnotationList |
Base class for an annotation, which records a name-value pair of arbitrary data when set.
After an annotation is declared, its value_ptr_
will not be captured in a crash report until a call to SetSize() specifies how much data from the value should be recorded.
Annotations should be declared with static storage duration.
An example declaration and usage:
Annotation objects are not inherently thread-safe. To manipulate them from multiple threads, external synchronization must be used.
Annotation objects should never be destroyed. Once they are Set(), they are permanently referenced by a global object.
|
strong |
Mode used to guard concurrent reads from writes.
Enumerator | |
---|---|
kUnguarded | !brief Annotation does not guard reads from concurrent writes. Annotation values can be corrupted if the process crashes mid-write and the handler tries to read from the Annotation while being written to. |
kScopedSpinGuard | !brief Annotation guards reads from concurrent writes using ScopedSpinGuard. Clients must use TryCreateScopedSpinGuard() before reading or writing the data in this Annotation. |
|
strong |
|
inlineconstexpr |
Constructs a new annotation.
Upon construction, the annotation will not be included in any crash reports until
0
.[in] | type | The data type of the value of the annotation. |
[in] | name | A NUL -terminated C-string name for the annotation. Names do not have to be unique, though not all crash processors may handle Annotations with the same name. Names should be constexpr data with static storage duration. |
[in] | value_ptr | A pointer to the value for the annotation. The pointer may not be changed once associated with an annotation, but the data may be mutated. |
|
inlineconstexprprotected |
Constructs a new annotation.
Upon construction, the annotation will not be included in any crash reports until
0
.[in] | type | The data type of the value of the annotation. |
[in] | name | A NUL -terminated C-string name for the annotation. Names do not have to be unique, though not all crash processors may handle Annotations with the same name. Names should be constexpr data with static storage duration. |
[in] | value_ptr | A pointer to the value for the annotation. The pointer may not be changed once associated with an annotation, but the data may be mutated. |
[in] | concurrent_access_guard_mode | Mode used to guard concurrent reads from writes. |
void crashpad::Annotation::Clear | ( | ) |
Marks the annotation as cleared, indicating the value_ptr_ should not be included in a crash report.
This method does not mutate the data referenced by the annotation, it merely updates the annotation system's bookkeeping.
void crashpad::Annotation::SetSize | ( | ValueSizeType | size | ) |
Specifies the number of bytes in value_ptr_ to include when generating a crash report.
A size of 0
indicates that no value should be recorded and is the equivalent of calling
This method does not mutate the data referenced by the annotation, it merely updates the annotation system's bookkeeping.
Subclasses of this base class that provide additional Set methods to mutate the value of the annotation must call always call this method.
[in] | size | The number of bytes. |
|
inline |
If this Annotation guards concurrent access using ScopedSpinGuard, tries to obtain the spin guard and returns the result.
[in] | timeout_ns | The timeout in nanoseconds after which to give up trying to obtain the spin guard. |
|
inlinestaticconstexpr |
Creates a user-defined Annotation::Type.
This exists to remove the casting overhead of enum class
.
[in] | value | A value used to create a user-defined type. |