[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-04-13 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf921006d379: [lldb] Remove the global platform list 
(authored by labath).

Changed prior to commit:
  https://reviews.llvm.org/D120810?vs=420507&id=422489#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120810/new/

https://reviews.llvm.org/D120810

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/packages/Python/lldbsuite/test/dotest.py
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/Interpreter/OptionGroupPlatform.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/Platform/POSIX/CMakeLists.txt
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Platform/Windows/CMakeLists.txt
  lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
  lldb/source/Plugins/Platform/gdb-server/CMakeLists.txt
  lldb/source/Target/Platform.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Target/TargetList.cpp
  lldb/test/API/python_api/debugger/TestDebuggerAPI.py
  lldb/test/API/python_api/debugger/elf.yaml
  lldb/test/API/python_api/debugger/macho.yaml
  lldb/test/API/python_api/sbplatform/TestSBPlatform.py
  lldb/unittests/Platform/PlatformTest.cpp

Index: lldb/unittests/Platform/PlatformTest.cpp
===
--- lldb/unittests/Platform/PlatformTest.cpp
+++ lldb/unittests/Platform/PlatformTest.cpp
@@ -21,7 +21,6 @@
 class TestPlatform : public PlatformPOSIX {
 public:
   TestPlatform() : PlatformPOSIX(false) {}
-  using Platform::Clear;
 };
 
 class PlatformArm : public TestPlatform {
@@ -75,67 +74,66 @@
 
 class PlatformTest : public ::testing::Test {
   SubsystemRAII subsystems;
-  void SetUp() override { TestPlatform::Clear(); }
+
+protected:
+  PlatformList list;
+
+  void SetHostPlatform(const PlatformSP &platform_sp) {
+Platform::SetHostPlatform(platform_sp);
+ASSERT_EQ(Platform::GetHostPlatform(), platform_sp);
+list.Append(platform_sp, /*set_selected=*/true);
+  }
 };
 
 TEST_F(PlatformTest, GetPlatformForArchitecturesHost) {
-  const PlatformSP host_platform_sp = std::make_shared();
-  Platform::SetHostPlatform(host_platform_sp);
-  ASSERT_EQ(Platform::GetHostPlatform(), host_platform_sp);
+  SetHostPlatform(std::make_shared());
 
   const std::vector archs = {ArchSpec("arm64-apple-ps4"),
ArchSpec("arm64e-apple-ps4")};
   std::vector candidates;
 
   // The host platform matches all architectures.
-  PlatformSP platform_sp =
-  Platform::GetPlatformForArchitectures(archs, {}, {}, candidates);
+  PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_TRUE(platform_sp);
-  EXPECT_EQ(platform_sp, host_platform_sp);
+  EXPECT_EQ(platform_sp, Platform::GetHostPlatform());
 }
 
 TEST_F(PlatformTest, GetPlatformForArchitecturesSelected) {
-  const PlatformSP host_platform_sp = std::make_shared();
-  Platform::SetHostPlatform(host_platform_sp);
-  ASSERT_EQ(Platform::GetHostPlatform(), host_platform_sp);
+  SetHostPlatform(std::make_shared());
 
   const std::vector archs = {ArchSpec("arm64-apple-ps4"),
ArchSpec("arm64e-apple-ps4")};
   std::vector candidates;
 
-  // The host platform matches no architectures. No selected platform.
-  PlatformSP platform_sp =
-  Platform::GetPlatformForArchitectures(archs, {}, {}, candidates);
+  // The host platform matches no architectures.
+  PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_FALSE(platform_sp);
 
   // The selected platform matches all architectures.
   const PlatformSP selected_platform_sp = std::make_shared();
-  platform_sp = Platform::GetPlatformForArchitectures(
-  archs, {}, selected_platform_sp, candidates);
+  list.Append(selected_platform_sp, /*set_selected=*/true);
+  platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_TRUE(platform_sp);
   EXPECT_EQ(platform_sp, selected_platform_sp);
 }
 
 TEST_F(PlatformTest, GetPlatformForArchitecturesSelectedOverHost) {
-  const PlatformSP host_platform_sp = std::make_shared();
-  Platform::SetHostPlatform(host_platform_sp);
-  ASSERT_EQ(Platform::GetHostPlatform(), host_platform_sp);
+  SetHostPlatform(std::make_shared());
 
   const std::vector archs = {ArchSpec("arm64-apple-ps4"),
ArchSpec("x86_64-apple-ps4")};
   std::vector candidates;
 
-  // The host platform matches one architecture. No selected platform.
-  PlatformSP platform_sp =
-  Platform::GetPlatformForArchitectures(archs, {}, {}, candidates);
+  // The host platform matches one architecture.
+  PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_TRUE(platform_sp);
-  EXPECT_EQ(platform_sp, host_platform_sp);
+  EXPECT_EQ(platform_sp, Platform::GetHostPlatform());
 
   // The selected 

[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-04-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Still LGTM. Apologies for the new rebase conflict introduced by e90d8f024b2b 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120810/new/

https://reviews.llvm.org/D120810

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
labath updated this revision to Diff 420507.
labath added a comment.

Reopening, since the last attempt was quite some time ago, and the rebase was
non-trivial.

Functionally, there are no real changes. The one-liner in dotest.py is somewhat
interesting, as it was necessary for (emu|simu)lator platform tests (which don't
have a connection url) to work. Previously, these worked even without setting
lldb.selected_platform, as they would get picked up from the global platform
list, but with this patch, they would become completely orphaned, and uneligible
for automatic selection.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120810/new/

https://reviews.llvm.org/D120810

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/packages/Python/lldbsuite/test/dotest.py
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/Interpreter/OptionGroupPlatform.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/Platform/POSIX/CMakeLists.txt
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Platform/Windows/CMakeLists.txt
  lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
  lldb/source/Plugins/Platform/gdb-server/CMakeLists.txt
  lldb/source/Target/Platform.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Target/TargetList.cpp
  lldb/test/API/python_api/debugger/TestDebuggerAPI.py
  lldb/test/API/python_api/debugger/elf.yaml
  lldb/test/API/python_api/debugger/macho.yaml
  lldb/test/API/python_api/sbplatform/TestSBPlatform.py
  lldb/unittests/Platform/PlatformTest.cpp

Index: lldb/unittests/Platform/PlatformTest.cpp
===
--- lldb/unittests/Platform/PlatformTest.cpp
+++ lldb/unittests/Platform/PlatformTest.cpp
@@ -21,7 +21,6 @@
 class TestPlatform : public PlatformPOSIX {
 public:
   TestPlatform() : PlatformPOSIX(false) {}
-  using Platform::Clear;
 };
 
 class PlatformArm : public TestPlatform {
@@ -75,67 +74,66 @@
 
 class PlatformTest : public ::testing::Test {
   SubsystemRAII subsystems;
-  void SetUp() override { TestPlatform::Clear(); }
+
+protected:
+  PlatformList list;
+
+  void SetHostPlatform(const PlatformSP &platform_sp) {
+Platform::SetHostPlatform(platform_sp);
+ASSERT_EQ(Platform::GetHostPlatform(), platform_sp);
+list.Append(platform_sp, /*set_selected=*/true);
+  }
 };
 
 TEST_F(PlatformTest, GetPlatformForArchitecturesHost) {
-  const PlatformSP host_platform_sp = std::make_shared();
-  Platform::SetHostPlatform(host_platform_sp);
-  ASSERT_EQ(Platform::GetHostPlatform(), host_platform_sp);
+  SetHostPlatform(std::make_shared());
 
   const std::vector archs = {ArchSpec("arm64-apple-ps4"),
ArchSpec("arm64e-apple-ps4")};
   std::vector candidates;
 
   // The host platform matches all architectures.
-  PlatformSP platform_sp =
-  Platform::GetPlatformForArchitectures(archs, {}, {}, candidates);
+  PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_TRUE(platform_sp);
-  EXPECT_EQ(platform_sp, host_platform_sp);
+  EXPECT_EQ(platform_sp, Platform::GetHostPlatform());
 }
 
 TEST_F(PlatformTest, GetPlatformForArchitecturesSelected) {
-  const PlatformSP host_platform_sp = std::make_shared();
-  Platform::SetHostPlatform(host_platform_sp);
-  ASSERT_EQ(Platform::GetHostPlatform(), host_platform_sp);
+  SetHostPlatform(std::make_shared());
 
   const std::vector archs = {ArchSpec("arm64-apple-ps4"),
ArchSpec("arm64e-apple-ps4")};
   std::vector candidates;
 
-  // The host platform matches no architectures. No selected platform.
-  PlatformSP platform_sp =
-  Platform::GetPlatformForArchitectures(archs, {}, {}, candidates);
+  // The host platform matches no architectures.
+  PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_FALSE(platform_sp);
 
   // The selected platform matches all architectures.
   const PlatformSP selected_platform_sp = std::make_shared();
-  platform_sp = Platform::GetPlatformForArchitectures(
-  archs, {}, selected_platform_sp, candidates);
+  list.Append(selected_platform_sp, /*set_selected=*/true);
+  platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_TRUE(platform_sp);
   EXPECT_EQ(platform_sp, selected_platform_sp);
 }
 
 TEST_F(PlatformTest, GetPlatformForArchitecturesSelectedOverHost) {
-  const PlatformSP host_platform_sp = std::make_shared();
-  Platform::SetHostPlatform(host_platform_sp);
-  ASSERT_EQ(Platform::GetHostPlatform(), host_platform_sp);
+  SetHostPlatform(std::make_shared());
 
   const std::vector archs = {ArchSpec("arm64-apple-ps4"),
ArchSpec("x86_64-apple-ps4")};
   std::vector candidates;
 
-  // The host platform matches one architecture. No selected platform.
-  PlatformSP platform_sp =
-  Platf

[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-03-11 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

(I'm not going to land this immediately, since I've also learned that this 
breaks running the test suite against the qemu platform -- which works right 
now, but it seems that is mostly accidental. I will switch gears and make the 
qemu platform more test-suite compatible first.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120810/new/

https://reviews.llvm.org/D120810

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-03-09 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: lldb/source/Plugins/Platform/gdb-server/CMakeLists.txt:10
 lldbPluginProcessUtility
+lldbPluginProcessGDBRemote
   )

thakis wrote:
> It doesn't seem like lldb cares about this kind of thing, but this adds a 
> dependency cycle: 
> lldbPluginPlatformGDB->lldbPluginProcessGDBRemote->lldbPluginPlatformMacOSX->lldbPluginPlatformPOSIX->lldbPluginPlatformGDB
Actually, this is something I wanted to address before landing this patch (but 
then forgot).  I think that the dependencies introduced (I would actually say 
"made explicit") here are reasonable, and the weird one is  
`lldbPluginProcessGDBRemote->lldbPluginPlatformMacOSX`). Lemme back this out 
until I figure out what to do with that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120810/new/

https://reviews.llvm.org/D120810

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-03-09 Thread Nico Weber via Phabricator via lldb-commits
thakis added inline comments.



Comment at: lldb/source/Plugins/Platform/gdb-server/CMakeLists.txt:10
 lldbPluginProcessUtility
+lldbPluginProcessGDBRemote
   )

It doesn't seem like lldb cares about this kind of thing, but this adds a 
dependency cycle: 
lldbPluginPlatformGDB->lldbPluginProcessGDBRemote->lldbPluginPlatformMacOSX->lldbPluginPlatformPOSIX->lldbPluginPlatformGDB


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120810/new/

https://reviews.llvm.org/D120810

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-03-09 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGffb9429b6f3c: [lldb] Remove the global platform list 
(authored by labath).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120810/new/

https://reviews.llvm.org/D120810

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/Interpreter/OptionGroupPlatform.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/Platform/POSIX/CMakeLists.txt
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Platform/Windows/CMakeLists.txt
  lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
  lldb/source/Plugins/Platform/gdb-server/CMakeLists.txt
  lldb/source/Target/Platform.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Target/TargetList.cpp
  lldb/test/API/python_api/debugger/TestDebuggerAPI.py
  lldb/test/API/python_api/debugger/elf.yaml
  lldb/test/API/python_api/debugger/macho.yaml
  lldb/test/API/python_api/sbplatform/TestSBPlatform.py

Index: lldb/test/API/python_api/sbplatform/TestSBPlatform.py
===
--- lldb/test/API/python_api/sbplatform/TestSBPlatform.py
+++ lldb/test/API/python_api/sbplatform/TestSBPlatform.py
@@ -25,6 +25,29 @@
 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())
Index: lldb/test/API/python_api/debugger/macho.yaml
===
--- /dev/null
+++ lldb/test/API/python_api/debugger/macho.yaml
@@ -0,0 +1,42 @@
+--- !mach-o
+FileHeader:  
+  magic:   0xFEEDFACF
+  cputype: 0x0107
+  cpusubtype:  0x0003
+  filetype:0x0001
+  ncmds:   4
+  sizeofcmds:  1160
+  flags:   0x2000
+  reserved:0x
+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:0x
+size:22
+offset:  0x04A8
+align:   4
+reloff:  0x
+nreloc:  0
+flags:   0x8400
+reserved1:   0x
+reserved2:   0x
+reserved3:   0x
+  - cmd: LC_BUILD_VERSION
+cmdsize: 24
+platform:1
+minos:   658944
+sdk: 658944
+ntools:  0
+...
Index: lldb/test/API/python_api/debugger/elf.yaml
===
--- /dev/null
+++ 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:

[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-03-09 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: lldb/source/Target/Platform.cpp:1891
+
+PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,
+ ArchSpec *platform_arch_ptr,

JDevlieghere wrote:
> [Nit/pedantic] We have a few calls to `IsCompatibleArchitecture` in this 
> function. Based on the existing comments you can infer that that's what the 
> second argument is for. Normally I'd suggest an inline comment, but given the 
> that there's a bunch of calls, could we have either have two constants:
> 
> ```
> enum ArchMatch : bool {
>   ExactArchMatch = true,
>   CompatibleArchMatch = false,
> };
> ```
> 
> Or maybe even better, can we change the signature of that function to take an 
> enum with those values? 
I've created a separate patch for that (https://reviews.llvm.org/D121290)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120810/new/

https://reviews.llvm.org/D120810

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-03-02 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

It's always great to see changes that enable more testing. I left one inline 
comment/nit but besides that this LGTM.




Comment at: lldb/source/Target/Platform.cpp:1891
+
+PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,
+ ArchSpec *platform_arch_ptr,

[Nit/pedantic] We have a few calls to `IsCompatibleArchitecture` in this 
function. Based on the existing comments you can infer that that's what the 
second argument is for. Normally I'd suggest an inline comment, but given the 
that there's a bunch of calls, could we have either have two constants:

```
enum ArchMatch : bool {
  ExactArchMatch = true,
  CompatibleArchMatch = false,
};
```

Or maybe even better, can we change the signature of that function to take an 
enum with those values? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120810/new/

https://reviews.llvm.org/D120810

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-03-02 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: JDevlieghere, clayborg, jingham.
Herald added subscribers: mgorny, emaste.
Herald added a project: All.
labath requested review of this revision.
Herald added a project: LLDB.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120810

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/Interpreter/OptionGroupPlatform.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/Platform/POSIX/CMakeLists.txt
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Platform/Windows/CMakeLists.txt
  lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
  lldb/source/Plugins/Platform/gdb-server/CMakeLists.txt
  lldb/source/Target/Platform.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Target/TargetList.cpp
  lldb/test/API/python_api/debugger/TestDebuggerAPI.py
  lldb/test/API/python_api/debugger/elf.yaml
  lldb/test/API/python_api/debugger/macho.yaml
  lldb/test/API/python_api/sbplatform/TestSBPlatform.py

Index: lldb/test/API/python_api/sbplatform/TestSBPlatform.py
===
--- lldb/test/API/python_api/sbplatform/TestSBPlatform.py
+++ lldb/test/API/python_api/sbplatform/TestSBPlatform.py
@@ -25,6 +25,29 @@
 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())
Index: lldb/test/API/python_api/debugger/macho.yaml
===
--- /dev/null
+++ lldb/test/API/python_api/debugger/macho.yaml
@@ -0,0 +1,42 @@
+--- !mach-o
+FileHeader:  
+  magic:   0xFEEDFACF
+  cputype: 0x0107
+  cpusubtype:  0x0003
+  filetype:0x0001
+  ncmds:   4
+  sizeofcmds:  1160
+  flags:   0x2000
+  reserved:0x
+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:0x
+size:22
+offset:  0x04A8
+align:   4
+reloff:  0x
+nreloc:  0
+flags:   0x8400
+reserved1:   0x
+reserved2:   0x
+reserved3:   0x
+  - cmd: LC_BUILD_VERSION
+cmdsize: 24
+platform: