2013-11-22 02:39:32 +08:00
|
|
|
//===-- lldb-gdbserver.cpp --------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-11-22 02:39:32 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-07-13 01:34:24 +08:00
|
|
|
|
2014-07-12 09:12:44 +08:00
|
|
|
#ifndef _WIN32
|
2014-07-13 01:34:24 +08:00
|
|
|
#include <signal.h>
|
2014-07-12 09:12:44 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2013-11-22 02:39:32 +08:00
|
|
|
|
2015-10-22 03:34:26 +08:00
|
|
|
#include "Acceptor.h"
|
2015-05-27 21:34:04 +08:00
|
|
|
#include "LLDBServerUtilities.h"
|
2015-02-11 18:29:30 +08:00
|
|
|
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h"
|
2013-11-22 02:39:32 +08:00
|
|
|
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
|
2019-12-13 02:00:45 +08:00
|
|
|
#include "lldb/Host/Config.h"
|
2014-10-07 05:22:36 +08:00
|
|
|
#include "lldb/Host/ConnectionFileDescriptor.h"
|
2018-11-02 05:05:36 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2015-05-27 21:34:04 +08:00
|
|
|
#include "lldb/Host/Pipe.h"
|
2014-08-07 02:16:26 +08:00
|
|
|
#include "lldb/Host/Socket.h"
|
2015-01-16 04:08:35 +08:00
|
|
|
#include "lldb/Host/StringConvert.h"
|
2017-07-07 19:02:19 +08:00
|
|
|
#include "lldb/Host/common/NativeProcessProtocol.h"
|
2019-05-03 02:15:03 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2017-06-06 22:06:17 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2020-10-15 23:22:33 +08:00
|
|
|
#include "llvm/Option/ArgList.h"
|
|
|
|
#include "llvm/Option/OptTable.h"
|
|
|
|
#include "llvm/Option/Option.h"
|
2017-06-06 22:06:17 +08:00
|
|
|
#include "llvm/Support/Errno.h"
|
2020-10-15 23:22:33 +08:00
|
|
|
#include "llvm/Support/WithColor.h"
|
2014-01-28 08:34:23 +08:00
|
|
|
|
2017-07-07 19:02:19 +08:00
|
|
|
#if defined(__linux__)
|
|
|
|
#include "Plugins/Process/Linux/NativeProcessLinux.h"
|
2020-09-10 14:24:15 +08:00
|
|
|
#elif defined(__FreeBSD__)
|
2021-02-12 07:40:52 +08:00
|
|
|
#include "Plugins/Process/FreeBSD/NativeProcessFreeBSD.h"
|
2017-07-07 19:02:19 +08:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
#include "Plugins/Process/NetBSD/NativeProcessNetBSD.h"
|
2019-08-15 00:39:41 +08:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
#include "Plugins/Process/Windows/Common/NativeProcessWindows.h"
|
2017-07-07 19:02:19 +08:00
|
|
|
#endif
|
|
|
|
|
2014-07-12 06:50:13 +08:00
|
|
|
#ifndef LLGS_PROGRAM_NAME
|
2015-03-06 22:36:33 +08:00
|
|
|
#define LLGS_PROGRAM_NAME "lldb-server"
|
2014-07-12 06:50:13 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LLGS_VERSION_STR
|
|
|
|
#define LLGS_VERSION_STR "local_build"
|
|
|
|
#endif
|
|
|
|
|
2015-05-10 23:22:09 +08:00
|
|
|
using namespace llvm;
|
2013-11-22 02:39:32 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
2015-05-27 21:34:04 +08:00
|
|
|
using namespace lldb_private::lldb_server;
|
2015-03-31 17:52:22 +08:00
|
|
|
using namespace lldb_private::process_gdb_remote;
|
2013-11-22 02:39:32 +08:00
|
|
|
|
2017-07-07 19:02:19 +08:00
|
|
|
namespace {
|
|
|
|
#if defined(__linux__)
|
|
|
|
typedef process_linux::NativeProcessLinux::Factory NativeProcessFactory;
|
2020-09-10 14:24:15 +08:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
typedef process_freebsd::NativeProcessFreeBSD::Factory NativeProcessFactory;
|
2017-07-07 19:02:19 +08:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
typedef process_netbsd::NativeProcessNetBSD::Factory NativeProcessFactory;
|
2019-08-15 00:39:41 +08:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
typedef NativeProcessWindows::Factory NativeProcessFactory;
|
2017-07-07 19:02:19 +08:00
|
|
|
#else
|
|
|
|
// Dummy implementation to make sure the code compiles
|
|
|
|
class NativeProcessFactory : public NativeProcessProtocol::Factory {
|
|
|
|
public:
|
2017-07-18 17:24:48 +08:00
|
|
|
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
|
2017-07-07 19:02:19 +08:00
|
|
|
Launch(ProcessLaunchInfo &launch_info,
|
|
|
|
NativeProcessProtocol::NativeDelegate &delegate,
|
|
|
|
MainLoop &mainloop) const override {
|
|
|
|
llvm_unreachable("Not implemented");
|
|
|
|
}
|
2017-07-18 17:24:48 +08:00
|
|
|
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
|
2017-07-07 19:02:19 +08:00
|
|
|
Attach(lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &delegate,
|
|
|
|
MainLoop &mainloop) const override {
|
|
|
|
llvm_unreachable("Not implemented");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-09-23 20:03:21 +08:00
|
|
|
#ifndef _WIN32
|
2013-11-22 02:39:32 +08:00
|
|
|
// Watch for signals
|
2014-07-01 05:05:18 +08:00
|
|
|
static int g_sighup_received_count = 0;
|
|
|
|
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
static void sighup_handler(MainLoopBase &mainloop) {
|
|
|
|
++g_sighup_received_count;
|
|
|
|
|
|
|
|
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "lldb-server:%s swallowing SIGHUP (receive count=%d)",
|
|
|
|
__FUNCTION__, g_sighup_received_count);
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
|
|
|
|
if (g_sighup_received_count >= 2)
|
|
|
|
mainloop.RequestTermination();
|
|
|
|
}
|
2014-07-13 01:34:24 +08:00
|
|
|
#endif // #ifndef _WIN32
|
2013-11-22 02:39:32 +08:00
|
|
|
|
2015-02-11 18:29:30 +08:00
|
|
|
void handle_attach_to_pid(GDBRemoteCommunicationServerLLGS &gdb_server,
|
|
|
|
lldb::pid_t pid) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error = gdb_server.AttachToProcess(pid);
|
2014-07-01 05:05:18 +08:00
|
|
|
if (error.Fail()) {
|
|
|
|
fprintf(stderr, "error: failed to attach to pid %" PRIu64 ": %s\n", pid,
|
|
|
|
error.AsCString());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 18:29:30 +08:00
|
|
|
void handle_attach_to_process_name(GDBRemoteCommunicationServerLLGS &gdb_server,
|
|
|
|
const std::string &process_name) {
|
2014-07-01 05:05:18 +08:00
|
|
|
// FIXME implement.
|
|
|
|
}
|
|
|
|
|
2015-02-11 18:29:30 +08:00
|
|
|
void handle_attach(GDBRemoteCommunicationServerLLGS &gdb_server,
|
|
|
|
const std::string &attach_target) {
|
2014-07-01 05:05:18 +08:00
|
|
|
assert(!attach_target.empty() && "attach_target cannot be empty");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-06-18 13:27:05 +08:00
|
|
|
// First check if the attach_target is convertible to a long. If so, we'll use
|
|
|
|
// it as a pid.
|
2014-07-01 05:05:18 +08:00
|
|
|
char *end_p = nullptr;
|
|
|
|
const long int pid = strtol(attach_target.c_str(), &end_p, 10);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
// We'll call it a match if the entire argument is consumed.
|
|
|
|
if (end_p &&
|
|
|
|
static_cast<size_t>(end_p - attach_target.c_str()) ==
|
|
|
|
attach_target.size())
|
|
|
|
handle_attach_to_pid(gdb_server, static_cast<lldb::pid_t>(pid));
|
|
|
|
else
|
|
|
|
handle_attach_to_process_name(gdb_server, attach_target);
|
|
|
|
}
|
|
|
|
|
2020-10-15 23:22:33 +08:00
|
|
|
void handle_launch(GDBRemoteCommunicationServerLLGS &gdb_server,
|
|
|
|
llvm::ArrayRef<llvm::StringRef> Arguments) {
|
2017-12-18 22:31:39 +08:00
|
|
|
ProcessLaunchInfo info;
|
|
|
|
info.GetFlags().Set(eLaunchFlagStopAtEntry | eLaunchFlagDebug |
|
|
|
|
eLaunchFlagDisableASLR);
|
2020-10-15 23:22:33 +08:00
|
|
|
info.SetArguments(Args(Arguments), true);
|
2017-12-18 22:31:39 +08:00
|
|
|
|
|
|
|
llvm::SmallString<64> cwd;
|
|
|
|
if (std::error_code ec = llvm::sys::fs::current_path(cwd)) {
|
|
|
|
llvm::errs() << "Error getting current directory: " << ec.message() << "\n";
|
2014-07-01 05:05:18 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec cwd_spec(cwd);
|
|
|
|
FileSystem::Instance().Resolve(cwd_spec);
|
|
|
|
info.SetWorkingDirectory(cwd_spec);
|
Add Utility/Environment class for handling... environments
Summary:
There was some confusion in the code about how to represent process
environment. Most of the code (ab)used the Args class for this purpose,
but some of it used a more basic StringList class instead. In either
case, the fact that the underlying abstraction did not provide primitive
operations for the typical environment operations meant that even a
simple operation like checking for an environment variable value was
several lines of code.
This patch adds a separate Environment class, which is essentialy a
llvm::StringMap<std::string> in disguise. To standard StringMap
functionality, it adds a couple of new functions, which are specific to
the environment use case:
- (most important) envp conversion for passing into execve() and likes.
Instead of trying to maintain a constantly up-to-date envp view, it
provides a function which creates a envp view on demand, with the
expectation that this will be called as the very last thing before
handing the value to the system function.
- insert(StringRef KeyEqValue) - splits KeyEqValue into (key, value)
pair and inserts it into the environment map.
- compose(value_type KeyValue) - takes a map entry and converts in back
into "KEY=VALUE" representation.
With this interface most of the environment-manipulating code becomes
one-liners. The only tricky part was maintaining compatibility in
SBLaunchInfo, which expects that the environment entries are accessible
by index and that the returned const char* is backed by the launch info
object (random access into maps is hard and the map stores the entry in
a deconstructed form, so we cannot just return a .c_str() value). To
solve this, I have the SBLaunchInfo convert the environment into the
"envp" form, and use it to answer the environment queries. Extra code is
added to make sure the envp version is always in sync.
(This also improves the layering situation as Args was in the Interpreter module
whereas Environment is in Utility.)
Reviewers: zturner, davide, jingham, clayborg
Subscribers: emaste, lldb-commits, mgorny
Differential Revision: https://reviews.llvm.org/D41359
llvm-svn: 322174
2018-01-10 19:57:31 +08:00
|
|
|
info.GetEnvironment() = Host::GetEnvironment();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-12-18 22:31:39 +08:00
|
|
|
gdb_server.SetLaunchInfo(info);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-12-18 22:31:39 +08:00
|
|
|
Status error = gdb_server.LaunchProcess();
|
2014-07-01 05:05:18 +08:00
|
|
|
if (error.Fail()) {
|
2017-12-18 22:31:39 +08:00
|
|
|
llvm::errs() << llvm::formatv("error: failed to launch '{0}': {1}\n",
|
2020-10-15 23:22:33 +08:00
|
|
|
Arguments[0], error);
|
2014-07-01 05:05:18 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status writeSocketIdToPipe(Pipe &port_pipe, const std::string &socket_id) {
|
2015-01-14 07:19:40 +08:00
|
|
|
size_t bytes_written = 0;
|
|
|
|
// Write the port number as a C string with the NULL terminator.
|
2015-10-22 05:58:22 +08:00
|
|
|
return port_pipe.Write(socket_id.c_str(), socket_id.size() + 1,
|
|
|
|
bytes_written);
|
2015-04-28 07:20:30 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status writeSocketIdToPipe(const char *const named_pipe_path,
|
|
|
|
const std::string &socket_id) {
|
2015-04-28 07:20:30 +08:00
|
|
|
Pipe port_name_pipe;
|
|
|
|
// Wait for 10 seconds for pipe to be opened.
|
|
|
|
auto error = port_name_pipe.OpenAsWriterWithTimeout(named_pipe_path, false,
|
|
|
|
std::chrono::seconds{10});
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
2015-10-22 03:34:26 +08:00
|
|
|
return writeSocketIdToPipe(port_name_pipe, socket_id);
|
2015-04-28 07:20:30 +08:00
|
|
|
}
|
|
|
|
|
2019-01-10 08:46:09 +08:00
|
|
|
Status writeSocketIdToPipe(lldb::pipe_t unnamed_pipe,
|
|
|
|
const std::string &socket_id) {
|
|
|
|
Pipe port_pipe{LLDB_INVALID_PIPE, unnamed_pipe};
|
2015-10-22 03:34:26 +08:00
|
|
|
return writeSocketIdToPipe(port_pipe, socket_id);
|
2014-11-28 04:51:24 +08:00
|
|
|
}
|
|
|
|
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
void ConnectToRemote(MainLoop &mainloop,
|
|
|
|
GDBRemoteCommunicationServerLLGS &gdb_server,
|
2020-10-15 23:22:33 +08:00
|
|
|
bool reverse_connect, llvm::StringRef host_and_port,
|
2015-04-28 07:20:30 +08:00
|
|
|
const char *const progname, const char *const subcommand,
|
2019-01-10 08:46:09 +08:00
|
|
|
const char *const named_pipe_path, pipe_t unnamed_pipe,
|
2017-09-26 01:41:16 +08:00
|
|
|
int connection_fd) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-09-26 01:41:16 +08:00
|
|
|
std::unique_ptr<Connection> connection_up;
|
|
|
|
if (connection_fd != -1) {
|
|
|
|
// Build the connection string.
|
|
|
|
char connection_url[512];
|
|
|
|
snprintf(connection_url, sizeof(connection_url), "fd://%d", connection_fd);
|
|
|
|
|
|
|
|
// Create the connection.
|
2019-12-13 02:00:45 +08:00
|
|
|
#if LLDB_ENABLE_POSIX && !defined _WIN32
|
2017-09-26 01:41:16 +08:00
|
|
|
::fcntl(connection_fd, F_SETFD, FD_CLOEXEC);
|
|
|
|
#endif
|
|
|
|
connection_up.reset(new ConnectionFileDescriptor);
|
|
|
|
auto connection_result = connection_up->Connect(connection_url, &error);
|
|
|
|
if (connection_result != eConnectionStatusSuccess) {
|
|
|
|
fprintf(stderr, "error: failed to connect to client at '%s' "
|
2017-09-29 03:49:00 +08:00
|
|
|
"(connection status: %d)\n",
|
2017-09-26 01:41:16 +08:00
|
|
|
connection_url, static_cast<int>(connection_result));
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
if (error.Fail()) {
|
2017-09-29 03:49:00 +08:00
|
|
|
fprintf(stderr, "error: failed to connect to client at '%s': %s\n",
|
2017-09-26 01:41:16 +08:00
|
|
|
connection_url, error.AsCString());
|
|
|
|
exit(-1);
|
|
|
|
}
|
2020-10-15 23:22:33 +08:00
|
|
|
} else if (!host_and_port.empty()) {
|
2014-07-27 04:39:17 +08:00
|
|
|
// Parse out host and port.
|
2014-07-12 06:50:13 +08:00
|
|
|
std::string final_host_and_port;
|
2014-07-27 04:39:17 +08:00
|
|
|
std::string connection_host;
|
|
|
|
std::string connection_port;
|
|
|
|
uint32_t connection_portno = 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-12 06:50:13 +08:00
|
|
|
// If host_and_port starts with ':', default the host to be "localhost" and
|
|
|
|
// expect the remainder to be the port.
|
|
|
|
if (host_and_port[0] == ':')
|
|
|
|
final_host_and_port.append("localhost");
|
2020-10-15 23:22:33 +08:00
|
|
|
final_host_and_port.append(host_and_port.str());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-10-01 01:47:48 +08:00
|
|
|
// Note: use rfind, because the host/port may look like "[::1]:12345".
|
|
|
|
const std::string::size_type colon_pos = final_host_and_port.rfind(':');
|
2014-07-12 06:50:13 +08:00
|
|
|
if (colon_pos != std::string::npos) {
|
2014-07-27 04:39:17 +08:00
|
|
|
connection_host = final_host_and_port.substr(0, colon_pos);
|
|
|
|
connection_port = final_host_and_port.substr(colon_pos + 1);
|
2015-01-16 04:08:35 +08:00
|
|
|
connection_portno = StringConvert::ToUInt32(connection_port.c_str(), 0);
|
2014-07-12 06:50:13 +08:00
|
|
|
}
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-27 04:39:17 +08:00
|
|
|
if (reverse_connect) {
|
|
|
|
// llgs will connect to the gdb-remote client.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-27 04:39:17 +08:00
|
|
|
// Ensure we have a port number for the connection.
|
|
|
|
if (connection_portno == 0) {
|
|
|
|
fprintf(stderr, "error: port number must be specified on when using "
|
2017-09-29 03:49:00 +08:00
|
|
|
"reverse connect\n");
|
2014-07-27 04:39:17 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-27 04:39:17 +08:00
|
|
|
// Build the connection string.
|
|
|
|
char connection_url[512];
|
|
|
|
snprintf(connection_url, sizeof(connection_url), "connect://%s",
|
|
|
|
final_host_and_port.c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-27 04:39:17 +08:00
|
|
|
// Create the connection.
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
connection_up.reset(new ConnectionFileDescriptor);
|
2014-07-27 04:39:17 +08:00
|
|
|
auto connection_result = connection_up->Connect(connection_url, &error);
|
|
|
|
if (connection_result != eConnectionStatusSuccess) {
|
|
|
|
fprintf(stderr, "error: failed to connect to client at '%s' "
|
2017-09-29 03:49:00 +08:00
|
|
|
"(connection status: %d)\n",
|
2014-07-27 04:39:17 +08:00
|
|
|
connection_url, static_cast<int>(connection_result));
|
|
|
|
exit(-1);
|
2014-07-12 06:50:13 +08:00
|
|
|
}
|
2015-10-22 03:34:26 +08:00
|
|
|
if (error.Fail()) {
|
2017-09-29 03:49:00 +08:00
|
|
|
fprintf(stderr, "error: failed to connect to client at '%s': %s\n",
|
2015-10-22 03:34:26 +08:00
|
|
|
connection_url, error.AsCString());
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
std::unique_ptr<Acceptor> acceptor_up(
|
|
|
|
Acceptor::Create(final_host_and_port, false, error));
|
2015-04-28 07:20:30 +08:00
|
|
|
if (error.Fail()) {
|
2017-09-29 03:49:00 +08:00
|
|
|
fprintf(stderr, "failed to create acceptor: %s\n", error.AsCString());
|
2015-04-28 07:20:30 +08:00
|
|
|
exit(1);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-04-28 07:20:30 +08:00
|
|
|
error = acceptor_up->Listen(1);
|
|
|
|
if (error.Fail()) {
|
2015-10-22 03:34:26 +08:00
|
|
|
fprintf(stderr, "failed to listen: %s\n", error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2015-10-22 03:34:26 +08:00
|
|
|
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 = writeSocketIdToPipe(named_pipe_path, socket_id);
|
|
|
|
if (error.Fail())
|
2017-09-29 03:49:00 +08:00
|
|
|
fprintf(stderr, "failed to write to the named pipe \'%s\': %s\n",
|
2015-10-22 03:34:26 +08:00
|
|
|
named_pipe_path, error.AsCString());
|
2014-07-12 06:50:13 +08:00
|
|
|
}
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
// If we have an unnamed pipe to write the socket id back to, do that
|
2016-09-07 04:57:50 +08:00
|
|
|
// now.
|
2019-01-10 08:46:09 +08:00
|
|
|
else if (unnamed_pipe != LLDB_INVALID_PIPE) {
|
|
|
|
error = writeSocketIdToPipe(unnamed_pipe, socket_id);
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
if (error.Fail())
|
2017-09-29 03:49:00 +08:00
|
|
|
fprintf(stderr, "failed to write to the unnamed pipe: %s\n",
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
error.AsCString());
|
2014-07-12 06:50:13 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2015-10-22 03:34:26 +08:00
|
|
|
fprintf(stderr,
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
"unable to get the socket id for the listening connection\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
Connection *conn = nullptr;
|
2015-10-22 03:34:26 +08:00
|
|
|
error = acceptor_up->Accept(false, conn);
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
if (error.Fail()) {
|
|
|
|
printf("failed to accept new connection: %s\n", error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
connection_up.reset(conn);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 01:41:16 +08:00
|
|
|
error = gdb_server.InitializeConnection(std::move(connection_up));
|
|
|
|
if (error.Fail()) {
|
|
|
|
fprintf(stderr, "Failed to initialize connection: %s\n",
|
|
|
|
error.AsCString());
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
printf("Connection established.\n");
|
2014-07-01 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
2020-10-15 23:22:33 +08:00
|
|
|
namespace {
|
|
|
|
enum ID {
|
|
|
|
OPT_INVALID = 0, // This is not an option ID.
|
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
OPT_##ID,
|
|
|
|
#include "LLGSOptions.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
|
|
|
|
#include "LLGSOptions.inc"
|
|
|
|
#undef PREFIX
|
|
|
|
|
|
|
|
const opt::OptTable::Info InfoTable[] = {
|
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
{ \
|
|
|
|
PREFIX, NAME, HELPTEXT, \
|
|
|
|
METAVAR, OPT_##ID, opt::Option::KIND##Class, \
|
|
|
|
PARAM, FLAGS, OPT_##GROUP, \
|
|
|
|
OPT_##ALIAS, ALIASARGS, VALUES},
|
|
|
|
#include "LLGSOptions.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
class LLGSOptTable : public opt::OptTable {
|
|
|
|
public:
|
|
|
|
LLGSOptTable() : OptTable(InfoTable) {}
|
|
|
|
|
|
|
|
void PrintHelp(llvm::StringRef Name) {
|
|
|
|
std::string Usage =
|
|
|
|
(Name + " [options] [[host]:port] [[--] program args...]").str();
|
|
|
|
OptTable::PrintHelp(llvm::outs(), Usage.c_str(), "lldb-server");
|
|
|
|
llvm::outs() << R"(
|
|
|
|
DESCRIPTION
|
|
|
|
lldb-server connects to the LLDB client, which drives the debugging session.
|
|
|
|
If no connection options are given, the [host]:port argument must be present
|
|
|
|
and will denote the address that lldb-server will listen on. [host] defaults
|
|
|
|
to "localhost" if empty. Port can be zero, in which case the port number will
|
|
|
|
be chosen dynamically and written to destinations given by --named-pipe and
|
|
|
|
--pipe arguments.
|
|
|
|
|
|
|
|
If no target is selected at startup, lldb-server can be directed by the LLDB
|
|
|
|
client to launch or attach to a process.
|
|
|
|
|
|
|
|
)";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2015-03-06 23:47:23 +08:00
|
|
|
int main_gdbserver(int argc, char *argv[]) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
MainLoop mainloop;
|
2015-03-12 05:14:22 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
// Setup signal handlers first thing.
|
2016-07-04 21:07:35 +08:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
MainLoop::SignalHandleUP sighup_handle =
|
|
|
|
mainloop.RegisterSignal(SIGHUP, sighup_handler, error);
|
2015-03-12 05:14:22 +08:00
|
|
|
#endif
|
2015-03-06 23:47:23 +08:00
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
const char *progname = argv[0];
|
2015-02-18 23:39:41 +08:00
|
|
|
const char *subcommand = argv[1];
|
2014-07-01 05:05:18 +08:00
|
|
|
std::string attach_target;
|
2014-07-12 06:50:13 +08:00
|
|
|
std::string named_pipe_path;
|
2015-05-10 23:22:09 +08:00
|
|
|
std::string log_file;
|
|
|
|
StringRef
|
|
|
|
log_channels; // e.g. "lldb process threads:gdb-remote default:linux all"
|
2019-01-10 08:46:09 +08:00
|
|
|
lldb::pipe_t unnamed_pipe = LLDB_INVALID_PIPE;
|
2014-07-27 04:39:17 +08:00
|
|
|
bool reverse_connect = false;
|
2017-09-26 01:41:16 +08:00
|
|
|
int connection_fd = -1;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-24 06:05:44 +08:00
|
|
|
// ProcessLaunchInfo launch_info;
|
2013-11-22 02:58:35 +08:00
|
|
|
ProcessAttachInfo attach_info;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-10-15 23:22:33 +08:00
|
|
|
LLGSOptTable Opts;
|
|
|
|
llvm::BumpPtrAllocator Alloc;
|
|
|
|
llvm::StringSaver Saver(Alloc);
|
|
|
|
bool HasError = false;
|
|
|
|
opt::InputArgList Args = Opts.parseArgs(argc - 1, argv + 1, OPT_UNKNOWN,
|
|
|
|
Saver, [&](llvm::StringRef Msg) {
|
|
|
|
WithColor::error() << Msg << "\n";
|
|
|
|
HasError = true;
|
|
|
|
});
|
|
|
|
std::string Name =
|
|
|
|
(llvm::sys::path::filename(argv[0]) + " g[dbserver]").str();
|
|
|
|
std::string HelpText =
|
|
|
|
"Use '" + Name + " --help' for a complete list of options.\n";
|
|
|
|
if (HasError) {
|
|
|
|
llvm::errs() << HelpText;
|
|
|
|
return 1;
|
|
|
|
}
|
2014-07-27 04:39:17 +08:00
|
|
|
|
2020-10-15 23:22:33 +08:00
|
|
|
if (Args.hasArg(OPT_help)) {
|
|
|
|
Opts.PrintHelp(Name);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-09-26 01:41:16 +08:00
|
|
|
|
2014-07-12 09:12:44 +08:00
|
|
|
#ifndef _WIN32
|
2020-10-15 23:22:33 +08:00
|
|
|
if (Args.hasArg(OPT_setsid)) {
|
|
|
|
// Put llgs into a new session. Terminals group processes
|
|
|
|
// into sessions and when a special terminal key sequences
|
|
|
|
// (like control+c) are typed they can cause signals to go out to
|
|
|
|
// all processes in a session. Using this --setsid (-S) option
|
|
|
|
// will cause debugserver to run in its own sessions and be free
|
|
|
|
// from such issues.
|
|
|
|
//
|
|
|
|
// This is useful when llgs is spawned from a command
|
|
|
|
// line application that uses llgs to do the debugging,
|
|
|
|
// yet that application doesn't want llgs receiving the
|
|
|
|
// signals sent to the session (i.e. dying when anyone hits ^C).
|
|
|
|
{
|
|
|
|
const ::pid_t new_sid = setsid();
|
|
|
|
if (new_sid == -1) {
|
|
|
|
WithColor::warning()
|
|
|
|
<< llvm::formatv("failed to set new session id for {0} ({1})\n",
|
|
|
|
LLGS_PROGRAM_NAME, llvm::sys::StrError());
|
2015-01-22 06:42:49 +08:00
|
|
|
}
|
2020-10-15 23:22:33 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
#endif
|
2013-11-22 02:39:32 +08:00
|
|
|
|
2020-10-15 23:22:33 +08:00
|
|
|
log_file = Args.getLastArgValue(OPT_log_file).str();
|
|
|
|
log_channels = Args.getLastArgValue(OPT_log_channels);
|
|
|
|
named_pipe_path = Args.getLastArgValue(OPT_named_pipe).str();
|
|
|
|
reverse_connect = Args.hasArg(OPT_reverse_connect);
|
|
|
|
attach_target = Args.getLastArgValue(OPT_attach).str();
|
|
|
|
if (Args.hasArg(OPT_pipe)) {
|
2020-10-21 23:45:51 +08:00
|
|
|
uint64_t Arg;
|
|
|
|
if (!llvm::to_integer(Args.getLastArgValue(OPT_pipe), Arg)) {
|
2020-10-15 23:22:33 +08:00
|
|
|
WithColor::error() << "invalid '--pipe' argument\n" << HelpText;
|
|
|
|
return 1;
|
2013-11-22 02:39:32 +08:00
|
|
|
}
|
2020-10-21 23:45:51 +08:00
|
|
|
unnamed_pipe = (pipe_t)Arg;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2020-10-15 23:22:33 +08:00
|
|
|
if (Args.hasArg(OPT_fd)) {
|
|
|
|
if (!llvm::to_integer(Args.getLastArgValue(OPT_fd), connection_fd)) {
|
|
|
|
WithColor::error() << "invalid '--fd' argument\n" << HelpText;
|
|
|
|
return 1;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
Add a more succinct logging syntax
This adds the LLDB_LOG macro, which enables one to write more succinct log
statements.
if (log)
log->Printf("log something: %d", var);
becomes
LLDB_LOG(log, "log something: {0}, var);
The macro still internally does the "if(log)" dance, so the arguments are only
evaluated if logging is enabled, meaning it has the same overhead as the
previous syntax.
Additionally, the log statements will be automatically prefixed with the file
and function generating the log (if the corresponding new argument to the "log
enable" command is enabled), so one does not need to manually specify this in
the log statement.
It also uses the new llvm formatv syntax, which means we don't have to worry
about PRIx64 macros and similar, and we can log complex object (llvm::StringRef,
lldb_private::Error, ...) more easily.
Differential Revision: https://reviews.llvm.org/D27459
llvm-svn: 292360
2017-01-18 19:00:26 +08:00
|
|
|
if (!LLDBServerUtilities::SetupLogging(
|
|
|
|
log_file, log_channels,
|
|
|
|
LLDB_LOG_OPTION_PREPEND_TIMESTAMP |
|
|
|
|
LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION))
|
2014-07-01 05:05:18 +08:00
|
|
|
return -1;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-10-15 23:22:33 +08:00
|
|
|
std::vector<llvm::StringRef> Inputs;
|
|
|
|
for (opt::Arg *Arg : Args.filtered(OPT_INPUT))
|
|
|
|
Inputs.push_back(Arg->getValue());
|
|
|
|
if (opt::Arg *Arg = Args.getLastArg(OPT_REM)) {
|
|
|
|
for (const char *Val : Arg->getValues())
|
|
|
|
Inputs.push_back(Val);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2020-10-15 23:22:33 +08:00
|
|
|
if (Inputs.empty() && connection_fd == -1) {
|
|
|
|
WithColor::error() << "no connection arguments\n" << HelpText;
|
|
|
|
return 1;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2017-07-07 19:02:19 +08:00
|
|
|
NativeProcessFactory factory;
|
|
|
|
GDBRemoteCommunicationServerLLGS gdb_server(mainloop, factory);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-10-15 23:22:33 +08:00
|
|
|
llvm::StringRef host_and_port;
|
|
|
|
if (!Inputs.empty()) {
|
|
|
|
host_and_port = Inputs.front();
|
|
|
|
Inputs.erase(Inputs.begin());
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-06-18 13:27:05 +08:00
|
|
|
// Any arguments left over are for the program that we need to launch. If
|
2016-09-07 04:57:50 +08:00
|
|
|
// there
|
2013-11-22 02:39:32 +08:00
|
|
|
// are no arguments, then the GDB server will start up and wait for an 'A'
|
2016-09-07 04:57:50 +08:00
|
|
|
// packet
|
2014-07-01 05:05:18 +08:00
|
|
|
// to launch a program, or a vAttach packet to attach to an existing process,
|
|
|
|
// unless
|
|
|
|
// explicitly asked to attach with the --attach={pid|program_name} form.
|
|
|
|
if (!attach_target.empty())
|
|
|
|
handle_attach(gdb_server, attach_target);
|
2020-10-15 23:22:33 +08:00
|
|
|
else if (!Inputs.empty())
|
|
|
|
handle_launch(gdb_server, Inputs);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-12 06:50:13 +08:00
|
|
|
// Print version info.
|
2019-08-14 07:50:54 +08:00
|
|
|
printf("%s-%s\n", LLGS_PROGRAM_NAME, LLGS_VERSION_STR);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
ConnectToRemote(mainloop, gdb_server, reverse_connect, host_and_port,
|
2019-12-13 02:00:45 +08:00
|
|
|
progname, subcommand, named_pipe_path.c_str(),
|
2019-01-10 08:46:09 +08:00
|
|
|
unnamed_pipe, connection_fd);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
Introduce a MainLoop class and switch llgs to use it
Summary:
This is the first part of our effort to make llgs single threaded. Currently, llgs consists of
about three threads and the synchronisation between them is a major source of latency when
debugging linux and android applications.
In order to be able to go single threaded, we must have the ability to listen for events from
multiple sources (primarily, client commands coming over the network and debug events from the
inferior) and perform necessary actions. For this reason I introduce the concept of a MainLoop.
A main loop has the ability to register callback's which will be invoked upon receipt of certain
events. MainLoopPosix has the ability to listen for file descriptors and signals.
For the moment, I have merely made the GDBRemoteCommunicationServerLLGS class use MainLoop
instead of waiting on the network socket directly, but the other threads still remain. In the
followup patches I indend to migrate NativeProcessLinux to this class and remove the remaining
threads.
Reviewers: ovyalov, clayborg, amccarth, zturner, emaste
Subscribers: tberghammer, lldb-commits
Differential Revision: http://reviews.llvm.org/D11066
llvm-svn: 242018
2015-07-13 18:44:55 +08:00
|
|
|
if (!gdb_server.IsConnected()) {
|
|
|
|
fprintf(stderr, "no connection information provided, unable to run\n");
|
|
|
|
return 1;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:52:37 +08:00
|
|
|
Status ret = mainloop.Run();
|
|
|
|
if (ret.Fail()) {
|
|
|
|
fprintf(stderr, "lldb-server terminating due to error: %s\n",
|
|
|
|
ret.AsCString());
|
|
|
|
return 1;
|
|
|
|
}
|
2015-03-06 22:36:33 +08:00
|
|
|
fprintf(stderr, "lldb-server exiting...\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|