diff --git a/lldb/bindings/interface/SBReproducer.i b/lldb/bindings/interface/SBReproducer.i index e976863f15c5e..7c9b007db3c06 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 5a298d1bcf43f..78044e9acbc31 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 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 diff --git a/lldb/include/lldb/Utility/Reproducer.h b/lldb/include/lldb/Utility/Reproducer.h index 499243b412020..5d810460a0c5b 100644 --- a/lldb/include/lldb/Utility/Reproducer.h +++ b/lldb/include/lldb/Utility/Reproducer.h @@ -147,6 +147,9 @@ class WorkingDirectoryProvider : public Provider { 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 3cea39ddcd571..9d119e08b6c33 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 329c1b55d16db..703d613c713fa 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().Update(path); + } +} + char lldb_private::repro::SBProvider::ID = 0; const char *SBProvider::Info::name = "sbapi"; const char *SBProvider::Info::file = "sbapi.bin";