1 //===-- GDBRemoteCommunicationServerPlatform.cpp --------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "GDBRemoteCommunicationServerPlatform.h"
10 
11 #include <errno.h>
12 
13 #include <chrono>
14 #include <csignal>
15 #include <cstring>
16 #include <mutex>
17 #include <sstream>
18 #include <thread>
19 
20 #include "llvm/Support/FileSystem.h"
21 #include "llvm/Support/JSON.h"
22 #include "llvm/Support/Threading.h"
23 
24 #include "lldb/Host/Config.h"
25 #include "lldb/Host/ConnectionFileDescriptor.h"
26 #include "lldb/Host/FileAction.h"
27 #include "lldb/Host/Host.h"
28 #include "lldb/Host/HostInfo.h"
29 #include "lldb/Interpreter/CommandCompletions.h"
30 #include "lldb/Target/Platform.h"
31 #include "lldb/Target/UnixSignals.h"
32 #include "lldb/Utility/GDBRemote.h"
33 #include "lldb/Utility/Log.h"
34 #include "lldb/Utility/StreamString.h"
35 #include "lldb/Utility/StructuredData.h"
36 #include "lldb/Utility/TildeExpressionResolver.h"
37 #include "lldb/Utility/UriParser.h"
38 
39 #include "lldb/Utility/StringExtractorGDBRemote.h"
40 
41 using namespace lldb;
42 using namespace lldb_private::process_gdb_remote;
43 using namespace lldb_private;
44 
45 GDBRemoteCommunicationServerPlatform::PortMap::PortMap(uint16_t min_port,
46                                                        uint16_t max_port) {
47   for (; min_port < max_port; ++min_port)
48     m_port_map[min_port] = LLDB_INVALID_PROCESS_ID;
49 }
50 
51 void GDBRemoteCommunicationServerPlatform::PortMap::AllowPort(uint16_t port) {
52   // Do not modify existing mappings
53   m_port_map.insert({port, LLDB_INVALID_PROCESS_ID});
54 }
55 
56 llvm::Expected<uint16_t>
57 GDBRemoteCommunicationServerPlatform::PortMap::GetNextAvailablePort() {
58   if (m_port_map.empty())
59     return 0; // Bind to port zero and get a port, we didn't have any
60               // limitations
61 
62   for (auto &pair : m_port_map) {
63     if (pair.second == LLDB_INVALID_PROCESS_ID) {
64       pair.second = ~(lldb::pid_t)LLDB_INVALID_PROCESS_ID;
65       return pair.first;
66     }
67   }
68   return llvm::createStringError(llvm::inconvertibleErrorCode(),
69                                  "No free port found in port map");
70 }
71 
72 bool GDBRemoteCommunicationServerPlatform::PortMap::AssociatePortWithProcess(
73     uint16_t port, lldb::pid_t pid) {
74   auto pos = m_port_map.find(port);
75   if (pos != m_port_map.end()) {
76     pos->second = pid;
77     return true;
78   }
79   return false;
80 }
81 
82 bool GDBRemoteCommunicationServerPlatform::PortMap::FreePort(uint16_t port) {
83   std::map<uint16_t, lldb::pid_t>::iterator pos = m_port_map.find(port);
84   if (pos != m_port_map.end()) {
85     pos->second = LLDB_INVALID_PROCESS_ID;
86     return true;
87   }
88   return false;
89 }
90 
91 bool GDBRemoteCommunicationServerPlatform::PortMap::FreePortForProcess(
92     lldb::pid_t pid) {
93   if (!m_port_map.empty()) {
94     for (auto &pair : m_port_map) {
95       if (pair.second == pid) {
96         pair.second = LLDB_INVALID_PROCESS_ID;
97         return true;
98       }
99     }
100   }
101   return false;
102 }
103 
104 bool GDBRemoteCommunicationServerPlatform::PortMap::empty() const {
105   return m_port_map.empty();
106 }
107 
108 // GDBRemoteCommunicationServerPlatform constructor
109 GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
110     const Socket::SocketProtocol socket_protocol, const char *socket_scheme)
111     : GDBRemoteCommunicationServerCommon("gdb-remote.server",
112                                          "gdb-remote.server.rx_packet"),
113       m_socket_protocol(socket_protocol), m_socket_scheme(socket_scheme),
114       m_spawned_pids_mutex(), m_port_map(), m_port_offset(0) {
115   m_pending_gdb_server.pid = LLDB_INVALID_PROCESS_ID;
116   m_pending_gdb_server.port = 0;
117 
118   RegisterMemberFunctionHandler(
119       StringExtractorGDBRemote::eServerPacketType_qC,
120       &GDBRemoteCommunicationServerPlatform::Handle_qC);
121   RegisterMemberFunctionHandler(
122       StringExtractorGDBRemote::eServerPacketType_qGetWorkingDir,
123       &GDBRemoteCommunicationServerPlatform::Handle_qGetWorkingDir);
124   RegisterMemberFunctionHandler(
125       StringExtractorGDBRemote::eServerPacketType_qLaunchGDBServer,
126       &GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer);
127   RegisterMemberFunctionHandler(
128       StringExtractorGDBRemote::eServerPacketType_qQueryGDBServer,
129       &GDBRemoteCommunicationServerPlatform::Handle_qQueryGDBServer);
130   RegisterMemberFunctionHandler(
131       StringExtractorGDBRemote::eServerPacketType_qKillSpawnedProcess,
132       &GDBRemoteCommunicationServerPlatform::Handle_qKillSpawnedProcess);
133   RegisterMemberFunctionHandler(
134       StringExtractorGDBRemote::eServerPacketType_qProcessInfo,
135       &GDBRemoteCommunicationServerPlatform::Handle_qProcessInfo);
136   RegisterMemberFunctionHandler(
137       StringExtractorGDBRemote::eServerPacketType_qPathComplete,
138       &GDBRemoteCommunicationServerPlatform::Handle_qPathComplete);
139   RegisterMemberFunctionHandler(
140       StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir,
141       &GDBRemoteCommunicationServerPlatform::Handle_QSetWorkingDir);
142   RegisterMemberFunctionHandler(
143       StringExtractorGDBRemote::eServerPacketType_jSignalsInfo,
144       &GDBRemoteCommunicationServerPlatform::Handle_jSignalsInfo);
145 
146   RegisterPacketHandler(StringExtractorGDBRemote::eServerPacketType_interrupt,
147                         [](StringExtractorGDBRemote packet, Status &error,
148                            bool &interrupt, bool &quit) {
149                           error.SetErrorString("interrupt received");
150                           interrupt = true;
151                           return PacketResult::Success;
152                         });
153 }
154 
155 // Destructor
156 GDBRemoteCommunicationServerPlatform::~GDBRemoteCommunicationServerPlatform() {}
157 
158 Status GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
159     const lldb_private::Args &args, std::string hostname, lldb::pid_t &pid,
160     uint16_t &port, std::string &socket_name) {
161   if (port == UINT16_MAX) {
162     llvm::Expected<uint16_t> available_port = m_port_map.GetNextAvailablePort();
163     if (available_port)
164       port = *available_port;
165     else
166       return Status(available_port.takeError());
167   }
168 
169   // Spawn a new thread to accept the port that gets bound after binding to
170   // port 0 (zero).
171 
172   // ignore the hostname send from the remote end, just use the ip address that
173   // we're currently communicating with as the hostname
174 
175   // Spawn a debugserver and try to get the port it listens to.
176   ProcessLaunchInfo debugserver_launch_info;
177   if (hostname.empty())
178     hostname = "127.0.0.1";
179 
180   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
181   LLDB_LOGF(log, "Launching debugserver with: %s:%u...", hostname.c_str(),
182             port);
183 
184   // Do not run in a new session so that it can not linger after the platform
185   // closes.
186   debugserver_launch_info.SetLaunchInSeparateProcessGroup(false);
187   debugserver_launch_info.SetMonitorProcessCallback(
188       std::bind(&GDBRemoteCommunicationServerPlatform::DebugserverProcessReaped,
189                 this, std::placeholders::_1),
190       false);
191 
192   std::ostringstream url;
193 // debugserver does not accept the URL scheme prefix.
194 #if !defined(__APPLE__)
195   url << m_socket_scheme << "://";
196 #endif
197   uint16_t *port_ptr = &port;
198   if (m_socket_protocol == Socket::ProtocolTcp) {
199     llvm::StringRef platform_scheme;
200     llvm::StringRef platform_ip;
201     int platform_port;
202     llvm::StringRef platform_path;
203     std::string platform_uri = GetConnection()->GetURI();
204     bool ok = UriParser::Parse(platform_uri, platform_scheme, platform_ip,
205                                platform_port, platform_path);
206     UNUSED_IF_ASSERT_DISABLED(ok);
207     assert(ok);
208     url << platform_ip.str() << ":" << port;
209   } else {
210     socket_name = GetDomainSocketPath("gdbserver").GetPath();
211     url << socket_name;
212     port_ptr = nullptr;
213   }
214 
215   Status error = StartDebugserverProcess(
216       url.str().c_str(), nullptr, debugserver_launch_info, port_ptr, &args, -1);
217 
218   pid = debugserver_launch_info.GetProcessID();
219   if (pid != LLDB_INVALID_PROCESS_ID) {
220     std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
221     m_spawned_pids.insert(pid);
222     if (port > 0)
223       m_port_map.AssociatePortWithProcess(port, pid);
224   } else {
225     if (port > 0)
226       m_port_map.FreePort(port);
227   }
228   return error;
229 }
230 
231 GDBRemoteCommunication::PacketResult
232 GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer(
233     StringExtractorGDBRemote &packet) {
234   // Spawn a local debugserver as a platform so we can then attach or launch a
235   // process...
236 
237   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
238   LLDB_LOGF(log, "GDBRemoteCommunicationServerPlatform::%s() called",
239             __FUNCTION__);
240 
241   ConnectionFileDescriptor file_conn;
242   std::string hostname;
243   packet.SetFilePos(::strlen("qLaunchGDBServer;"));
244   llvm::StringRef name;
245   llvm::StringRef value;
246   uint16_t port = UINT16_MAX;
247   while (packet.GetNameColonValue(name, value)) {
248     if (name.equals("host"))
249       hostname = std::string(value);
250     else if (name.equals("port"))
251       value.getAsInteger(0, port);
252   }
253 
254   lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
255   std::string socket_name;
256   Status error =
257       LaunchGDBServer(Args(), hostname, debugserver_pid, port, socket_name);
258   if (error.Fail()) {
259     LLDB_LOGF(log,
260               "GDBRemoteCommunicationServerPlatform::%s() debugserver "
261               "launch failed: %s",
262               __FUNCTION__, error.AsCString());
263     return SendErrorResponse(9);
264   }
265 
266   LLDB_LOGF(log,
267             "GDBRemoteCommunicationServerPlatform::%s() debugserver "
268             "launched successfully as pid %" PRIu64,
269             __FUNCTION__, debugserver_pid);
270 
271   StreamGDBRemote response;
272   response.Printf("pid:%" PRIu64 ";port:%u;", debugserver_pid,
273                   port + m_port_offset);
274   if (!socket_name.empty()) {
275     response.PutCString("socket_name:");
276     response.PutStringAsRawHex8(socket_name);
277     response.PutChar(';');
278   }
279 
280   PacketResult packet_result = SendPacketNoLock(response.GetString());
281   if (packet_result != PacketResult::Success) {
282     if (debugserver_pid != LLDB_INVALID_PROCESS_ID)
283       Host::Kill(debugserver_pid, SIGINT);
284   }
285   return packet_result;
286 }
287 
288 GDBRemoteCommunication::PacketResult
289 GDBRemoteCommunicationServerPlatform::Handle_qQueryGDBServer(
290     StringExtractorGDBRemote &packet) {
291   namespace json = llvm::json;
292 
293   if (m_pending_gdb_server.pid == LLDB_INVALID_PROCESS_ID)
294     return SendErrorResponse(4);
295 
296   json::Object server{{"port", m_pending_gdb_server.port}};
297 
298   if (!m_pending_gdb_server.socket_name.empty())
299     server.try_emplace("socket_name", m_pending_gdb_server.socket_name);
300 
301   json::Array server_list;
302   server_list.push_back(std::move(server));
303 
304   StreamGDBRemote response;
305   response.AsRawOstream() << std::move(server_list);
306 
307   StreamGDBRemote escaped_response;
308   escaped_response.PutEscapedBytes(response.GetString().data(),
309                                    response.GetSize());
310   return SendPacketNoLock(escaped_response.GetString());
311 }
312 
313 GDBRemoteCommunication::PacketResult
314 GDBRemoteCommunicationServerPlatform::Handle_qKillSpawnedProcess(
315     StringExtractorGDBRemote &packet) {
316   packet.SetFilePos(::strlen("qKillSpawnedProcess:"));
317 
318   lldb::pid_t pid = packet.GetU64(LLDB_INVALID_PROCESS_ID);
319 
320   // verify that we know anything about this pid. Scope for locker
321   {
322     std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
323     if (m_spawned_pids.find(pid) == m_spawned_pids.end()) {
324       // not a pid we know about
325       return SendErrorResponse(10);
326     }
327   }
328 
329   // go ahead and attempt to kill the spawned process
330   if (KillSpawnedProcess(pid))
331     return SendOKResponse();
332   else
333     return SendErrorResponse(11);
334 }
335 
336 bool GDBRemoteCommunicationServerPlatform::KillSpawnedProcess(lldb::pid_t pid) {
337   // make sure we know about this process
338   {
339     std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
340     if (m_spawned_pids.find(pid) == m_spawned_pids.end())
341       return false;
342   }
343 
344   // first try a SIGTERM (standard kill)
345   Host::Kill(pid, SIGTERM);
346 
347   // check if that worked
348   for (size_t i = 0; i < 10; ++i) {
349     {
350       std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
351       if (m_spawned_pids.find(pid) == m_spawned_pids.end()) {
352         // it is now killed
353         return true;
354       }
355     }
356     std::this_thread::sleep_for(std::chrono::milliseconds(10));
357   }
358 
359   {
360     std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
361     if (m_spawned_pids.find(pid) == m_spawned_pids.end())
362       return true;
363   }
364 
365   // the launched process still lives.  Now try killing it again, this time
366   // with an unblockable signal.
367   Host::Kill(pid, SIGKILL);
368 
369   for (size_t i = 0; i < 10; ++i) {
370     {
371       std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
372       if (m_spawned_pids.find(pid) == m_spawned_pids.end()) {
373         // it is now killed
374         return true;
375       }
376     }
377     std::this_thread::sleep_for(std::chrono::milliseconds(10));
378   }
379 
380   // check one more time after the final sleep
381   {
382     std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
383     if (m_spawned_pids.find(pid) == m_spawned_pids.end())
384       return true;
385   }
386 
387   // no luck - the process still lives
388   return false;
389 }
390 
391 GDBRemoteCommunication::PacketResult
392 GDBRemoteCommunicationServerPlatform::Handle_qProcessInfo(
393     StringExtractorGDBRemote &packet) {
394   lldb::pid_t pid = m_process_launch_info.GetProcessID();
395   m_process_launch_info.Clear();
396 
397   if (pid == LLDB_INVALID_PROCESS_ID)
398     return SendErrorResponse(1);
399 
400   ProcessInstanceInfo proc_info;
401   if (!Host::GetProcessInfo(pid, proc_info))
402     return SendErrorResponse(1);
403 
404   StreamString response;
405   CreateProcessInfoResponse_DebugServerStyle(proc_info, response);
406   return SendPacketNoLock(response.GetString());
407 }
408 
409 GDBRemoteCommunication::PacketResult
410 GDBRemoteCommunicationServerPlatform::Handle_qPathComplete(
411     StringExtractorGDBRemote &packet) {
412   packet.SetFilePos(::strlen("qPathComplete:"));
413   const bool only_dir = (packet.GetHexMaxU32(false, 0) == 1);
414   if (packet.GetChar() != ',')
415     return SendErrorResponse(85);
416   std::string path;
417   packet.GetHexByteString(path);
418 
419   StringList matches;
420   StandardTildeExpressionResolver resolver;
421   if (only_dir)
422     CommandCompletions::DiskDirectories(path, matches, resolver);
423   else
424     CommandCompletions::DiskFiles(path, matches, resolver);
425 
426   StreamString response;
427   response.PutChar('M');
428   llvm::StringRef separator;
429   std::sort(matches.begin(), matches.end());
430   for (const auto &match : matches) {
431     response << separator;
432     separator = ",";
433     // encode result strings into hex bytes to avoid unexpected error caused by
434     // special characters like '$'.
435     response.PutStringAsRawHex8(match.c_str());
436   }
437 
438   return SendPacketNoLock(response.GetString());
439 }
440 
441 GDBRemoteCommunication::PacketResult
442 GDBRemoteCommunicationServerPlatform::Handle_qGetWorkingDir(
443     StringExtractorGDBRemote &packet) {
444 
445   llvm::SmallString<64> cwd;
446   if (std::error_code ec = llvm::sys::fs::current_path(cwd))
447     return SendErrorResponse(ec.value());
448 
449   StreamString response;
450   response.PutBytesAsRawHex8(cwd.data(), cwd.size());
451   return SendPacketNoLock(response.GetString());
452 }
453 
454 GDBRemoteCommunication::PacketResult
455 GDBRemoteCommunicationServerPlatform::Handle_QSetWorkingDir(
456     StringExtractorGDBRemote &packet) {
457   packet.SetFilePos(::strlen("QSetWorkingDir:"));
458   std::string path;
459   packet.GetHexByteString(path);
460 
461   if (std::error_code ec = llvm::sys::fs::set_current_path(path))
462     return SendErrorResponse(ec.value());
463   return SendOKResponse();
464 }
465 
466 GDBRemoteCommunication::PacketResult
467 GDBRemoteCommunicationServerPlatform::Handle_qC(
468     StringExtractorGDBRemote &packet) {
469   // NOTE: lldb should now be using qProcessInfo for process IDs.  This path
470   // here
471   // should not be used.  It is reporting process id instead of thread id.  The
472   // correct answer doesn't seem to make much sense for lldb-platform.
473   // CONSIDER: flip to "unsupported".
474   lldb::pid_t pid = m_process_launch_info.GetProcessID();
475 
476   StreamString response;
477   response.Printf("QC%" PRIx64, pid);
478 
479   // If we launch a process and this GDB server is acting as a platform, then
480   // we need to clear the process launch state so we can start launching
481   // another process. In order to launch a process a bunch or packets need to
482   // be sent: environment packets, working directory, disable ASLR, and many
483   // more settings. When we launch a process we then need to know when to clear
484   // this information. Currently we are selecting the 'qC' packet as that
485   // packet which seems to make the most sense.
486   if (pid != LLDB_INVALID_PROCESS_ID) {
487     m_process_launch_info.Clear();
488   }
489 
490   return SendPacketNoLock(response.GetString());
491 }
492 
493 GDBRemoteCommunication::PacketResult
494 GDBRemoteCommunicationServerPlatform::Handle_jSignalsInfo(
495     StringExtractorGDBRemote &packet) {
496   StructuredData::Array signal_array;
497 
498   lldb::UnixSignalsSP signals = UnixSignals::CreateForHost();
499   for (auto signo = signals->GetFirstSignalNumber();
500        signo != LLDB_INVALID_SIGNAL_NUMBER;
501        signo = signals->GetNextSignalNumber(signo)) {
502     auto dictionary = std::make_shared<StructuredData::Dictionary>();
503 
504     dictionary->AddIntegerItem("signo", signo);
505     dictionary->AddStringItem("name", signals->GetSignalAsCString(signo));
506 
507     bool suppress, stop, notify;
508     signals->GetSignalInfo(signo, suppress, stop, notify);
509     dictionary->AddBooleanItem("suppress", suppress);
510     dictionary->AddBooleanItem("stop", stop);
511     dictionary->AddBooleanItem("notify", notify);
512 
513     signal_array.Push(dictionary);
514   }
515 
516   StreamString response;
517   signal_array.Dump(response);
518   return SendPacketNoLock(response.GetString());
519 }
520 
521 bool GDBRemoteCommunicationServerPlatform::DebugserverProcessReaped(
522     lldb::pid_t pid) {
523   std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
524   m_port_map.FreePortForProcess(pid);
525   m_spawned_pids.erase(pid);
526   return true;
527 }
528 
529 Status GDBRemoteCommunicationServerPlatform::LaunchProcess() {
530   if (!m_process_launch_info.GetArguments().GetArgumentCount())
531     return Status("%s: no process command line specified to launch",
532                   __FUNCTION__);
533 
534   // specify the process monitor if not already set.  This should generally be
535   // what happens since we need to reap started processes.
536   if (!m_process_launch_info.GetMonitorProcessCallback())
537     m_process_launch_info.SetMonitorProcessCallback(
538         std::bind(
539             &GDBRemoteCommunicationServerPlatform::DebugserverProcessReaped,
540             this, std::placeholders::_1),
541         false);
542 
543   Status error = Host::LaunchProcess(m_process_launch_info);
544   if (!error.Success()) {
545     fprintf(stderr, "%s: failed to launch executable %s", __FUNCTION__,
546             m_process_launch_info.GetArguments().GetArgumentAtIndex(0));
547     return error;
548   }
549 
550   printf("Launched '%s' as process %" PRIu64 "...\n",
551          m_process_launch_info.GetArguments().GetArgumentAtIndex(0),
552          m_process_launch_info.GetProcessID());
553 
554   // add to list of spawned processes.  On an lldb-gdbserver, we would expect
555   // there to be only one.
556   const auto pid = m_process_launch_info.GetProcessID();
557   if (pid != LLDB_INVALID_PROCESS_ID) {
558     // add to spawned pids
559     std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex);
560     m_spawned_pids.insert(pid);
561   }
562 
563   return error;
564 }
565 
566 void GDBRemoteCommunicationServerPlatform::SetPortMap(PortMap &&port_map) {
567   m_port_map = port_map;
568 }
569 
570 const FileSpec &GDBRemoteCommunicationServerPlatform::GetDomainSocketDir() {
571   static FileSpec g_domainsocket_dir;
572   static llvm::once_flag g_once_flag;
573 
574   llvm::call_once(g_once_flag, []() {
575     const char *domainsocket_dir_env =
576         ::getenv("LLDB_DEBUGSERVER_DOMAINSOCKET_DIR");
577     if (domainsocket_dir_env != nullptr)
578       g_domainsocket_dir = FileSpec(domainsocket_dir_env);
579     else
580       g_domainsocket_dir = HostInfo::GetProcessTempDir();
581   });
582 
583   return g_domainsocket_dir;
584 }
585 
586 FileSpec
587 GDBRemoteCommunicationServerPlatform::GetDomainSocketPath(const char *prefix) {
588   llvm::SmallString<128> socket_path;
589   llvm::SmallString<128> socket_name(
590       (llvm::StringRef(prefix) + ".%%%%%%").str());
591 
592   FileSpec socket_path_spec(GetDomainSocketDir());
593   socket_path_spec.AppendPathComponent(socket_name.c_str());
594 
595   llvm::sys::fs::createUniqueFile(socket_path_spec.GetCString(), socket_path);
596   return FileSpec(socket_path.c_str());
597 }
598 
599 void GDBRemoteCommunicationServerPlatform::SetPortOffset(uint16_t port_offset) {
600   m_port_offset = port_offset;
601 }
602 
603 void GDBRemoteCommunicationServerPlatform::SetPendingGdbServer(
604     lldb::pid_t pid, uint16_t port, const std::string &socket_name) {
605   m_pending_gdb_server.pid = pid;
606   m_pending_gdb_server.port = port;
607   m_pending_gdb_server.socket_name = socket_name;
608 }
609