Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: snapshot/mac/mach_o_image_reader_test.cc

Issue 700383007: Use implicit_cast<> instead of static_cast<> whenever possible (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 const MachHeader* mh_execute_header = 503 const MachHeader* mh_execute_header =
504 reinterpret_cast<MachHeader*>(dlsym(RTLD_MAIN_ONLY, MH_EXECUTE_SYM)); 504 reinterpret_cast<MachHeader*>(dlsym(RTLD_MAIN_ONLY, MH_EXECUTE_SYM));
505 ASSERT_NE(nullptr, mh_execute_header); 505 ASSERT_NE(nullptr, mh_execute_header);
506 mach_vm_address_t mh_execute_header_address = 506 mach_vm_address_t mh_execute_header_address =
507 reinterpret_cast<mach_vm_address_t>(mh_execute_header); 507 reinterpret_cast<mach_vm_address_t>(mh_execute_header);
508 508
509 MachOImageReader image_reader; 509 MachOImageReader image_reader;
510 ASSERT_TRUE(image_reader.Initialize( 510 ASSERT_TRUE(image_reader.Initialize(
511 &process_reader, mh_execute_header_address, "executable")); 511 &process_reader, mh_execute_header_address, "executable"));
512 512
513 EXPECT_EQ(static_cast<uint32_t>(MH_EXECUTE), image_reader.FileType()); 513 EXPECT_EQ(implicit_cast<uint32_t>(MH_EXECUTE), image_reader.FileType());
514 514
515 // The main executable has image index 0. 515 // The main executable has image index 0.
516 intptr_t image_slide = _dyld_get_image_vmaddr_slide(0); 516 intptr_t image_slide = _dyld_get_image_vmaddr_slide(0);
517 517
518 ASSERT_NO_FATAL_FAILURE(ExpectMachImage(mh_execute_header, 518 ASSERT_NO_FATAL_FAILURE(ExpectMachImage(mh_execute_header,
519 mh_execute_header_address, 519 mh_execute_header_address,
520 image_slide, 520 image_slide,
521 &image_reader, 521 &image_reader,
522 true)); 522 true));
523 523
(...skipping 25 matching lines...) Expand all
549 reinterpret_cast<const MachHeader*>(_dyld_get_image_header(index)); 549 reinterpret_cast<const MachHeader*>(_dyld_get_image_header(index));
550 mach_vm_address_t image_address = 550 mach_vm_address_t image_address =
551 reinterpret_cast<mach_vm_address_t>(mach_header); 551 reinterpret_cast<mach_vm_address_t>(mach_header);
552 552
553 MachOImageReader image_reader; 553 MachOImageReader image_reader;
554 ASSERT_TRUE( 554 ASSERT_TRUE(
555 image_reader.Initialize(&process_reader, image_address, image_name)); 555 image_reader.Initialize(&process_reader, image_address, image_name));
556 556
557 uint32_t file_type = image_reader.FileType(); 557 uint32_t file_type = image_reader.FileType();
558 if (index == 0) { 558 if (index == 0) {
559 EXPECT_EQ(static_cast<uint32_t>(MH_EXECUTE), file_type); 559 EXPECT_EQ(implicit_cast<uint32_t>(MH_EXECUTE), file_type);
560 } else { 560 } else {
561 EXPECT_TRUE(file_type == MH_DYLIB || file_type == MH_BUNDLE); 561 EXPECT_TRUE(file_type == MH_DYLIB || file_type == MH_BUNDLE);
562 } 562 }
563 563
564 intptr_t image_slide = _dyld_get_image_vmaddr_slide(index); 564 intptr_t image_slide = _dyld_get_image_vmaddr_slide(index);
565 ASSERT_NO_FATAL_FAILURE(ExpectMachImage( 565 ASSERT_NO_FATAL_FAILURE(ExpectMachImage(
566 mach_header, image_address, image_slide, &image_reader, false)); 566 mach_header, image_address, image_slide, &image_reader, false));
567 567
568 ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader)); 568 ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader));
569 } 569 }
(...skipping 11 matching lines...) Expand all
581 // dyld_all_image_infos::dyldImageLoadAddress is poorly-declared too. 581 // dyld_all_image_infos::dyldImageLoadAddress is poorly-declared too.
582 const MachHeader* mach_header = reinterpret_cast<const MachHeader*>( 582 const MachHeader* mach_header = reinterpret_cast<const MachHeader*>(
583 dyld_image_infos->dyldImageLoadAddress); 583 dyld_image_infos->dyldImageLoadAddress);
584 mach_vm_address_t image_address = 584 mach_vm_address_t image_address =
585 reinterpret_cast<mach_vm_address_t>(mach_header); 585 reinterpret_cast<mach_vm_address_t>(mach_header);
586 586
587 MachOImageReader image_reader; 587 MachOImageReader image_reader;
588 ASSERT_TRUE( 588 ASSERT_TRUE(
589 image_reader.Initialize(&process_reader, image_address, "dyld")); 589 image_reader.Initialize(&process_reader, image_address, "dyld"));
590 590
591 EXPECT_EQ(static_cast<uint32_t>(MH_DYLINKER), image_reader.FileType()); 591 EXPECT_EQ(implicit_cast<uint32_t>(MH_DYLINKER), image_reader.FileType());
592 592
593 // There’s no good API to get dyld’s slide, so don’t bother checking it. 593 // There’s no good API to get dyld’s slide, so don’t bother checking it.
594 ASSERT_NO_FATAL_FAILURE(ExpectMachImage( 594 ASSERT_NO_FATAL_FAILURE(ExpectMachImage(
595 mach_header, image_address, kSlideUnknown, &image_reader, false)); 595 mach_header, image_address, kSlideUnknown, &image_reader, false));
596 596
597 ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader)); 597 ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader));
598 } 598 }
599 599
600 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 600 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
601 // If dyld is new enough to record UUIDs, check the UUID of any module that 601 // If dyld is new enough to record UUIDs, check the UUID of any module that
(...skipping 29 matching lines...) Expand all
631 image_reader.UUID(&actual_uuid); 631 image_reader.UUID(&actual_uuid);
632 EXPECT_EQ(expected_uuid, actual_uuid); 632 EXPECT_EQ(expected_uuid, actual_uuid);
633 } 633 }
634 } 634 }
635 #endif 635 #endif
636 } 636 }
637 637
638 } // namespace 638 } // namespace
639 } // namespace test 639 } // namespace test
640 } // namespace crashpad 640 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698