Skip to content
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
18 changes: 10 additions & 8 deletions lldb/include/lldb/Target/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ class Platform : public PluginInterface {

/// Locate the scripting resource given a module specification.
///
/// Locating the file should happen only on the local computer or using the
/// current computers global settings.
FileSpecList LocateExecutableScriptingResources(Target *target,
Module &module,
Stream &feedback_stream);
/// Returns a map from a located script's \c FileSpec to the
/// \c LoadScriptFromSymFile with which LLDB should load it.
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
LocateExecutableScriptingResources(Target *target, Module &module,
Stream &feedback_stream);

/// Locate the platform-specific scripting resource given a module
/// specification.
virtual FileSpecList
virtual llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
LocateExecutableScriptingResourcesForPlatform(Target *target, Module &module,
Stream &feedback_stream);

Expand All @@ -291,8 +291,10 @@ class Platform : public PluginInterface {
///
/// E.g., for Python it will look for a script at:
/// \c <safe-path>/<module-name>/<module-name>.py
static FileSpecList LocateExecutableScriptingResourcesFromSafePaths(
Stream &feedback_stream, FileSpec module_spec, const Target &target);
static llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
LocateExecutableScriptingResourcesFromSafePaths(Stream &feedback_stream,
FileSpec module_spec,
const Target &target);

/// \param[in] module_spec
/// The ModuleSpec of a binary to find.
Expand Down
21 changes: 7 additions & 14 deletions lldb/source/Core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,12 +1440,6 @@ bool Module::LoadScriptingResourceInTarget(Target *target, Status &error) {
return false;
}

LoadScriptFromSymFile should_load =
target->TargetProperties::GetLoadScriptFromSymbolFile();

if (should_load == eLoadScriptFromSymFileFalse)
return false;

Debugger &debugger = target->GetDebugger();
const ScriptLanguage script_language = debugger.GetScriptLanguage();
if (script_language == eScriptLanguageNone)
Expand All @@ -1465,22 +1459,21 @@ bool Module::LoadScriptingResourceInTarget(Target *target, Status &error) {
}

StreamString feedback_stream;
FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources(
target, *this, feedback_stream);
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> file_specs =
platform_sp->LocateExecutableScriptingResources(target, *this,
feedback_stream);

if (!feedback_stream.Empty())
debugger.ReportWarning(feedback_stream.GetString().str(), debugger.GetID());

const uint32_t num_specs = file_specs.GetSize();
if (num_specs == 0)
return true;
for (const auto &[scripting_fspec, load_style] : file_specs) {
if (load_style == eLoadScriptFromSymFileFalse)
continue;

for (uint32_t i = 0; i < num_specs; ++i) {
FileSpec scripting_fspec(file_specs.GetFileSpecAtIndex(i));
if (!FileSystem::Instance().Exists(scripting_fspec))
continue;

if (should_load == eLoadScriptFromSymFileWarn) {
if (load_style == eLoadScriptFromSymFileWarn) {
// clang-format off
debugger.ReportWarning(
llvm::formatv(
Expand Down
26 changes: 15 additions & 11 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,16 @@ PlatformDarwin::PutFile(const lldb_private::FileSpec &source,
return PlatformPOSIX::PutFile(source, destination, uid, gid);
}

FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesFromDSYM(
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
PlatformDarwin::LocateExecutableScriptingResourcesFromDSYM(
Stream &feedback_stream, FileSpec module_spec, const Target &target,
const FileSpec &symfile_spec) {

assert(target.GetDebugger().GetScriptInterpreter() &&
"Trying to locate scripting resources but no ScriptInterpreter is "
"available.");

FileSpecList file_list;
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> file_specs;
while (module_spec.GetFilename()) {
ScriptInterpreter::SanitizedScriptingModuleName sanitized_name =
target.GetDebugger()
Expand Down Expand Up @@ -234,7 +235,8 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesFromDSYM(
orig_script_fspec, script_fspec);

if (FileSystem::Instance().Exists(script_fspec)) {
file_list.Append(script_fspec);
file_specs.try_emplace(std::move(script_fspec),
target.GetLoadScriptFromSymbolFile());
break;
}

Expand All @@ -248,17 +250,19 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesFromDSYM(
module_spec.SetFilename(filename_no_extension);
}

return file_list;
return file_specs;
}

FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesForPlatform(
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
PlatformDarwin::LocateExecutableScriptingResourcesForPlatform(
Target *target, Module &module, Stream &feedback_stream) {
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> empty;
if (!target)
return {};
return empty;

// For now only Python scripts supported for auto-loading.
if (target->GetDebugger().GetScriptLanguage() != eScriptLanguagePython)
return {};
return empty;

// NB some extensions might be meaningful and should not be stripped -
// "this.binary.file"
Expand All @@ -270,15 +274,15 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesForPlatform(
const FileSpec &module_spec = module.GetFileSpec();

if (!module_spec)
return {};
return empty;

SymbolFile *symfile = module.GetSymbolFile();
if (!symfile)
return {};
return empty;

ObjectFile *objfile = symfile->GetObjectFile();
if (!objfile)
return {};
return empty;

const FileSpec &symfile_spec = objfile->GetFileSpec();
if (symfile_spec &&
Expand All @@ -288,7 +292,7 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResourcesForPlatform(
return LocateExecutableScriptingResourcesFromDSYM(
feedback_stream, module_spec, *target, symfile_spec);

return {};
return empty;
}

Status PlatformDarwin::ResolveSymbolFile(Target &target,
Expand Down
11 changes: 7 additions & 4 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class PlatformDarwin : public PlatformPOSIX {
Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec,
FileSpec &sym_file) override;

FileSpecList LocateExecutableScriptingResourcesForPlatform(
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
LocateExecutableScriptingResourcesForPlatform(
Target *target, Module &module_spec, Stream &feedback_stream) override;

Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
Expand Down Expand Up @@ -150,9 +151,11 @@ class PlatformDarwin : public PlatformPOSIX {
/// Resources directory in the same dSYM.
/// E.g., \c /path/to/.dSYM/Contents/Resources/DWARF/a.out
///
static FileSpecList LocateExecutableScriptingResourcesFromDSYM(
Stream &feedback_stream, FileSpec module_spec, const Target &target,
const FileSpec &symfile_spec);
static llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
LocateExecutableScriptingResourcesFromDSYM(Stream &feedback_stream,
FileSpec module_spec,
const Target &target,
const FileSpec &symfile_spec);

protected:
static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx);
Expand Down
30 changes: 18 additions & 12 deletions lldb/source/Target/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,24 @@ Status Platform::GetFileWithUUID(const FileSpec &platform_file,
return Status();
}

FileSpecList Platform::LocateExecutableScriptingResourcesFromSafePaths(
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
Platform::LocateExecutableScriptingResourcesFromSafePaths(
Stream &feedback_stream, FileSpec module_spec, const Target &target) {
assert(module_spec);
assert(target.GetDebugger().GetScriptInterpreter());

llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> file_specs;

// For now only Python scripts supported for auto-loading.
if (target.GetDebugger().GetScriptLanguage() != eScriptLanguagePython)
return {};
return file_specs;

ScriptInterpreter::SanitizedScriptingModuleName sanitized_name =
target.GetDebugger()
.GetScriptInterpreter()
->GetSanitizedScriptingModuleName(
module_spec.GetFileNameStrippingExtension().GetStringRef());

FileSpecList file_list;
FileSpecList paths = Debugger::GetSafeAutoLoadPaths();

// Iterate in reverse so we consider the latest appended path first.
Expand All @@ -197,36 +199,40 @@ FileSpecList Platform::LocateExecutableScriptingResourcesFromSafePaths(
orig_script_fspec, script_fspec);

if (FileSystem::Instance().Exists(script_fspec))
file_list.Append(script_fspec);
file_specs.try_emplace(std::move(script_fspec),
target.GetLoadScriptFromSymbolFile());

// If we successfully found a directory in a safe auto-load path
// stop looking at any other paths.
break;
}

return file_list;
return file_specs;
}

FileSpecList Platform::LocateExecutableScriptingResourcesForPlatform(
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
Platform::LocateExecutableScriptingResourcesForPlatform(
Target *target, Module &module, Stream &feedback_stream) {
return {};
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> empty;
return empty;
}

FileSpecList
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
Platform::LocateExecutableScriptingResources(Target *target, Module &module,
Stream &feedback_stream) {
llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> empty;
if (!target)
return {};
return empty;

// Give derived platforms a chance to locate scripting resources.
if (FileSpecList fspecs = LocateExecutableScriptingResourcesForPlatform(
if (auto fspecs = LocateExecutableScriptingResourcesForPlatform(
target, module, feedback_stream);
!fspecs.IsEmpty())
!fspecs.empty())
return fspecs;

const FileSpec &module_spec = module.GetFileSpec();
if (!module_spec)
return {};
return empty;

return LocateExecutableScriptingResourcesFromSafePaths(feedback_stream,
module_spec, *target);
Expand Down
Loading
Loading