@@ -7052,6 +7052,23 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
7052
7052
}
7053
7053
image_infos.all_image_infos .push_back (image_entry);
7054
7054
}
7055
+ } else if (strcmp (" load binary" , data_owner) == 0 ) {
7056
+ uint32_t version = m_data.GetU32 (&fileoff);
7057
+ if (version == 1 ) {
7058
+ uuid_t uuid;
7059
+ memcpy (&uuid, m_data.GetData (&fileoff, sizeof (uuid_t )),
7060
+ sizeof (uuid_t ));
7061
+ uint64_t load_address = m_data.GetU64 (&fileoff);
7062
+ uint64_t slide = m_data.GetU64 (&fileoff);
7063
+ std::string filename = m_data.GetCStr (&fileoff);
7064
+
7065
+ MachOCorefileImageEntry image_entry;
7066
+ image_entry.filename = filename;
7067
+ image_entry.uuid = UUID::fromData (uuid, sizeof (uuid_t ));
7068
+ image_entry.load_address = load_address;
7069
+ image_entry.slide = slide;
7070
+ image_infos.all_image_infos .push_back (image_entry);
7071
+ }
7055
7072
}
7056
7073
}
7057
7074
offset = cmd_offset + lc.cmdsize ;
@@ -7062,29 +7079,42 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
7062
7079
7063
7080
bool ObjectFileMachO::LoadCoreFileImages (lldb_private::Process &process) {
7064
7081
MachOCorefileAllImageInfos image_infos = GetCorefileAllImageInfos ();
7065
- bool added_images = false ;
7066
- if (image_infos. IsValid ()) {
7067
- for ( const MachOCorefileImageEntry &image : image_infos. all_image_infos ) {
7068
- ModuleSpec module_spec;
7069
- module_spec. GetUUID () = image. uuid ;
7070
- module_spec.GetFileSpec () = FileSpec ( image.filename . c_str ()) ;
7071
- if (image.currently_executing ) {
7072
- Symbols::DownloadObjectAndSymbolFile (module_spec, true );
7073
- if ( FileSystem::Instance (). Exists ( module_spec. GetFileSpec ())) {
7074
- process. GetTarget (). GetOrCreateModule (module_spec, false );
7075
- }
7082
+ Log * log ( lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER)) ;
7083
+
7084
+ ModuleList added_modules;
7085
+ for ( const MachOCorefileImageEntry &image : image_infos. all_image_infos ) {
7086
+ ModuleSpec module_spec;
7087
+ module_spec.GetUUID () = image.uuid ;
7088
+ module_spec. GetFileSpec () = FileSpec (image.filename . c_str ());
7089
+ if (image. currently_executing ) {
7090
+ Symbols::DownloadObjectAndSymbolFile ( module_spec, true );
7091
+ if ( FileSystem::Instance (). Exists (module_spec. GetFileSpec ())) {
7092
+ process. GetTarget (). GetOrCreateModule (module_spec, false );
7076
7093
}
7077
- Status error;
7078
- ModuleSP module_sp =
7079
- process. GetTarget (). GetOrCreateModule (module_spec, false , &error);
7080
- if (!module_sp. get () || !module_sp-> GetObjectFile ()) {
7081
- if (image. load_address != LLDB_INVALID_ADDRESS ) {
7082
- module_sp = process. ReadModuleFromMemory (module_spec. GetFileSpec (),
7083
- image. load_address );
7084
- }
7094
+ }
7095
+ Status error;
7096
+ ModuleSP module_sp =
7097
+ process. GetTarget (). GetOrCreateModule (module_spec, false , &error);
7098
+ if (!module_sp. get () || !module_sp-> GetObjectFile () ) {
7099
+ if (image. load_address != LLDB_INVALID_ADDRESS) {
7100
+ module_sp = process. ReadModuleFromMemory (module_spec. GetFileSpec (),
7101
+ image. load_address );
7085
7102
}
7086
- if (module_sp.get ()) {
7087
- added_images = true ;
7103
+ }
7104
+ if (module_sp.get ()) {
7105
+ // Will call ModulesDidLoad with all modules once they've all
7106
+ // been added to the Target with load addresses. Don't notify
7107
+ // here, before the load address is set.
7108
+ const bool notify = false ;
7109
+ process.GetTarget ().GetImages ().AppendIfNeeded (module_sp, notify);
7110
+ added_modules.Append (module_sp, notify);
7111
+ if (image.segment_load_addresses .size () > 0 ) {
7112
+ if (log) {
7113
+ std::string uuidstr = image.uuid .GetAsString ();
7114
+ log->Printf (" ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
7115
+ " UUID %s with section load addresses" ,
7116
+ image.filename .c_str (), uuidstr.c_str ());
7117
+ }
7088
7118
for (auto name_vmaddr_tuple : image.segment_load_addresses ) {
7089
7119
SectionList *sectlist = module_sp->GetObjectFile ()->GetSectionList ();
7090
7120
if (sectlist) {
@@ -7096,8 +7126,47 @@ bool ObjectFileMachO::LoadCoreFileImages(lldb_private::Process &process) {
7096
7126
}
7097
7127
}
7098
7128
}
7129
+ } else if (image.load_address != LLDB_INVALID_ADDRESS) {
7130
+ if (log) {
7131
+ std::string uuidstr = image.uuid .GetAsString ();
7132
+ log->Printf (" ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
7133
+ " UUID %s with load address 0x%" PRIx64,
7134
+ image.filename .c_str (), uuidstr.c_str (),
7135
+ image.load_address );
7136
+ }
7137
+ const bool address_is_slide = false ;
7138
+ bool changed = false ;
7139
+ module_sp->SetLoadAddress (process.GetTarget (), image.load_address ,
7140
+ address_is_slide, changed);
7141
+ } else if (image.slide != 0 ) {
7142
+ if (log) {
7143
+ std::string uuidstr = image.uuid .GetAsString ();
7144
+ log->Printf (" ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
7145
+ " UUID %s with slide amount 0x%" PRIx64,
7146
+ image.filename .c_str (), uuidstr.c_str (), image.slide );
7147
+ }
7148
+ const bool address_is_slide = true ;
7149
+ bool changed = false ;
7150
+ module_sp->SetLoadAddress (process.GetTarget (), image.slide ,
7151
+ address_is_slide, changed);
7152
+ } else {
7153
+ if (log) {
7154
+ std::string uuidstr = image.uuid .GetAsString ();
7155
+ log->Printf (" ObjectFileMachO::LoadCoreFileImages adding binary '%s' "
7156
+ " UUID %s at its file address, no slide applied" ,
7157
+ image.filename .c_str (), uuidstr.c_str ());
7158
+ }
7159
+ const bool address_is_slide = true ;
7160
+ bool changed = false ;
7161
+ module_sp->SetLoadAddress (process.GetTarget (), 0 , address_is_slide,
7162
+ changed);
7099
7163
}
7100
7164
}
7101
7165
}
7102
- return added_images;
7166
+ if (added_modules.GetSize () > 0 ) {
7167
+ process.GetTarget ().ModulesDidLoad (added_modules);
7168
+ process.Flush ();
7169
+ return true ;
7170
+ }
7171
+ return false ;
7103
7172
}
0 commit comments