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

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

Issue 997713002: Allow exception forwarding to the system’s native crash reporter to be disabled (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Remove unused function declaration Created 5 years, 9 months 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
« no previous file with comments | « snapshot/mac/mach_o_image_reader.cc ('k') | snapshot/mac/module_snapshot_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
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 #include "snapshot/mac/mach_o_image_reader.h" 15 #include "snapshot/mac/mach_o_image_reader.h"
16 16
17 #include <AvailabilityMacros.h> 17 #include <AvailabilityMacros.h>
18 #include <dlfcn.h> 18 #include <dlfcn.h>
19 #include <mach-o/dyld.h> 19 #include <mach-o/dyld.h>
20 #include <mach-o/dyld_images.h> 20 #include <mach-o/dyld_images.h>
21 #include <mach-o/getsect.h> 21 #include <mach-o/getsect.h>
22 #include <mach-o/ldsyms.h> 22 #include <mach-o/ldsyms.h>
23 #include <mach-o/loader.h> 23 #include <mach-o/loader.h>
24 #include <mach-o/nlist.h> 24 #include <mach-o/nlist.h>
25 #include <stdint.h> 25 #include <stdint.h>
26 26
27 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "client/crashpad_info.h"
29 #include "gtest/gtest.h" 30 #include "gtest/gtest.h"
30 #include "snapshot/mac/mach_o_image_segment_reader.h" 31 #include "snapshot/mac/mach_o_image_segment_reader.h"
31 #include "snapshot/mac/process_reader.h" 32 #include "snapshot/mac/process_reader.h"
32 #include "snapshot/mac/process_types.h" 33 #include "snapshot/mac/process_types.h"
33 #include "util/misc/uuid.h" 34 #include "util/misc/uuid.h"
34 #include "util/test/mac/dyld.h" 35 #include "util/test/mac/dyld.h"
35 36
36 // This file is responsible for testing MachOImageReader, 37 // This file is responsible for testing MachOImageReader,
37 // MachOImageSegmentReader, and MachOImageSymbolTableReader. 38 // MachOImageSegmentReader, and MachOImageSymbolTableReader.
38 39
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mh_execute_header, &image_reader)); 526 ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mh_execute_header, &image_reader));
526 } 527 }
527 528
528 TEST(MachOImageReader, Self_DyldImages) { 529 TEST(MachOImageReader, Self_DyldImages) {
529 ProcessReader process_reader; 530 ProcessReader process_reader;
530 ASSERT_TRUE(process_reader.Initialize(mach_task_self())); 531 ASSERT_TRUE(process_reader.Initialize(mach_task_self()));
531 532
532 uint32_t count = _dyld_image_count(); 533 uint32_t count = _dyld_image_count();
533 ASSERT_GE(count, 1u); 534 ASSERT_GE(count, 1u);
534 535
536 size_t modules_with_crashpad_info = 0;
537
535 for (uint32_t index = 0; index < count; ++index) { 538 for (uint32_t index = 0; index < count; ++index) {
536 const char* image_name = _dyld_get_image_name(index); 539 const char* image_name = _dyld_get_image_name(index);
537 SCOPED_TRACE(base::StringPrintf("index %u, image %s", index, image_name)); 540 SCOPED_TRACE(base::StringPrintf("index %u, image %s", index, image_name));
538 541
539 // _dyld_get_image_header() is poorly-declared: it’s declared as returning 542 // _dyld_get_image_header() is poorly-declared: it’s declared as returning
540 // const mach_header* in both 32-bit and 64-bit environments, but in the 543 // const mach_header* in both 32-bit and 64-bit environments, but in the
541 // 64-bit environment, it should be const mach_header_64*. 544 // 64-bit environment, it should be const mach_header_64*.
542 const MachHeader* mach_header = 545 const MachHeader* mach_header =
543 reinterpret_cast<const MachHeader*>(_dyld_get_image_header(index)); 546 reinterpret_cast<const MachHeader*>(_dyld_get_image_header(index));
544 mach_vm_address_t image_address = 547 mach_vm_address_t image_address =
545 reinterpret_cast<mach_vm_address_t>(mach_header); 548 reinterpret_cast<mach_vm_address_t>(mach_header);
546 549
547 MachOImageReader image_reader; 550 MachOImageReader image_reader;
548 ASSERT_TRUE( 551 ASSERT_TRUE(
549 image_reader.Initialize(&process_reader, image_address, image_name)); 552 image_reader.Initialize(&process_reader, image_address, image_name));
550 553
551 uint32_t file_type = image_reader.FileType(); 554 uint32_t file_type = image_reader.FileType();
552 if (index == 0) { 555 if (index == 0) {
553 EXPECT_EQ(implicit_cast<uint32_t>(MH_EXECUTE), file_type); 556 EXPECT_EQ(implicit_cast<uint32_t>(MH_EXECUTE), file_type);
554 } else { 557 } else {
555 EXPECT_TRUE(file_type == MH_DYLIB || file_type == MH_BUNDLE); 558 EXPECT_TRUE(file_type == MH_DYLIB || file_type == MH_BUNDLE);
556 } 559 }
557 560
558 intptr_t image_slide = _dyld_get_image_vmaddr_slide(index); 561 intptr_t image_slide = _dyld_get_image_vmaddr_slide(index);
559 ASSERT_NO_FATAL_FAILURE(ExpectMachImage( 562 ASSERT_NO_FATAL_FAILURE(ExpectMachImage(
560 mach_header, image_address, image_slide, &image_reader, false)); 563 mach_header, image_address, image_slide, &image_reader, false));
561 564
562 ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader)); 565 ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader));
566
567 process_types::CrashpadInfo crashpad_info;
568 if (image_reader.GetCrashpadInfo(&crashpad_info)) {
569 ++modules_with_crashpad_info;
570 }
563 } 571 }
564 572
573 EXPECT_GE(modules_with_crashpad_info, 1u);
574
565 // Now that all of the modules have been verified, make sure that dyld itself 575 // Now that all of the modules have been verified, make sure that dyld itself
566 // can be read properly too. 576 // can be read properly too.
567 const struct dyld_all_image_infos* dyld_image_infos = 577 const struct dyld_all_image_infos* dyld_image_infos =
568 _dyld_get_all_image_infos(); 578 _dyld_get_all_image_infos();
569 ASSERT_GE(dyld_image_infos->version, 1u); 579 ASSERT_GE(dyld_image_infos->version, 1u);
570 EXPECT_EQ(count, dyld_image_infos->infoArrayCount); 580 EXPECT_EQ(count, dyld_image_infos->infoArrayCount);
571 581
572 if (dyld_image_infos->version >= 2) { 582 if (dyld_image_infos->version >= 2) {
573 SCOPED_TRACE("dyld"); 583 SCOPED_TRACE("dyld");
574 584
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 image_reader.UUID(&actual_uuid); 635 image_reader.UUID(&actual_uuid);
626 EXPECT_EQ(expected_uuid, actual_uuid); 636 EXPECT_EQ(expected_uuid, actual_uuid);
627 } 637 }
628 } 638 }
629 #endif 639 #endif
630 } 640 }
631 641
632 } // namespace 642 } // namespace
633 } // namespace test 643 } // namespace test
634 } // namespace crashpad 644 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/mac/mach_o_image_reader.cc ('k') | snapshot/mac/module_snapshot_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698