#include <cerrno>
#if defined(__APPLE__)
#include <netinet/in.h>
#endif
#include <csignal>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#if !defined(_WIN32)
#include <sys/wait.h>
#endif
#include <fstream>
#include <optional>
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include "LLDBServerUtilities.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/HostGetOpt.h"
#include "lldb/Host/MainLoop.h"
#include "lldb/Host/OptionParser.h"
#include "lldb/Host/Socket.h"
#include "lldb/Host/common/TCPSocket.h"
#if LLDB_ENABLE_POSIX
#include "lldb/Host/posix/DomainSocket.h"
#endif
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/UriParser.h"
usingnamespacelldb;
usingnamespacelldb_private;
usingnamespacelldb_private::lldb_server;
usingnamespacelldb_private::process_gdb_remote;
usingnamespacellvm;
static const int backlog = …;
static const int socket_error = …;
static int g_debug = …;
static int g_verbose = …;
static int g_server = …;
static struct option g_long_options[] = …;
#if defined(__APPLE__)
#define LOW_PORT …
#define HIGH_PORT …
#else
#define LOW_PORT …
#define HIGH_PORT …
#endif
#if !defined(_WIN32)
static void signal_handler(int signo) { … }
#endif
static void display_usage(const char *progname, const char *subcommand) { … }
static Status parse_listen_host_port(Socket::SocketProtocol &protocol,
const std::string &listen_host_port,
std::string &address,
uint16_t &platform_port,
std::string &gdb_address,
const uint16_t gdbserver_port) { … }
static Status save_socket_id_to_file(const std::string &socket_id,
const FileSpec &file_spec) { … }
static Status ListenGdbConnectionsIfNeeded(
const Socket::SocketProtocol protocol, std::unique_ptr<TCPSocket> &gdb_sock,
const std::string &gdb_address, uint16_t &gdbserver_port) { … }
static llvm::Expected<std::vector<MainLoopBase::ReadHandleUP>>
AcceptGdbConnectionsIfNeeded(const Socket::SocketProtocol protocol,
std::unique_ptr<TCPSocket> &gdb_sock,
MainLoop &main_loop, const uint16_t gdbserver_port,
const lldb_private::Args &args) { … }
static void client_handle(GDBRemoteCommunicationServerPlatform &platform,
const lldb_private::Args &args) { … }
static Status spawn_process(const char *progname, const Socket *conn_socket,
uint16_t gdb_port, const lldb_private::Args &args,
const std::string &log_file,
const StringRef log_channels, MainLoop &main_loop,
std::promise<void> &child_exited) { … }
int main_platform(int argc, char *argv[]) { … }