#include <cerrno>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#ifndef _WIN32
#include <csignal>
#include <unistd.h>
#endif
#include "LLDBServerUtilities.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
#include "lldb/Host/Config.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Pipe.h"
#include "lldb/Host/Socket.h"
#include "lldb/Host/common/NativeProcessProtocol.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Status.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/WithColor.h"
#if defined(__linux__)
#include "Plugins/Process/Linux/NativeProcessLinux.h"
#elif defined(__FreeBSD__)
#include "Plugins/Process/FreeBSD/NativeProcessFreeBSD.h"
#elif defined(__NetBSD__)
#include "Plugins/Process/NetBSD/NativeProcessNetBSD.h"
#elif defined(_WIN32)
#include "Plugins/Process/Windows/Common/NativeProcessWindows.h"
#endif
#ifndef LLGS_PROGRAM_NAME
#define LLGS_PROGRAM_NAME …
#endif
#ifndef LLGS_VERSION_STR
#define LLGS_VERSION_STR …
#endif
usingnamespacellvm;
usingnamespacelldb;
usingnamespacelldb_private;
usingnamespacelldb_private::lldb_server;
usingnamespacelldb_private::process_gdb_remote;
namespace {
#if defined(__linux__)
NativeProcessManager;
#elif defined(__FreeBSD__)
typedef process_freebsd::NativeProcessFreeBSD::Manager NativeProcessManager;
#elif defined(__NetBSD__)
typedef process_netbsd::NativeProcessNetBSD::Manager NativeProcessManager;
#elif defined(_WIN32)
typedef NativeProcessWindows::Manager NativeProcessManager;
#else
class NativeProcessManager : public NativeProcessProtocol::Manager {
public:
NativeProcessManager(MainLoop &mainloop)
: NativeProcessProtocol::Manager(mainloop) {}
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
Launch(ProcessLaunchInfo &launch_info,
NativeProcessProtocol::NativeDelegate &native_delegate) override {
llvm_unreachable("Not implemented");
}
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
Attach(lldb::pid_t pid,
NativeProcessProtocol::NativeDelegate &native_delegate) override {
llvm_unreachable("Not implemented");
}
};
#endif
}
#ifndef _WIN32
static int g_sighup_received_count = …;
static void sighup_handler(MainLoopBase &mainloop) { … }
#endif
void handle_attach_to_pid(GDBRemoteCommunicationServerLLGS &gdb_server,
lldb::pid_t pid) { … }
void handle_attach_to_process_name(GDBRemoteCommunicationServerLLGS &gdb_server,
const std::string &process_name) { … }
void handle_attach(GDBRemoteCommunicationServerLLGS &gdb_server,
const std::string &attach_target) { … }
void handle_launch(GDBRemoteCommunicationServerLLGS &gdb_server,
llvm::ArrayRef<llvm::StringRef> Arguments) { … }
Status writeSocketIdToPipe(Pipe &port_pipe, llvm::StringRef socket_id) { … }
Status writeSocketIdToPipe(const char *const named_pipe_path,
llvm::StringRef socket_id) { … }
Status writeSocketIdToPipe(lldb::pipe_t unnamed_pipe,
llvm::StringRef socket_id) { … }
void ConnectToRemote(MainLoop &mainloop,
GDBRemoteCommunicationServerLLGS &gdb_server,
bool reverse_connect, llvm::StringRef host_and_port,
const char *const progname, const char *const subcommand,
const char *const named_pipe_path, pipe_t unnamed_pipe,
shared_fd_t connection_fd) { … }
namespace {
usingnamespacellvm::opt;
enum ID { … };
#define PREFIX …
#include "LLGSOptions.inc"
#undef PREFIX
static constexpr opt::OptTable::Info InfoTable[] = …;
class LLGSOptTable : public opt::GenericOptTable { … };
}
int main_gdbserver(int argc, char *argv[]) { … }