From 6671a81bc71cc2635c5a10d6f688fea46ca4e5d6 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 13 May 2020 08:54:57 -0700 Subject: [PATCH] [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 --- lldb/bindings/interface/SBReproducer.i | 1 + lldb/include/lldb/API/SBReproducer.h | 7 +++++++ lldb/include/lldb/Utility/Reproducer.h | 3 +++ lldb/packages/Python/lldbsuite/test/lldbtest.py | 1 + lldb/source/API/SBReproducer.cpp | 6 ++++++ 5 files changed, 18 insertions(+) diff --git a/lldb/bindings/interface/SBReproducer.i b/lldb/bindings/interface/SBReproducer.i index e976863..7c9b007 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 5a298d1..78044e9 100644 --- a/lldb/include/lldb/API/SBReproducer.h +++ b/lldb/include/lldb/API/SBReproducer.h @@ -26,6 +26,13 @@ public: 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 499243b..5d81046 100644 --- a/lldb/include/lldb/Utility/Reproducer.h +++ b/lldb/include/lldb/Utility/Reproducer.h @@ -147,6 +147,9 @@ public: 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 3cea39d..9d119e0 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -526,6 +526,7 @@ class Base(unittest2.TestCase): 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 329c1b5..703d613 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"; -- 2.7.4