<div dir="ltr">Oops - typo in class name in the description...<div><br></div><div>s/GDBProcessCommunicationServer/GDBRemoteCommunicationServer/g;</div><div><br></div><div>-Todd</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, Jan 27, 2014 at 4:34 PM, Todd Fiala <span dir="ltr"><<a href="mailto:tfiala@google.com" target="_blank">tfiala@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: tfiala<br>
Date: Mon Jan 27 18:34:23 2014<br>
New Revision: 200266<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=200266&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=200266&view=rev</a><br>
Log:<br>
Modified GDBProcessCommunicationServer to launch via the platform.<br>
<br>
GDBProcessCommunicationServer now optionally takes a PlatformSP that<br>
defaults to the default platform for the host.<br>
GDBProcessCommunicationServer::LaunchProcess () now uses the platform<br>
to launch the process.<br>
<br>
lldb-gdbserver now takes an optional --platform={platform_plugin_name}<br>
or -p {platform_plugin_name} command line option. If no platform is<br>
specified, the default platform for the host is used; otherwise, if<br>
the platform_plugin_name matches a registered platform plugin or<br>
matches the default platform's name (which is not necessarily<br>
registered by name in the case of 'host'), that platform is used. If<br>
the platform name cannot be resolved, lldb-gdbserver exits after<br>
printing all the available platform plugin names and the default<br>
platform plugin name.<br>
<br>
Modified:<br>
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp<br>
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h<br>
    lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp<br>
<br>
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=200266&r1=200265&r2=200266&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=200266&r1=200265&r2=200266&view=diff</a><br>

==============================================================================<br>
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original)<br>
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Mon Jan 27 18:34:23 2014<br>
@@ -25,6 +25,7 @@<br>
 #include "lldb/Host/File.h"<br>
 #include "lldb/Host/Host.h"<br>
 #include "lldb/Host/TimeValue.h"<br>
+#include "lldb/Target/Platform.h"<br>
 #include "lldb/Target/Process.h"<br>
<br>
 // Project includes<br>
@@ -40,6 +41,7 @@ using namespace lldb_private;<br>
 //----------------------------------------------------------------------<br>
 GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform) :<br>
     GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet", is_platform),<br>
+    m_platform_sp (Platform::GetDefaultPlatform ()),<br>
     m_async_thread (LLDB_INVALID_HOST_THREAD),<br>
     m_process_launch_info (),<br>
     m_process_launch_error (),<br>
@@ -52,6 +54,23 @@ GDBRemoteCommunicationServer::GDBRemoteC<br>
 {<br>
 }<br>
<br>
+GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform,<br>
+                                                           const lldb::PlatformSP& platform_sp) :<br>
+    GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet", is_platform),<br>
+    m_platform_sp (platform_sp),<br>
+    m_async_thread (LLDB_INVALID_HOST_THREAD),<br>
+    m_process_launch_info (),<br>
+    m_process_launch_error (),<br>
+    m_spawned_pids (),<br>
+    m_spawned_pids_mutex (Mutex::eMutexTypeRecursive),<br>
+    m_proc_infos (),<br>
+    m_proc_infos_index (0),<br>
+    m_port_map (),<br>
+    m_port_offset(0)<br>
+{<br>
+    assert(platform_sp);<br>
+}<br>
+<br>
 //----------------------------------------------------------------------<br>
 // Destructor<br>
 //----------------------------------------------------------------------<br>
@@ -304,7 +323,7 @@ GDBRemoteCommunicationServer::LaunchProc<br>
     if (!m_process_launch_info.GetMonitorProcessCallback ())<br>
         m_process_launch_info.SetMonitorProcessCallback(ReapDebuggedProcess, this, false);<br>
