diff options
3 files changed, 108 insertions, 6 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp index f002cc05041..df95542d2c0 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp @@ -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::GDBRemoteCommunicationServer(bool is_platform) : { } +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::LaunchProcess () 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)); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h index 6085016665d..913c6b673cf 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h @@ -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); diff --git a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp index 54b47712672..1034a780eec 100644 --- a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp +++ b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp @@ -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"); |