21#include "llvm/Support/FileSystem.h"
22#include "llvm/Support/JSON.h"
23#include "llvm/Support/Threading.h"
25#include "lldb/Host/Config.h"
50 uint16_t gdbserver_port)
84 bool &interrupt,
bool &quit) {
118 std::ostringstream url;
120#if !defined(__APPLE__)
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 packet.
SetFilePos(::strlen(
"qLaunchGDBServer;"));
160 llvm::StringRef name;
161 llvm::StringRef value;
162 std::optional<uint16_t> port;
164 if (name ==
"port") {
167 value.getAsInteger(0, *port);
174 std::string socket_name;
182 response.
Printf(
"pid:%" PRIu64
";port:%u;", debugserver_pid, gdbserver_port);
183 if (!socket_name.empty()) {
194 return packet_result;
212 json::Array server_list;
213 server_list.push_back(std::move(server));
227 packet.
SetFilePos(::strlen(
"qKillSpawnedProcess:"));
267 for (
size_t i = 0; i < 10; ++i) {
272 std::this_thread::sleep_for(std::chrono::milliseconds(10));
282 for (
size_t i = 0; i < 10; ++i) {
287 std::this_thread::sleep_for(std::chrono::milliseconds(10));
315 packet.
SetFilePos(::strlen(
"qPathComplete:"));
316 const bool only_dir = (packet.
GetHexMaxU32(
false, 0) == 1);
331 llvm::StringRef separator;
332 std::sort(matches.
begin(), matches.
end());
333 for (
const auto &match : matches) {
334 response << separator;
348 llvm::SmallString<64> cwd;
349 if (std::error_code ec = llvm::sys::fs::current_path(cwd))
360 packet.
SetFilePos(::strlen(
"QSetWorkingDir:"));
364 if (std::error_code ec = llvm::sys::fs::set_current_path(path))
380 response.
Printf(
"QC%" PRIx64, pid);
402 for (
auto signo = signals->GetFirstSignalNumber();
404 signo = signals->GetNextSignalNumber(signo)) {
405 auto dictionary = std::make_shared<StructuredData::Dictionary>();
407 dictionary->AddIntegerItem(
"signo", signo);
408 dictionary->AddStringItem(
"name", signals->GetSignalAsStringRef(signo));
410 bool suppress, stop, notify;
411 signals->GetSignalInfo(signo, suppress, stop, notify);
412 dictionary->AddBooleanItem(
"suppress", suppress);
413 dictionary->AddBooleanItem(
"stop", stop);
414 dictionary->AddBooleanItem(
"notify", notify);
416 signal_array.
Push(dictionary);
420 signal_array.
Dump(response);
433 "%s: no process command line specified to launch", __FUNCTION__);
440 std::placeholders::_1));
443 if (!
error.Success()) {
444 fprintf(stderr,
"%s: failed to launch executable %s", __FUNCTION__,
449 printf(
"Launched '%s' as process %" PRIu64
"...\n",
463 static llvm::once_flag g_once_flag;
465 llvm::call_once(g_once_flag, []() {
466 const char *domainsocket_dir_env =
467 ::getenv(
"LLDB_DEBUGSERVER_DOMAINSOCKET_DIR");
468 if (domainsocket_dir_env !=
nullptr)
469 g_domainsocket_dir =
FileSpec(domainsocket_dir_env);
471 g_domainsocket_dir = HostInfo::GetProcessTempDir();
474 return g_domainsocket_dir;
479 llvm::SmallString<128> socket_path;
480 llvm::SmallString<128> socket_name(
481 (llvm::StringRef(prefix) +
".%%%%%%").str());
486 llvm::sys::fs::createUniqueFile(socket_path_spec.
GetPath().c_str(),
488 return FileSpec(socket_path.c_str());
492 const std::string &socket_name) {
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
A command line argument class.
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 FileSystem & Instance()
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)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
lldb::pid_t GetProcessID() 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()
static Status StartDebugserverProcess(std::variant< llvm::StringRef, shared_fd_t > comm, ProcessLaunchInfo &launch_info, const Args *inferior_args)
PacketResult SendPacketNoLock(llvm::StringRef payload)
#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