@@ -7012,44 +7012,81 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
7012
7012
bool ObjectFileMachO::LoadCoreFileImages (lldb_private::Process &process) {
7013
7013
MachOCorefileAllImageInfos image_infos = GetCorefileAllImageInfos ();
7014
7014
Log *log = GetLog (LLDBLog::DynamicLoader);
7015
+ Status error;
7015
7016
7017
+ bool found_platform_binary = false ;
7016
7018
ModuleList added_modules;
7017
- for (const MachOCorefileImageEntry &image : image_infos.all_image_infos ) {
7018
- ModuleSP module_sp;
7019
+ for (MachOCorefileImageEntry &image : image_infos.all_image_infos ) {
7020
+ ModuleSP module_sp, local_filesystem_module_sp;
7021
+
7022
+ // If this is a platform binary, it has been loaded (or registered with
7023
+ // the DynamicLoader to be loaded), we don't need to do any further
7024
+ // processing. We're not going to call ModulesDidLoad on this in this
7025
+ // method, so notify==true.
7026
+ if (process.GetTarget ()
7027
+ .GetDebugger ()
7028
+ .GetPlatformList ()
7029
+ .LoadPlatformBinaryAndSetup (&process, image.load_address ,
7030
+ true /* notify */ )) {
7031
+ LLDB_LOGF (log,
7032
+ " ObjectFileMachO::%s binary at 0x%" PRIx64
7033
+ " is a platform binary, has been handled by a Platform plugin." ,
7034
+ __FUNCTION__, image.load_address );
7035
+ continue ;
7036
+ }
7019
7037
7020
- if (!image.filename .empty ()) {
7021
- Status error;
7038
+ // If this binary is currently executing, we want to force a
7039
+ // possibly expensive search for the binary and its dSYM.
7040
+ if (image.currently_executing && image.uuid .IsValid ()) {
7022
7041
ModuleSpec module_spec;
7023
7042
module_spec.GetUUID () = image.uuid ;
7024
- module_spec.GetFileSpec () = FileSpec (image.filename .c_str ());
7025
- if (image.currently_executing ) {
7026
- Symbols::DownloadObjectAndSymbolFile (module_spec, error, true );
7027
- if (FileSystem::Instance ().Exists (module_spec.GetFileSpec ())) {
7028
- process.GetTarget ().GetOrCreateModule (module_spec, false );
7029
- }
7043
+ Symbols::DownloadObjectAndSymbolFile (module_spec, error, true );
7044
+ if (FileSystem::Instance ().Exists (module_spec.GetFileSpec ())) {
7045
+ module_sp = process.GetTarget ().GetOrCreateModule (module_spec, false );
7046
+ process.GetTarget ().GetImages ().AppendIfNeeded (module_sp,
7047
+ false /* notify */ );
7030
7048
}
7049
+ }
7050
+
7051
+ // We have an address, that's the best way to discover the binary.
7052
+ if (!module_sp && image.load_address != LLDB_INVALID_ADDRESS) {
7053
+ module_sp = DynamicLoader::LoadBinaryWithUUIDAndAddress (
7054
+ &process, image.filename , image.uuid , image.load_address ,
7055
+ false /* value_is_offset */ , image.currently_executing ,
7056
+ false /* notify */ );
7057
+ }
7058
+
7059
+ // If we have a slide, we need to find the original binary
7060
+ // by UUID, then we can apply the slide value.
7061
+ if (!module_sp && image.uuid .IsValid () &&
7062
+ image.slide != LLDB_INVALID_ADDRESS) {
7063
+ module_sp = DynamicLoader::LoadBinaryWithUUIDAndAddress (
7064
+ &process, image.filename , image.uuid , image.slide ,
7065
+ true /* value_is_offset */ , image.currently_executing ,
7066
+ false /* notify */ );
7067
+ }
7068
+
7069
+ // Try to find the binary by UUID or filename on the local
7070
+ // filesystem or in lldb's global module cache.
7071
+ if (!module_sp) {
7072
+ Status error;
7073
+ ModuleSpec module_spec;
7074
+ if (image.uuid .IsValid ())
7075
+ module_spec.GetUUID () = image.uuid ;
7076
+ if (!image.filename .empty ())
7077
+ module_spec.GetFileSpec () = FileSpec (image.filename .c_str ());
7031
7078
module_sp =
7032
7079
process.GetTarget ().GetOrCreateModule (module_spec, false , &error);
7033
7080
process.GetTarget ().GetImages ().AppendIfNeeded (module_sp,
7034
7081
false /* notify */ );
7035
- } else {
7036
- if (image.load_address != LLDB_INVALID_ADDRESS) {
7037
- module_sp = DynamicLoader::LoadBinaryWithUUIDAndAddress (
7038
- &process, image.uuid , image.load_address ,
7039
- false /* value_is_offset */ , image.currently_executing ,
7040
- false /* notify */ );
7041
- } else if (image.slide != LLDB_INVALID_ADDRESS) {
7042
- module_sp = DynamicLoader::LoadBinaryWithUUIDAndAddress (
7043
- &process, image.uuid , image.slide , true /* value_is_offset */ ,
7044
- image.currently_executing , false /* notify */ );
7045
- }
7046
7082
}
7047
7083
7048
- if (module_sp.get ()) {
7049
- // Will call ModulesDidLoad with all modules once they've all
7050
- // been added to the Target with load addresses. Don't notify
7051
- // here, before the load address is set.
7084
+ // We have a ModuleSP to load in the Target. Load it at the
7085
+ // correct address/slide and notify/load scripting resources.
7086
+ if (module_sp) {
7052
7087
added_modules.Append (module_sp, false /* notify */ );
7088
+
7089
+ // We have a list of segment load address
7053
7090
if (image.segment_load_addresses .size () > 0 ) {
7054
7091
if (log) {
7055
7092
std::string uuidstr = image.uuid .GetAsString ();
@@ -7110,5 +7147,11 @@ bool ObjectFileMachO::LoadCoreFileImages(lldb_private::Process &process) {
7110
7147
process.Flush ();
7111
7148
return true ;
7112
7149
}
7150
+ // Return true if the only binary we found was the platform binary,
7151
+ // and it was loaded outside the scope of this method.
7152
+ if (found_platform_binary)
7153
+ return true ;
7154
+
7155
+ // No binaries.
7113
7156
return false ;
7114
7157
}
0 commit comments