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_TEST_MINIDUMP_WRITABLE_TEST_UTIL_H_ | 15 #ifndef CRASHPAD_MINIDUMP_TEST_MINIDUMP_WRITABLE_TEST_UTIL_H_ |
16 #define CRASHPAD_MINIDUMP_TEST_MINIDUMP_WRITABLE_TEST_UTIL_H_ | 16 #define CRASHPAD_MINIDUMP_TEST_MINIDUMP_WRITABLE_TEST_UTIL_H_ |
17 | 17 |
18 #include <dbghelp.h> | 18 #include <dbghelp.h> |
19 #include <stdint.h> | 19 #include <stdint.h> |
20 | 20 |
21 #include <string> | 21 #include <string> |
22 | 22 |
23 #include "gtest/gtest.h" | 23 #include "gtest/gtest.h" |
24 #include "minidump/minidump_extensions.h" | 24 #include "minidump/minidump_extensions.h" |
25 | 25 |
26 namespace crashpad { | 26 namespace crashpad { |
27 namespace test { | 27 namespace test { |
28 | 28 |
29 //! \brief Returns an untyped minidump object located within a minidump file’s | 29 //! \brief Returns an untyped minidump object located within a minidump file’s |
30 //! contents, where the offset of the object is known. | |
31 //! | |
32 //! \param[in] file_contents The contents of the minidump file. | |
33 //! \param[in] rva The offset within the minidump file of the desired object. | |
34 //! | |
35 //! \return If \a rva is within the range of \a file_contents, returns a pointer | |
36 //! into \a file_contents at offset \a rva. Otherwise, raises a gtest | |
37 //! assertion failure and returns `nullptr`. | |
38 //! | |
39 //! Do not call this function. Use the typed version, MinidumpWritableAtRVA<>(), | |
40 //! or another type-specific function. | |
41 //! | |
42 //! \sa MinidumpWritableAtLocationDescriptorInternal() | |
43 const void* MinidumpWritableAtRVAInternal(const std::string& file_contents, | |
44 RVA rva); | |
45 | |
46 //! \brief Returns an untyped minidump object located within a minidump file’s | |
47 //! contents, where the offset and size of the object are known. | 30 //! contents, where the offset and size of the object are known. |
48 //! | 31 //! |
49 //! \param[in] file_contents The contents of the minidump file. | 32 //! \param[in] file_contents The contents of the minidump file. |
50 //! \param[in] location A MINIDUMP_LOCATION_DESCRIPTOR giving the offset within | 33 //! \param[in] location A MINIDUMP_LOCATION_DESCRIPTOR giving the offset within |
51 //! the minidump file of the desired object, as well as its size. | 34 //! the minidump file of the desired object, as well as its size. |
52 //! \param[in] expected_size The expected size of the object. If \a | 35 //! \param[in] expected_size The expected size of the object. If \a |
53 //! allow_oversized_data is `true`, \a expected_size is treated as the | 36 //! allow_oversized_data is `true`, \a expected_size is treated as the |
54 //! minimum size of \a location, but it is permitted to be larger. If \a | 37 //! minimum size of \a location, but it is permitted to be larger. If \a |
55 //! allow_oversized_data is `false`, the size of \a location must match | 38 //! allow_oversized_data is `false`, the size of \a location must match |
56 //! \a expected_size exactly. | 39 //! \a expected_size exactly. |
57 //! \param[in] allow_oversized_data Controls whether \a expected_size is a | 40 //! \param[in] allow_oversized_data Controls whether \a expected_size is a |
58 //! minimum limit (`true`) or an exact match is required (`false`). | 41 //! minimum limit (`true`) or an exact match is required (`false`). |
59 //! | 42 //! |
60 //! \return If the size of \a location is agrees with \a expected_size, and if | 43 //! \return If the size of \a location is agrees with \a expected_size, and if |
61 //! \a location is within the range of \a file_contents, returns a pointer | 44 //! \a location is within the range of \a file_contents, returns a pointer |
62 //! into \a file_contents at offset \a rva. Otherwise, raises a gtest | 45 //! into \a file_contents at offset \a rva. Otherwise, raises a gtest |
63 //! assertion failure and returns `nullptr`. | 46 //! assertion failure and returns `nullptr`. |
64 //! | 47 //! |
65 //! Do not call this function. Use the typed version, | 48 //! Do not call this function. Use the typed version, |
66 //! MinidumpWritableAtLocationDescriptor<>(), or another type-specific function. | 49 //! MinidumpWritableAtLocationDescriptor<>(), or another type-specific function. |
67 //! | |
68 //! \sa MinidumpWritableAtRVAInternal() | |
69 const void* MinidumpWritableAtLocationDescriptorInternal( | 50 const void* MinidumpWritableAtLocationDescriptorInternal( |
70 const std::string& file_contents, | 51 const std::string& file_contents, |
71 const MINIDUMP_LOCATION_DESCRIPTOR& location, | 52 const MINIDUMP_LOCATION_DESCRIPTOR& location, |
72 size_t expected_size, | 53 size_t expected_size, |
73 bool allow_oversized_data); | 54 bool allow_oversized_data); |
74 | 55 |
75 //! \brief A traits class defining whether a minidump object type is required to | 56 //! \brief A traits class defining whether a minidump object type is required to |
76 //! appear only as a fixed-size object or if it is variable-sized. | 57 //! appear only as a fixed-size object or if it is variable-sized. |
77 //! | 58 //! |
78 //! Variable-sized data is data referenced by a MINIDUMP_LOCATION_DESCRIPTOR | 59 //! Variable-sized data is data referenced by a MINIDUMP_LOCATION_DESCRIPTOR |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 MINIDUMP_ALLOW_OVERSIZED_DATA(MinidumpModuleCodeViewRecordPDB70); | 94 MINIDUMP_ALLOW_OVERSIZED_DATA(MinidumpModuleCodeViewRecordPDB70); |
114 MINIDUMP_ALLOW_OVERSIZED_DATA(MinidumpUTF8String); | 95 MINIDUMP_ALLOW_OVERSIZED_DATA(MinidumpUTF8String); |
115 | 96 |
116 // minidump_file_writer_test accesses its variable-sized test streams via a | 97 // minidump_file_writer_test accesses its variable-sized test streams via a |
117 // uint8_t*. | 98 // uint8_t*. |
118 MINIDUMP_ALLOW_OVERSIZED_DATA(uint8_t); | 99 MINIDUMP_ALLOW_OVERSIZED_DATA(uint8_t); |
119 | 100 |
120 #undef MINIDUMP_ALLOW_OVERSIZED_DATA | 101 #undef MINIDUMP_ALLOW_OVERSIZED_DATA |
121 | 102 |
122 //! \brief Returns a typed minidump object located within a minidump file’s | 103 //! \brief Returns a typed minidump object located within a minidump file’s |
123 //! contents, where the offset of the object is known. | |
124 //! | |
125 //! \param[in] file_contents The contents of the minidump file. | |
126 //! \param[in] rva The offset within the minidump file of the desired object. | |
127 //! | |
128 //! \return If \a rva is within the range of \a file_contents, returns a pointer | |
129 //! into \a file_contents at offset \a rva. Otherwise, raises a gtest | |
130 //! assertion failure and returns `nullptr`. | |
131 //! | |
132 //! \sa MinidumpWritableAtLocationDescriptor<>() | |
133 template <typename T> | |
134 const T* MinidumpWritableAtRVA(const std::string& file_contents, RVA rva) { | |
135 return reinterpret_cast<const T*>( | |
136 MinidumpWritableAtRVAInternal(file_contents, rva)); | |
137 } | |
138 | |
139 //! \brief Returns a typed minidump object located within a minidump file’s | |
140 //! contents, where the offset and size of the object are known. | 104 //! contents, where the offset and size of the object are known. |
141 //! | 105 //! |
142 //! This function is similar to MinidumpWritableAtLocationDescriptor<>() and is | 106 //! This function is similar to MinidumpWritableAtLocationDescriptor<>() and is |
143 //! used to implement that function. It exists independently so that template | 107 //! used to implement that function. It exists independently so that template |
144 //! specializations are able to call this function, which provides the default | 108 //! specializations are able to call this function, which provides the default |
145 //! implementation. | 109 //! implementation. |
146 //! | 110 //! |
147 //! Do not call this function directly. Use | 111 //! Do not call this function directly. Use |
148 //! MinidumpWritableAtLocationDescriptor<>() instead. | 112 //! MinidumpWritableAtLocationDescriptor<>() instead. |
149 template <typename T> | 113 template <typename T> |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 MinidumpWritableAtLocationDescriptor<MinidumpModuleCodeViewRecordPDB70>( | 198 MinidumpWritableAtLocationDescriptor<MinidumpModuleCodeViewRecordPDB70>( |
235 const std::string& file_contents, | 199 const std::string& file_contents, |
236 const MINIDUMP_LOCATION_DESCRIPTOR& location); | 200 const MINIDUMP_LOCATION_DESCRIPTOR& location); |
237 | 201 |
238 template <> | 202 template <> |
239 const MinidumpSimpleStringDictionary* | 203 const MinidumpSimpleStringDictionary* |
240 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>( | 204 MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>( |
241 const std::string& file_contents, | 205 const std::string& file_contents, |
242 const MINIDUMP_LOCATION_DESCRIPTOR& location); | 206 const MINIDUMP_LOCATION_DESCRIPTOR& location); |
243 | 207 |
| 208 //! \brief Returns a typed minidump object located within a minidump file’s |
| 209 //! contents, where the offset of the object is known. |
| 210 //! |
| 211 //! \param[in] file_contents The contents of the minidump file. |
| 212 //! \param[in] rva The offset within the minidump file of the desired object. |
| 213 //! |
| 214 //! \return If \a rva plus the size of an object of type \a T is within the |
| 215 //! range of \a file_contents, returns a pointer into \a file_contents at |
| 216 //! offset \a rva. Otherwise, raises a gtest assertion failure and returns |
| 217 //! `nullptr`. |
| 218 //! |
| 219 //! \sa MinidumpWritableAtLocationDescriptor<>() |
| 220 template <typename T> |
| 221 const T* MinidumpWritableAtRVA(const std::string& file_contents, RVA rva) { |
| 222 MINIDUMP_LOCATION_DESCRIPTOR location; |
| 223 location.DataSize = sizeof(T); |
| 224 location.Rva = rva; |
| 225 return MinidumpWritableAtLocationDescriptor<T>(file_contents, location); |
| 226 } |
| 227 |
244 } // namespace test | 228 } // namespace test |
245 } // namespace crashpad | 229 } // namespace crashpad |
246 | 230 |
247 #endif // CRASHPAD_MINIDUMP_TEST_MINIDUMP_WRITABLE_TEST_UTIL_H_ | 231 #endif // CRASHPAD_MINIDUMP_TEST_MINIDUMP_WRITABLE_TEST_UTIL_H_ |
OLD | NEW |