Skip to content

Clean up PlatformDarwinKernel::GetSharedModule, document (#78652) #8001

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lldb/include/lldb/Target/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,32 @@ class Platform : public PluginInterface {
LocateExecutableScriptingResources(Target *target, Module &module,
Stream &feedback_stream);

/// \param[in] module_spec
/// The ModuleSpec of a binary to find.
///
/// \param[in] process
/// A Process.
///
/// \param[out] module_sp
/// A Module that matches the ModuleSpec, if one is found.
///
/// \param[in] module_search_paths_ptr
/// Locations to possibly look for a binary that matches the ModuleSpec.
///
/// \param[out] old_modules
/// Existing Modules in the Process' Target image list which match
/// the FileSpec.
///
/// \param[out] did_create_ptr
/// Optional boolean, nullptr may be passed for this argument.
/// If this method is returning a *new* ModuleSP, this
/// will be set to true.
/// If this method is returning a ModuleSP that is already in the
/// Target's image list, it will be false.
///
/// \return
/// The Status object for any errors found while searching for
/// the binary.
virtual Status GetSharedModule(
const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr,
Expand Down
67 changes: 24 additions & 43 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "lldb/Interpreter/OptionValueFileSpecList.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Interpreter/Property.h"
#include "lldb/Symbol/LocateSymbolFile.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
Expand Down Expand Up @@ -791,9 +792,10 @@ Status PlatformDarwinKernel::GetSharedModuleKernel(
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();
assert(module_sp.get() == nullptr);
UpdateKextandKernelsLocalScan();
if (did_create_ptr)
*did_create_ptr = false;

// First try all kernel binaries that have a dSYM next to them
for (auto possible_kernel : m_kernel_binaries_with_dsyms) {
Expand All @@ -803,22 +805,19 @@ Status PlatformDarwinKernel::GetSharedModuleKernel(
module_sp.reset(new Module(kern_spec));
if (module_sp && module_sp->GetObjectFile() &&
module_sp->MatchesModuleSpec(kern_spec)) {
// module_sp is an actual kernel binary we want to add.
if (process) {
const bool notify = false;
process->GetTarget().GetImages().AppendIfNeeded(module_sp, notify);
error.Clear();
return error;
} else {
error = ModuleList::GetSharedModule(kern_spec, module_sp, nullptr,
nullptr, nullptr);
if (module_sp && module_sp->GetObjectFile() &&
module_sp->GetObjectFile()->GetType() !=
ObjectFile::Type::eTypeCoreFile) {
return error;
}
module_sp.reset();
}
// The dSYM is next to the binary (that's the only
// way it ends up in the index), but it might be a
// .dSYM.yaa that needs to be expanded, don't just
// append ".dSYM" to the filename for the SymbolFile.
FileSpecList search_paths =
process->GetTarget().GetDebugFileSearchPaths();
FileSpec dsym_fspec =
Symbols::LocateExecutableSymbolFile(kern_spec, search_paths);
if (FileSystem::Instance().Exists(dsym_fspec))
module_sp->SetSymbolFileFileSpec(dsym_fspec);
if (did_create_ptr)
*did_create_ptr = true;
return {};
}
}
}
Expand All @@ -836,36 +835,18 @@ Status PlatformDarwinKernel::GetSharedModuleKernel(
module_sp.reset(new Module(kern_spec));
if (module_sp && module_sp->GetObjectFile() &&
module_sp->MatchesModuleSpec(kern_spec)) {
// module_sp is an actual kernel binary we want to add.
if (process) {
const bool notify = false;
process->GetTarget().GetImages().AppendIfNeeded(module_sp, notify);
error.Clear();
return error;
} else {
error = ModuleList::GetSharedModule(kern_spec, module_sp, nullptr,
nullptr, nullptr);
if (module_sp && module_sp->GetObjectFile() &&
module_sp->GetObjectFile()->GetType() !=
ObjectFile::Type::eTypeCoreFile) {
return error;
}
module_sp.reset();
}
if (did_create_ptr)
*did_create_ptr = true;
return {};
}
}
}

// Give the generic methods, including possibly calling into DebugSymbols
// Give the generic methods, including possibly calling into DebugSymbols
// framework on macOS systems, a chance.
error = PlatformDarwin::GetSharedModule(module_spec, process, module_sp,
module_search_paths_ptr, old_modules,
did_create_ptr);
if (error.Success() && module_sp.get()) {
return error;
}

return error;
return PlatformDarwin::GetSharedModule(module_spec, process, module_sp,
module_search_paths_ptr, old_modules,
did_create_ptr);
}

std::vector<lldb_private::FileSpec>
Expand Down