[Lldb-commits] [lldb] r200266 - Modified GDBProcessCommunicationServer to launch via the platform.

Todd Fiala tfiala at google.com
Mon Jan 27 16:34:23 PST 2014


Author: tfiala
Date: Mon Jan 27 18:34:23 2014
New Revision: 200266

URL: http://llvm.org/viewvc/llvm-project?rev=200266&view=rev
Log:
Modified GDBProcessCommunicationServer to launch via the platform.

GDBProcessCommunicationServer now optionally takes a PlatformSP that
defaults to the default platform for the host.
GDBProcessCommunicationServer::LaunchProcess () now uses the platform
to launch the process.

lldb-gdbserver now takes an optional --platform={platform_plugin_name}
or -p {platform_plugin_name} command line option. If no platform is
specified, the default platform for the host is used; otherwise, if
the platform_plugin_name matches a registered platform plugin or
matches the default platform's name (which is not necessarily
registered by name in the case of 'host'), that platform is used. If
the platform name cannot be resolved, lldb-gdbserver exits after
printing all the available platform plugin names and the default
platform plugin name.

Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
    lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp

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

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

Modified: lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp?rev=200266&r1=200265&r2=200266&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp (original)
+++ lldb/trunk/tools/lldb-gdbserver/lldb-gdbserver.cpp Mon Jan 27 18:34:23 2014
@@ -26,12 +26,14 @@
 #include "lldb/Core/ConnectionFileDescriptor.h"
 #include "lldb/Core/ConnectionMachPort.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Host/OptionParser.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -45,6 +47,7 @@ int g_verbose = 0;
 static struct option g_long_options[] =
 {
     { "debug",              no_argument,        &g_debug,           1   },
+    { "platform",           required_argument,  NULL,               'p' },
     { "verbose",            no_argument,        &g_verbose,         1   },
     { "lldb-command",       required_argument,  NULL,               'c' },
     { "log-file",           required_argument,  NULL,               'l' },
@@ -78,11 +81,49 @@ signal_handler(int signo)
 static void
 display_usage (const char *progname)
 {
-    fprintf(stderr, "Usage:\n  %s [--log-file log-file-path] [--log-flags flags] [--lldb-command command]* HOST:PORT "
+    fprintf(stderr, "Usage:\n  %s [--log-file log-file-path] [--log-flags flags] [--lldb-command command]* [--platform platform_name] HOST:PORT "
             "[-- PROGRAM ARG1 ARG2 ...]\n", progname);
     exit(0);
 }
 
+static void
+dump_available_platforms (FILE *output_file)
+{
+    fprintf (output_file, "Available platform plugins:\n");
+    for (int i = 0; ; ++i)
+    {
+        const char *plugin_name = PluginManager::GetPlatformPluginNameAtIndex (i);
+        const char *plugin_desc = PluginManager::GetPlatformPluginDescriptionAtIndex (i);
+
+        if (!plugin_name || !plugin_desc)
+            break;
+
+        fprintf (output_file, "%s\t%s\n", plugin_name, plugin_desc);
+    }
+
+    if ( Platform::GetDefaultPlatform () )
+    {
+        // add this since the default platform doesn't necessarily get registered by
+        // the plugin name (e.g. 'host' doesn't show up as a
+        // registered platform plugin even though it's the default).
+        fprintf (output_file, "%s\tDefault platform for this host.\n", Platform::GetDefaultPlatform ()->GetPluginName ().AsCString ());
+    }
+}
+
+static void
+initialize_lldb_gdbserver ()
+{
+    PluginManager::Initialize ();
+    Debugger::Initialize (NULL);
+}
+
+static void
+terminate_lldb_gdbserver ()
+{
+    Debugger::Terminate();
+    PluginManager::Terminate ();
+}
+
 //----------------------------------------------------------------------
 // main
 //----------------------------------------------------------------------
@@ -97,7 +138,9 @@ main (int argc, char *argv[])
     Args log_args;
     Error error;
     int ch;
-    Debugger::Initialize(NULL);
+    std::string platform_name;
+
+    initialize_lldb_gdbserver ();
 
     lldb::DebuggerSP debugger_sp = Debugger::CreateInstance ();
 
@@ -167,6 +210,11 @@ main (int argc, char *argv[])
                 lldb_commands.push_back(optarg);
             break;
 
+        case 'p': // platform name
+            if (optarg && optarg[0])
+                platform_name = optarg;
+            break;
+
         case 'h':   /* fall-through is intentional */
         case '?':
             show_usage = true;
@@ -210,8 +258,39 @@ main (int argc, char *argv[])
             puts (output);
     }
 
+    // setup the platform that GDBRemoteCommunicationServer will use
+    lldb::PlatformSP platform_sp;
+    if (platform_name.empty())
+    {
+        printf ("using the default platform: ");
+        platform_sp = Platform::GetDefaultPlatform ();
+        printf ("%s\n", platform_sp->GetPluginName ().AsCString ());
+    }
+    else
+    {
+        Error error;
+        platform_sp = Platform::Create (platform_name.c_str(), error);
+        if (error.Fail ())
+        {
+            // the host platform isn't registered with that name (at
+            // least, not always.  Check if the given name matches
+            // the default platform name.  If so, use it.
+            if ( Platform::GetDefaultPlatform () && ( Platform::GetDefaultPlatform ()->GetPluginName () == ConstString (platform_name.c_str()) ) )
+            {
+                platform_sp = Platform::GetDefaultPlatform ();
+            }
+            else
+            {
+                fprintf (stderr, "error: failed to create platform with name '%s'\n", platform_name.c_str());
+                dump_available_platforms (stderr);
+                exit (1);
+            }
+        }
+        printf ("using platform: %s\n", platform_name.c_str ());
+    }
+
     const bool is_platform = false;
-    GDBRemoteCommunicationServer gdb_server (is_platform);
+    GDBRemoteCommunicationServer gdb_server (is_platform, platform_sp);
 
     const char *host_and_port = argv[0];
     argc -= 1;
@@ -289,7 +368,7 @@ main (int argc, char *argv[])
         }
     }
 
-    Debugger::Terminate();
+    terminate_lldb_gdbserver ();
 
     fprintf(stderr, "lldb-gdbserver exiting...\n");
 





More information about the lldb-commits mailing list