21#include "llvm/Support/FileSystem.h"
22#include "llvm/Support/JSON.h"
23#include "llvm/Support/Threading.h"
25#include "lldb/Host/Config.h"
49 uint16_t gdbserver_port)
80 bool &interrupt,
bool &quit) {
114 std::ostringstream url;
116#if !defined(__APPLE__)
128 if (
error.Success()) {
132 "GDBRemoteCommunicationServerPlatform::%s() "
133 "debugserver launched successfully as pid %" PRIu64,
137 "GDBRemoteCommunicationServerPlatform::%s() "
138 "debugserver launch failed: %s",
139 __FUNCTION__,
error.AsCString());
151 LLDB_LOGF(log,
"GDBRemoteCommunicationServerPlatform::%s() called",
155 packet.
SetFilePos(::strlen(
"qLaunchGDBServer;"));
156 llvm::StringRef name;
157 llvm::StringRef value;
158 std::optional<uint16_t> port;
160 if (name ==
"port") {
163 value.getAsInteger(
BASE_10, *port);
170 std::string socket_name;
178 response.
Printf(
"pid:%" PRIu64
";port:%u;", debugserver_pid, gdbserver_port);
179 if (!socket_name.empty()) {
190 return packet_result;
208 json::Array server_list;
209 server_list.push_back(std::move(server));
223 packet.
SetFilePos(::strlen(
"qKillSpawnedProcess:"));
263 for (
size_t i = 0; i < 10; ++i) {
268 std::this_thread::sleep_for(std::chrono::milliseconds(10));
278 for (
size_t i = 0; i < 10; ++i) {
283 std::this_thread::sleep_for(std::chrono::milliseconds(10));
311 packet.
SetFilePos(::strlen(
"qPathComplete:"));
312 const bool only_dir = (packet.
GetHexMaxU32(
false, 0) == 1);
327 llvm::StringRef separator;
328 std::sort(matches.
begin(), matches.
end());
329 for (
const auto &match : matches) {
330 response << separator;
344 llvm::SmallString<64> cwd;
345 if (std::error_code ec = llvm::sys::fs::current_path(cwd))
356 packet.
SetFilePos(::strlen(
"QSetWorkingDir:"));
360 if (std::error_code ec = llvm::sys::fs::set_current_path(path))
376 response.
Printf(
"QC%" PRIx64, pid);
401 "%s: no process command line specified to launch", __FUNCTION__);
408 std::placeholders::_1));
411 if (!
error.Success()) {
412 fprintf(stderr,
"%s: failed to launch executable %s", __FUNCTION__,
417 printf(
"Launched '%s' as process %" PRIu64
"...\n",
431 static llvm::once_flag g_once_flag;
433 llvm::call_once(g_once_flag, []() {
434 const char *domainsocket_dir_env =
435 ::getenv(
"LLDB_DEBUGSERVER_DOMAINSOCKET_DIR");
436 if (domainsocket_dir_env !=
nullptr)
437 g_domainsocket_dir =
FileSpec(domainsocket_dir_env);
439 g_domainsocket_dir = HostInfo::GetProcessTempDir();
442 return g_domainsocket_dir;
447 llvm::SmallString<128> socket_path;
448 llvm::SmallString<128> socket_name(
449 (llvm::StringRef(prefix) +
".%%%%%%").str());
454 llvm::sys::fs::createUniqueFile(socket_path_spec.
GetPath().c_str(),
456 return FileSpec(socket_path.c_str());
460 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 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_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.