21#include "llvm/Support/FileSystem.h"
22#include "llvm/Support/JSON.h"
23#include "llvm/Support/Threading.h"
25#include "lldb/Host/Config.h"
51 m_gdbserver_port(gdbserver_port) {
83 bool &interrupt,
bool &quit) {
97 std::ostringstream url;
108#if !defined(__APPLE__)
121 LLDB_LOG(log,
"Launching debugserver url='{0}', fd={1}...", url.str(), fd);
130 url.str().c_str(),
nullptr, debugserver_launch_info,
nullptr, &args, fd);
132 if (
error.Success()) {
136 "GDBRemoteCommunicationServerPlatform::%s() "
137 "debugserver launched successfully as pid %" PRIu64,
141 "GDBRemoteCommunicationServerPlatform::%s() "
142 "debugserver launch failed: %s",
143 __FUNCTION__,
error.AsCString());
155 LLDB_LOGF(log,
"GDBRemoteCommunicationServerPlatform::%s() called",
159 std::string hostname;
160 packet.
SetFilePos(::strlen(
"qLaunchGDBServer;"));
161 llvm::StringRef name;
162 llvm::StringRef value;
163 std::optional<uint16_t> port;
166 hostname = std::string(value);
167 else if (name ==
"port") {
170 value.getAsInteger(0, *port);
177 std::string socket_name;
185 response.
Printf(
"pid:%" PRIu64
";port:%u;", debugserver_pid, gdbserver_port);
186 if (!socket_name.empty()) {
197 return packet_result;
215 json::Array server_list;
216 server_list.push_back(std::move(server));
230 packet.
SetFilePos(::strlen(
"qKillSpawnedProcess:"));
270 for (
size_t i = 0; i < 10; ++i) {
275 std::this_thread::sleep_for(std::chrono::milliseconds(10));
285 for (
size_t i = 0; i < 10; ++i) {
290 std::this_thread::sleep_for(std::chrono::milliseconds(10));
318 packet.
SetFilePos(::strlen(
"qPathComplete:"));
319 const bool only_dir = (packet.
GetHexMaxU32(
false, 0) == 1);
334 llvm::StringRef separator;
335 std::sort(matches.
begin(), matches.
end());
336 for (
const auto &match : matches) {
337 response << separator;
351 llvm::SmallString<64> cwd;
352 if (std::error_code ec = llvm::sys::fs::current_path(cwd))
363 packet.
SetFilePos(::strlen(
"QSetWorkingDir:"));
367 if (std::error_code ec = llvm::sys::fs::set_current_path(path))
383 response.
Printf(
"QC%" PRIx64, pid);
405 for (
auto signo = signals->GetFirstSignalNumber();
407 signo = signals->GetNextSignalNumber(signo)) {
408 auto dictionary = std::make_shared<StructuredData::Dictionary>();
410 dictionary->AddIntegerItem(
"signo", signo);
411 dictionary->AddStringItem(
"name", signals->GetSignalAsStringRef(signo));
413 bool suppress, stop, notify;
414 signals->GetSignalInfo(signo, suppress, stop, notify);
415 dictionary->AddBooleanItem(
"suppress", suppress);
416 dictionary->AddBooleanItem(
"stop", stop);
417 dictionary->AddBooleanItem(
"notify", notify);
419 signal_array.
Push(dictionary);
423 signal_array.
Dump(response);
436 "%s: no process command line specified to launch", __FUNCTION__);
443 std::placeholders::_1));
446 if (!
error.Success()) {
447 fprintf(stderr,
"%s: failed to launch executable %s", __FUNCTION__,
452 printf(
"Launched '%s' as process %" PRIu64
"...\n",
466 static llvm::once_flag g_once_flag;
468 llvm::call_once(g_once_flag, []() {
469 const char *domainsocket_dir_env =
470 ::getenv(
"LLDB_DEBUGSERVER_DOMAINSOCKET_DIR");
471 if (domainsocket_dir_env !=
nullptr)
472 g_domainsocket_dir =
FileSpec(domainsocket_dir_env);
474 g_domainsocket_dir = HostInfo::GetProcessTempDir();
477 return g_domainsocket_dir;
482 llvm::SmallString<128> socket_path;
483 llvm::SmallString<128> socket_name(
484 (llvm::StringRef(prefix) +
".%%%%%%").str());
489 llvm::sys::fs::createUniqueFile(socket_path_spec.
GetPath().c_str(),
491 return FileSpec(socket_path.c_str());
495 const std::string &socket_name) {
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
A command line argument class.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
static void DiskDirectories(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
static void DiskFiles(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher)
void AppendPathComponent(llvm::StringRef component)
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static Status LaunchProcess(ProcessLaunchInfo &launch_info)
Launch the process specified in launch_info.
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
static void Kill(lldb::pid_t pid, int signo)
lldb::pid_t GetProcessID() const
const Host::MonitorChildProcessCallback & GetMonitorProcessCallback() const
void SetMonitorProcessCallback(Host::MonitorChildProcessCallback callback)
void SetLaunchInSeparateProcessGroup(bool separate)
static const shared_fd_t kInvalidFD
static const char * FindSchemeByProtocol(const SocketProtocol protocol)
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
int PutEscapedBytes(const void *s, size_t src_len)
Output a block of data to the stream performing GDB-remote escaping.
llvm::StringRef GetString() const
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t PutStringAsRawHex8(llvm::StringRef s)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t PutBytesAsRawHex8(const void *src, size_t src_len, lldb::ByteOrder src_byte_order=lldb::eByteOrderInvalid, lldb::ByteOrder dst_byte_order=lldb::eByteOrderInvalid)
void Push(const ObjectSP &item)
void Dump(lldb_private::Stream &s, bool pretty_print=true) const
static lldb::UnixSignalsSP CreateForHost()
void RegisterMemberFunctionHandler(StringExtractorGDBRemote::ServerPacketType packet_type, PacketResult(T::*handler)(StringExtractorGDBRemote &packet))
static void CreateProcessInfoResponse_DebugServerStyle(const ProcessInstanceInfo &proc_info, StreamString &response)
ProcessLaunchInfo m_process_launch_info
void RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, PacketHandler handler)
PacketResult SendErrorResponse(const Status &error)
PacketResult SendOKResponse()
PacketResult SendPacketNoLock(llvm::StringRef payload)
FileSpec GetDebugserverPath(Platform *platform)
Status StartDebugserverProcess(const char *url, Platform *platform, ProcessLaunchInfo &launch_info, uint16_t *port, const Args *inferior_args, shared_fd_t pass_comm_fd)
#define LLDB_INVALID_SIGNAL_NUMBER
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::UnixSignals > UnixSignalsSP