[Lldb-commits] [lldb] 1f80e51 - [lldb/Reproducers] Collect files imported by command script import

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 24 09:08:09 PDT 2020


Author: Jonas Devlieghere
Date: 2020-03-24T08:54:26-07:00
New Revision: 1f80e51546bf2bf77982fd013519631f4c86898b

URL: https://github.com/llvm/llvm-project/commit/1f80e51546bf2bf77982fd013519631f4c86898b
DIFF: https://github.com/llvm/llvm-project/commit/1f80e51546bf2bf77982fd013519631f4c86898b.diff

LOG: [lldb/Reproducers] Collect files imported by command script import

Files imported by the script interpreter aren't opened by LLDB so they
don't end up in the reproducer. The solution is to explicitly add them
to the FileCollector.

Differential revision: https://reviews.llvm.org/D76626

Added: 
    lldb/test/Shell/Reproducer/Inputs/foo.lua
    lldb/test/Shell/Reproducer/Inputs/foo.py
    lldb/test/Shell/Reproducer/TestLuaImport.test
    lldb/test/Shell/Reproducer/TestPythonImport.test

Modified: 
    lldb/include/lldb/Host/FileSystem.h
    lldb/source/Host/common/FileSystem.cpp
    lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
    lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Host/FileSystem.h b/lldb/include/lldb/Host/FileSystem.h
index 565d1f24e456..8dcff3402592 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<FileSystem> &InstanceImpl();
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
   std::shared_ptr<llvm::FileCollector> m_collector;

diff  --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp
index 220d7672cfb5..dcfa594597a1 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<DataBufferLLVM>
 FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size,
                              uint64_t offset) {
-  AddFile(path);
+  Collect(path);
 
   const bool is_volatile = !IsLocal(path);
   const ErrorOr<std::string> external_path = GetExternalPath(path);
@@ -417,7 +417,7 @@ static mode_t GetOpenMode(uint32_t permissions) {
 Expected<FileUP> 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<std::string> 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 ecbd30c10ae0..f9b24ad83de5 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 3e93ddbf18c8..f59b70ac31d2 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 000000000000..8ed0c94cbba9
--- /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 000000000000..8ed0c94cbba9
--- /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 000000000000..315cfd396028
--- /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 000000000000..7bea97c91d98
--- /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


        


More information about the lldb-commits mailing list