Skip to content

Commit

Permalink
[lldb] Introduce SBPlatform::SetSDKRoot
Browse files Browse the repository at this point in the history
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
  • Loading branch information
labath committed Jan 19, 2022
1 parent b2a162e commit 9034245
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
3 changes: 3 additions & 0 deletions lldb/bindings/interface/SBPlatform.i
Expand Up @@ -177,6 +177,9 @@ public:
uint32_t
GetOSUpdateVersion ();

void
SetSDKRoot(const char *sysroot);

lldb::SBError
Get (lldb::SBFileSpec &src, lldb::SBFileSpec &dst);

Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBPlatform.h
Expand Up @@ -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);
Expand Down
15 changes: 3 additions & 12 deletions lldb/source/API/SBDebugger.cpp
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/API/SBPlatform.cpp
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Target/Platform.cpp
Expand Up @@ -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());
}
Expand Down
8 changes: 8 additions & 0 deletions lldb/test/API/python_api/sbplatform/TestSBPlatform.py
Expand Up @@ -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()])

0 comments on commit 9034245

Please sign in to comment.