@@ -6973,6 +6973,23 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
6973
6973
}
6974
6974
image_infos.all_image_infos .push_back (image_entry);
6975
6975
}
6976
+ } else if (strcmp (" load binary" , data_owner) == 0 ) {
6977
+ uint32_t version = m_data.GetU32 (&fileoff);
6978
+ if (version == 1 ) {
6979
+ uuid_t uuid;
6980
+ memcpy (&uuid, m_data.GetData (&fileoff, sizeof (uuid_t )),
6981
+ sizeof (uuid_t ));
6982
+ uint64_t load_address = m_data.GetU64 (&fileoff);
6983
+ uint64_t slide = m_data.GetU64 (&fileoff);
6984
+ std::string filename = m_data.GetCStr (&fileoff);
6985
+
6986
+ MachOCorefileImageEntry image_entry;
6987
+ image_entry.filename = filename;
6988
+ image_entry.uuid = UUID::fromData (uuid, sizeof (uuid_t ));
6989
+ image_entry.load_address = load_address;
6990
+ image_entry.slide = slide;
6991
+ image_infos.all_image_infos .push_back (image_entry);
6992
+ }
6976
6993
}
6977
6994
}
6978
6995
offset = cmd_offset + lc.cmdsize ;
@@ -6983,29 +7000,42 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
6983
7000
6984
7001
bool ObjectFileMachO::LoadCoreFileImages (lldb_private::Process &process) {
6985
7002
MachOCorefileAllImageInfos image_infos = GetCorefileAllImageInfos ();
6986
- bool added_images = false ;
6987
- if (image_infos. IsValid ()) {
6988
- for ( const MachOCorefileImageEntry &image : image_infos. all_image_infos ) {
6989
- ModuleSpec module_spec;
6990
- module_spec. GetUUID () = image. uuid ;
6991
- module_spec.GetFileSpec () = FileSpec ( image.filename . c_str ()) ;
6992
- if (image.currently_executing ) {
6993
- Symbols::DownloadObjectAndSymbolFile (module_spec, true );
6994
- if ( FileSystem::Instance (). Exists ( module_spec. GetFileSpec ())) {
6995
- process. GetTarget (). GetOrCreateModule (module_spec, false );
6996
- }
7003
+ Log * log ( lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER)) ;
7004
+
7005
+ ModuleList added_modules;
7006
+ for ( const MachOCorefileImageEntry &image : image_infos. all_image_infos ) {
7007
+ ModuleSpec module_spec;
7008
+ module_spec.GetUUID () = image.uuid ;
7009
+ module_spec. GetFileSpec () = FileSpec (image.filename . c_str ());
7010
+ if (image. currently_executing ) {
7011
+ Symbols::DownloadObjectAndSymbolFile ( module_spec, true );
7012
+ if ( FileSystem::Instance (). Exists (module_spec. GetFileSpec ())) {
7013
+ process. GetTarget (). GetOrCreateModule (module_spec, false );
6997
7014
}
6998
- Status error;
6999
- ModuleSP module_sp =
7000
- process. GetTarget (). GetOrCreateModule (module_spec, false , &error);
7001
- if (!module_sp. get () || !module_sp-> GetObjectFile ()) {
7002
- if (image. load_address != LLDB_INVALID_ADDRESS ) {
7003
- module_sp = process. ReadModuleFromMemory (module_spec. GetFileSpec (),
7004
- image. load_address );
7005
- }
7015
+ }
7016
+ Status error;
7017
+ ModuleSP module_sp =
7018
+ process. GetTarget (). GetOrCreateModule (module_spec, false , &error);
7019
+ if (!module_sp. get () || !module_sp-> GetObjectFile () ) {
7020
+ if (image. load_address != LLDB_INVALID_ADDRESS) {
7021
+ module_sp = process. ReadModuleFromMemory (module_spec. GetFileSpec (),
7022
+ image. load_address );
7006
7023
}
7007
- if (module_sp.get ()) {
7008
- added_images = true ;
7024
+ }
7025
+ if (module_sp.get ()) {
7026
+ // Will call ModulesDidLoad with all modules once they've all
7027
+ // been added to the Target with load addresses. Don't notify
7028
+ // here, before the load address is set.
7029
+ const bool notify = false ;
7030
+ process.GetTarget ().GetImages ().AppendIfNeeded (module_sp, notify);
7031
+ added_modules.Append (module_sp, notify);
7032
+ if (image.segment_load_addresses .size () > 0 ) {
7033
+ if (log) {
7034
+ std::string uuidstr = image.uuid .GetAsString ();
7035
+ log->Printf (" ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
7036
+ " UUID %s with section load addresses" ,
7037
+ image.filename .c_str (), uuidstr.c_str ());
7038
+ }
7009
7039
for (auto name_vmaddr_tuple : image.segment_load_addresses ) {
7010
7040
SectionList *sectlist = module_sp->GetObjectFile ()->GetSectionList ();
7011
7041
if (sectlist) {
@@ -7017,8 +7047,47 @@ bool ObjectFileMachO::LoadCoreFileImages(lldb_private::Process &process) {
7017
7047
}
7018
7048
}
7019
7049
}
7050
+ } else if (image.load_address != LLDB_INVALID_ADDRESS) {
7051
+ if (log) {
7052
+ std::string uuidstr = image.uuid .GetAsString ();
7053
+ log->Printf (" ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
7054
+ " UUID %s with load address 0x%" PRIx64,
7055
+ image.filename .c_str (), uuidstr.c_str (),
7056
+ image.load_address );
7057
+ }
7058
+ const bool address_is_slide = false ;
7059
+ bool changed = false ;
7060
+ module_sp->SetLoadAddress (process.GetTarget (), image.load_address ,
7061
+ address_is_slide, changed);
7062
+ } else if (image.slide != 0 ) {
7063
+ if (log) {
7064
+ std::string uuidstr = image.uuid .GetAsString ();
7065
+ log->Printf (" ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
7066
+ " UUID %s with slide amount 0x%" PRIx64,
7067
+ image.filename .c_str (), uuidstr.c_str (), image.slide );
7068
+ }
7069
+ const bool address_is_slide = true ;
7070
+ bool changed = false ;
7071
+ module_sp->SetLoadAddress (process.GetTarget (), image.slide ,
7072
+ address_is_slide, changed);
7073
+ } else {
7074
+ if (log) {
7075
+ std::string uuidstr = image.uuid .GetAsString ();
7076
+ log->Printf (" ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
7077
+ " UUID %s at its file address, no slide applied" ,
7078
+ image.filename .c_str (), uuidstr.c_str ());
7079
+ }
7080
+ const bool address_is_slide = true ;
7081
+ bool changed = false ;
7082
+ module_sp->SetLoadAddress (process.GetTarget (), 0 , address_is_slide,
7083
+ changed);
7020
7084
}
7021
7085
}
7022
7086
}
7023
- return added_images;
7087
+ if (added_modules.GetSize () > 0 ) {
7088
+ process.GetTarget ().ModulesDidLoad (added_modules);
7089
+ process.Flush ();
7090
+ return true ;
7091
+ }
7092
+ return false ;
7024
7093
}
0 commit comments