@@ -75,7 +75,7 @@ TryGetSymbol(ICorDebugDataTarget* dataTarget, uint64_t baseAddress, const char*
7575// MachO module
7676// --------------------------------------------------------------------
7777
78- MachOModule::MachOModule (MachOReader& reader, mach_vm_address_t baseAddress, mach_header_64* header, std::string* name) :
78+ MachOModule::MachOModule (MachOReader& reader, mach_vm_address_t baseAddress, std::string* name) :
7979 m_reader(reader),
8080 m_baseAddress(baseAddress),
8181 m_loadBias(0 ),
@@ -84,9 +84,6 @@ MachOModule::MachOModule(MachOReader& reader, mach_vm_address_t baseAddress, mac
8484 m_nlists(nullptr ),
8585 m_strtabAddress(0 )
8686{
87- if (header != nullptr ) {
88- m_header = *header;
89- }
9087 if (name != nullptr ) {
9188 m_name = *name;
9289 }
@@ -363,43 +360,25 @@ MachOReader::MachOReader()
363360}
364361
365362bool
366- MachOReader::EnumerateModules (mach_vm_address_t address, mach_header_64* header )
363+ MachOReader::EnumerateModules (mach_vm_address_t dyldInfoAddress )
367364{
368- _ASSERTE (header->magic == MH_MAGIC_64);
369- _ASSERTE (header->filetype == MH_DYLINKER);
370-
371- MachOModule dylinker (*this , address, header);
372-
373- // Search for symbol for the dyld image info cache
374- uint64_t dyldInfoAddress = 0 ;
375- if (!dylinker.TryLookupSymbol (" dyld_all_image_infos" , &dyldInfoAddress))
376- {
377- Trace (" ERROR: Can not find the _dyld_all_image_infos symbol\n " );
378- return false ;
379- }
380-
381365 // Read the all image info from the dylinker image
382366 dyld_all_image_infos dyldInfo;
383-
384367 if (!ReadMemory ((void *)dyldInfoAddress, &dyldInfo, sizeof (dyld_all_image_infos)))
385368 {
386369 Trace (" ERROR: Failed to read dyld_all_image_infos at %p\n " , (void *)dyldInfoAddress);
387370 return false ;
388371 }
389- std::string dylinkerPath;
390- if (!ReadString (dyldInfo.dyldPath , dylinkerPath))
372+ Trace (" MOD: infoArray %p infoArrayCount %d\n " , dyldInfo.infoArray , dyldInfo.infoArrayCount );
373+
374+ // Create the dyld module info
375+ if (!TryRegisterModule (dyldInfo.dyldImageLoadAddress , dyldInfo.dyldPath , true ))
391376 {
392- Trace (" ERROR: Failed to read name at %p\n " , dyldInfo.dyldPath );
377+ Trace (" ERROR: Failed to read dyld header at %p\n " , dyldInfo.dyldImageLoadAddress );
393378 return false ;
394379 }
395- dylinker.SetName (dylinkerPath);
396- Trace (" MOD: %016llx %08x %s\n " , dylinker.BaseAddress (), dylinker.Header ().flags , dylinker.Name ().c_str ());
397- VisitModule (dylinker);
398-
399380 void * imageInfosAddress = (void *)dyldInfo.infoArray ;
400381 size_t imageInfosSize = dyldInfo.infoArrayCount * sizeof (dyld_image_info);
401- Trace (" MOD: infoArray %p infoArrayCount %d\n " , dyldInfo.infoArray , dyldInfo.infoArrayCount );
402-
403382 ArrayHolder<dyld_image_info> imageInfos = new (std::nothrow) dyld_image_info[dyldInfo.infoArrayCount ];
404383 if (imageInfos == nullptr )
405384 {
@@ -413,22 +392,38 @@ MachOReader::EnumerateModules(mach_vm_address_t address, mach_header_64* header)
413392 }
414393 for (int i = 0 ; i < dyldInfo.infoArrayCount ; i++)
415394 {
416- mach_vm_address_t imageAddress = (mach_vm_address_t )imageInfos[i].imageLoadAddress ;
417- const char * imageFilePathAddress = imageInfos[i].imageFilePath ;
395+ // Ignore any errors and continue to next module
396+ TryRegisterModule (imageInfos[i].imageLoadAddress , imageInfos[i].imageFilePath , false );
397+ }
398+ return true ;
399+ }
418400
419- std::string imagePath;
420- if (!ReadString (imageFilePathAddress, imagePath))
421- {
422- Trace (" ERROR: Failed to read image name at %p\n " , imageFilePathAddress);
423- continue ;
424- }
425- MachOModule module (*this , imageAddress, nullptr , &imagePath);
426- if (!module .ReadHeader ())
401+ bool
402+ MachOReader::TryRegisterModule (const struct mach_header * imageAddress, const char * imageFilePathAddress, bool dylinker)
403+ {
404+ std::string imagePath;
405+ if (!ReadString (imageFilePathAddress, imagePath))
406+ {
407+ return false ;
408+ }
409+ MachOModule module (*this , (mach_vm_address_t )imageAddress, &imagePath);
410+ if (!module .ReadHeader ())
411+ {
412+ return false ;
413+ }
414+ Trace (" MOD: %016llx %08x %s\n " , imageAddress, module .Header ().flags , imagePath.c_str ());
415+ VisitModule (module );
416+ if (dylinker)
417+ {
418+ // Make sure the memory for the symbol and string tables are in the core dump for our
419+ // dump readers which still use this symbol to enumerate modules.
420+ uint64_t dyldInfoAddress = 0 ;
421+ if (!module .TryLookupSymbol (" dyld_all_image_infos" , &dyldInfoAddress))
427422 {
428- continue ;
423+ Trace (" ERROR: Can not find the _dyld_all_image_infos symbol\n " );
424+ return false ;
429425 }
430- Trace (" MOD: %016llx %08x %s\n " , imageAddress, module .Header ().flags , imagePath.c_str ());
431- VisitModule (module );
426+ Trace (" MOD: dyldInfoAddress %016llx\n " , dyldInfoAddress);
432427 }
433428 return true ;
434429}
0 commit comments