Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ FileSpec GDBRemoteCommunication::GetDebugserverPath(Platform *platform) {

Status GDBRemoteCommunication::StartDebugserverProcess(
const char *url, Platform *platform, ProcessLaunchInfo &launch_info,
uint16_t *port, const Args *inferior_args, int pass_comm_fd) {
uint16_t *port, const Args *inferior_args, shared_fd_t pass_comm_fd) {
Log *log = GetLog(GDBRLog::Process);
LLDB_LOGF(log, "GDBRemoteCommunication::%s(url=%s, port=%" PRIu16 ")",
__FUNCTION__, url ? url : "<empty>", port ? *port : uint16_t(0));
Expand All @@ -962,16 +962,19 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
#endif

// If a url is supplied then use it
if (url)
if (url && url[0])
debugserver_args.AppendArgument(llvm::StringRef(url));

if (pass_comm_fd >= 0) {
if (pass_comm_fd != SharedSocket::kInvalidFD) {
StreamString fd_arg;
fd_arg.Printf("--fd=%i", pass_comm_fd);
fd_arg.Printf("--fd=%" PRIi64, (int64_t)pass_comm_fd);
debugserver_args.AppendArgument(fd_arg.GetString());
// Send "pass_comm_fd" down to the inferior so it can use it to
// communicate back with this process
launch_info.AppendDuplicateFileAction(pass_comm_fd, pass_comm_fd);
// communicate back with this process. Ignored on Windows.
#ifndef _WIN32
launch_info.AppendDuplicateFileAction((int)pass_comm_fd,
(int)pass_comm_fd);
#endif
}

// use native registers, not the GDB registers
Expand All @@ -991,7 +994,7 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
// port is null when debug server should listen on domain socket - we're
// not interested in port value but rather waiting for debug server to
// become available.
if (pass_comm_fd == -1) {
if (pass_comm_fd == SharedSocket::kInvalidFD) {
if (url) {
// Create a temporary file to get the stdout/stderr and redirect the output of
// the command into this file. We will later read this file if all goes well
Expand Down Expand Up @@ -1137,7 +1140,7 @@ Status GDBRemoteCommunication::StartDebugserverProcess(

if (error.Success() &&
(launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) &&
pass_comm_fd == -1) {
pass_comm_fd == SharedSocket::kInvalidFD) {
if (named_pipe_path.size() > 0) {
error = socket_pipe.OpenAsReader(named_pipe_path, false);
if (error.Fail())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "lldb/Core/Communication.h"
#include "lldb/Host/Config.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/Socket.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Listener.h"
#include "lldb/Utility/Predicate.h"
Expand Down Expand Up @@ -156,8 +157,8 @@ class GDBRemoteCommunication : public Communication {
Platform *platform, // If non nullptr, then check with the platform for
// the GDB server binary if it can't be located
ProcessLaunchInfo &launch_info, uint16_t *port, const Args *inferior_args,
int pass_comm_fd); // Communication file descriptor to pass during
// fork/exec to avoid having to connect/accept
shared_fd_t pass_comm_fd); // Communication file descriptor to pass during
// fork/exec to avoid having to connect/accept

void DumpHistory(Stream &strm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ Status GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
port_ptr = nullptr;
}

Status error = StartDebugserverProcess(
url.str().c_str(), nullptr, debugserver_launch_info, port_ptr, &args, -1);
Status error = StartDebugserverProcess(url.str().c_str(), nullptr,
debugserver_launch_info, port_ptr,
&args, SharedSocket::kInvalidFD);

pid = debugserver_launch_info.GetProcessID();
if (pid != LLDB_INVALID_PROCESS_ID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3447,7 +3447,7 @@ Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
}
#endif

int communication_fd = -1;
shared_fd_t communication_fd = SharedSocket::kInvalidFD;
#ifdef USE_SOCKETPAIR_FOR_LOCAL_CONNECTION
// Use a socketpair on non-Windows systems for security and performance
// reasons.
Expand Down
14 changes: 8 additions & 6 deletions lldb/tools/lldb-server/lldb-gdbserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ void ConnectToRemote(MainLoop &mainloop,
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,
int connection_fd) {
shared_fd_t connection_fd) {
Status error;

std::unique_ptr<Connection> connection_up;
std::string url;

if (connection_fd != -1) {
if (connection_fd != SharedSocket::kInvalidFD) {
url = llvm::formatv("fd://{0}", connection_fd).str();

// Create the connection.
Expand Down Expand Up @@ -338,7 +338,7 @@ int main_gdbserver(int argc, char *argv[]) {
log_channels; // e.g. "lldb process threads:gdb-remote default:linux all"
lldb::pipe_t unnamed_pipe = LLDB_INVALID_PIPE;
bool reverse_connect = false;
int connection_fd = -1;
shared_fd_t connection_fd = SharedSocket::kInvalidFD;

// ProcessLaunchInfo launch_info;
ProcessAttachInfo attach_info;
Expand Down Expand Up @@ -404,10 +404,12 @@ int main_gdbserver(int argc, char *argv[]) {
unnamed_pipe = (pipe_t)Arg;
}
if (Args.hasArg(OPT_fd)) {
if (!llvm::to_integer(Args.getLastArgValue(OPT_fd), connection_fd)) {
int64_t fd;
if (!llvm::to_integer(Args.getLastArgValue(OPT_fd), fd)) {
WithColor::error() << "invalid '--fd' argument\n" << HelpText;
return 1;
}
connection_fd = (shared_fd_t)fd;
}

if (!LLDBServerUtilities::SetupLogging(
Expand All @@ -423,7 +425,7 @@ int main_gdbserver(int argc, char *argv[]) {
for (const char *Val : Arg->getValues())
Inputs.push_back(Val);
}
if (Inputs.empty() && connection_fd == -1) {
if (Inputs.empty() && connection_fd == SharedSocket::kInvalidFD) {
WithColor::error() << "no connection arguments\n" << HelpText;
return 1;
}
Expand All @@ -432,7 +434,7 @@ int main_gdbserver(int argc, char *argv[]) {
GDBRemoteCommunicationServerLLGS gdb_server(mainloop, manager);

llvm::StringRef host_and_port;
if (!Inputs.empty()) {
if (!Inputs.empty() && connection_fd == SharedSocket::kInvalidFD) {
host_and_port = Inputs.front();
Inputs.erase(Inputs.begin());
}
Expand Down
4 changes: 0 additions & 4 deletions lldb/unittests/tools/lldb-server/tests/LLGSTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ using namespace llgs_tests;
using namespace lldb_private;
using namespace llvm;

#ifdef SendMessage
#undef SendMessage
#endif

// Disable this test on Windows as it appears to have a race condition
// that causes lldb-server not to exit after the inferior hangs up.
#if !defined(_WIN32)
Expand Down
4 changes: 0 additions & 4 deletions lldb/unittests/tools/lldb-server/tests/TestClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ using namespace lldb_private;
using namespace llvm;
using namespace llgs_tests;

#ifdef SendMessage
#undef SendMessage
#endif

TestClient::TestClient(std::unique_ptr<Connection> Conn) {
SetConnection(std::move(Conn));
SetPacketTimeout(std::chrono::seconds(10));
Expand Down
4 changes: 4 additions & 0 deletions lldb/unittests/tools/lldb-server/tests/TestClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <optional>
#include <string>

#ifdef SendMessage
#undef SendMessage
#endif

#if LLDB_SERVER_IS_DEBUGSERVER
#define LLGS_TEST(x) DISABLED_ ## x
#define DS_TEST(x) x
Expand Down