-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Allow option to ignore module load errors in ScriptedProcess #127153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rchamala
merged 5 commits into
llvm:main
from
rchamala:user/rachamal/llvmscriptedprocess
Feb 23, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
#include "lldb/Utility/ScriptedMetadata.h" | ||
#include "lldb/Utility/State.h" | ||
|
||
#include "Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.h" | ||
|
||
#include <mutex> | ||
|
||
LLDB_PLUGIN_DEFINE(ScriptedProcess) | ||
|
@@ -165,7 +167,7 @@ Status ScriptedProcess::DoLoadCore() { | |
Status ScriptedProcess::DoLaunch(Module *exe_module, | ||
ProcessLaunchInfo &launch_info) { | ||
LLDB_LOGF(GetLog(LLDBLog::Process), "ScriptedProcess::%s launching process", __FUNCTION__); | ||
|
||
/* MARK: This doesn't reflect how lldb actually launches a process. | ||
In reality, it attaches to debugserver, then resume the process. | ||
That's not true in all cases. If debugserver is remote, lldb | ||
|
@@ -444,7 +446,6 @@ ScriptedProcess::GetLoadedDynamicLibrariesInfos() { | |
return error_with_message("Couldn't cast image object into dictionary."); | ||
|
||
ModuleSpec module_spec; | ||
llvm::StringRef value; | ||
|
||
bool has_path = dict->HasKey("path"); | ||
bool has_uuid = dict->HasKey("uuid"); | ||
|
@@ -453,22 +454,17 @@ ScriptedProcess::GetLoadedDynamicLibrariesInfos() { | |
if (!dict->HasKey("load_addr")) | ||
return error_with_message("Dictionary is missing key 'load_addr'"); | ||
|
||
llvm::StringRef path = ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're using a new |
||
if (has_path) { | ||
dict->GetValueForKeyAsString("path", value); | ||
module_spec.GetFileSpec().SetPath(value); | ||
dict->GetValueForKeyAsString("path", path); | ||
module_spec.GetFileSpec().SetPath(path); | ||
} | ||
|
||
llvm::StringRef uuid = ""; | ||
if (has_uuid) { | ||
dict->GetValueForKeyAsString("uuid", value); | ||
module_spec.GetUUID().SetFromStringRef(value); | ||
dict->GetValueForKeyAsString("uuid", uuid); | ||
module_spec.GetUUID().SetFromStringRef(uuid); | ||
} | ||
module_spec.GetArchitecture() = target.GetArchitecture(); | ||
|
||
ModuleSP module_sp = | ||
target.GetOrCreateModule(module_spec, true /* notify */); | ||
|
||
if (!module_sp) | ||
return error_with_message("Couldn't create or get module."); | ||
|
||
lldb::addr_t load_addr = LLDB_INVALID_ADDRESS; | ||
lldb::offset_t slide = LLDB_INVALID_OFFSET; | ||
|
@@ -481,23 +477,55 @@ ScriptedProcess::GetLoadedDynamicLibrariesInfos() { | |
if (slide != LLDB_INVALID_OFFSET) | ||
load_addr += slide; | ||
|
||
module_spec.GetArchitecture() = target.GetArchitecture(); | ||
|
||
ModuleSP module_sp = | ||
target.GetOrCreateModule(module_spec, true /* notify */); | ||
|
||
bool is_placeholder_module = false; | ||
|
||
if (!module_sp) { | ||
// Create a placeholder module | ||
LLDB_LOGF( | ||
GetLog(LLDBLog::Process), | ||
"ScriptedProcess::%s unable to locate the matching " | ||
"object file path %s, creating a placeholder module at 0x%" PRIx64, | ||
__FUNCTION__, path.str().c_str(), load_addr); | ||
|
||
module_sp = Module::CreateModuleFromObjectFile<ObjectFilePlaceholder>( | ||
module_spec, load_addr, module_spec.GetFileSpec().MemorySize()); | ||
|
||
is_placeholder_module = true; | ||
} | ||
|
||
bool changed = false; | ||
module_sp->SetLoadAddress(target, load_addr, false /*=value_is_offset*/, | ||
changed); | ||
|
||
if (!changed && !module_sp->GetObjectFile()) | ||
return error_with_message("Couldn't set the load address for module."); | ||
|
||
dict->GetValueForKeyAsString("path", value); | ||
FileSpec objfile(value); | ||
FileSpec objfile(path); | ||
module_sp->SetFileSpecAndObjectName(objfile, objfile.GetFilename()); | ||
|
||
if (is_placeholder_module) { | ||
target.GetImages().AppendIfNeeded(module_sp, true /*notify=*/); | ||
return true; | ||
} | ||
|
||
return module_list.AppendIfNeeded(module_sp); | ||
}; | ||
|
||
if (!loaded_images_sp->ForEach(reload_image)) | ||
return ScriptedInterface::ErrorWithMessage<StructuredData::ObjectSP>( | ||
LLVM_PRETTY_FUNCTION, "Couldn't reload all images.", error); | ||
size_t loaded_images_size = loaded_images_sp->GetSize(); | ||
bool print_error = true; | ||
for (size_t idx = 0; idx < loaded_images_size; idx++) { | ||
const auto &loaded_image = loaded_images_sp->GetItemAtIndex(idx); | ||
if (!reload_image(loaded_image.get()) && print_error) { | ||
print_error = false; | ||
ScriptedInterface::ErrorWithMessage<StructuredData::ObjectSP>( | ||
LLVM_PRETTY_FUNCTION, "Couldn't reload all images.", error); | ||
} | ||
} | ||
|
||
target.ModulesDidLoad(module_list); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.