aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/python_api
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2022-02-25 14:47:27 +0100
committerPavel Labath <pavel@labath.sk>2022-04-13 14:41:13 +0200
commitaf921006d3792fa28d1070f015dcfd145e082ed2 (patch)
treecef66cd21a920de4d0e7596f9a53da2756740f91 /lldb/test/API/python_api
parentba4537b22796a561dbcd7cd4e666bb5039510b21 (diff)
downloadllvm-af921006d3792fa28d1070f015dcfd145e082ed2.zip
llvm-af921006d3792fa28d1070f015dcfd145e082ed2.tar.gz
llvm-af921006d3792fa28d1070f015dcfd145e082ed2.tar.bz2
[lldb] Remove the global platform list
This patch moves the platform creation and selection logic into the per-debugger platform lists. I've tried to keep functional changes to a minimum -- the main (only) observable difference in this change is that APIs, which select a platform by name (e.g., Debugger::SetCurrentPlatform) will not automatically pick up a platform associated with another debugger (or no debugger at all). I've also added several tests for this functionality -- one of the pleasant consequences of the debugger isolation is that it is now possible to test the platform selection and creation logic. This is a product of the discussion at <https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>. Differential Revision: https://reviews.llvm.org/D120810
Diffstat (limited to 'lldb/test/API/python_api')
-rw-r--r--lldb/test/API/python_api/debugger/TestDebuggerAPI.py52
-rw-r--r--lldb/test/API/python_api/debugger/elf.yaml35
-rw-r--r--lldb/test/API/python_api/debugger/macho.yaml42
-rw-r--r--lldb/test/API/python_api/sbplatform/TestSBPlatform.py25
4 files changed, 153 insertions, 1 deletions
diff --git a/lldb/test/API/python_api/debugger/TestDebuggerAPI.py b/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
index 0a19945..f0ba1d1 100644
--- a/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
+++ b/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
@@ -92,3 +92,55 @@ class DebuggerAPITestCase(TestBase):
# Test the local property again, is it set to new_cache_line_size?
self.assertEqual(get_cache_line_size(), new_cache_line_size)
+
+ def test_CreateTarget_platform(self):
+ exe = self.getBuildArtifact("a.out")
+ self.yaml2obj("elf.yaml", exe)
+ error = lldb.SBError()
+ target1 = self.dbg.CreateTarget(exe, None, "remote-linux",
+ False, error)
+ self.assertSuccess(error)
+ platform1 = target1.GetPlatform()
+ platform1.SetWorkingDirectory("/foo/bar")
+
+ # Reuse a platform if it matches the currently selected one...
+ target2 = self.dbg.CreateTarget(exe, None, "remote-linux",
+ False, error)
+ self.assertSuccess(error)
+ platform2 = target2.GetPlatform()
+ self.assertEqual(platform2.GetWorkingDirectory(), "/foo/bar")
+
+ # ... but create a new one if it doesn't.
+ self.dbg.SetSelectedPlatform(lldb.SBPlatform("remote-windows"))
+ target3 = self.dbg.CreateTarget(exe, None, "remote-linux",
+ False, error)
+ self.assertSuccess(error)
+ platform3 = target3.GetPlatform()
+ self.assertIsNone(platform3.GetWorkingDirectory())
+
+ def test_CreateTarget_arch(self):
+ exe = self.getBuildArtifact("a.out")
+ if lldbplatformutil.getHostPlatform() == 'linux':
+ self.yaml2obj("macho.yaml", exe)
+ arch = "x86_64-apple-macosx"
+ else:
+ self.yaml2obj("elf.yaml", exe)
+ arch = "x86_64-pc-linux"
+
+ fbsd = lldb.SBPlatform("remote-freebsd")
+ self.dbg.SetSelectedPlatform(fbsd)
+
+ error = lldb.SBError()
+ target1 = self.dbg.CreateTarget(exe, arch, None, False, error)
+ self.assertSuccess(error)
+ platform1 = target1.GetPlatform()
+ self.assertEqual(platform1.GetName(), "remote-macosx")
+ platform1.SetWorkingDirectory("/foo/bar")
+
+ # Reuse a platform even if it is not currently selected.
+ self.dbg.SetSelectedPlatform(fbsd)
+ target2 = self.dbg.CreateTarget(exe, arch, None, False, error)
+ self.assertSuccess(error)
+ platform2 = target2.GetPlatform()
+ self.assertEqual(platform2.GetName(), "remote-macosx")
+ self.assertEqual(platform2.GetWorkingDirectory(), "/foo/bar")
diff --git a/lldb/test/API/python_api/debugger/elf.yaml b/lldb/test/API/python_api/debugger/elf.yaml
new file mode 100644
index 0000000..d62ebaa
--- /dev/null
+++ b/lldb/test/API/python_api/debugger/elf.yaml
@@ -0,0 +1,35 @@
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x1000
+ AddressAlign: 0x4
+ Content: "c3c3c3c3"
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ Address: 0x2000
+ AddressAlign: 0x4
+ Content: "3232"
+ProgramHeaders:
+ - Type: PT_LOAD
+ Flags: [ PF_X, PF_R ]
+ VAddr: 0x1000
+ PAddr: 0x1000
+ Align: 0x4
+ FirstSec: .text
+ LastSec: .text
+ - Type: PT_LOAD
+ Flags: [ PF_R, PF_W ]
+ VAddr: 0x2000
+ PAddr: 0x1004
+ Align: 0x4
+ FirstSec: .data
+ LastSec: .data
+
diff --git a/lldb/test/API/python_api/debugger/macho.yaml b/lldb/test/API/python_api/debugger/macho.yaml
new file mode 100644
index 0000000..5fdef29
--- /dev/null
+++ b/lldb/test/API/python_api/debugger/macho.yaml
@@ -0,0 +1,42 @@
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x01000007
+ cpusubtype: 0x00000003
+ filetype: 0x00000001
+ ncmds: 4
+ sizeofcmds: 1160
+ flags: 0x00002000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 1032
+ segname: ''
+ vmaddr: 0
+ vmsize: 744
+ fileoff: 1192
+ filesize: 744
+ maxprot: 7
+ initprot: 7
+ nsects: 12
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ size: 22
+ offset: 0x000004A8
+ align: 4
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_BUILD_VERSION
+ cmdsize: 24
+ platform: 1
+ minos: 658944
+ sdk: 658944
+ ntools: 0
+...
diff --git a/lldb/test/API/python_api/sbplatform/TestSBPlatform.py b/lldb/test/API/python_api/sbplatform/TestSBPlatform.py
index 002d9a6..dbb3f4c 100644
--- a/lldb/test/API/python_api/sbplatform/TestSBPlatform.py
+++ b/lldb/test/API/python_api/sbplatform/TestSBPlatform.py
@@ -25,6 +25,29 @@ class SBPlatformAPICase(TestBase):
plat = lldb.SBPlatform("remote-linux") # arbitrary choice
self.assertTrue(plat)
plat.SetSDKRoot(self.getBuildDir())
- self.dbg.SetCurrentPlatform("remote-linux")
+ self.dbg.SetSelectedPlatform(plat)
self.expect("platform status",
substrs=["Sysroot:", self.getBuildDir()])
+
+ def test_SetCurrentPlatform_floating(self):
+ # floating platforms cannot be referenced by name until they are
+ # associated with a debugger
+ floating_platform = lldb.SBPlatform("remote-netbsd")
+ floating_platform.SetWorkingDirectory(self.getBuildDir())
+ self.assertSuccess(self.dbg.SetCurrentPlatform("remote-netbsd"))
+ dbg_platform = self.dbg.GetSelectedPlatform()
+ self.assertEqual(dbg_platform.GetName(), "remote-netbsd")
+ self.assertIsNone(dbg_platform.GetWorkingDirectory())
+
+ def test_SetCurrentPlatform_associated(self):
+ # associated platforms are found by name-based lookup
+ floating_platform = lldb.SBPlatform("remote-netbsd")
+ floating_platform.SetWorkingDirectory(self.getBuildDir())
+ orig_platform = self.dbg.GetSelectedPlatform()
+
+ self.dbg.SetSelectedPlatform(floating_platform)
+ self.dbg.SetSelectedPlatform(orig_platform)
+ self.assertSuccess(self.dbg.SetCurrentPlatform("remote-netbsd"))
+ dbg_platform = self.dbg.GetSelectedPlatform()
+ self.assertEqual(dbg_platform.GetName(), "remote-netbsd")
+ self.assertEqual(dbg_platform.GetWorkingDirectory(), self.getBuildDir())