Run-time reg context selection for POSIX targets

Instantiate RegisterContext... based on getOS() instead of with
compile-time #ifdef-ery.

The assert() here is unfortunate, but better than crashing with no
explanation.

This change is equivalent to r186865 for elf-core.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@187422 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/POSIX/POSIXThread.cpp b/source/Plugins/Process/POSIX/POSIXThread.cpp
index 0f3e7be..a5cccee 100644
--- a/source/Plugins/Process/POSIX/POSIXThread.cpp
+++ b/source/Plugins/Process/POSIX/POSIXThread.cpp
@@ -145,14 +145,18 @@
             break;
 
         case ArchSpec::eCore_x86_64_x86_64:
-// TODO: Use target OS/architecture detection rather than ifdefs so that
-// lldb built on FreeBSD can debug on Linux and vice-versa.
-#ifdef __linux__
-            m_reg_context_sp.reset(new RegisterContextLinux_x86_64(*this, 0));
-#endif
-#ifdef __FreeBSD__
-            m_reg_context_sp.reset(new RegisterContextFreeBSD_x86_64(*this, 0));
-#endif
+            switch (arch.GetTriple().getOS())
+            {
+                case llvm::Triple::FreeBSD:
+                    m_reg_context_sp.reset(new RegisterContextFreeBSD_x86_64(*this, 0));
+                    break;
+                case llvm::Triple::Linux:
+                    m_reg_context_sp.reset(new RegisterContextLinux_x86_64(*this, 0));
+                    break;
+                default:
+                    assert(false && "OS not supported");
+                    break;
+            }
             break;
         }
     }