-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lldb] Enable locate module callback for main executable #160199
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
c6534a1
2dc6595
1c8dcac
cfe7d17
23f1b98
d8bba3a
dff74fa
f8a3cbb
8d6ef4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
#include "lldb/Symbol/SymbolContext.h" | ||
#include "lldb/Symbol/TypeList.h" | ||
#include "lldb/Symbol/VariableList.h" | ||
#include "lldb/Target/Platform.h" | ||
#include "lldb/Target/Target.h" | ||
#include "lldb/Utility/ArchSpec.h" | ||
#include "lldb/Utility/ConstString.h" | ||
#include "lldb/Utility/FileSpecList.h" | ||
|
@@ -1038,9 +1040,9 @@ size_t ModuleList::RemoveOrphanSharedModules(bool mandatory) { | |
|
||
Status | ||
ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp, | ||
const FileSpecList *module_search_paths_ptr, | ||
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, | ||
bool *did_create_ptr, bool always_create) { | ||
bool *did_create_ptr, bool always_create, | ||
bool invoke_locate_callback) { | ||
SharedModuleList &shared_module_list = GetSharedModuleList(); | ||
std::lock_guard<std::recursive_mutex> guard(shared_module_list.GetMutex()); | ||
char path[PATH_MAX]; | ||
|
@@ -1095,6 +1097,22 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp, | |
if (module_sp) | ||
return error; | ||
|
||
// Try target's platform locate module callback before second attempt. | ||
if (invoke_locate_callback) { | ||
TargetSP target_sp = module_spec.GetTargetSP(); | ||
if (target_sp && target_sp->IsValid()) { | ||
if (PlatformSP platform_sp = target_sp->GetPlatform()) { | ||
FileSpec symbol_file_spec; | ||
platform_sp->CallLocateModuleCallbackIfSet( | ||
module_spec, module_sp, symbol_file_spec, did_create_ptr); | ||
if (module_sp) { | ||
// The callback found a module. | ||
return error; | ||
} | ||
} | ||
} | ||
} | ||
|
||
module_sp = std::make_shared<Module>(module_spec); | ||
// Make sure there are a module and an object file since we can specify a | ||
// valid file path with an architecture that might not be in that file. By | ||
|
@@ -1122,6 +1140,15 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp, | |
module_sp.reset(); | ||
} | ||
|
||
// Get module search paths from the target if available. | ||
lldb::TargetSP target_sp = module_spec.GetTargetSP(); | ||
FileSpecList module_search_paths; | ||
FileSpecList *module_search_paths_ptr = nullptr; | ||
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. We don't need this pointer, just use |
||
if (target_sp && target_sp->IsValid()) { | ||
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. No need to check |
||
module_search_paths = target_sp->GetExecutableSearchPaths(); | ||
module_search_paths_ptr = &module_search_paths; | ||
} | ||
|
||
if (module_search_paths_ptr) { | ||
const auto num_directories = module_search_paths_ptr->GetSize(); | ||
for (size_t idx = 0; idx < num_directories; ++idx) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,7 +331,6 @@ Status PlatformDarwin::ResolveSymbolFile(Target &target, | |
|
||
Status PlatformDarwin::GetSharedModule( | ||
const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp, | ||
const FileSpecList *module_search_paths_ptr, | ||
llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) { | ||
Status error; | ||
module_sp.reset(); | ||
|
@@ -341,19 +340,23 @@ Status PlatformDarwin::GetSharedModule( | |
// module first. | ||
if (m_remote_platform_sp) { | ||
error = m_remote_platform_sp->GetSharedModule( | ||
module_spec, process, module_sp, module_search_paths_ptr, old_modules, | ||
did_create_ptr); | ||
module_spec, process, module_sp, old_modules, did_create_ptr); | ||
} | ||
} | ||
|
||
if (!module_sp) { | ||
// Fall back to the local platform and find the file locally | ||
error = Platform::GetSharedModule(module_spec, process, module_sp, | ||
module_search_paths_ptr, old_modules, | ||
did_create_ptr); | ||
old_modules, did_create_ptr); | ||
|
||
const FileSpec &platform_file = module_spec.GetFileSpec(); | ||
if (!module_sp && module_search_paths_ptr && platform_file) { | ||
// Get module search paths from the target if available. | ||
TargetSP target_sp = module_spec.GetTargetSP(); | ||
FileSpecList module_search_paths; | ||
if (target_sp) { | ||
module_search_paths = target_sp->GetExecutableSearchPaths(); | ||
} | ||
if (!module_sp && !module_search_paths.IsEmpty() && platform_file) { | ||
// We can try to pull off part of the file path up to the bundle | ||
// directory level and try any module search paths... | ||
FileSpec bundle_directory; | ||
|
@@ -362,9 +365,9 @@ Status PlatformDarwin::GetSharedModule( | |
ModuleSpec new_module_spec(module_spec); | ||
new_module_spec.GetFileSpec() = bundle_directory; | ||
if (Host::ResolveExecutableInBundle(new_module_spec.GetFileSpec())) { | ||
Status new_error(Platform::GetSharedModule( | ||
new_module_spec, process, module_sp, nullptr, old_modules, | ||
did_create_ptr)); | ||
Status new_error(Platform::GetSharedModule(new_module_spec, process, | ||
module_sp, old_modules, | ||
did_create_ptr)); | ||
|
||
if (module_sp) | ||
return new_error; | ||
|
@@ -376,10 +379,10 @@ Status PlatformDarwin::GetSharedModule( | |
const size_t bundle_directory_len = | ||
bundle_directory.GetPath(bundle_dir, sizeof(bundle_dir)); | ||
char new_path[PATH_MAX]; | ||
size_t num_module_search_paths = module_search_paths_ptr->GetSize(); | ||
size_t num_module_search_paths = module_search_paths.GetSize(); | ||
for (size_t i = 0; i < num_module_search_paths; ++i) { | ||
const size_t search_path_len = | ||
module_search_paths_ptr->GetFileSpecAtIndex(i).GetPath( | ||
module_search_paths.GetFileSpecAtIndex(i).GetPath( | ||
new_path, sizeof(new_path)); | ||
if (search_path_len < sizeof(new_path)) { | ||
snprintf(new_path + search_path_len, | ||
|
@@ -390,7 +393,7 @@ Status PlatformDarwin::GetSharedModule( | |
ModuleSpec new_module_spec(module_spec); | ||
new_module_spec.GetFileSpec() = new_file_spec; | ||
Status new_error(Platform::GetSharedModule( | ||
new_module_spec, process, module_sp, nullptr, old_modules, | ||
new_module_spec, process, module_sp, old_modules, | ||
did_create_ptr)); | ||
|
||
if (module_sp) { | ||
|
@@ -1303,12 +1306,16 @@ PlatformDarwin::LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) { | |
|
||
lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths( | ||
const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp, | ||
const FileSpecList *module_search_paths_ptr, | ||
llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) { | ||
const FileSpec &platform_file = module_spec.GetFileSpec(); | ||
// See if the file is present in any of the module_search_paths_ptr | ||
TargetSP target_sp = module_spec.GetTargetSP(); | ||
FileSpecList module_search_paths; | ||
if (target_sp) { | ||
|
||
module_search_paths = target_sp->GetExecutableSearchPaths(); | ||
} | ||
// See if the file is present in any of the module_search_paths | ||
// directories. | ||
if (!module_sp && module_search_paths_ptr && platform_file) { | ||
if (!module_sp && !module_search_paths.IsEmpty() && platform_file) { | ||
// create a vector of all the file / directory names in platform_file e.g. | ||
// this might be | ||
// /System/Library/PrivateFrameworks/UIFoundation.framework/UIFoundation | ||
|
@@ -1322,21 +1329,21 @@ lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths( | |
std::reverse(path_parts.begin(), path_parts.end()); | ||
const size_t path_parts_size = path_parts.size(); | ||
|
||
size_t num_module_search_paths = module_search_paths_ptr->GetSize(); | ||
size_t num_module_search_paths = module_search_paths.GetSize(); | ||
for (size_t i = 0; i < num_module_search_paths; ++i) { | ||
Log *log_verbose = GetLog(LLDBLog::Host); | ||
LLDB_LOGF( | ||
log_verbose, | ||
"PlatformRemoteDarwinDevice::GetSharedModule searching for binary in " | ||
"search-path %s", | ||
module_search_paths_ptr->GetFileSpecAtIndex(i).GetPath().c_str()); | ||
module_search_paths.GetFileSpecAtIndex(i).GetPath().c_str()); | ||
// Create a new FileSpec with this module_search_paths_ptr plus just the | ||
// filename ("UIFoundation"), then the parent dir plus filename | ||
// ("UIFoundation.framework/UIFoundation") etc - up to four names (to | ||
// handle "Foo.framework/Contents/MacOS/Foo") | ||
|
||
for (size_t j = 0; j < 4 && j < path_parts_size - 1; ++j) { | ||
FileSpec path_to_try(module_search_paths_ptr->GetFileSpecAtIndex(i)); | ||
FileSpec path_to_try(module_search_paths.GetFileSpecAtIndex(i)); | ||
|
||
// Add the components backwards. For | ||
// .../PrivateFrameworks/UIFoundation.framework/UIFoundation path_parts | ||
|
@@ -1356,9 +1363,9 @@ lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths( | |
if (FileSystem::Instance().Exists(path_to_try)) { | ||
ModuleSpec new_module_spec(module_spec); | ||
new_module_spec.GetFileSpec() = path_to_try; | ||
Status new_error( | ||
Platform::GetSharedModule(new_module_spec, process, module_sp, | ||
nullptr, old_modules, did_create_ptr)); | ||
Status new_error(Platform::GetSharedModule(new_module_spec, process, | ||
module_sp, old_modules, | ||
did_create_ptr)); | ||
|
||
if (module_sp) { | ||
module_sp->SetPlatformFileSpec(path_to_try); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put comment above with ///