[Lldb-commits] [lldb] 9034245 - [lldb] Introduce SBPlatform::SetSDKRoot
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 19 03:50:09 PST 2022
Author: Pavel Labath
Date: 2022-01-19T12:49:47+01:00
New Revision: 903424532f0b018447a00f8a534f362a9b3c246b
URL: https://github.com/llvm/llvm-project/commit/903424532f0b018447a00f8a534f362a9b3c246b
DIFF: https://github.com/llvm/llvm-project/commit/903424532f0b018447a00f8a534f362a9b3c246b.diff
LOG: [lldb] Introduce SBPlatform::SetSDKRoot
It complements the existing SBDebugger::SetCurrentPlatformSDKRoot and
allows one to set the sysroot of a platform without making it current.
Differential Revision: https://reviews.llvm.org/D117550
Added:
Modified:
lldb/bindings/interface/SBPlatform.i
lldb/include/lldb/API/SBPlatform.h
lldb/source/API/SBDebugger.cpp
lldb/source/API/SBPlatform.cpp
lldb/source/Target/Platform.cpp
lldb/test/API/python_api/sbplatform/TestSBPlatform.py
Removed:
################################################################################
diff --git a/lldb/bindings/interface/SBPlatform.i b/lldb/bindings/interface/SBPlatform.i
index 65615be7a361c..6413784e69e7c 100644
--- a/lldb/bindings/interface/SBPlatform.i
+++ b/lldb/bindings/interface/SBPlatform.i
@@ -177,6 +177,9 @@ public:
uint32_t
GetOSUpdateVersion ();
+ void
+ SetSDKRoot(const char *sysroot);
+
lldb::SBError
Get (lldb::SBFileSpec &src, lldb::SBFileSpec &dst);
diff --git a/lldb/include/lldb/API/SBPlatform.h b/lldb/include/lldb/API/SBPlatform.h
index 98291f18247dc..dcc8a14ff0c1f 100644
--- a/lldb/include/lldb/API/SBPlatform.h
+++ b/lldb/include/lldb/API/SBPlatform.h
@@ -137,6 +137,8 @@ class LLDB_API SBPlatform {
uint32_t GetOSUpdateVersion();
+ void SetSDKRoot(const char *sysroot);
+
SBError Put(SBFileSpec &src, SBFileSpec &dst);
SBError Get(SBFileSpec &src, SBFileSpec &dst);
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index aa7d4805cf14f..e8d723810fb4b 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1533,18 +1533,9 @@ bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot) {
LLDB_RECORD_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot,
(const char *), sysroot);
- Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
- if (m_opaque_sp) {
- PlatformSP platform_sp(
- m_opaque_sp->GetPlatformList().GetSelectedPlatform());
-
- if (platform_sp) {
- if (log && sysroot)
- LLDB_LOGF(log, "SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")",
- sysroot);
- platform_sp->SetSDKRootDirectory(ConstString(sysroot));
- return true;
- }
+ if (SBPlatform platform = GetSelectedPlatform()) {
+ platform.SetSDKRoot(sysroot);
+ return true;
}
return false;
}
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index 5e314ec8f59b5..5b0f1c3e1e213 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -513,6 +513,12 @@ uint32_t SBPlatform::GetOSUpdateVersion() {
return version.getSubminor().getValueOr(UINT32_MAX);
}
+void SBPlatform::SetSDKRoot(const char *sysroot) {
+ LLDB_RECORD_METHOD(void, SBPlatform, SetSDKRoot, (const char *), sysroot);
+ if (PlatformSP platform_sp = GetSP())
+ platform_sp->SetSDKRootDirectory(ConstString(sysroot));
+}
+
SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Get,
(lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index af5ca0225169f..00e1c16032275 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -428,6 +428,9 @@ void Platform::GetStatus(Stream &strm) {
strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
}
+ if (GetSDKRootDirectory()) {
+ strm.Format(" Sysroot: {0}\n", GetSDKRootDirectory());
+ }
if (GetWorkingDirectory()) {
strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
}
diff --git a/lldb/test/API/python_api/sbplatform/TestSBPlatform.py b/lldb/test/API/python_api/sbplatform/TestSBPlatform.py
index b354a6e28a085..f47e0b2660a47 100644
--- a/lldb/test/API/python_api/sbplatform/TestSBPlatform.py
+++ b/lldb/test/API/python_api/sbplatform/TestSBPlatform.py
@@ -20,3 +20,11 @@ def cleanup():
cmd = lldb.SBPlatformShellCommand(self.getBuildArtifact("a.out"))
self.assertTrue(plat.Run(cmd).Success())
self.assertIn("MY_TEST_ENV_VAR=SBPlatformAPICase.test_run", cmd.GetOutput())
+
+ def test_SetSDKRoot(self):
+ plat = lldb.SBPlatform("remote-linux") # arbitrary choice
+ self.assertTrue(plat)
+ plat.SetSDKRoot(self.getBuildDir())
+ self.dbg.SetCurrentPlatform("remote-linux")
+ self.expect("platform status",
+ substrs=["Sysroot:", self.getBuildDir()])
More information about the lldb-commits
mailing list