OLD | NEW |
1 // Copyright (c) 2010, Google Inc. | 1 // Copyright (c) 2010, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> | 30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
31 | 31 |
32 // dwarf2reader_cfi_unittest.cc: Unit tests for dwarf2reader::CallFrameInfo | 32 // dwarf2reader_cfi_unittest.cc: Unit tests for dwarf2reader::CallFrameInfo |
33 | 33 |
| 34 #include <stdint.h> |
34 #include <stdlib.h> | 35 #include <stdlib.h> |
35 | 36 |
36 #include <string> | 37 #include <string> |
37 #include <vector> | 38 #include <vector> |
38 | 39 |
39 // The '.eh_frame' format, used by the Linux C++ ABI for exception | 40 // The '.eh_frame' format, used by the Linux C++ ABI for exception |
40 // handling, is poorly specified. To help test our support for .eh_frame, | 41 // handling, is poorly specified. To help test our support for .eh_frame, |
41 // if you #define WRITE_ELF while compiling this file, and add the | 42 // if you #define WRITE_ELF while compiling this file, and add the |
42 // 'include' directory from the binutils, gcc, or gdb source tree to the | 43 // 'include' directory from the binutils, gcc, or gdb source tree to the |
43 // #include path, then each test that calls the | 44 // #include path, then each test that calls the |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 180 |
180 MockCallFrameInfoHandler handler; | 181 MockCallFrameInfoHandler handler; |
181 MockCallFrameErrorReporter reporter; | 182 MockCallFrameErrorReporter reporter; |
182 }; | 183 }; |
183 | 184 |
184 class CFI: public CFIFixture, public Test { }; | 185 class CFI: public CFIFixture, public Test { }; |
185 | 186 |
186 TEST_F(CFI, EmptyRegion) { | 187 TEST_F(CFI, EmptyRegion) { |
187 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); | 188 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); |
188 EXPECT_CALL(handler, End()).Times(0); | 189 EXPECT_CALL(handler, End()).Times(0); |
189 static const char data[1] = { 42 }; | 190 static const uint8_t data[] = { 42 }; |
190 | 191 |
191 ByteReader byte_reader(ENDIANNESS_BIG); | 192 ByteReader byte_reader(ENDIANNESS_BIG); |
192 CallFrameInfo parser(data, 0, &byte_reader, &handler, &reporter); | 193 CallFrameInfo parser(data, 0, &byte_reader, &handler, &reporter); |
193 EXPECT_TRUE(parser.Start()); | 194 EXPECT_TRUE(parser.Start()); |
194 } | 195 } |
195 | 196 |
196 TEST_F(CFI, IncompleteLength32) { | 197 TEST_F(CFI, IncompleteLength32) { |
197 CFISection section(kBigEndian, 8); | 198 CFISection section(kBigEndian, 8); |
198 section | 199 section |
199 // Not even long enough for an initial length. | 200 // Not even long enough for an initial length. |
200 .D16(0xa0f) | 201 .D16(0xa0f) |
201 // Padding to keep valgrind happy. We subtract these off when we | 202 // Padding to keep valgrind happy. We subtract these off when we |
202 // construct the parser. | 203 // construct the parser. |
203 .D16(0); | 204 .D16(0); |
204 | 205 |
205 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); | 206 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); |
206 EXPECT_CALL(handler, End()).Times(0); | 207 EXPECT_CALL(handler, End()).Times(0); |
207 | 208 |
208 EXPECT_CALL(reporter, Incomplete(_, CallFrameInfo::kUnknown)) | 209 EXPECT_CALL(reporter, Incomplete(_, CallFrameInfo::kUnknown)) |
209 .WillOnce(Return()); | 210 .WillOnce(Return()); |
210 | 211 |
211 string contents; | 212 string contents; |
212 ASSERT_TRUE(section.GetContents(&contents)); | 213 ASSERT_TRUE(section.GetContents(&contents)); |
213 | 214 |
214 ByteReader byte_reader(ENDIANNESS_BIG); | 215 ByteReader byte_reader(ENDIANNESS_BIG); |
215 byte_reader.SetAddressSize(8); | 216 byte_reader.SetAddressSize(8); |
216 CallFrameInfo parser(contents.data(), contents.size() - 2, | 217 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 218 contents.size() - 2, |
217 &byte_reader, &handler, &reporter); | 219 &byte_reader, &handler, &reporter); |
218 EXPECT_FALSE(parser.Start()); | 220 EXPECT_FALSE(parser.Start()); |
219 } | 221 } |
220 | 222 |
221 TEST_F(CFI, IncompleteLength64) { | 223 TEST_F(CFI, IncompleteLength64) { |
222 CFISection section(kLittleEndian, 4); | 224 CFISection section(kLittleEndian, 4); |
223 section | 225 section |
224 // An incomplete 64-bit DWARF initial length. | 226 // An incomplete 64-bit DWARF initial length. |
225 .D32(0xffffffff).D32(0x71fbaec2) | 227 .D32(0xffffffff).D32(0x71fbaec2) |
226 // Padding to keep valgrind happy. We subtract these off when we | 228 // Padding to keep valgrind happy. We subtract these off when we |
227 // construct the parser. | 229 // construct the parser. |
228 .D32(0); | 230 .D32(0); |
229 | 231 |
230 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); | 232 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); |
231 EXPECT_CALL(handler, End()).Times(0); | 233 EXPECT_CALL(handler, End()).Times(0); |
232 | 234 |
233 EXPECT_CALL(reporter, Incomplete(_, CallFrameInfo::kUnknown)) | 235 EXPECT_CALL(reporter, Incomplete(_, CallFrameInfo::kUnknown)) |
234 .WillOnce(Return()); | 236 .WillOnce(Return()); |
235 | 237 |
236 string contents; | 238 string contents; |
237 ASSERT_TRUE(section.GetContents(&contents)); | 239 ASSERT_TRUE(section.GetContents(&contents)); |
238 | 240 |
239 ByteReader byte_reader(ENDIANNESS_LITTLE); | 241 ByteReader byte_reader(ENDIANNESS_LITTLE); |
240 byte_reader.SetAddressSize(4); | 242 byte_reader.SetAddressSize(4); |
241 CallFrameInfo parser(contents.data(), contents.size() - 4, | 243 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 244 contents.size() - 4, |
242 &byte_reader, &handler, &reporter); | 245 &byte_reader, &handler, &reporter); |
243 EXPECT_FALSE(parser.Start()); | 246 EXPECT_FALSE(parser.Start()); |
244 } | 247 } |
245 | 248 |
246 TEST_F(CFI, IncompleteId32) { | 249 TEST_F(CFI, IncompleteId32) { |
247 CFISection section(kBigEndian, 8); | 250 CFISection section(kBigEndian, 8); |
248 section | 251 section |
249 .D32(3) // Initial length, not long enough for id | 252 .D32(3) // Initial length, not long enough for id |
250 .D8(0xd7).D8(0xe5).D8(0xf1) // incomplete id | 253 .D8(0xd7).D8(0xe5).D8(0xf1) // incomplete id |
251 .CIEHeader(8727, 3983, 8889, 3, "") | 254 .CIEHeader(8727, 3983, 8889, 3, "") |
252 .FinishEntry(); | 255 .FinishEntry(); |
253 | 256 |
254 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); | 257 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); |
255 EXPECT_CALL(handler, End()).Times(0); | 258 EXPECT_CALL(handler, End()).Times(0); |
256 | 259 |
257 EXPECT_CALL(reporter, Incomplete(_, CallFrameInfo::kUnknown)) | 260 EXPECT_CALL(reporter, Incomplete(_, CallFrameInfo::kUnknown)) |
258 .WillOnce(Return()); | 261 .WillOnce(Return()); |
259 | 262 |
260 string contents; | 263 string contents; |
261 ASSERT_TRUE(section.GetContents(&contents)); | 264 ASSERT_TRUE(section.GetContents(&contents)); |
262 | 265 |
263 ByteReader byte_reader(ENDIANNESS_BIG); | 266 ByteReader byte_reader(ENDIANNESS_BIG); |
264 byte_reader.SetAddressSize(8); | 267 byte_reader.SetAddressSize(8); |
265 CallFrameInfo parser(contents.data(), contents.size(), | 268 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 269 contents.size(), |
266 &byte_reader, &handler, &reporter); | 270 &byte_reader, &handler, &reporter); |
267 EXPECT_FALSE(parser.Start()); | 271 EXPECT_FALSE(parser.Start()); |
268 } | 272 } |
269 | 273 |
270 TEST_F(CFI, BadId32) { | 274 TEST_F(CFI, BadId32) { |
271 CFISection section(kBigEndian, 8); | 275 CFISection section(kBigEndian, 8); |
272 section | 276 section |
273 .D32(0x100) // Initial length | 277 .D32(0x100) // Initial length |
274 .D32(0xe802fade) // bogus ID | 278 .D32(0xe802fade) // bogus ID |
275 .Append(0x100 - 4, 0x42); // make the length true | 279 .Append(0x100 - 4, 0x42); // make the length true |
276 section | 280 section |
277 .CIEHeader(1672, 9872, 8529, 3, "") | 281 .CIEHeader(1672, 9872, 8529, 3, "") |
278 .FinishEntry(); | 282 .FinishEntry(); |
279 | 283 |
280 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); | 284 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); |
281 EXPECT_CALL(handler, End()).Times(0); | 285 EXPECT_CALL(handler, End()).Times(0); |
282 | 286 |
283 EXPECT_CALL(reporter, CIEPointerOutOfRange(_, 0xe802fade)) | 287 EXPECT_CALL(reporter, CIEPointerOutOfRange(_, 0xe802fade)) |
284 .WillOnce(Return()); | 288 .WillOnce(Return()); |
285 | 289 |
286 string contents; | 290 string contents; |
287 ASSERT_TRUE(section.GetContents(&contents)); | 291 ASSERT_TRUE(section.GetContents(&contents)); |
288 | 292 |
289 ByteReader byte_reader(ENDIANNESS_BIG); | 293 ByteReader byte_reader(ENDIANNESS_BIG); |
290 byte_reader.SetAddressSize(8); | 294 byte_reader.SetAddressSize(8); |
291 CallFrameInfo parser(contents.data(), contents.size(), | 295 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 296 contents.size(), |
292 &byte_reader, &handler, &reporter); | 297 &byte_reader, &handler, &reporter); |
293 EXPECT_FALSE(parser.Start()); | 298 EXPECT_FALSE(parser.Start()); |
294 } | 299 } |
295 | 300 |
296 // A lone CIE shouldn't cause any handler calls. | 301 // A lone CIE shouldn't cause any handler calls. |
297 TEST_F(CFI, SingleCIE) { | 302 TEST_F(CFI, SingleCIE) { |
298 CFISection section(kLittleEndian, 4); | 303 CFISection section(kLittleEndian, 4); |
299 section.CIEHeader(0xffe799a8, 0x3398dcdd, 0x6e9683de, 3, ""); | 304 section.CIEHeader(0xffe799a8, 0x3398dcdd, 0x6e9683de, 3, ""); |
300 section.Append(10, dwarf2reader::DW_CFA_nop); | 305 section.Append(10, dwarf2reader::DW_CFA_nop); |
301 section.FinishEntry(); | 306 section.FinishEntry(); |
302 | 307 |
303 PERHAPS_WRITE_DEBUG_FRAME_FILE("SingleCIE", section); | 308 PERHAPS_WRITE_DEBUG_FRAME_FILE("SingleCIE", section); |
304 | 309 |
305 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); | 310 EXPECT_CALL(handler, Entry(_, _, _, _, _, _)).Times(0); |
306 EXPECT_CALL(handler, End()).Times(0); | 311 EXPECT_CALL(handler, End()).Times(0); |
307 | 312 |
308 string contents; | 313 string contents; |
309 EXPECT_TRUE(section.GetContents(&contents)); | 314 EXPECT_TRUE(section.GetContents(&contents)); |
310 ByteReader byte_reader(ENDIANNESS_LITTLE); | 315 ByteReader byte_reader(ENDIANNESS_LITTLE); |
311 byte_reader.SetAddressSize(4); | 316 byte_reader.SetAddressSize(4); |
312 CallFrameInfo parser(contents.data(), contents.size(), | 317 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 318 contents.size(), |
313 &byte_reader, &handler, &reporter); | 319 &byte_reader, &handler, &reporter); |
314 EXPECT_TRUE(parser.Start()); | 320 EXPECT_TRUE(parser.Start()); |
315 } | 321 } |
316 | 322 |
317 // One FDE, one CIE. | 323 // One FDE, one CIE. |
318 TEST_F(CFI, OneFDE) { | 324 TEST_F(CFI, OneFDE) { |
319 CFISection section(kBigEndian, 4); | 325 CFISection section(kBigEndian, 4); |
320 Label cie; | 326 Label cie; |
321 section | 327 section |
322 .Mark(&cie) | 328 .Mark(&cie) |
323 .CIEHeader(0x4be22f75, 0x2492236e, 0x6b6efb87, 3, "") | 329 .CIEHeader(0x4be22f75, 0x2492236e, 0x6b6efb87, 3, "") |
324 .FinishEntry() | 330 .FinishEntry() |
325 .FDEHeader(cie, 0x7714740d, 0x3d5a10cd) | 331 .FDEHeader(cie, 0x7714740d, 0x3d5a10cd) |
326 .FinishEntry(); | 332 .FinishEntry(); |
327 | 333 |
328 PERHAPS_WRITE_DEBUG_FRAME_FILE("OneFDE", section); | 334 PERHAPS_WRITE_DEBUG_FRAME_FILE("OneFDE", section); |
329 | 335 |
330 { | 336 { |
331 InSequence s; | 337 InSequence s; |
332 EXPECT_CALL(handler, | 338 EXPECT_CALL(handler, |
333 Entry(_, 0x7714740d, 0x3d5a10cd, 3, "", 0x6b6efb87)) | 339 Entry(_, 0x7714740d, 0x3d5a10cd, 3, "", 0x6b6efb87)) |
334 .WillOnce(Return(true)); | 340 .WillOnce(Return(true)); |
335 EXPECT_CALL(handler, End()).WillOnce(Return(true)); | 341 EXPECT_CALL(handler, End()).WillOnce(Return(true)); |
336 } | 342 } |
337 | 343 |
338 string contents; | 344 string contents; |
339 EXPECT_TRUE(section.GetContents(&contents)); | 345 EXPECT_TRUE(section.GetContents(&contents)); |
340 ByteReader byte_reader(ENDIANNESS_BIG); | 346 ByteReader byte_reader(ENDIANNESS_BIG); |
341 byte_reader.SetAddressSize(4); | 347 byte_reader.SetAddressSize(4); |
342 CallFrameInfo parser(contents.data(), contents.size(), | 348 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 349 contents.size(), |
343 &byte_reader, &handler, &reporter); | 350 &byte_reader, &handler, &reporter); |
344 EXPECT_TRUE(parser.Start()); | 351 EXPECT_TRUE(parser.Start()); |
345 } | 352 } |
346 | 353 |
347 // Two FDEs share a CIE. | 354 // Two FDEs share a CIE. |
348 TEST_F(CFI, TwoFDEsOneCIE) { | 355 TEST_F(CFI, TwoFDEsOneCIE) { |
349 CFISection section(kBigEndian, 4); | 356 CFISection section(kBigEndian, 4); |
350 Label cie; | 357 Label cie; |
351 section | 358 section |
352 // First FDE. readelf complains about this one because it makes | 359 // First FDE. readelf complains about this one because it makes |
(...skipping 22 matching lines...) Expand all Loading... |
375 EXPECT_CALL(handler, | 382 EXPECT_CALL(handler, |
376 Entry(_, 0x6057d391, 0x700f608d, 3, "", 0xbd43cb59)) | 383 Entry(_, 0x6057d391, 0x700f608d, 3, "", 0xbd43cb59)) |
377 .WillOnce(Return(true)); | 384 .WillOnce(Return(true)); |
378 EXPECT_CALL(handler, End()).WillOnce(Return(true)); | 385 EXPECT_CALL(handler, End()).WillOnce(Return(true)); |
379 } | 386 } |
380 | 387 |
381 string contents; | 388 string contents; |
382 EXPECT_TRUE(section.GetContents(&contents)); | 389 EXPECT_TRUE(section.GetContents(&contents)); |
383 ByteReader byte_reader(ENDIANNESS_BIG); | 390 ByteReader byte_reader(ENDIANNESS_BIG); |
384 byte_reader.SetAddressSize(4); | 391 byte_reader.SetAddressSize(4); |
385 CallFrameInfo parser(contents.data(), contents.size(), | 392 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 393 contents.size(), |
386 &byte_reader, &handler, &reporter); | 394 &byte_reader, &handler, &reporter); |
387 EXPECT_TRUE(parser.Start()); | 395 EXPECT_TRUE(parser.Start()); |
388 } | 396 } |
389 | 397 |
390 // Two FDEs, two CIEs. | 398 // Two FDEs, two CIEs. |
391 TEST_F(CFI, TwoFDEsTwoCIEs) { | 399 TEST_F(CFI, TwoFDEsTwoCIEs) { |
392 CFISection section(kLittleEndian, 8); | 400 CFISection section(kLittleEndian, 8); |
393 Label cie1, cie2; | 401 Label cie1, cie2; |
394 section | 402 section |
395 // First CIE. | 403 // First CIE. |
(...skipping 28 matching lines...) Expand all Loading... |
424 Entry(_, 0xf6054ca18b10bf5fULL, 0x45fdb970d8bca342ULL, 3, | 432 Entry(_, 0xf6054ca18b10bf5fULL, 0x45fdb970d8bca342ULL, 3, |
425 "", 0xbf45e65a)) | 433 "", 0xbf45e65a)) |
426 .WillOnce(Return(true)); | 434 .WillOnce(Return(true)); |
427 EXPECT_CALL(handler, End()).WillOnce(Return(true)); | 435 EXPECT_CALL(handler, End()).WillOnce(Return(true)); |
428 } | 436 } |
429 | 437 |
430 string contents; | 438 string contents; |
431 EXPECT_TRUE(section.GetContents(&contents)); | 439 EXPECT_TRUE(section.GetContents(&contents)); |
432 ByteReader byte_reader(ENDIANNESS_LITTLE); | 440 ByteReader byte_reader(ENDIANNESS_LITTLE); |
433 byte_reader.SetAddressSize(8); | 441 byte_reader.SetAddressSize(8); |
434 CallFrameInfo parser(contents.data(), contents.size(), | 442 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 443 contents.size(), |
435 &byte_reader, &handler, &reporter); | 444 &byte_reader, &handler, &reporter); |
436 EXPECT_TRUE(parser.Start()); | 445 EXPECT_TRUE(parser.Start()); |
437 } | 446 } |
438 | 447 |
439 // An FDE whose CIE specifies a version we don't recognize. | 448 // An FDE whose CIE specifies a version we don't recognize. |
440 TEST_F(CFI, BadVersion) { | 449 TEST_F(CFI, BadVersion) { |
441 CFISection section(kBigEndian, 4); | 450 CFISection section(kBigEndian, 4); |
442 Label cie1, cie2; | 451 Label cie1, cie2; |
443 section | 452 section |
444 .Mark(&cie1) | 453 .Mark(&cie1) |
(...skipping 23 matching lines...) Expand all Loading... |
468 0x96cb3264)) | 477 0x96cb3264)) |
469 .WillOnce(Return(true)); | 478 .WillOnce(Return(true)); |
470 EXPECT_CALL(handler, End()) | 479 EXPECT_CALL(handler, End()) |
471 .WillOnce(Return(true)); | 480 .WillOnce(Return(true)); |
472 } | 481 } |
473 | 482 |
474 string contents; | 483 string contents; |
475 EXPECT_TRUE(section.GetContents(&contents)); | 484 EXPECT_TRUE(section.GetContents(&contents)); |
476 ByteReader byte_reader(ENDIANNESS_BIG); | 485 ByteReader byte_reader(ENDIANNESS_BIG); |
477 byte_reader.SetAddressSize(4); | 486 byte_reader.SetAddressSize(4); |
478 CallFrameInfo parser(contents.data(), contents.size(), | 487 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 488 contents.size(), |
479 &byte_reader, &handler, &reporter); | 489 &byte_reader, &handler, &reporter); |
480 EXPECT_FALSE(parser.Start()); | 490 EXPECT_FALSE(parser.Start()); |
481 } | 491 } |
482 | 492 |
483 // An FDE whose CIE specifies an augmentation we don't recognize. | 493 // An FDE whose CIE specifies an augmentation we don't recognize. |
484 TEST_F(CFI, BadAugmentation) { | 494 TEST_F(CFI, BadAugmentation) { |
485 CFISection section(kBigEndian, 4); | 495 CFISection section(kBigEndian, 4); |
486 Label cie1, cie2; | 496 Label cie1, cie2; |
487 section | 497 section |
488 .Mark(&cie1) | 498 .Mark(&cie1) |
(...skipping 23 matching lines...) Expand all Loading... |
512 0xf2f519b2)) | 522 0xf2f519b2)) |
513 .WillOnce(Return(true)); | 523 .WillOnce(Return(true)); |
514 EXPECT_CALL(handler, End()) | 524 EXPECT_CALL(handler, End()) |
515 .WillOnce(Return(true)); | 525 .WillOnce(Return(true)); |
516 } | 526 } |
517 | 527 |
518 string contents; | 528 string contents; |
519 EXPECT_TRUE(section.GetContents(&contents)); | 529 EXPECT_TRUE(section.GetContents(&contents)); |
520 ByteReader byte_reader(ENDIANNESS_BIG); | 530 ByteReader byte_reader(ENDIANNESS_BIG); |
521 byte_reader.SetAddressSize(4); | 531 byte_reader.SetAddressSize(4); |
522 CallFrameInfo parser(contents.data(), contents.size(), | 532 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 533 contents.size(), |
523 &byte_reader, &handler, &reporter); | 534 &byte_reader, &handler, &reporter); |
524 EXPECT_FALSE(parser.Start()); | 535 EXPECT_FALSE(parser.Start()); |
525 } | 536 } |
526 | 537 |
527 // The return address column field is a byte in CFI version 1 | 538 // The return address column field is a byte in CFI version 1 |
528 // (DWARF2), but a ULEB128 value in version 3 (DWARF3). | 539 // (DWARF2), but a ULEB128 value in version 3 (DWARF3). |
529 TEST_F(CFI, CIEVersion1ReturnColumn) { | 540 TEST_F(CFI, CIEVersion1ReturnColumn) { |
530 CFISection section(kBigEndian, 4); | 541 CFISection section(kBigEndian, 4); |
531 Label cie; | 542 Label cie; |
532 section | 543 section |
(...skipping 13 matching lines...) Expand all Loading... |
546 InSequence s; | 557 InSequence s; |
547 EXPECT_CALL(handler, Entry(_, 0xb8d347b5, 0x825e55dc, 1, "", 0x9f)) | 558 EXPECT_CALL(handler, Entry(_, 0xb8d347b5, 0x825e55dc, 1, "", 0x9f)) |
548 .WillOnce(Return(true)); | 559 .WillOnce(Return(true)); |
549 EXPECT_CALL(handler, End()).WillOnce(Return(true)); | 560 EXPECT_CALL(handler, End()).WillOnce(Return(true)); |
550 } | 561 } |
551 | 562 |
552 string contents; | 563 string contents; |
553 EXPECT_TRUE(section.GetContents(&contents)); | 564 EXPECT_TRUE(section.GetContents(&contents)); |
554 ByteReader byte_reader(ENDIANNESS_BIG); | 565 ByteReader byte_reader(ENDIANNESS_BIG); |
555 byte_reader.SetAddressSize(4); | 566 byte_reader.SetAddressSize(4); |
556 CallFrameInfo parser(contents.data(), contents.size(), | 567 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 568 contents.size(), |
557 &byte_reader, &handler, &reporter); | 569 &byte_reader, &handler, &reporter); |
558 EXPECT_TRUE(parser.Start()); | 570 EXPECT_TRUE(parser.Start()); |
559 } | 571 } |
560 | 572 |
561 // The return address column field is a byte in CFI version 1 | 573 // The return address column field is a byte in CFI version 1 |
562 // (DWARF2), but a ULEB128 value in version 3 (DWARF3). | 574 // (DWARF2), but a ULEB128 value in version 3 (DWARF3). |
563 TEST_F(CFI, CIEVersion3ReturnColumn) { | 575 TEST_F(CFI, CIEVersion3ReturnColumn) { |
564 CFISection section(kBigEndian, 4); | 576 CFISection section(kBigEndian, 4); |
565 Label cie; | 577 Label cie; |
566 section | 578 section |
(...skipping 13 matching lines...) Expand all Loading... |
580 InSequence s; | 592 InSequence s; |
581 EXPECT_CALL(handler, Entry(_, 0x86763f2b, 0x2a66dc23, 3, "", 0x89)) | 593 EXPECT_CALL(handler, Entry(_, 0x86763f2b, 0x2a66dc23, 3, "", 0x89)) |
582 .WillOnce(Return(true)); | 594 .WillOnce(Return(true)); |
583 EXPECT_CALL(handler, End()).WillOnce(Return(true)); | 595 EXPECT_CALL(handler, End()).WillOnce(Return(true)); |
584 } | 596 } |
585 | 597 |
586 string contents; | 598 string contents; |
587 EXPECT_TRUE(section.GetContents(&contents)); | 599 EXPECT_TRUE(section.GetContents(&contents)); |
588 ByteReader byte_reader(ENDIANNESS_BIG); | 600 ByteReader byte_reader(ENDIANNESS_BIG); |
589 byte_reader.SetAddressSize(4); | 601 byte_reader.SetAddressSize(4); |
590 CallFrameInfo parser(contents.data(), contents.size(), | 602 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 603 contents.size(), |
591 &byte_reader, &handler, &reporter); | 604 &byte_reader, &handler, &reporter); |
592 EXPECT_TRUE(parser.Start()); | 605 EXPECT_TRUE(parser.Start()); |
593 } | 606 } |
594 | 607 |
595 struct CFIInsnFixture: public CFIFixture { | 608 struct CFIInsnFixture: public CFIFixture { |
596 CFIInsnFixture() : CFIFixture() { | 609 CFIInsnFixture() : CFIFixture() { |
597 data_factor = 0xb6f; | 610 data_factor = 0xb6f; |
598 return_register = 0x9be1ed9f; | 611 return_register = 0x9be1ed9f; |
599 version = 3; | 612 version = 3; |
600 cfa_base_register = 0x383a3aa; | 613 cfa_base_register = 0x383a3aa; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 EXPECT_TRUE(section->GetContents(&contents)); | 674 EXPECT_TRUE(section->GetContents(&contents)); |
662 dwarf2reader::Endianness endianness; | 675 dwarf2reader::Endianness endianness; |
663 if (section->endianness() == kBigEndian) | 676 if (section->endianness() == kBigEndian) |
664 endianness = ENDIANNESS_BIG; | 677 endianness = ENDIANNESS_BIG; |
665 else { | 678 else { |
666 assert(section->endianness() == kLittleEndian); | 679 assert(section->endianness() == kLittleEndian); |
667 endianness = ENDIANNESS_LITTLE; | 680 endianness = ENDIANNESS_LITTLE; |
668 } | 681 } |
669 ByteReader byte_reader(endianness); | 682 ByteReader byte_reader(endianness); |
670 byte_reader.SetAddressSize(section->AddressSize()); | 683 byte_reader.SetAddressSize(section->AddressSize()); |
671 CallFrameInfo parser(contents.data(), contents.size(), | 684 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 685 contents.size(), |
672 &byte_reader, &handler, &reporter); | 686 &byte_reader, &handler, &reporter); |
673 if (succeeds) | 687 if (succeeds) |
674 EXPECT_TRUE(parser.Start()); | 688 EXPECT_TRUE(parser.Start()); |
675 else | 689 else |
676 EXPECT_FALSE(parser.Start()); | 690 EXPECT_FALSE(parser.Start()); |
677 } | 691 } |
678 | 692 |
679 Label cie_label; | 693 Label cie_label; |
680 Sequence s; | 694 Sequence s; |
681 uint64 code_factor; | 695 uint64 code_factor; |
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 EXPECT_TRUE(section->GetContents(&contents)); | 1996 EXPECT_TRUE(section->GetContents(&contents)); |
1983 dwarf2reader::Endianness endianness; | 1997 dwarf2reader::Endianness endianness; |
1984 if (section->endianness() == kBigEndian) | 1998 if (section->endianness() == kBigEndian) |
1985 endianness = ENDIANNESS_BIG; | 1999 endianness = ENDIANNESS_BIG; |
1986 else { | 2000 else { |
1987 assert(section->endianness() == kLittleEndian); | 2001 assert(section->endianness() == kLittleEndian); |
1988 endianness = ENDIANNESS_LITTLE; | 2002 endianness = ENDIANNESS_LITTLE; |
1989 } | 2003 } |
1990 ByteReader byte_reader(endianness); | 2004 ByteReader byte_reader(endianness); |
1991 byte_reader.SetAddressSize(section->AddressSize()); | 2005 byte_reader.SetAddressSize(section->AddressSize()); |
1992 byte_reader.SetCFIDataBase(encoded_pointer_bases.cfi, contents.data()); | 2006 byte_reader.SetCFIDataBase(encoded_pointer_bases.cfi, |
| 2007 reinterpret_cast<const uint8_t *>(contents.data()
)); |
1993 byte_reader.SetTextBase(encoded_pointer_bases.text); | 2008 byte_reader.SetTextBase(encoded_pointer_bases.text); |
1994 byte_reader.SetDataBase(encoded_pointer_bases.data); | 2009 byte_reader.SetDataBase(encoded_pointer_bases.data); |
1995 CallFrameInfo parser(contents.data(), contents.size(), | 2010 CallFrameInfo parser(reinterpret_cast<const uint8_t *>(contents.data()), |
| 2011 contents.size(), |
1996 &byte_reader, &handler, &reporter, true); | 2012 &byte_reader, &handler, &reporter, true); |
1997 if (succeeds) | 2013 if (succeeds) |
1998 EXPECT_TRUE(parser.Start()); | 2014 EXPECT_TRUE(parser.Start()); |
1999 else | 2015 else |
2000 EXPECT_FALSE(parser.Start()); | 2016 EXPECT_FALSE(parser.Start()); |
2001 } | 2017 } |
2002 | 2018 |
2003 }; | 2019 }; |
2004 | 2020 |
2005 class EHFrame: public EHFrameFixture, public Test { }; | 2021 class EHFrame: public EHFrameFixture, public Test { }; |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2443 exit(1); | 2459 exit(1); |
2444 } | 2460 } |
2445 | 2461 |
2446 if (fclose(out) == EOF) { | 2462 if (fclose(out) == EOF) { |
2447 fprintf(stderr, "error closing ELF file '%s': %s\n", | 2463 fprintf(stderr, "error closing ELF file '%s': %s\n", |
2448 filename, strerror(errno)); | 2464 filename, strerror(errno)); |
2449 exit(1); | 2465 exit(1); |
2450 } | 2466 } |
2451 } | 2467 } |
2452 #endif | 2468 #endif |
OLD | NEW |