[Lldb-commits] [PATCH] D79825: [lldb/Reproducers] Add test-specific API to set the test CWD

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue May 12 16:43:05 PDT 2020


JDevlieghere created this revision.
JDevlieghere added reviewers: labath, teemperor, friss.

The reproducers' working directory is set to the current working directory when
they are initialized. While this is not optimal, as the cwd can change during a
debug session, it has been sufficient so far.

The current approach doesn't work for the API test suite however because dotest
temporarily changes the directory to where the test's Python file lives.

This patch adds an API to tell the reproducers what to set the CWD to. This is
a NO-OP in every mode but capture.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D79825

Files:
  lldb/bindings/interface/SBReproducer.i
  lldb/include/lldb/API/SBReproducer.h
  lldb/include/lldb/Utility/Reproducer.h
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/API/SBReproducer.cpp


Index: lldb/source/API/SBReproducer.cpp
===================================================================
--- lldb/source/API/SBReproducer.cpp
+++ lldb/source/API/SBReproducer.cpp
@@ -231,6 +231,12 @@
   return path.c_str();
 }
 
+void SBReproducer::SetWorkingDirectory(const char *path) {
+  if (auto *g = lldb_private::repro::Reproducer::Instance().GetGenerator()) {
+    g->GetOrCreate<WorkingDirectoryProvider>().Update(path);
+  }
+}
+
 char lldb_private::repro::SBProvider::ID = 0;
 const char *SBProvider::Info::name = "sbapi";
 const char *SBProvider::Info::file = "sbapi.bin";
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -526,6 +526,7 @@
             if traceAlways:
                 print("Change dir to:", full_dir, file=sys.stderr)
             os.chdir(full_dir)
+            lldb.SBReproducer.SetWorkingDirectory(full_dir)
 
         # Set platform context.
         cls.platformContext = lldbplatformutil.createPlatformContext()
Index: lldb/include/lldb/Utility/Reproducer.h
===================================================================
--- lldb/include/lldb/Utility/Reproducer.h
+++ lldb/include/lldb/Utility/Reproducer.h
@@ -147,6 +147,9 @@
       return;
     m_cwd = std::string(cwd.str());
   }
+
+  void Update(llvm::StringRef path) { m_cwd = std::string(path); }
+
   struct Info {
     static const char *name;
     static const char *file;
Index: lldb/include/lldb/API/SBReproducer.h
===================================================================
--- lldb/include/lldb/API/SBReproducer.h
+++ lldb/include/lldb/API/SBReproducer.h
@@ -26,6 +26,13 @@
   static const char *GetPath();
   static bool SetAutoGenerate(bool b);
   static bool Generate();
+
+  /// The working directory is set to the current working directory when the
+  /// reproducers are initialized. This method allows setting a different
+  /// working directory. This is used by the API test suite  which temporarily
+  /// changes the directory to where the test lives. This is a NO-OP in every
+  /// mode but capture.
+  static void SetWorkingDirectory(const char *path);
 };
 
 } // namespace lldb
Index: lldb/bindings/interface/SBReproducer.i
===================================================================
--- lldb/bindings/interface/SBReproducer.i
+++ lldb/bindings/interface/SBReproducer.i
@@ -13,5 +13,6 @@
         static const char *Capture(const char *path);
         static const char *PassiveReplay(const char *path);
         static bool SetAutoGenerate(bool b);
+        static void SetWorkingDirectory(const char *path);
 };
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79825.263564.patch
Type: text/x-patch
Size: 2738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200512/af613fdf/attachment.bin>


More information about the lldb-commits mailing list