-
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
Open
GeorgeHuyubo
wants to merge
9
commits into
llvm:main
Choose a base branch
from
GeorgeHuyubo:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c6534a1
Call locate module callback for main executable
2dc6595
[lldb] Refactor add target into ModuleSpec
1c8dcac
Revert "Call locate module callback for main executable"
cfe7d17
[lldb] Enable locate module callback in GetSharedModule
23f1b98
Address comment
d8bba3a
Merge branch 'main' into main
GeorgeHuyubo dff74fa
Merge branch 'main' into main
GeorgeHuyubo f8a3cbb
Code style fix
8d6ef4d
Add test
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
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
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
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
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) { | ||
|
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
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
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.
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.
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.
change the name to
m_target_wp
to indicate a weak pointer. We name shared pointers with a_sp
suffix and weak pointers with a_wp