diff --git a/lldb/include/lldb/Host/FileSystem.h b/lldb/include/lldb/Host/FileSystem.h index 565d1f24e456cf..8dcff340259294 100644 --- a/lldb/include/lldb/Host/FileSystem.h +++ b/lldb/include/lldb/Host/FileSystem.h @@ -186,8 +186,10 @@ class FileSystem { return m_fs; } + void Collect(const FileSpec &file_spec); + void Collect(const llvm::Twine &file); + private: - void AddFile(const llvm::Twine &file); static llvm::Optional &InstanceImpl(); llvm::IntrusiveRefCntPtr m_fs; std::shared_ptr m_collector; diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp index 220d7672cfb561..dcfa594597a1b3 100644 --- a/lldb/source/Host/common/FileSystem.cpp +++ b/lldb/source/Host/common/FileSystem.cpp @@ -279,7 +279,7 @@ void FileSystem::Resolve(FileSpec &file_spec) { std::shared_ptr FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size, uint64_t offset) { - AddFile(path); + Collect(path); const bool is_volatile = !IsLocal(path); const ErrorOr external_path = GetExternalPath(path); @@ -417,7 +417,7 @@ static mode_t GetOpenMode(uint32_t permissions) { Expected FileSystem::Open(const FileSpec &file_spec, File::OpenOptions options, uint32_t permissions, bool should_close_fd) { - AddFile(file_spec.GetPath()); + Collect(file_spec.GetPath()); const int open_flags = GetOpenFlags(options); const mode_t open_mode = @@ -465,7 +465,11 @@ ErrorOr FileSystem::GetExternalPath(const FileSpec &file_spec) { return GetExternalPath(file_spec.GetPath()); } -void FileSystem::AddFile(const llvm::Twine &file) { +void FileSystem::Collect(const FileSpec &file_spec) { + Collect(file_spec.GetPath()); +} + +void FileSystem::Collect(const llvm::Twine &file) { if (m_collector && !llvm::sys::fs::is_directory(file)) { m_collector->addFile(file); } diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp index ecbd30c10ae014..f9b24ad83de515 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp @@ -89,6 +89,7 @@ bool ScriptInterpreterLua::LoadScriptingModule( const char *filename, bool init_session, lldb_private::Status &error, StructuredData::ObjectSP *module_sp) { + FileSystem::Instance().Collect(filename); if (llvm::Error e = m_lua->LoadModule(filename)) { error.SetErrorStringWithFormatv("lua failed to import '{0}': {1}\n", filename, llvm::toString(std::move(e))); diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 3e93ddbf18c8e1..f59b70ac31d277 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -2772,6 +2772,7 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule( { FileSpec target_file(pathname); FileSystem::Instance().Resolve(target_file); + FileSystem::Instance().Collect(target_file); std::string basename(target_file.GetFilename().GetCString()); StreamString command_stream; diff --git a/lldb/test/Shell/Reproducer/Inputs/foo.lua b/lldb/test/Shell/Reproducer/Inputs/foo.lua new file mode 100644 index 00000000000000..8ed0c94cbba969 --- /dev/null +++ b/lldb/test/Shell/Reproducer/Inputs/foo.lua @@ -0,0 +1 @@ +print('95126') diff --git a/lldb/test/Shell/Reproducer/Inputs/foo.py b/lldb/test/Shell/Reproducer/Inputs/foo.py new file mode 100644 index 00000000000000..8ed0c94cbba969 --- /dev/null +++ b/lldb/test/Shell/Reproducer/Inputs/foo.py @@ -0,0 +1 @@ +print('95126') diff --git a/lldb/test/Shell/Reproducer/TestLuaImport.test b/lldb/test/Shell/Reproducer/TestLuaImport.test new file mode 100644 index 00000000000000..315cfd396028e6 --- /dev/null +++ b/lldb/test/Shell/Reproducer/TestLuaImport.test @@ -0,0 +1,11 @@ +# REQUIRES: lua +# UNSUPPORTED: system-windows +# Ensure that the reproducers know about imported Lua modules. + +# RUN: rm -rf %t.repro +# RUN: %lldb -x -b --script-language lua --capture --capture-path %t.repro -o 'command script import %S/Inputs/foo.lua' -o 'reproducer generate' | FileCheck %s --check-prefix CAPTURE + +# CAPTURE: 95126 + +# RUN: %lldb -b -o 'reproducer dump -p files -f %t.repro' | FileCheck %s --check-prefix FILES +# FILES: foo.lua diff --git a/lldb/test/Shell/Reproducer/TestPythonImport.test b/lldb/test/Shell/Reproducer/TestPythonImport.test new file mode 100644 index 00000000000000..7bea97c91d986f --- /dev/null +++ b/lldb/test/Shell/Reproducer/TestPythonImport.test @@ -0,0 +1,11 @@ +# REQUIRES: python +# UNSUPPORTED: system-windows +# Ensure that the reproducers know about imported Python modules. + +# RUN: rm -rf %t.repro +# RUN: %lldb -x -b --capture --capture-path %t.repro -o 'command script import %S/Inputs/foo.py' -o 'reproducer generate' | FileCheck %s --check-prefix CAPTURE + +# CAPTURE: 95126 + +# RUN: %lldb -b -o 'reproducer dump -p files -f %t.repro' | FileCheck %s --check-prefix FILES +# FILES: foo.py