<br>
-    lldb_private::Error error = Host::LaunchProcess (m_process_launch_info);<br>
+    lldb_private::Error error = m_platform_sp->LaunchProcess (m_process_launch_info);<br>
     if (!error.Success ())<br>
     {<br>
         fprintf (stderr, "%s: failed to launch executable %s", __FUNCTION__, m_process_launch_info.GetArguments ().GetArgumentAtIndex (0));<br>
<br>
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h?rev=200266&r1=200265&r2=200266&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h?rev=200266&r1=200265&r2=200266&view=diff</a><br>

==============================================================================<br>
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h (original)<br>
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h Mon Jan 27 18:34:23 2014<br>
@@ -37,6 +37,9 @@ public:<br>
     //------------------------------------------------------------------<br>
     GDBRemoteCommunicationServer(bool is_platform);<br>
<br>
+    GDBRemoteCommunicationServer(bool is_platform,<br>
+                                 const lldb::PlatformSP& platform_sp);<br>
+<br>
     virtual<br>
     ~GDBRemoteCommunicationServer();<br>
<br>
@@ -186,6 +189,7 @@ public:<br>
     LaunchProcess ();<br>
<br>
 protected:<br>
+    lldb::PlatformSP m_platform_sp;<br>
     lldb::thread_t m_async_thread;<br>
     lldb_private::ProcessLaunchInfo m_process_launch_info;<br>
     lldb_private::Error m_process_launch_error;<br>
@@ -195,7 +199,7 @@ protected:<br>
     uint32_t m_proc_infos_index;<br>
     PortMap m_port_map;<br>
     uint16_t m_port_offset;<br>
-<br>
+<br>
<br>
     PacketResult<br>
     SendUnimplementedResponse (const char *packet);<br>
<br>
Modified: lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp?rev=200266&r1=200265&r2=200266&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp?rev=200266&r1=200265&r2=200266&view=diff</a><br>

==============================================================================<br>
--- lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp (original)<br>
+++ lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp Mon Jan 27 18:34:23 2014<br>
@@ -26,12 +26,14 @@<br>
 #include "lldb/Core/ConnectionFileDescriptor.h"<br>
 #include "lldb/Core/ConnectionMachPort.h"<br>
 #include "lldb/Core/Debugger.h"<br>
+#include "lldb/Core/PluginManager.h"<br>
 #include "lldb/Core/StreamFile.h"<br>
 #include "lldb/Host/OptionParser.h"<br>
 #include "lldb/Interpreter/CommandInterpreter.h"<br>
 #include "lldb/Interpreter/CommandReturnObject.h"<br>
 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"<br>
 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"<br>
+<br>
 using namespace lldb;<br>
 using namespace lldb_private;<br>
<br>
@@ -45,6 +47,7 @@ int g_verbose = 0;<br>
 static struct option g_long_options[] =<br>
 {<br>
     { "debug",              no_argument,        &g_debug,           1   },<br>
+    { "platform",           required_argument,  NULL,               'p' },<br>
     { "verbose",            no_argument,        &g_verbose,         1   },<br>
     { "lldb-command",       required_argument,  NULL,               'c' },<br>
     { "log-file",           required_argument,  NULL,               'l' },<br>
@@ -78,11 +81,49 @@ signal_handler(int signo)<br>
 static void<br>
 display_usage (const char *progname)<br>
 {<br>
-    fprintf(stderr, "Usage:\n  %s [--log-file log-file-path] [--log-flags flags] [--lldb-command command]* HOST:PORT "<br>
+    fprintf(stderr, "Usage:\n  %s [--log-file log-file-path] [--log-flags flags] [--lldb-command command]* [--platform platform_name] HOST:PORT "<br>
             "[-- PROGRAM ARG1 ARG2 ...]\n", progname);<br>
     exit(0);<br>
 }<br>
<br>
+static void<br>
+dump_available_platforms (FILE *output_file)<br>
+{<br>
+    fprintf (output_file, "Available platform plugins:\n");<br>
+    for (int i = 0; ; ++i)<br>
+    {<br>
+        const char *plugin_name = PluginManager::GetPlatformPluginNameAtIndex (i);<br>
+        const char *plugin_desc = PluginManager::GetPlatformPluginDescriptionAtIndex (i);<br>
+<br>
+        if (!plugin_name || !plugin_desc)<br>
+            break;<br>
+<br>
+        fprintf (output_file, "%s\t%s\n", plugin_name, plugin_desc);<br>
+    }<br>
+<br>
+    if ( Platform::GetDefaultPlatform () )<br>
+    {<br>
+        // add this since the default platform doesn't necessarily get registered by<br>
+        // the plugin name (e.g. 'host' doesn't show up as a<br>
+        // registered platform plugin even though it's the default).<br>
+        fprintf (output_file, "%s\tDefault platform for this host.\n", Platform::GetDefaultPlatform ()->GetPluginName ().AsCString ());<br>
+    }<br>
+}<br>
+<br>
+static void<br>
+initialize_lldb_gdbserver ()<br>
+{<br>
+    PluginManager::Initialize ();<br>
+    Debugger::Initialize (NULL);<br>
+}<br>
+<br>
+static void<br>
+terminate_lldb_gdbserver ()<br>
+{<br>
+    Debugger::Terminate();<br>
+    PluginManager::Terminate ();<br>
+}<br>
+<br>
 //----------------------------------------------------------------------<br>
 // main<br>
 //----------------------------------------------------------------------<br>
@@ -97,7 +138,9 @@ main (int argc, char *argv[])<br>
     Args log_args;<br>
     Error error;<br>
     int ch;<br>
-    Debugger::Initialize(NULL);<br>
+    std::string platform_name;<br>
+<br>
+    initialize_lldb_gdbserver ();<br>
<br>
     lldb::DebuggerSP debugger_sp = Debugger::CreateInstance ();<br>
<br>
@@ -167,6 +210,11 @@ main (int argc, char *argv[])<br>
                 lldb_commands.push_back(optarg);<br>
             break;<br>
<br>
+        case 'p': // platform name<br>
+            if (optarg && optarg[0])<br>
+                platform_name = optarg;<br>
+            break;<br>
+<br>
         case 'h':   /* fall-through is intentional */<br>
         case '?':<br>
             show_usage = true;<br>
@@ -210,8 +258,39 @@ main (int argc, char *argv[])<br>
             puts (output);<br>
     }<br>
<br>
+    // setup the platform that GDBRemoteCommunicationServer will use<br>
+    lldb::PlatformSP platform_sp;<br>
+    if (platform_name.empty())<br>
+    {<br>
+        printf ("using the default platform: ");<br>
+        platform_sp = Platform::GetDefaultPlatform ();<br>
+        printf ("%s\n", platform_sp->GetPluginName ().AsCString ());<br>
+    }<br>
+    else<br>
+    {<br>
+        Error error;<br>
+        platform_sp = Platform::Create (platform_name.c_str(), error);<br>
+        if (error.Fail ())<br>
+        {<br>
+            // the host platform isn't registered with that name (at<br>
+            // least, not always.  Check if the given name matches<br>
+            // the default platform name.  If so, use it.<br>
+            if ( Platform::GetDefaultPlatform () && ( Platform::GetDefaultPlatform ()->GetPluginName () == ConstString (platform_name.c_str()) ) )<br>
+            {<br>
+                platform_sp = Platform::GetDefaultPlatform ();<br>
+            }<br>
+            else<br>
+            {<br>
+                fprintf (stderr, "error: failed to create platform with name '%s'\n", platform_name.c_str());<br>
+                dump_available_platforms (stderr);<br>
+                exit (1);<br>
+            }<br>
+        }<br>
+        printf ("using platform: %s\n", platform_name.c_str ());<br>
+    }<br>
+<br>
     const bool is_platform = false;<br>
-    GDBRemoteCommunicationServer gdb_server (is_platform);<br>
+    GDBRemoteCommunicationServer gdb_server (is_platform, platform_sp);<br>
<br>
     const char *host_and_port = argv[0];<br>
     argc -= 1;<br>
@@ -289,7 +368,7 @@ main (int argc, char *argv[])<br>
         }<br>
     }<br>
<br>
-    Debugger::Terminate();<br>
+    terminate_lldb_gdbserver ();<br>
<br>
     fprintf(stderr, "lldb-gdbserver exiting...\n");<br>
<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><table cellspacing="0" cellpadding="0" style="color:rgb(136,136,136);font-family:'Times New Roman'"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small">
<td nowrap style="border-top-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px">Todd Fiala |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px"> Software Engineer |</td>
<td nowrap style="border-top-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px"> <a href="mailto:tfiala@google.com" style="color:rgb(17,85,204)" target="_blank"><span style="background-color:rgb(255,255,204);color:rgb(34,34,34);background-repeat:initial initial">tfiala@google.com</span></a> |</td>
<td nowrap style="border-top-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px"><font color="#1155cc"> <a>650-943-3180</a></font></td></tr></tbody></table><br></div>
</div>