OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_WRITER_H_ | 15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_WRITER_H_ |
16 #define CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_WRITER_H_ | 16 #define CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_WRITER_H_ |
17 | 17 |
18 #include <sys/types.h> | 18 #include <sys/types.h> |
19 | 19 |
20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
| 21 #include "base/memory/scoped_ptr.h" |
21 #include "minidump/minidump_context.h" | 22 #include "minidump/minidump_context.h" |
22 #include "minidump/minidump_writable.h" | 23 #include "minidump/minidump_writable.h" |
23 | 24 |
24 namespace crashpad { | 25 namespace crashpad { |
25 | 26 |
| 27 struct CPUContext; |
| 28 struct CPUContextX86; |
| 29 struct CPUContextX86_64; |
| 30 |
26 //! \brief The base class for writers of CPU context structures in minidump | 31 //! \brief The base class for writers of CPU context structures in minidump |
27 //! files. | 32 //! files. |
28 class MinidumpContextWriter : public internal::MinidumpWritable { | 33 class MinidumpContextWriter : public internal::MinidumpWritable { |
29 public: | 34 public: |
30 ~MinidumpContextWriter() override; | 35 ~MinidumpContextWriter() override; |
31 | 36 |
| 37 //! \brief Creates a MinidumpContextWriter based on \a context_snapshot. |
| 38 //! |
| 39 //! \param[in] context_snapshot The context snapshot to use as source data. |
| 40 //! |
| 41 //! \return A MinidumpContextWriter subclass, such as MinidumpContextWriterX86 |
| 42 //! or MinidumpContextWriterAMD64, appropriate to the CPU type of \a |
| 43 //! context_snapshot. The returned object is initialized using the source |
| 44 //! data in \a context_snapshot. If \a context_snapshot is an unknown CPU |
| 45 //! type’s context, logs a message and returns `nullptr`. |
| 46 static scoped_ptr<MinidumpContextWriter> CreateFromSnapshot( |
| 47 const CPUContext* context_snapshot); |
| 48 |
32 protected: | 49 protected: |
33 MinidumpContextWriter() : MinidumpWritable() {} | 50 MinidumpContextWriter() : MinidumpWritable() {} |
34 | 51 |
35 //! \brief Returns the size of the context structure that this object will | 52 //! \brief Returns the size of the context structure that this object will |
36 //! write. | 53 //! write. |
37 //! | 54 //! |
38 //! \note This method will only be called in #kStateFrozen or a subsequent | 55 //! \note This method will only be called in #kStateFrozen or a subsequent |
39 //! state. | 56 //! state. |
40 virtual size_t ContextSize() const = 0; | 57 virtual size_t ContextSize() const = 0; |
41 | 58 |
42 // MinidumpWritable: | 59 // MinidumpWritable: |
43 size_t SizeOfObject() final; | 60 size_t SizeOfObject() final; |
44 | 61 |
45 private: | 62 private: |
46 DISALLOW_COPY_AND_ASSIGN(MinidumpContextWriter); | 63 DISALLOW_COPY_AND_ASSIGN(MinidumpContextWriter); |
47 }; | 64 }; |
48 | 65 |
49 //! \brief The writer for a MinidumpContextX86 structure in a minidump file. | 66 //! \brief The writer for a MinidumpContextX86 structure in a minidump file. |
50 class MinidumpContextX86Writer final : public MinidumpContextWriter { | 67 class MinidumpContextX86Writer final : public MinidumpContextWriter { |
51 public: | 68 public: |
52 MinidumpContextX86Writer(); | 69 MinidumpContextX86Writer(); |
53 ~MinidumpContextX86Writer() override; | 70 ~MinidumpContextX86Writer() override; |
54 | 71 |
| 72 //! \brief Initializes the MinidumpContextX86 based on \a context_snapshot. |
| 73 //! |
| 74 //! \param[in] context_snapshot The context snapshot to use as source data. |
| 75 //! |
| 76 //! \note Valid in #kStateMutable. No mutation of context() may be done before |
| 77 //! calling this method, and it is not normally necessary to alter |
| 78 //! context() after calling this method. |
| 79 void InitializeFromSnapshot(const CPUContextX86* context_snapshot); |
| 80 |
55 //! \brief Returns a pointer to the context structure that this object will | 81 //! \brief Returns a pointer to the context structure that this object will |
56 //! write. | 82 //! write. |
57 //! | 83 //! |
58 //! \attention This returns a non-`const` pointer to this object’s private | 84 //! \attention This returns a non-`const` pointer to this object’s private |
59 //! data so that a caller can populate the context structure directly. | 85 //! data so that a caller can populate the context structure directly. |
60 //! This is done because providing setter interfaces to each field in the | 86 //! This is done because providing setter interfaces to each field in the |
61 //! context structure would be unwieldy and cumbersome. Care must be taken | 87 //! context structure would be unwieldy and cumbersome. Care must be taken |
62 //! to populate the context structure correctly. The context structure | 88 //! to populate the context structure correctly. The context structure |
63 //! must only be modified while this object is in the #kStateMutable | 89 //! must only be modified while this object is in the #kStateMutable |
64 //! state. | 90 //! state. |
(...skipping 11 matching lines...) Expand all Loading... |
76 | 102 |
77 DISALLOW_COPY_AND_ASSIGN(MinidumpContextX86Writer); | 103 DISALLOW_COPY_AND_ASSIGN(MinidumpContextX86Writer); |
78 }; | 104 }; |
79 | 105 |
80 //! \brief The writer for a MinidumpContextAMD64 structure in a minidump file. | 106 //! \brief The writer for a MinidumpContextAMD64 structure in a minidump file. |
81 class MinidumpContextAMD64Writer final : public MinidumpContextWriter { | 107 class MinidumpContextAMD64Writer final : public MinidumpContextWriter { |
82 public: | 108 public: |
83 MinidumpContextAMD64Writer(); | 109 MinidumpContextAMD64Writer(); |
84 ~MinidumpContextAMD64Writer() override; | 110 ~MinidumpContextAMD64Writer() override; |
85 | 111 |
| 112 //! \brief Initializes the MinidumpContextAMD64 based on \a context_snapshot. |
| 113 //! |
| 114 //! \param[in] context_snapshot The context snapshot to use as source data. |
| 115 //! |
| 116 //! \note Valid in #kStateMutable. No mutation of context() may be done before |
| 117 //! calling this method, and it is not normally necessary to alter |
| 118 //! context() after calling this method. |
| 119 void InitializeFromSnapshot(const CPUContextX86_64* context_snapshot); |
| 120 |
86 //! \brief Returns a pointer to the context structure that this object will | 121 //! \brief Returns a pointer to the context structure that this object will |
87 //! write. | 122 //! write. |
88 //! | 123 //! |
89 //! \attention This returns a non-`const` pointer to this object’s private | 124 //! \attention This returns a non-`const` pointer to this object’s private |
90 //! data so that a caller can populate the context structure directly. | 125 //! data so that a caller can populate the context structure directly. |
91 //! This is done because providing setter interfaces to each field in the | 126 //! This is done because providing setter interfaces to each field in the |
92 //! context structure would be unwieldy and cumbersome. Care must be taken | 127 //! context structure would be unwieldy and cumbersome. Care must be taken |
93 //! to populate the context structure correctly. The context structure | 128 //! to populate the context structure correctly. The context structure |
94 //! must only be modified while this object is in the #kStateMutable | 129 //! must only be modified while this object is in the #kStateMutable |
95 //! state. | 130 //! state. |
96 MinidumpContextAMD64* context() { return &context_; } | 131 MinidumpContextAMD64* context() { return &context_; } |
97 | 132 |
98 protected: | 133 protected: |
99 // MinidumpWritable: | 134 // MinidumpWritable: |
100 size_t Alignment() override; | 135 size_t Alignment() override; |
101 bool WriteObject(FileWriterInterface* file_writer) override; | 136 bool WriteObject(FileWriterInterface* file_writer) override; |
102 | 137 |
103 // MinidumpContextWriter: | 138 // MinidumpContextWriter: |
104 size_t ContextSize() const override; | 139 size_t ContextSize() const override; |
105 | 140 |
106 private: | 141 private: |
107 MinidumpContextAMD64 context_; | 142 MinidumpContextAMD64 context_; |
108 | 143 |
109 DISALLOW_COPY_AND_ASSIGN(MinidumpContextAMD64Writer); | 144 DISALLOW_COPY_AND_ASSIGN(MinidumpContextAMD64Writer); |
110 }; | 145 }; |
111 | 146 |
112 } // namespace crashpad | 147 } // namespace crashpad |
113 | 148 |
114 #endif // CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_WRITER_H_ | 149 #endif // CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_WRITER_H_ |
OLD | NEW |