Skip to content

Commit b62b393

Browse files
authored
Merge pull request #8001 from jasonmolenda/r120895951-clean-up-platformdarwinkernel-getsharedmodule
Clean up PlatformDarwinKernel::GetSharedModule, document (llvm#78652)
2 parents a876461 + 7ea5107 commit b62b393

File tree

2 files changed

+50
-43
lines changed

2 files changed

+50
-43
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,32 @@ class Platform : public PluginInterface {
288288
LocateExecutableScriptingResources(Target *target, Module &module,
289289
Stream &feedback_stream);
290290

291+
/// \param[in] module_spec
292+
/// The ModuleSpec of a binary to find.
293+
///
294+
/// \param[in] process
295+
/// A Process.
296+
///
297+
/// \param[out] module_sp
298+
/// A Module that matches the ModuleSpec, if one is found.
299+
///
300+
/// \param[in] module_search_paths_ptr
301+
/// Locations to possibly look for a binary that matches the ModuleSpec.
302+
///
303+
/// \param[out] old_modules
304+
/// Existing Modules in the Process' Target image list which match
305+
/// the FileSpec.
306+
///
307+
/// \param[out] did_create_ptr
308+
/// Optional boolean, nullptr may be passed for this argument.
309+
/// If this method is returning a *new* ModuleSP, this
310+
/// will be set to true.
311+
/// If this method is returning a ModuleSP that is already in the
312+
/// Target's image list, it will be false.
313+
///
314+
/// \return
315+
/// The Status object for any errors found while searching for
316+
/// the binary.
291317
virtual Status GetSharedModule(
292318
const ModuleSpec &module_spec, Process *process,
293319
lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr,

lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "lldb/Interpreter/OptionValueFileSpecList.h"
2323
#include "lldb/Interpreter/OptionValueProperties.h"
2424
#include "lldb/Interpreter/Property.h"
25+
#include "lldb/Symbol/LocateSymbolFile.h"
2526
#include "lldb/Symbol/ObjectFile.h"
2627
#include "lldb/Target/Platform.h"
2728
#include "lldb/Target/Process.h"
@@ -791,9 +792,10 @@ Status PlatformDarwinKernel::GetSharedModuleKernel(
791792
const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
792793
const FileSpecList *module_search_paths_ptr,
793794
llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) {
794-
Status error;
795-
module_sp.reset();
795+
assert(module_sp.get() == nullptr);
796796
UpdateKextandKernelsLocalScan();
797+
if (did_create_ptr)
798+
*did_create_ptr = false;
797799

798800
// First try all kernel binaries that have a dSYM next to them
799801
for (auto possible_kernel : m_kernel_binaries_with_dsyms) {
@@ -803,22 +805,19 @@ Status PlatformDarwinKernel::GetSharedModuleKernel(
803805
module_sp.reset(new Module(kern_spec));
804806
if (module_sp && module_sp->GetObjectFile() &&
805807
module_sp->MatchesModuleSpec(kern_spec)) {
806-
// module_sp is an actual kernel binary we want to add.
807-
if (process) {
808-
const bool notify = false;
809-
process->GetTarget().GetImages().AppendIfNeeded(module_sp, notify);
810-
error.Clear();
811-
return error;
812-
} else {
813-
error = ModuleList::GetSharedModule(kern_spec, module_sp, nullptr,
814-
nullptr, nullptr);
815-
if (module_sp && module_sp->GetObjectFile() &&
816-
module_sp->GetObjectFile()->GetType() !=
817-
ObjectFile::Type::eTypeCoreFile) {
818-
return error;
819-
}
820-
module_sp.reset();
821-
}
808+
// The dSYM is next to the binary (that's the only
809+
// way it ends up in the index), but it might be a
810+
// .dSYM.yaa that needs to be expanded, don't just
811+
// append ".dSYM" to the filename for the SymbolFile.
812+
FileSpecList search_paths =
813+
process->GetTarget().GetDebugFileSearchPaths();
814+
FileSpec dsym_fspec =
815+
Symbols::LocateExecutableSymbolFile(kern_spec, search_paths);
816+
if (FileSystem::Instance().Exists(dsym_fspec))
817+
module_sp->SetSymbolFileFileSpec(dsym_fspec);
818+
if (did_create_ptr)
819+
*did_create_ptr = true;
820+
return {};
822821
}
823822
}
824823
}
@@ -836,36 +835,18 @@ Status PlatformDarwinKernel::GetSharedModuleKernel(
836835
module_sp.reset(new Module(kern_spec));
837836
if (module_sp && module_sp->GetObjectFile() &&
838837
module_sp->MatchesModuleSpec(kern_spec)) {
839-
// module_sp is an actual kernel binary we want to add.
840-
if (process) {
841-
const bool notify = false;
842-
process->GetTarget().GetImages().AppendIfNeeded(module_sp, notify);
843-
error.Clear();
844-
return error;
845-
} else {
846-
error = ModuleList::GetSharedModule(kern_spec, module_sp, nullptr,
847-
nullptr, nullptr);
848-
if (module_sp && module_sp->GetObjectFile() &&
849-
module_sp->GetObjectFile()->GetType() !=
850-
ObjectFile::Type::eTypeCoreFile) {
851-
return error;
852-
}
853-
module_sp.reset();
854-
}
838+
if (did_create_ptr)
839+
*did_create_ptr = true;
840+
return {};
855841
}
856842
}
857843
}
858844

859-
// Give the generic methods, including possibly calling into DebugSymbols
845+
// Give the generic methods, including possibly calling into DebugSymbols
860846
// framework on macOS systems, a chance.
861-
error = PlatformDarwin::GetSharedModule(module_spec, process, module_sp,
862-
module_search_paths_ptr, old_modules,
863-
did_create_ptr);
864-
if (error.Success() && module_sp.get()) {
865-
return error;
866-
}
867-
868-
return error;
847+
return PlatformDarwin::GetSharedModule(module_spec, process, module_sp,
848+
module_search_paths_ptr, old_modules,
849+
did_create_ptr);
869850
}
870851

871852
std::vector<lldb_private::FileSpec>

0 commit comments

Comments
 (0)