LLDB now has "Platform" plug-ins. Platform plug-ins are plug-ins that provide
an interface to a local or remote debugging platform. By default each host OS
that supports LLDB should be registering a "default" platform that will be
used unless a new platform is selected. Platforms are responsible for things
such as:
- getting process information by name or by processs ID
- finding platform files. This is useful for remote debugging where there is 
  an SDK with files that might already or need to be cached for debug access.
- getting a list of platform supported architectures in the exact order they
  should be selected. This helps the native x86 platform on MacOSX select the
  correct x86_64/i386 slice from universal binaries.
- Connect to remote platforms for remote debugging
- Resolving an executable including finding an executable inside platform
  specific bundles (macosx uses .app bundles that contain files) and also
  selecting the appropriate slice of universal files for a given platform.

So by default there is always a local platform, but remote platforms can be
connected to. I will soon be adding a new "platform" command that will support
the following commands:
(lldb) platform connect --name machine1 macosx connect://host:port
Connected to "machine1" platform.
(lldb) platform disconnect macosx

This allows LLDB to be well setup to do remote debugging and also once 
connected process listing and finding for things like:
(lldb) process attach --name x<TAB>

The currently selected platform plug-in can now auto complete any available
processes that start with "x". The responsibilities for the platform plug-in
will soon grow and expand.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@127286 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/lldb.cpp b/source/lldb.cpp
index b78cc4d..8096153 100644
--- a/source/lldb.cpp
+++ b/source/lldb.cpp
@@ -12,6 +12,7 @@
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/Log.h"
 #include "lldb/Core/PluginManager.h"
+#include "lldb/Core/RegularExpression.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/Mutex.h"
@@ -19,6 +20,8 @@
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
 
+#include "llvm/ADT/StringRef.h"
+
 #include "Plugins/Disassembler/llvm/DisassemblerLLVM.h"
 #include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h"
 #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
@@ -30,7 +33,7 @@
 #include "Plugins/Process/Utility/ArchDefaultUnwindPlan-x86.h"
 #include "Plugins/Process/Utility/ArchVolatileRegs-x86.h"
 
-#ifdef __APPLE__
+#if defined (__APPLE__)
 #include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h"
 #include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h"
 #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
@@ -41,11 +44,13 @@
 #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
 #include "Plugins/Process/MacOSX-User/source/ProcessMacOSX.h"
 #include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
 #endif
 
-#ifdef __linux__
-#include "Plugins/Process/Linux/ProcessLinux.h"
+#if defined (__linux__)
 #include "Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.h"
+#include "Plugins/Platform/Linux/PlatformLinux.h"
+#include "Plugins/Process/Linux/ProcessLinux.h"
 #endif
 
 #include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
@@ -83,7 +88,7 @@
         ArchVolatileRegs_x86::Initialize();
         ScriptInterpreter::Initialize ();
 
-#ifdef __APPLE__
+#if defined (__APPLE__)
         ABIMacOSX_i386::Initialize();
         ABISysV_x86_64::Initialize();
         DynamicLoaderMacOSXDYLD::Initialize();
@@ -96,8 +101,10 @@
         ProcessGDBRemote::Initialize();
         //ProcessMacOSX::Initialize();
         SymbolVendorMacOSX::Initialize();
+        PlatformMacOSX::Initialize();
 #endif
-#ifdef __linux__
+#if defined (__linux__)
+        ProcessLinux::Initialize();
         ProcessLinux::Initialize();
         DynamicLoaderLinuxDYLD::Initialize();
 #endif
@@ -136,7 +143,7 @@
     ArchVolatileRegs_x86::Terminate();
     ScriptInterpreter::Terminate ();
 
-#ifdef __APPLE__
+#if defined (__APPLE__)
     DynamicLoaderMacOSXDYLD::Terminate();
     SymbolFileDWARFDebugMap::Terminate();
     ItaniumABILanguageRuntime::Terminate();
@@ -147,13 +154,15 @@
     ProcessGDBRemote::Terminate();
     //ProcessMacOSX::Terminate();
     SymbolVendorMacOSX::Terminate();
+    PlatformMacOSX::Terminate();
 #endif
 
     Thread::Terminate ();
     Process::Terminate ();
     Target::Terminate ();
 
-#ifdef __linux__
+#if defined (__linux__)
+    PlatformLinux::Terminate();
     ProcessLinux::Terminate();
     DynamicLoaderLinuxDYLD::Terminate();
 #endif
@@ -227,3 +236,39 @@
 
 }
 
+bool
+lldb_private::NameMatches (const char *name, 
+                           lldb::NameMatchType match_type, 
+                           const char *match)
+{
+    if (match_type == eNameMatchIgnore)
+        return true;
+
+    if (name == match)
+        return true;
+
+    if (name && match)
+    {
+        llvm::StringRef name_sref(name);
+        llvm::StringRef match_sref(match);
+        switch (match_type)
+        {
+        case eNameMatchIgnore:
+            return true;
+        case eNameMatchEquals:      return name_sref == match_sref;
+        case eNameMatchContains:    return name_sref.find (match_sref) != llvm::StringRef::npos;
+        case eNameMatchStartsWith:  return name_sref.startswith (match_sref);
+        case eNameMatchEndsWith:    return name_sref.endswith (match_sref);
+        case eNameMatchRegularExpression:
+            {
+                RegularExpression regex (match);
+                return regex.Execute (name);
+            }
+            break;
+        default:
+            assert (!"unhandled NameMatchType in lldb_private::NameMatches()");
+            break;
+        }
+    }
+    return false;
+}