1// Copyright (c) 2019 Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// exception_record.h: A snapshot of an exception record.
31//
32// Author: Ivan Penkov
33
34#ifndef THIRD_PARTY_BREAKPAD_SRC_GOOGLE_BREAKPAD_PROCESSOR_EXCEPTION_RECORD_H_
35#define THIRD_PARTY_BREAKPAD_SRC_GOOGLE_BREAKPAD_PROCESSOR_EXCEPTION_RECORD_H_
36
37#include <vector>
38
39namespace google_breakpad {
40
41// Additional argument that describes the exception.
42class ExceptionParameter {
43 public:
44 ExceptionParameter(uint64_t value, const string& description)
45 : value_(value), description_(description) {}
46 // Accessors. See the data declarations below.
47 uint64_t value() const { return value_; }
48 void set_value(uint64_t value) { value_ = value; }
49 const string& description() const { return description_; }
50 void set_description(const string& description) {
51 description_ = description;
52 }
53
54 private:
55 // Parameter value.
56 uint64_t value_;
57 // Human readable description/interpretation of the above value.
58 string description_;
59};
60
61// A snapshot of an exception record. Contains exception record details: code,
62// flags, address, parameters.
63class ExceptionRecord {
64 public:
65 // Accessors. See the data declarations below.
66 uint32_t code() const { return code_; }
67 const string& code_description() const { return code_description_; }
68 void set_code(uint32_t code, const string& description) {
69 code_ = code;
70 code_description_ = description;
71 }
72
73 uint32_t flags() const { return flags_; }
74 const string& flags_description() const { return flags_description_; }
75 void set_flags(uint32_t flags, const string& description) {
76 flags_ = flags;
77 flags_description_ = description;
78 }
79
80 uint64_t nested_exception_record_address() const {
81 return nested_exception_record_address_;
82 }
83 void set_nested_exception_record_address(
84 uint64_t nested_exception_record_address) {
85 nested_exception_record_address_ = nested_exception_record_address;
86 }
87
88 uint64_t address() const { return address_; }
89 void set_address(uint64_t address) { address_ = address; }
90
91 const std::vector<ExceptionParameter>* parameters() const {
92 return &parameters_;
93 }
94 void add_parameter(uint64_t value, const string& description) {
95 parameters_.push_back(ExceptionParameter(value, description));
96 }
97
98 private:
99 // Exception code.
100 uint32_t code_;
101 string code_description_;
102
103 // Exception flags.
104 uint32_t flags_;
105 string flags_description_;
106
107 // The address of an associated MDException structure. Exception records can
108 // be chained together to provide additional information when nested
109 // exceptions occur.
110 uint64_t nested_exception_record_address_;
111
112 // The memory address that caused the exception. For data access errors,
113 // this will be the data address that caused the fault. For code errors,
114 // this will be the address of the instruction that caused the fault.
115 uint64_t address_;
116
117 // An array of additional arguments that describe the exception.
118 std::vector<ExceptionParameter> parameters_;
119};
120
121} // namespace google_breakpad
122
123
124#endif // THIRD_PARTY_BREAKPAD_SRC_GOOGLE_BREAKPAD_PROCESSOR_EXCEPTION_RECORD_H_
125