| 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, |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 // dyld_image_count doesn’t include an entry for dyld itself, but |modules| | 533 // dyld_image_count doesn’t include an entry for dyld itself, but |modules| |
| 534 // does. | 534 // does. |
| 535 ASSERT_EQ(dyld_image_count + 1, modules.size()); | 535 ASSERT_EQ(dyld_image_count + 1, modules.size()); |
| 536 | 536 |
| 537 for (uint32_t index = 0; index < dyld_image_count; ++index) { | 537 for (uint32_t index = 0; index < dyld_image_count; ++index) { |
| 538 SCOPED_TRACE(base::StringPrintf( | 538 SCOPED_TRACE(base::StringPrintf( |
| 539 "index %u, name %s", index, modules[index].name.c_str())); | 539 "index %u, name %s", index, modules[index].name.c_str())); |
| 540 | 540 |
| 541 const char* dyld_image_name = _dyld_get_image_name(index); | 541 const char* dyld_image_name = _dyld_get_image_name(index); |
| 542 EXPECT_EQ(dyld_image_name, modules[index].name); | 542 EXPECT_EQ(dyld_image_name, modules[index].name); |
| 543 ASSERT_TRUE(modules[index].reader); |
| 543 EXPECT_EQ( | 544 EXPECT_EQ( |
| 544 reinterpret_cast<mach_vm_address_t>(_dyld_get_image_header(index)), | 545 reinterpret_cast<mach_vm_address_t>(_dyld_get_image_header(index)), |
| 545 modules[index].reader->Address()); | 546 modules[index].reader->Address()); |
| 546 | 547 |
| 547 if (index == 0) { | 548 if (index == 0) { |
| 548 // dyld didn’t load the main executable, so it couldn’t record its | 549 // dyld didn’t load the main executable, so it couldn’t record its |
| 549 // timestamp, and it is reported as 0. | 550 // timestamp, and it is reported as 0. |
| 550 EXPECT_EQ(0, modules[index].timestamp); | 551 EXPECT_EQ(0, modules[index].timestamp); |
| 551 } else { | 552 } else { |
| 552 // Hope that the module didn’t change on disk. | 553 // Hope that the module didn’t change on disk. |
| 553 struct stat stat_buf; | 554 struct stat stat_buf; |
| 554 int rv = stat(dyld_image_name, &stat_buf); | 555 int rv = stat(dyld_image_name, &stat_buf); |
| 555 EXPECT_EQ(0, rv) << ErrnoMessage("stat"); | 556 EXPECT_EQ(0, rv) << ErrnoMessage("stat"); |
| 556 if (rv == 0) { | 557 if (rv == 0) { |
| 557 EXPECT_EQ(stat_buf.st_mtime, modules[index].timestamp); | 558 EXPECT_EQ(stat_buf.st_mtime, modules[index].timestamp); |
| 558 } | 559 } |
| 559 } | 560 } |
| 560 } | 561 } |
| 561 | 562 |
| 562 size_t index = modules.size() - 1; | 563 size_t index = modules.size() - 1; |
| 563 EXPECT_EQ("/usr/lib/dyld", modules[index].name); | 564 EXPECT_EQ("/usr/lib/dyld", modules[index].name); |
| 564 | 565 |
| 565 // dyld didn’t load itself either, so it couldn’t record its timestamp, and it | 566 // dyld didn’t load itself either, so it couldn’t record its timestamp, and it |
| 566 // is also reported as 0. | 567 // is also reported as 0. |
| 567 EXPECT_EQ(0, modules[index].timestamp); | 568 EXPECT_EQ(0, modules[index].timestamp); |
| 568 | 569 |
| 569 const struct dyld_all_image_infos* dyld_image_infos = | 570 const struct dyld_all_image_infos* dyld_image_infos = |
| 570 _dyld_get_all_image_infos(); | 571 _dyld_get_all_image_infos(); |
| 571 if (dyld_image_infos->version >= 2) { | 572 if (dyld_image_infos->version >= 2) { |
| 573 ASSERT_TRUE(modules[index].reader); |
| 572 EXPECT_EQ( | 574 EXPECT_EQ( |
| 573 reinterpret_cast<mach_vm_address_t>( | 575 reinterpret_cast<mach_vm_address_t>( |
| 574 dyld_image_infos->dyldImageLoadAddress), | 576 dyld_image_infos->dyldImageLoadAddress), |
| 575 modules[index].reader->Address()); | 577 modules[index].reader->Address()); |
| 576 } | 578 } |
| 577 } | 579 } |
| 578 | 580 |
| 579 class ProcessReaderModulesChild final : public MachMultiprocess { | 581 class ProcessReaderModulesChild final : public MachMultiprocess { |
| 580 public: | 582 public: |
| 581 ProcessReaderModulesChild() : MachMultiprocess() {} | 583 ProcessReaderModulesChild() : MachMultiprocess() {} |
| (...skipping 27 matching lines...) Expand all Loading... |
| 609 CheckedReadFile( | 611 CheckedReadFile( |
| 610 read_handle, &expect_name_length, sizeof(expect_name_length)); | 612 read_handle, &expect_name_length, sizeof(expect_name_length)); |
| 611 | 613 |
| 612 // The NUL terminator is not read. | 614 // The NUL terminator is not read. |
| 613 std::string expect_name(expect_name_length, '\0'); | 615 std::string expect_name(expect_name_length, '\0'); |
| 614 CheckedReadFile(read_handle, &expect_name[0], expect_name_length); | 616 CheckedReadFile(read_handle, &expect_name[0], expect_name_length); |
| 615 EXPECT_EQ(expect_name, modules[index].name); | 617 EXPECT_EQ(expect_name, modules[index].name); |
| 616 | 618 |
| 617 mach_vm_address_t expect_address; | 619 mach_vm_address_t expect_address; |
| 618 CheckedReadFile(read_handle, &expect_address, sizeof(expect_address)); | 620 CheckedReadFile(read_handle, &expect_address, sizeof(expect_address)); |
| 621 ASSERT_TRUE(modules[index].reader); |
| 619 EXPECT_EQ(expect_address, modules[index].reader->Address()); | 622 EXPECT_EQ(expect_address, modules[index].reader->Address()); |
| 620 | 623 |
| 621 if (index == 0 || index == modules.size() - 1) { | 624 if (index == 0 || index == modules.size() - 1) { |
| 622 // dyld didn’t load the main executable or itself, so it couldn’t record | 625 // dyld didn’t load the main executable or itself, so it couldn’t record |
| 623 // these timestamps, and they are reported as 0. | 626 // these timestamps, and they are reported as 0. |
| 624 EXPECT_EQ(0, modules[index].timestamp); | 627 EXPECT_EQ(0, modules[index].timestamp); |
| 625 } else { | 628 } else { |
| 626 // Hope that the module didn’t change on disk. | 629 // Hope that the module didn’t change on disk. |
| 627 struct stat stat_buf; | 630 struct stat stat_buf; |
| 628 int rv = stat(expect_name.c_str(), &stat_buf); | 631 int rv = stat(expect_name.c_str(), &stat_buf); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 }; | 689 }; |
| 687 | 690 |
| 688 TEST(ProcessReader, ChildModules) { | 691 TEST(ProcessReader, ChildModules) { |
| 689 ProcessReaderModulesChild process_reader_modules_child; | 692 ProcessReaderModulesChild process_reader_modules_child; |
| 690 process_reader_modules_child.Run(); | 693 process_reader_modules_child.Run(); |
| 691 } | 694 } |
| 692 | 695 |
| 693 } // namespace | 696 } // namespace |
| 694 } // namespace test | 697 } // namespace test |
| 695 } // namespace crashpad | 698 } // namespace crashpad |
| OLD | NEW |