2525#include " lldb/Utility/ScriptedMetadata.h"
2626#include " lldb/Utility/State.h"
2727
28+ #include " Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.h"
29+
2830#include < mutex>
2931
3032LLDB_PLUGIN_DEFINE (ScriptedProcess)
@@ -422,11 +424,9 @@ bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) {
422424lldb_private::StructuredData::ObjectSP
423425ScriptedProcess::GetLoadedDynamicLibrariesInfos () {
424426 Status error;
425- auto handle_error_with_message = [&error](llvm::StringRef message,
426- bool ignore_error) {
427- ScriptedInterface::ErrorWithMessage<bool >(LLVM_PRETTY_FUNCTION,
428- message.data (), error);
429- return ignore_error;
427+ auto error_with_message = [&error](llvm::StringRef message) {
428+ return ScriptedInterface::ErrorWithMessage<bool >(LLVM_PRETTY_FUNCTION,
429+ message.data (), error);
430430 };
431431
432432 StructuredData::ArraySP loaded_images_sp = GetInterface ().GetLoadedImages ();
@@ -438,79 +438,94 @@ ScriptedProcess::GetLoadedDynamicLibrariesInfos() {
438438 ModuleList module_list;
439439 Target &target = GetTarget ();
440440
441- auto reload_image = [&target, &module_list, &handle_error_with_message ](
441+ auto reload_image = [&target, &module_list, &error_with_message ](
442442 StructuredData::Object *obj) -> bool {
443443 StructuredData::Dictionary *dict = obj->GetAsDictionary ();
444444
445445 if (!dict)
446- return handle_error_with_message (
447- " Couldn't cast image object into dictionary." , false );
446+ return error_with_message (" Couldn't cast image object into dictionary." );
448447
449448 ModuleSpec module_spec;
450449 llvm::StringRef value;
451450
452451 bool has_path = dict->HasKey (" path" );
453452 bool has_uuid = dict->HasKey (" uuid" );
454453 if (!has_path && !has_uuid)
455- return handle_error_with_message (
456- " Dictionary should have key 'path' or 'uuid'" , false );
454+ return error_with_message (" Dictionary should have key 'path' or 'uuid'" );
457455 if (!dict->HasKey (" load_addr" ))
458- return handle_error_with_message (" Dictionary is missing key 'load_addr'" ,
459- false );
456+ return error_with_message (" Dictionary is missing key 'load_addr'" );
460457
458+ llvm::StringRef path = " " ;
461459 if (has_path) {
462- dict->GetValueForKeyAsString (" path" , value );
463- module_spec.GetFileSpec ().SetPath (value );
460+ dict->GetValueForKeyAsString (" path" , path );
461+ module_spec.GetFileSpec ().SetPath (path );
464462 }
465463
466464 if (has_uuid) {
467465 dict->GetValueForKeyAsString (" uuid" , value);
468466 module_spec.GetUUID ().SetFromStringRef (value);
469467 }
470- module_spec.GetArchitecture () = target.GetArchitecture ();
471-
472- ModuleSP module_sp =
473- target.GetOrCreateModule (module_spec, true /* notify */ );
474-
475- bool ignore_module_load_error = false ;
476- dict->GetValueForKeyAsBoolean (" ignore_module_load_error" ,
477- ignore_module_load_error);
478- if (!module_sp)
479- return handle_error_with_message (" Couldn't create or get module." ,
480- ignore_module_load_error);
481468
482469 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
483470 lldb::offset_t slide = LLDB_INVALID_OFFSET;
484471 dict->GetValueForKeyAsInteger (" load_addr" , load_addr);
485472 dict->GetValueForKeyAsInteger (" slide" , slide);
486473 if (load_addr == LLDB_INVALID_ADDRESS)
487- return handle_error_with_message (
488- " Couldn't get valid load address or slide offset." ,
489- ignore_module_load_error);
474+ return error_with_message (
475+ " Couldn't get valid load address or slide offset." );
490476
491477 if (slide != LLDB_INVALID_OFFSET)
492478 load_addr += slide;
493479
480+ module_spec.GetArchitecture () = target.GetArchitecture ();
481+
482+ ModuleSP module_sp =
483+ target.GetOrCreateModule (module_spec, true /* notify */ );
484+
485+ bool is_placeholder_module = false ;
486+
487+ if (!module_sp) {
488+ // Create a placeholder module
489+ LLDB_LOGF (
490+ GetLog (LLDBLog::Process),
491+ " ScriptedProcess::%s unable to locate the matching "
492+ " object file path %s, creating a placeholder module at 0x%" PRIx64,
493+ __FUNCTION__, path.str ().c_str (), load_addr);
494+
495+ module_sp = Module::CreateModuleFromObjectFile<ObjectFilePlaceholder>(
496+ module_spec, load_addr, module_spec.GetFileSpec ().MemorySize ());
497+
498+ is_placeholder_module = true ;
499+ }
500+
494501 bool changed = false ;
495502 module_sp->SetLoadAddress (target, load_addr, false /* =value_is_offset*/ ,
496503 changed);
497504
498505 if (!changed && !module_sp->GetObjectFile ())
499- return handle_error_with_message (
500- " Couldn't set the load address for module." ,
501- ignore_module_load_error);
506+ return error_with_message (" Couldn't set the load address for module." );
502507
503- dict->GetValueForKeyAsString (" path" , value);
504- FileSpec objfile (value);
508+ FileSpec objfile (path);
505509 module_sp->SetFileSpecAndObjectName (objfile, objfile.GetFilename ());
506510
507- return ignore_module_load_error ? true
508- : module_list.AppendIfNeeded (module_sp);
511+ if (is_placeholder_module) {
512+ target.GetImages ().AppendIfNeeded (module_sp, true /* notify=*/ );
513+ return true ;
514+ }
515+
516+ return module_list.AppendIfNeeded (module_sp);
509517 };
510518
511- if (!loaded_images_sp->ForEach (reload_image))
512- return ScriptedInterface::ErrorWithMessage<StructuredData::ObjectSP>(
513- LLVM_PRETTY_FUNCTION, " Couldn't reload all images." , error);
519+ size_t loaded_images_size = loaded_images_sp->GetSize ();
520+ bool print_error = true ;
521+ for (size_t idx = 0 ; idx < loaded_images_size; idx++) {
522+ const auto &loaded_image = loaded_images_sp->GetItemAtIndex (idx);
523+ if (!reload_image (loaded_image.get ()) && print_error) {
524+ print_error = false ;
525+ ScriptedInterface::ErrorWithMessage<StructuredData::ObjectSP>(
526+ LLVM_PRETTY_FUNCTION, " Couldn't reload all images." , error);
527+ }
528+ }
514529
515530 target.ModulesDidLoad (module_list);
516531
0 commit comments