aboutsummaryrefslogtreecommitdiff
path: root/tools/lldb-server
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:55:28 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:55:28 +0000
commite81d9d49145e432d917eea3a70d2ae74dcad1d89 (patch)
tree9ed5e1a91f242e2cb5911577356e487a55c01b78 /tools/lldb-server
parent85d8ef8f1f0e0e063a8571944302be2d2026f823 (diff)
downloadsrc-e81d9d49145e432d917eea3a70d2ae74dcad1d89.tar.gz
src-e81d9d49145e432d917eea3a70d2ae74dcad1d89.zip
Vendor import of stripped lldb trunk r256633:
Notes
Notes: svn path=/vendor/lldb/dist/; revision=292932
Diffstat (limited to 'tools/lldb-server')
-rw-r--r--tools/lldb-server/Acceptor.cpp170
-rw-r--r--tools/lldb-server/Acceptor.h68
-rw-r--r--tools/lldb-server/LLDBServerUtilities.cpp2
-rw-r--r--tools/lldb-server/lldb-gdbserver.cpp158
-rw-r--r--tools/lldb-server/lldb-platform.cpp95
-rw-r--r--tools/lldb-server/lldb-server.exports (renamed from tools/lldb-server/exports)0
6 files changed, 339 insertions, 154 deletions
diff --git a/tools/lldb-server/Acceptor.cpp b/tools/lldb-server/Acceptor.cpp
new file mode 100644
index 000000000000..634319594853
--- /dev/null
+++ b/tools/lldb-server/Acceptor.cpp
@@ -0,0 +1,170 @@
+//===-- Acceptor.cpp --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Acceptor.h"
+
+#include "llvm/ADT/StringRef.h"
+
+#include "lldb/Core/StreamString.h"
+#include "lldb/Host/ConnectionFileDescriptor.h"
+#include "lldb/Host/common/TCPSocket.h"
+
+#include "Utility/UriParser.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::lldb_server;
+using namespace llvm;
+
+namespace {
+
+struct SocketScheme
+{
+ const char* m_scheme;
+ const Socket::SocketProtocol m_protocol;
+};
+
+SocketScheme socket_schemes[] = {
+ {"tcp", Socket::ProtocolTcp},
+ {"udp", Socket::ProtocolUdp},
+ {"unix", Socket::ProtocolUnixDomain},
+ {"unix-abstract", Socket::ProtocolUnixAbstract},
+};
+
+bool
+FindProtocolByScheme(const char* scheme, Socket::SocketProtocol& protocol)
+{
+ for (auto s: socket_schemes)
+ {
+ if (!strcmp(s.m_scheme, scheme))
+ {
+ protocol = s.m_protocol;
+ return true;
+ }
+ }
+ return false;
+}
+
+const char*
+FindSchemeByProtocol(const Socket::SocketProtocol protocol)
+{
+ for (auto s: socket_schemes)
+ {
+ if (s.m_protocol == protocol)
+ return s.m_scheme;
+ }
+ return nullptr;
+}
+
+}
+
+Error
+Acceptor::Listen(int backlog)
+{
+ return m_listener_socket_up->Listen(StringRef(m_name.c_str()),
+ backlog);
+}
+
+Error
+Acceptor::Accept(const bool child_processes_inherit, Connection *&conn)
+{
+ Socket* conn_socket = nullptr;
+ auto error = m_listener_socket_up->Accept(StringRef(m_name.c_str()),
+ child_processes_inherit,
+ conn_socket);
+ if (error.Success())
+ conn = new ConnectionFileDescriptor(conn_socket);
+
+ return error;
+}
+
+Socket::SocketProtocol
+Acceptor::GetSocketProtocol() const
+{
+ return m_listener_socket_up->GetSocketProtocol();
+}
+
+const char*
+Acceptor::GetSocketScheme() const
+{
+ return FindSchemeByProtocol(GetSocketProtocol());
+}
+
+std::string
+Acceptor::GetLocalSocketId() const
+{
+ return m_local_socket_id();
+}
+
+std::unique_ptr<Acceptor>
+Acceptor::Create(StringRef name, const bool child_processes_inherit, Error &error)
+{
+ error.Clear();
+
+ Socket::SocketProtocol socket_protocol = Socket::ProtocolUnixDomain;
+ int port;
+ std::string scheme, host, path;
+ // Try to match socket name as URL - e.g., tcp://localhost:5555
+ if (UriParser::Parse(name.str(), scheme, host, port, path))
+ {
+ if (!FindProtocolByScheme(scheme.c_str(), socket_protocol))
+ error.SetErrorStringWithFormat("Unknown protocol scheme \"%s\"", scheme.c_str());
+ else
+ name = name.drop_front(scheme.size() + strlen("://"));
+ }
+ else
+ {
+ std::string host_str;
+ std::string port_str;
+ int32_t port = INT32_MIN;
+ // Try to match socket name as $host:port - e.g., localhost:5555
+ if (Socket::DecodeHostAndPort (name, host_str, port_str, port, nullptr))
+ socket_protocol = Socket::ProtocolTcp;
+ }
+
+ if (error.Fail())
+ return std::unique_ptr<Acceptor>();
+
+ std::unique_ptr<Socket> listener_socket_up = Socket::Create(
+ socket_protocol, child_processes_inherit, error);
+
+ LocalSocketIdFunc local_socket_id;
+ if (error.Success())
+ {
+ if (listener_socket_up->GetSocketProtocol() == Socket::ProtocolTcp)
+ {
+ TCPSocket* tcp_socket = static_cast<TCPSocket*>(listener_socket_up.get());
+ local_socket_id = [tcp_socket]() {
+ auto local_port = tcp_socket->GetLocalPortNumber();
+ return (local_port != 0) ? std::to_string(local_port) : "";
+ };
+ }
+ else
+ {
+ const std::string socket_name = name;
+ local_socket_id = [socket_name](){
+ return socket_name;
+ };
+ }
+
+ return std::unique_ptr<Acceptor>(
+ new Acceptor(std::move(listener_socket_up), name, local_socket_id));
+ }
+
+ return std::unique_ptr<Acceptor>();
+}
+
+Acceptor::Acceptor(std::unique_ptr<Socket> &&listener_socket,
+ StringRef name,
+ const LocalSocketIdFunc &local_socket_id)
+ : m_listener_socket_up(std::move(listener_socket)),
+ m_name(name.str()),
+ m_local_socket_id(local_socket_id)
+{
+}
diff --git a/tools/lldb-server/Acceptor.h b/tools/lldb-server/Acceptor.h
new file mode 100644
index 000000000000..37fba26c881f
--- /dev/null
+++ b/tools/lldb-server/Acceptor.h
@@ -0,0 +1,68 @@
+//===-- Acceptor.h ----------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef lldb_server_Acceptor_h_
+#define lldb_server_Acceptor_h_
+
+#include "lldb/Core/Connection.h"
+#include "lldb/Core/Error.h"
+#include "lldb/Host/Socket.h"
+
+#include <functional>
+#include <memory>
+#include <string>
+
+namespace llvm
+{
+ class StringRef;
+}
+
+namespace lldb_private {
+namespace lldb_server {
+
+class Acceptor
+{
+public:
+ virtual ~Acceptor() = default;
+
+ Error
+ Listen(int backlog);
+
+ Error
+ Accept(const bool child_processes_inherit, Connection *&conn);
+
+ static std::unique_ptr<Acceptor>
+ Create(llvm::StringRef name, const bool child_processes_inherit, Error &error);
+
+ Socket::SocketProtocol
+ GetSocketProtocol() const;
+
+ const char*
+ GetSocketScheme() const;
+
+ // Returns either TCP port number as string or domain socket path.
+ // Empty string is returned in case of error.
+ std::string
+ GetLocalSocketId() const;
+
+private:
+ typedef std::function<std::string()> LocalSocketIdFunc;
+
+ Acceptor(std::unique_ptr<Socket> &&listener_socket,
+ llvm::StringRef name,
+ const LocalSocketIdFunc &local_socket_id);
+
+ const std::unique_ptr<Socket> m_listener_socket_up;
+ const std::string m_name;
+ const LocalSocketIdFunc m_local_socket_id;
+};
+
+} // namespace lldb_server
+} // namespace lldb_private
+
+#endif // lldb_server_Acceptor_h_
diff --git a/tools/lldb-server/LLDBServerUtilities.cpp b/tools/lldb-server/LLDBServerUtilities.cpp
index 8df4875e5d1d..438d9f127d63 100644
--- a/tools/lldb-server/LLDBServerUtilities.cpp
+++ b/tools/lldb-server/LLDBServerUtilities.cpp
@@ -42,7 +42,7 @@ LLDBServerUtilities::SetupLogging(const std::string& log_file,
}
SmallVector<StringRef, 32> channel_array;
- log_channels.split(channel_array, ":");
+ log_channels.split(channel_array, ":", /*MaxSplit*/ -1, /*KeepEmpty*/ false);
for (auto channel_with_categories : channel_array)
{
StreamString error_stream;
diff --git a/tools/lldb-server/lldb-gdbserver.cpp b/tools/lldb-server/lldb-gdbserver.cpp
index 30bb2d686770..df8cb6e68554 100644
--- a/tools/lldb-server/lldb-gdbserver.cpp
+++ b/tools/lldb-server/lldb-gdbserver.cpp
@@ -9,7 +9,6 @@
// C Includes
#include <errno.h>
-#include <getopt.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -25,17 +24,16 @@
// Other libraries and framework includes
#include "llvm/ADT/StringRef.h"
-#include "lldb/Core/ConnectionMachPort.h"
#include "lldb/Core/Error.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
-#include "lldb/Host/HostThread.h"
+#include "lldb/Host/HostGetOpt.h"
#include "lldb/Host/OptionParser.h"
#include "lldb/Host/Pipe.h"
#include "lldb/Host/Socket.h"
#include "lldb/Host/StringConvert.h"
-#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Target/Platform.h"
+#include "Acceptor.h"
#include "LLDBServerUtilities.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
@@ -54,15 +52,6 @@ using namespace lldb_private;
using namespace lldb_private::lldb_server;
using namespace lldb_private::process_gdb_remote;
-// lldb-gdbserver state
-
-namespace
-{
-HostThread s_listen_thread;
- std::unique_ptr<ConnectionFileDescriptor> s_listen_connection_up;
- std::string s_listen_url;
-}
-
//----------------------------------------------------------------------
// option descriptors for getopt_long_only()
//----------------------------------------------------------------------
@@ -263,64 +252,16 @@ handle_launch (GDBRemoteCommunicationServerLLGS &gdb_server, int argc, const cha
}
}
-static lldb::thread_result_t
-ListenThread (lldb::thread_arg_t /* arg */)
-{
- Error error;
-
- if (s_listen_connection_up)
- {
- // Do the listen on another thread so we can continue on...
- if (s_listen_connection_up->Connect(s_listen_url.c_str(), &error) != eConnectionStatusSuccess)
- s_listen_connection_up.reset();
- }
- return nullptr;
-}
-
-static Error
-StartListenThread (const char *hostname, uint16_t port)
-{
- Error error;
- if (s_listen_thread.IsJoinable())
- {
- error.SetErrorString("listen thread already running");
- }
- else
- {
- char listen_url[512];
- if (hostname && hostname[0])
- snprintf(listen_url, sizeof(listen_url), "listen://%s:%i", hostname, port);
- else
- snprintf(listen_url, sizeof(listen_url), "listen://%i", port);
-
- s_listen_url = listen_url;
- s_listen_connection_up.reset (new ConnectionFileDescriptor ());
- s_listen_thread = ThreadLauncher::LaunchThread(listen_url, ListenThread, nullptr, &error);
- }
- return error;
-}
-
-static bool
-JoinListenThread ()
-{
- if (s_listen_thread.IsJoinable())
- s_listen_thread.Join(nullptr);
- return true;
-}
-
Error
-WritePortToPipe(Pipe &port_pipe, const uint16_t port)
+writeSocketIdToPipe(Pipe &port_pipe, const std::string &socket_id)
{
- char port_str[64];
- const auto port_str_len = ::snprintf(port_str, sizeof(port_str), "%u", port);
-
size_t bytes_written = 0;
// Write the port number as a C string with the NULL terminator.
- return port_pipe.Write(port_str, port_str_len + 1, bytes_written);
+ return port_pipe.Write(socket_id.c_str(), socket_id.size() + 1, bytes_written);
}
Error
-writePortToPipe(const char *const named_pipe_path, const uint16_t port)
+writeSocketIdToPipe(const char *const named_pipe_path, const std::string &socket_id)
{
Pipe port_name_pipe;
// Wait for 10 seconds for pipe to be opened.
@@ -328,17 +269,17 @@ writePortToPipe(const char *const named_pipe_path, const uint16_t port)
std::chrono::seconds{10});
if (error.Fail())
return error;
- return WritePortToPipe(port_name_pipe, port);
+ return writeSocketIdToPipe(port_name_pipe, socket_id);
}
Error
-writePortToPipe(int unnamed_pipe_fd, const uint16_t port)
+writeSocketIdToPipe(int unnamed_pipe_fd, const std::string &socket_id)
{
#if defined(_WIN32)
return Error("Unnamed pipes are not supported on Windows.");
#else
Pipe port_pipe{Pipe::kInvalidDescriptor, unnamed_pipe_fd};
- return WritePortToPipe(port_pipe, port);
+ return writeSocketIdToPipe(port_pipe, socket_id);
#endif
}
@@ -370,14 +311,8 @@ ConnectToRemote(MainLoop &mainloop, GDBRemoteCommunicationServerLLGS &gdb_server
connection_port = final_host_and_port.substr (colon_pos + 1);
connection_portno = StringConvert::ToUInt32 (connection_port.c_str (), 0);
}
- else
- {
- fprintf (stderr, "failed to parse host and port from connection string '%s'\n", final_host_and_port.c_str ());
- display_usage (progname, subcommand);
- exit (1);
- }
- std::unique_ptr<ConnectionFileDescriptor> connection_up;
+ std::unique_ptr<Connection> connection_up;
if (reverse_connect)
{
@@ -410,66 +345,51 @@ ConnectToRemote(MainLoop &mainloop, GDBRemoteCommunicationServerLLGS &gdb_server
}
else
{
- // llgs will listen for connections on the given port from the given address.
- // Start the listener on a new thread. We need to do this so we can resolve the
- // bound listener port.
- StartListenThread(connection_host.c_str (), static_cast<uint16_t> (connection_portno));
- printf ("Listening to port %s for a connection from %s...\n", connection_port.c_str (), connection_host.c_str ());
-
- // If we have a named pipe to write the port number back to, do that now.
- if (named_pipe_path && named_pipe_path[0] && connection_portno == 0)
+ std::unique_ptr<Acceptor> acceptor_up(Acceptor::Create(final_host_and_port, false, error));
+ if (error.Fail())
+ {
+ fprintf(stderr, "failed to create acceptor: %s", error.AsCString());
+ exit(1);
+ }
+ error = acceptor_up->Listen(1);
+ if (error.Fail())
{
- const uint16_t bound_port = s_listen_connection_up->GetListeningPort (10);
- if (bound_port > 0)
+ fprintf(stderr, "failed to listen: %s\n", error.AsCString());
+ exit(1);
+ }
+ const std::string socket_id = acceptor_up->GetLocalSocketId();
+ if (!socket_id.empty())
+ {
+ // If we have a named pipe to write the socket id back to, do that now.
+ if (named_pipe_path && named_pipe_path[0])
{
- error = writePortToPipe (named_pipe_path, bound_port);
+ error = writeSocketIdToPipe (named_pipe_path, socket_id);
if (error.Fail ())
- {
- fprintf (stderr, "failed to write to the named pipe \'%s\': %s", named_pipe_path, error.AsCString());
- }
+ fprintf (stderr, "failed to write to the named pipe \'%s\': %s",
+ named_pipe_path, error.AsCString());
}
- else
+ // If we have an unnamed pipe to write the socket id back to, do that now.
+ else if (unnamed_pipe_fd >= 0)
{
- fprintf (stderr, "unable to get the bound port for the listening connection\n");
- }
- }
-
- // If we have an unnamed pipe to write the port number back to, do that now.
- if (unnamed_pipe_fd >= 0 && connection_portno == 0)
- {
- const uint16_t bound_port = s_listen_connection_up->GetListeningPort(10);
- if (bound_port > 0)
- {
- error = writePortToPipe(unnamed_pipe_fd, bound_port);
+ error = writeSocketIdToPipe(unnamed_pipe_fd, socket_id);
if (error.Fail())
- {
fprintf(stderr, "failed to write to the unnamed pipe: %s",
error.AsCString());
- }
- }
- else
- {
- fprintf(stderr, "unable to get the bound port for the listening connection\n");
}
}
-
- // Join the listener thread.
- if (!JoinListenThread ())
+ else
{
- fprintf (stderr, "failed to join the listener thread\n");
- display_usage (progname, subcommand);
- exit (1);
+ fprintf (stderr, "unable to get the socket id for the listening connection\n");
}
- // Ensure we connected.
- if (s_listen_connection_up)
- connection_up = std::move(s_listen_connection_up);
- else
+ Connection* conn = nullptr;
+ error = acceptor_up->Accept(false, conn);
+ if (error.Fail())
{
- fprintf (stderr, "failed to connect to '%s': %s\n", final_host_and_port.c_str (), error.AsCString ());
- display_usage (progname, subcommand);
- exit (1);
+ printf ("failed to accept new connection: %s\n", error.AsCString());
+ exit(1);
}
+ connection_up.reset(conn);
}
error = gdb_server.InitializeConnection (std::move(connection_up));
if (error.Fail())
diff --git a/tools/lldb-server/lldb-platform.cpp b/tools/lldb-server/lldb-platform.cpp
index 4dfa7d23a4a8..3292080da63a 100644
--- a/tools/lldb-server/lldb-platform.cpp
+++ b/tools/lldb-server/lldb-platform.cpp
@@ -23,15 +23,17 @@
#include <fstream>
// Other libraries and framework includes
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+
#include "lldb/Core/Error.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostGetOpt.h"
#include "lldb/Host/OptionParser.h"
-#include "lldb/Host/Socket.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
+#include "lldb/Host/common/TCPSocket.h"
+#include "Acceptor.h"
#include "LLDBServerUtilities.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
@@ -61,7 +63,7 @@ static struct option g_long_options[] =
{ "gdbserver-port", required_argument, NULL, 'P' },
{ "min-gdbserver-port", required_argument, NULL, 'm' },
{ "max-gdbserver-port", required_argument, NULL, 'M' },
- { "port-file", required_argument, NULL, 'f' },
+ { "socket-file", required_argument, NULL, 'f' },
{ "server", no_argument, &g_server, 1 },
{ NULL, 0, NULL, 0 }
};
@@ -100,9 +102,9 @@ display_usage (const char *progname, const char *subcommand)
}
static Error
-save_port_to_file(const uint16_t port, const FileSpec &port_file_spec)
+save_socket_id_to_file(const std::string &socket_id, const FileSpec &file_spec)
{
- FileSpec temp_file_spec(port_file_spec.GetDirectory().AsCString(), false);
+ FileSpec temp_file_spec(file_spec.GetDirectory().AsCString(), false);
auto error = FileSystem::MakeDirectory(temp_file_spec, eFilePermissionsDirectoryDefault);
if (error.Fail())
return Error("Failed to create directory %s: %s", temp_file_spec.GetCString(), error.AsCString());
@@ -119,13 +121,13 @@ save_port_to_file(const uint16_t port, const FileSpec &port_file_spec)
std::ofstream temp_file(temp_file_path.c_str(), std::ios::out);
if (!temp_file.is_open())
return Error("Failed to open temp file %s", temp_file_path.c_str());
- temp_file << port;
+ temp_file << socket_id;
}
- err_code = llvm::sys::fs::rename(temp_file_path.c_str(), port_file_spec.GetPath().c_str());
+ err_code = llvm::sys::fs::rename(temp_file_path.c_str(), file_spec.GetPath().c_str());
if (err_code)
return Error("Failed to rename file %s to %s: %s",
- temp_file_path.c_str(), port_file_spec.GetPath().c_str(), err_code.message().c_str());
+ temp_file_path.c_str(), file_spec.GetPath().c_str(), err_code.message().c_str());
tmp_file_remover.releaseFile();
return Error();
@@ -156,7 +158,7 @@ main_platform (int argc, char *argv[])
int max_gdbserver_port = 0;
uint16_t port_offset = 0;
- FileSpec port_file;
+ FileSpec socket_file;
bool show_usage = false;
int option_error = 0;
int socket_error = -1;
@@ -191,9 +193,9 @@ main_platform (int argc, char *argv[])
log_channels = StringRef(optarg);
break;
- case 'f': // Port file
+ case 'f': // Socket file
if (optarg && optarg[0])
- port_file.SetFile(optarg, false);
+ socket_file.SetFile(optarg, false);
break;
case 'p':
@@ -282,36 +284,46 @@ main_platform (int argc, char *argv[])
display_usage(progname, subcommand);
exit(option_error);
}
-
- std::unique_ptr<Socket> listening_socket_up;
- Socket *socket = nullptr;
- const bool children_inherit_listen_socket = false;
+ // Skip any options we consumed with getopt_long_only.
+ argc -= optind;
+ argv += optind;
+ lldb_private::Args inferior_arguments;
+ inferior_arguments.SetArguments(argc, const_cast<const char**>(argv));
+
+ const bool children_inherit_listen_socket = false;
// the test suite makes many connections in parallel, let's not miss any.
- // The highest this should get reasonably is a function of the number
- // of target CPUs. For now, let's just use 100
+ // The highest this should get reasonably is a function of the number
+ // of target CPUs. For now, let's just use 100.
const int backlog = 100;
- error = Socket::TcpListen(listen_host_port.c_str(), children_inherit_listen_socket, socket, NULL, backlog);
+
+ std::unique_ptr<Acceptor> acceptor_up(Acceptor::Create(listen_host_port, children_inherit_listen_socket, error));
if (error.Fail())
{
- printf("error: %s\n", error.AsCString());
+ fprintf(stderr, "failed to create acceptor: %s", error.AsCString());
exit(socket_error);
}
- listening_socket_up.reset(socket);
- printf ("Listening for a connection from %u...\n", listening_socket_up->GetLocalPortNumber());
- if (port_file)
+
+ error = acceptor_up->Listen(backlog);
+ if (error.Fail())
+ {
+ printf("failed to listen: %s\n", error.AsCString());
+ exit(socket_error);
+ }
+ if (socket_file)
{
- error = save_port_to_file(listening_socket_up->GetLocalPortNumber(), port_file);
+ error = save_socket_id_to_file(acceptor_up->GetLocalSocketId(), socket_file);
if (error.Fail())
{
- fprintf(stderr, "failed to write port to %s: %s", port_file.GetPath().c_str(), error.AsCString());
+ fprintf(stderr, "failed to write socket id to %s: %s\n", socket_file.GetPath().c_str(), error.AsCString());
return 1;
}
}
do {
- GDBRemoteCommunicationServerPlatform platform;
-
+ GDBRemoteCommunicationServerPlatform platform(acceptor_up->GetSocketProtocol(),
+ acceptor_up->GetSocketScheme());
+
if (port_offset > 0)
platform.SetPortOffset(port_offset);
@@ -321,8 +333,8 @@ main_platform (int argc, char *argv[])
}
const bool children_inherit_accept_socket = true;
- socket = nullptr;
- error = listening_socket_up->BlockingAccept(listen_host_port.c_str(), children_inherit_accept_socket, socket);
+ Connection* conn = nullptr;
+ error = acceptor_up->Accept(children_inherit_accept_socket, conn);
if (error.Fail())
{
printf ("error: %s\n", error.AsCString());
@@ -336,8 +348,7 @@ main_platform (int argc, char *argv[])
if (fork())
{
// Parent doesn't need a connection to the lldb client
- delete socket;
- socket = nullptr;
+ delete conn;
// Parent will continue to listen for new connections.
continue;
@@ -347,19 +358,35 @@ main_platform (int argc, char *argv[])
// Child process will handle the connection and exit.
g_server = 0;
// Listening socket is owned by parent process.
- listening_socket_up.release();
+ acceptor_up.release();
}
}
else
{
// If not running as a server, this process will not accept
// connections while a connection is active.
- listening_socket_up.reset();
+ acceptor_up.reset();
}
- platform.SetConnection (new ConnectionFileDescriptor(socket));
+ platform.SetConnection (conn);
if (platform.IsConnected())
{
+ if (inferior_arguments.GetArgumentCount() > 0)
+ {
+ lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
+ uint16_t port = 0;
+ std::string socket_name;
+ Error error = platform.LaunchGDBServer(inferior_arguments,
+ "", // hostname
+ pid,
+ port,
+ socket_name);
+ if (error.Success())
+ platform.SetPendingGdbServer(pid, port, socket_name);
+ else
+ fprintf(stderr, "failed to start gdbserver: %s\n", error.AsCString());
+ }
+
// After we connected, we need to get an initial ack from...
if (platform.HandshakeWithClient())
{
diff --git a/tools/lldb-server/exports b/tools/lldb-server/lldb-server.exports
index e69de29bb2d1..e69de29bb2d1 100644
--- a/tools/lldb-server/exports
+++ b/tools/lldb-server/lldb-server.exports