[Lldb-commits] [lldb] 6671a81 - [lldb/Reproducers] Add test-specific API to set the test CWD

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed May 13 09:05:51 PDT 2020


Author: Jonas Devlieghere
Date: 2020-05-13T09:00:07-07:00
New Revision: 6671a81bc71cc2635c5a10d6f688fea46ca4e5d6

URL: https://github.com/llvm/llvm-project/commit/6671a81bc71cc2635c5a10d6f688fea46ca4e5d6
DIFF: https://github.com/llvm/llvm-project/commit/6671a81bc71cc2635c5a10d6f688fea46ca4e5d6.diff

LOG: [lldb/Reproducers] Add test-specific API to set the test CWD

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.

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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/bindings/interface/SBReproducer.i b/lldb/bindings/interface/SBReproducer.i
index e976863f15c5..7c9b007db3c0 100644
--- a/lldb/bindings/interface/SBReproducer.i
+++ b/lldb/bindings/interface/SBReproducer.i
@@ -13,5 +13,6 @@ class SBReproducer
         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);
 };
 }

diff  --git a/lldb/include/lldb/API/SBReproducer.h b/lldb/include/lldb/API/SBReproducer.h
index 5a298d1bcf43..78044e9acbc3 100644
--- a/lldb/include/lldb/API/SBReproducer.h
+++ b/lldb/include/lldb/API/SBReproducer.h
@@ -26,6 +26,13 @@ class LLDB_API SBReproducer {
   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 
diff erent
+  /// 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

diff  --git a/lldb/include/lldb/Utility/Reproducer.h b/lldb/include/lldb/Utility/Reproducer.h
index 499243b41202..5d810460a0c5 100644
--- a/lldb/include/lldb/Utility/Reproducer.h
+++ b/lldb/include/lldb/Utility/Reproducer.h
@@ -147,6 +147,9 @@ class WorkingDirectoryProvider : public Provider<WorkingDirectoryProvider> {
       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;

diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 3cea39ddcd57..9d119e08b6c3 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -526,6 +526,7 @@ def setUpClass(cls):
             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()

diff  --git a/lldb/source/API/SBReproducer.cpp b/lldb/source/API/SBReproducer.cpp
index 329c1b55d16d..703d613c713f 100644
--- a/lldb/source/API/SBReproducer.cpp
+++ b/lldb/source/API/SBReproducer.cpp
@@ -231,6 +231,12 @@ const char *SBReproducer::GetPath() {
   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";


        


More information about the lldb-commits mailing list