@@ -223,16 +223,20 @@ void ProcessMachCore::CreateMemoryRegions() {
223
223
}
224
224
}
225
225
226
- void ProcessMachCore::LoadBinariesViaMetadata () {
226
+ bool ProcessMachCore::LoadBinariesViaMetadata () {
227
227
Log *log (GetLog (LLDBLog::DynamicLoader | LLDBLog::Process));
228
228
ObjectFile *core_objfile = m_core_module_sp->GetObjectFile ();
229
- bool found_main_binary_definitively = false ;
230
229
231
230
addr_t objfile_binary_value;
232
231
bool objfile_binary_value_is_offset;
233
232
UUID objfile_binary_uuid;
234
233
ObjectFile::BinaryType type;
235
234
235
+ // This will be set to true if we had a metadata hint
236
+ // specifying a UUID or address -- and we should not fall back
237
+ // to doing an exhaustive search.
238
+ bool found_binary_spec_in_metadata = false ;
239
+
236
240
if (core_objfile->GetCorefileMainBinaryInfo (objfile_binary_value,
237
241
objfile_binary_value_is_offset,
238
242
objfile_binary_uuid, type)) {
@@ -244,14 +248,14 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
244
248
objfile_binary_uuid.GetAsString ().c_str (),
245
249
objfile_binary_value, objfile_binary_value_is_offset, type);
246
250
}
251
+ found_binary_spec_in_metadata = true ;
247
252
248
253
// If this is the xnu kernel, don't load it now. Note the correct
249
254
// DynamicLoader plugin to use, and the address of the kernel, and
250
255
// let the DynamicLoader handle the finding & loading of the binary.
251
256
if (type == ObjectFile::eBinaryTypeKernel) {
252
257
m_mach_kernel_addr = objfile_binary_value;
253
258
m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic ();
254
- found_main_binary_definitively = true ;
255
259
} else if (type == ObjectFile::eBinaryTypeUser) {
256
260
m_dyld_addr = objfile_binary_value;
257
261
m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic ();
@@ -265,7 +269,6 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
265
269
objfile_binary_value, objfile_binary_value_is_offset,
266
270
force_symbol_search, notify, set_address_in_target,
267
271
allow_memory_image_last_resort)) {
268
- found_main_binary_definitively = true ;
269
272
m_dyld_plugin_name = DynamicLoaderStatic::GetPluginNameStatic ();
270
273
}
271
274
}
@@ -276,7 +279,6 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
276
279
// load command is present, let's use the contents.
277
280
UUID ident_uuid;
278
281
addr_t ident_binary_addr = LLDB_INVALID_ADDRESS;
279
- if (!found_main_binary_definitively) {
280
282
std::string corefile_identifier = core_objfile->GetIdentifierString ();
281
283
282
284
// Search for UUID= and stext= strings in the identifier str.
@@ -287,6 +289,7 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
287
289
if (log )
288
290
log ->Printf (" Got a UUID from LC_IDENT/kern ver str LC_NOTE: %s" ,
289
291
ident_uuid.GetAsString ().c_str ());
292
+ found_binary_spec_in_metadata = true ;
290
293
}
291
294
if (corefile_identifier.find (" stext=" ) != std::string::npos) {
292
295
size_t p = corefile_identifier.find (" stext=" ) + strlen (" stext=" );
@@ -297,6 +300,7 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
297
300
log ->Printf (" Got a load address from LC_IDENT/kern ver str "
298
301
" LC_NOTE: 0x%" PRIx64,
299
302
ident_binary_addr);
303
+ found_binary_spec_in_metadata = true ;
300
304
}
301
305
}
302
306
@@ -309,7 +313,7 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
309
313
" ProcessMachCore::LoadBinariesViaMetadata: Found kernel binary via "
310
314
" LC_IDENT/kern ver str LC_NOTE" );
311
315
m_mach_kernel_addr = ident_binary_addr;
312
- found_main_binary_definitively = true ;
316
+ found_binary_spec_in_metadata = true ;
313
317
} else if (ident_uuid.IsValid ()) {
314
318
// We have no address specified, only a UUID. Load it at the file
315
319
// address.
@@ -322,16 +326,15 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
322
326
this , llvm::StringRef (), ident_uuid, ident_binary_addr,
323
327
value_is_offset, force_symbol_search, notify,
324
328
set_address_in_target, allow_memory_image_last_resort)) {
325
- found_main_binary_definitively = true ;
329
+ found_binary_spec_in_metadata = true ;
326
330
m_dyld_plugin_name = DynamicLoaderStatic::GetPluginNameStatic ();
327
331
}
328
332
}
329
- }
330
333
331
334
// Finally, load any binaries noted by "load binary" LC_NOTEs in the
332
335
// corefile
333
336
if (core_objfile->LoadCoreFileImages (*this )) {
334
- found_main_binary_definitively = true ;
337
+ found_binary_spec_in_metadata = true ;
335
338
m_dyld_plugin_name = DynamicLoaderStatic::GetPluginNameStatic ();
336
339
}
337
340
@@ -341,6 +344,8 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
341
344
// un-set it later.
342
345
if (m_dyld_up)
343
346
m_dyld_plugin_name = GetDynamicLoader ()->GetPluginName ();
347
+
348
+ return found_binary_spec_in_metadata;
344
349
}
345
350
346
351
void ProcessMachCore::LoadBinariesViaExhaustiveSearch () {
@@ -417,8 +422,8 @@ void ProcessMachCore::LoadBinariesViaExhaustiveSearch() {
417
422
void ProcessMachCore::LoadBinariesAndSetDYLD () {
418
423
Log *log (GetLog (LLDBLog::DynamicLoader | LLDBLog::Process));
419
424
420
- LoadBinariesViaMetadata ();
421
- if (m_dyld_plugin_name. empty () )
425
+ bool found_binary_spec_in_metadata = LoadBinariesViaMetadata ();
426
+ if (!found_binary_spec_in_metadata )
422
427
LoadBinariesViaExhaustiveSearch ();
423
428
424
429
if (m_dyld_plugin_name.empty ()) {
0 commit comments