LLDB mainline
PlatformRemoteGDBServer.cpp
Go to the documentation of this file.
1//===-- PlatformRemoteGDBServer.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
10#include "lldb/Host/Config.h"
11
13#include "lldb/Core/Debugger.h"
14#include "lldb/Core/Module.h"
20#include "lldb/Host/Host.h"
21#include "lldb/Host/HostInfo.h"
22#include "lldb/Host/PosixApi.h"
23#include "lldb/Target/Process.h"
24#include "lldb/Target/Target.h"
27#include "lldb/Utility/Log.h"
29#include "lldb/Utility/Status.h"
32#include "llvm/Support/FormatAdapters.h"
33
36#include <optional>
37
38using namespace lldb;
39using namespace lldb_private;
41
43
44static bool g_initialized = false;
45
46void PlatformRemoteGDBServer::Initialize() {
48
49 if (!g_initialized) {
50 g_initialized = true;
55 }
56}
57
59 if (g_initialized) {
60 g_initialized = false;
62 }
63
65}
66
68 const ArchSpec *arch) {
69 bool create = force;
70 if (!create) {
71 create = !arch->TripleVendorWasSpecified() && !arch->TripleOSWasSpecified();
72 }
73 if (create)
74 return PlatformSP(new PlatformRemoteGDBServer());
75 return PlatformSP();
76}
77
79 return "A platform that uses the GDB remote protocol as the communication "
80 "transport.";
81}
82
84 if (m_platform_description.empty()) {
85 if (IsConnected()) {
86 // Send the get description packet
87 }
88 }
89
90 if (!m_platform_description.empty())
91 return m_platform_description.c_str();
92 return GetDescriptionStatic();
93}
94
96 const ArchSpec &arch,
97 ModuleSpec &module_spec) {
99
100 const auto module_path = module_file_spec.GetPath(false);
101
102 if (!m_gdb_client_up ||
103 !m_gdb_client_up->GetModuleInfo(module_file_spec, arch, module_spec)) {
104 LLDB_LOGF(
105 log,
106 "PlatformRemoteGDBServer::%s - failed to get module info for %s:%s",
107 __FUNCTION__, module_path.c_str(),
108 arch.GetTriple().getTriple().c_str());
109 return false;
110 }
111
112 if (log) {
113 StreamString stream;
114 module_spec.Dump(stream);
115 LLDB_LOGF(log,
116 "PlatformRemoteGDBServer::%s - got module info for (%s:%s) : %s",
117 __FUNCTION__, module_path.c_str(),
118 arch.GetTriple().getTriple().c_str(), stream.GetData());
119 }
120
121 return true;
122}
123
125 const UUID *uuid_ptr,
126 FileSpec &local_file) {
127 // Default to the local case
128 local_file = platform_file;
129 return Status();
130}
131
132/// Default Constructor
134 : Platform(/*is_host=*/false) {}
135
136/// Destructor.
137///
138/// The destructor is virtual since this class is designed to be
139/// inherited from by the plug-in instance.
141
143 Target &target, BreakpointSite *bp_site) {
144 // This isn't needed if the z/Z packets are supported in the GDB remote
145 // server. But we might need a packet to detect this.
146 return 0;
147}
148
150 if (m_gdb_client_up)
151 m_os_version = m_gdb_client_up->GetOSVersion();
152 return !m_os_version.empty();
153}
154
156 if (!m_gdb_client_up)
157 return std::nullopt;
158 return m_gdb_client_up->GetOSBuildString();
159}
160
161std::optional<std::string>
163 if (!m_gdb_client_up)
164 return std::nullopt;
165 return m_gdb_client_up->GetOSKernelDescription();
166}
167
168// Remote Platform subclasses need to override this function
170 if (!m_gdb_client_up)
171 return ArchSpec();
172 return m_gdb_client_up->GetSystemArchitecture();
173}
174
176 if (IsConnected()) {
178 FileSpec working_dir;
179 if (m_gdb_client_up->GetWorkingDir(working_dir) && log)
180 LLDB_LOGF(log,
181 "PlatformRemoteGDBServer::GetRemoteWorkingDirectory() -> '%s'",
182 working_dir.GetPath().c_str());
183 return working_dir;
184 } else {
186 }
187}
188
190 const FileSpec &working_dir) {
191 if (IsConnected()) {
192 // Clear the working directory it case it doesn't get set correctly. This
193 // will for use to re-read it
195 LLDB_LOGF(log, "PlatformRemoteGDBServer::SetRemoteWorkingDirectory('%s')",
196 working_dir.GetPath().c_str());
197 return m_gdb_client_up->SetWorkingDir(working_dir) == 0;
198 } else
199 return Platform::SetRemoteWorkingDirectory(working_dir);
200}
201
203 if (m_gdb_client_up) {
204 assert(m_gdb_client_up->IsConnected());
205 return true;
206 }
207 return false;
208}
209
212 if (IsConnected()) {
213 error.SetErrorStringWithFormat("the platform is already connected to '%s', "
214 "execute 'platform disconnect' to close the "
215 "current connection",
216 GetHostname());
217 return error;
218 }
219
220 if (args.GetArgumentCount() != 1) {
221 error.SetErrorString(
222 "\"platform connect\" takes a single argument: <connect-url>");
223 return error;
224 }
225
226 const char *url = args.GetArgumentAtIndex(0);
227 if (!url)
228 return Status("URL is null.");
229
230 std::optional<URI> parsed_url = URI::Parse(url);
231 if (!parsed_url)
232 return Status("Invalid URL: %s", url);
233
234 // We're going to reuse the hostname when we connect to the debugserver.
235 m_platform_scheme = parsed_url->scheme.str();
236 m_platform_hostname = parsed_url->hostname.str();
237
238 auto client_up =
239 std::make_unique<process_gdb_remote::GDBRemoteCommunicationClient>();
240 client_up->SetPacketTimeout(
242 client_up->SetConnection(std::make_unique<ConnectionFileDescriptor>());
243 client_up->Connect(url, &error);
244
245 if (error.Fail())
246 return error;
247
248 if (client_up->HandshakeWithServer(&error)) {
249 m_gdb_client_up = std::move(client_up);
250 m_gdb_client_up->GetHostInfo();
251 // If a working directory was set prior to connecting, send it down
252 // now.
253 if (m_working_dir)
254 m_gdb_client_up->SetWorkingDir(m_working_dir);
255
257 ArchSpec remote_arch = m_gdb_client_up->GetSystemArchitecture();
258 if (remote_arch) {
259 m_supported_architectures.push_back(remote_arch);
260 if (remote_arch.GetTriple().isArch64Bit())
262 ArchSpec(remote_arch.GetTriple().get32BitArchVariant()));
263 }
264 } else {
265 client_up->Disconnect();
266 if (error.Success())
267 error.SetErrorString("handshake failed");
268 }
269 return error;
270}
271
274 m_gdb_client_up.reset();
275 m_remote_signals_sp.reset();
276 return error;
277}
278
280 if (m_gdb_client_up)
281 m_gdb_client_up->GetHostname(m_hostname);
282 if (m_hostname.empty())
283 return nullptr;
284 return m_hostname.c_str();
285}
286
287std::optional<std::string>
289 std::string name;
290 if (m_gdb_client_up && m_gdb_client_up->GetUserName(uid, name))
291 return std::move(name);
292 return std::nullopt;
293}
294
295std::optional<std::string>
297 std::string name;
298 if (m_gdb_client_up && m_gdb_client_up->GetGroupName(gid, name))
299 return std::move(name);
300 return std::nullopt;
301}
302
304 const ProcessInstanceInfoMatch &match_info,
305 ProcessInstanceInfoList &process_infos) {
306 if (m_gdb_client_up)
307 return m_gdb_client_up->FindProcesses(match_info, process_infos);
308 return 0;
309}
310
312 lldb::pid_t pid, ProcessInstanceInfo &process_info) {
313 if (m_gdb_client_up)
314 return m_gdb_client_up->GetProcessInfo(pid, process_info);
315 return false;
316}
317
321
322 LLDB_LOGF(log, "PlatformRemoteGDBServer::%s() called", __FUNCTION__);
323
324 if (!IsConnected())
325 return Status("Not connected.");
326 auto num_file_actions = launch_info.GetNumFileActions();
327 for (decltype(num_file_actions) i = 0; i < num_file_actions; ++i) {
328 const auto file_action = launch_info.GetFileActionAtIndex(i);
329 if (file_action->GetAction() != FileAction::eFileActionOpen)
330 continue;
331 switch (file_action->GetFD()) {
332 case STDIN_FILENO:
333 m_gdb_client_up->SetSTDIN(file_action->GetFileSpec());
334 break;
335 case STDOUT_FILENO:
336 m_gdb_client_up->SetSTDOUT(file_action->GetFileSpec());
337 break;
338 case STDERR_FILENO:
339 m_gdb_client_up->SetSTDERR(file_action->GetFileSpec());
340 break;
341 }
342 }
343
344 m_gdb_client_up->SetDisableASLR(
345 launch_info.GetFlags().Test(eLaunchFlagDisableASLR));
346 m_gdb_client_up->SetDetachOnError(
347 launch_info.GetFlags().Test(eLaunchFlagDetachOnError));
348
349 FileSpec working_dir = launch_info.GetWorkingDirectory();
350 if (working_dir) {
351 m_gdb_client_up->SetWorkingDir(working_dir);
352 }
353
354 // Send the environment and the program + arguments after we connect
355 m_gdb_client_up->SendEnvironment(launch_info.GetEnvironment());
356
357 ArchSpec arch_spec = launch_info.GetArchitecture();
358 const char *arch_triple = arch_spec.GetTriple().str().c_str();
359
360 m_gdb_client_up->SendLaunchArchPacket(arch_triple);
361 LLDB_LOGF(
362 log,
363 "PlatformRemoteGDBServer::%s() set launch architecture triple to '%s'",
364 __FUNCTION__, arch_triple ? arch_triple : "<NULL>");
365
366 {
367 // Scope for the scoped timeout object
369 *m_gdb_client_up, std::chrono::seconds(5));
370 // Since we can't send argv0 separate from the executable path, we need to
371 // make sure to use the actual executable path found in the launch_info...
372 Args args = launch_info.GetArguments();
373 if (FileSpec exe_file = launch_info.GetExecutableFile())
374 args.ReplaceArgumentAtIndex(0, exe_file.GetPath(false));
375 if (llvm::Error err = m_gdb_client_up->LaunchProcess(args)) {
376 error.SetErrorStringWithFormatv("Cannot launch '{0}': {1}",
377 args.GetArgumentAtIndex(0),
378 llvm::fmt_consume(std::move(err)));
379 return error;
380 }
381 }
382
383 const auto pid = m_gdb_client_up->GetCurrentProcessID(false);
384 if (pid != LLDB_INVALID_PROCESS_ID) {
385 launch_info.SetProcessID(pid);
386 LLDB_LOGF(log,
387 "PlatformRemoteGDBServer::%s() pid %" PRIu64
388 " launched successfully",
389 __FUNCTION__, pid);
390 } else {
391 LLDB_LOGF(log,
392 "PlatformRemoteGDBServer::%s() launch succeeded but we "
393 "didn't get a valid process id back!",
394 __FUNCTION__);
395 error.SetErrorString("failed to get PID");
396 }
397 return error;
398}
399
401 if (!KillSpawnedProcess(pid))
402 return Status("failed to kill remote spawned process");
403 return Status();
404}
405
406lldb::ProcessSP
408 Debugger &debugger, Target &target,
409 Status &error) {
410 lldb::ProcessSP process_sp;
411 if (IsRemote()) {
412 if (IsConnected()) {
413 lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
414 std::string connect_url;
415 if (!LaunchGDBServer(debugserver_pid, connect_url)) {
416 error.SetErrorStringWithFormat("unable to launch a GDB server on '%s'",
417 GetHostname());
418 } else {
419 // The darwin always currently uses the GDB remote debugger plug-in
420 // so even when debugging locally we are debugging remotely!
421 process_sp = target.CreateProcess(launch_info.GetListener(),
422 "gdb-remote", nullptr, true);
423
424 if (process_sp) {
425 process_sp->HijackProcessEvents(launch_info.GetHijackListener());
426 process_sp->SetShadowListener(launch_info.GetShadowListener());
427
428 error = process_sp->ConnectRemote(connect_url.c_str());
429 // Retry the connect remote one time...
430 if (error.Fail())
431 error = process_sp->ConnectRemote(connect_url.c_str());
432 if (error.Success())
433 error = process_sp->Launch(launch_info);
434 else if (debugserver_pid != LLDB_INVALID_PROCESS_ID) {
435 printf("error: connect remote failed (%s)\n", error.AsCString());
436 KillSpawnedProcess(debugserver_pid);
437 }
438 }
439 }
440 } else {
441 error.SetErrorString("not connected to remote gdb server");
442 }
443 }
444 return process_sp;
445}
446
448 std::string &connect_url) {
449 assert(IsConnected());
450
452 llvm::Triple &remote_triple = remote_arch.GetTriple();
453
454 uint16_t port = 0;
455 std::string socket_name;
456 bool launch_result = false;
457 if (remote_triple.getVendor() == llvm::Triple::Apple &&
458 remote_triple.getOS() == llvm::Triple::IOS) {
459 // When remote debugging to iOS, we use a USB mux that always talks to
460 // localhost, so we will need the remote debugserver to accept connections
461 // only from localhost, no matter what our current hostname is
462 launch_result =
463 m_gdb_client_up->LaunchGDBServer("127.0.0.1", pid, port, socket_name);
464 } else {
465 // All other hosts should use their actual hostname
466 launch_result =
467 m_gdb_client_up->LaunchGDBServer(nullptr, pid, port, socket_name);
468 }
469
470 if (!launch_result)
471 return false;
472
473 connect_url =
475 (socket_name.empty()) ? nullptr : socket_name.c_str());
476 return true;
477}
478
480 assert(IsConnected());
481 return m_gdb_client_up->KillSpawnedProcess(pid);
482}
483
485 ProcessAttachInfo &attach_info, Debugger &debugger,
486 Target *target, // Can be NULL, if NULL create a new target, else use
487 // existing one
488 Status &error) {
489 lldb::ProcessSP process_sp;
490 if (IsRemote()) {
491 if (IsConnected()) {
492 lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
493 std::string connect_url;
494 if (!LaunchGDBServer(debugserver_pid, connect_url)) {
495 error.SetErrorStringWithFormat("unable to launch a GDB server on '%s'",
496 GetHostname());
497 } else {
498 if (target == nullptr) {
499 TargetSP new_target_sp;
500
501 error = debugger.GetTargetList().CreateTarget(
502 debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
503 target = new_target_sp.get();
504 } else
505 error.Clear();
506
507 if (target && error.Success()) {
508 // The darwin always currently uses the GDB remote debugger plug-in
509 // so even when debugging locally we are debugging remotely!
510 process_sp =
511 target->CreateProcess(attach_info.GetListenerForProcess(debugger),
512 "gdb-remote", nullptr, true);
513 if (process_sp) {
514 error = process_sp->ConnectRemote(connect_url.c_str());
515 if (error.Success()) {
516 ListenerSP listener_sp = attach_info.GetHijackListener();
517 if (listener_sp)
518 process_sp->HijackProcessEvents(listener_sp);
519 process_sp->SetShadowListener(attach_info.GetShadowListener());
520 error = process_sp->Attach(attach_info);
521 }
522
523 if (error.Fail() && debugserver_pid != LLDB_INVALID_PROCESS_ID) {
524 KillSpawnedProcess(debugserver_pid);
525 }
526 }
527 }
528 }
529 } else {
530 error.SetErrorString("not connected to remote gdb server");
531 }
532 }
533 return process_sp;
534}
535
537 uint32_t mode) {
538 if (!IsConnected())
539 return Status("Not connected.");
540 Status error = m_gdb_client_up->MakeDirectory(file_spec, mode);
542 LLDB_LOGF(log,
543 "PlatformRemoteGDBServer::MakeDirectory(path='%s', mode=%o) "
544 "error = %u (%s)",
545 file_spec.GetPath().c_str(), mode, error.GetError(),
546 error.AsCString());
547 return error;
548}
549
551 uint32_t &file_permissions) {
552 if (!IsConnected())
553 return Status("Not connected.");
554 Status error =
555 m_gdb_client_up->GetFilePermissions(file_spec, file_permissions);
557 LLDB_LOGF(log,
558 "PlatformRemoteGDBServer::GetFilePermissions(path='%s', "
559 "file_permissions=%o) error = %u (%s)",
560 file_spec.GetPath().c_str(), file_permissions, error.GetError(),
561 error.AsCString());
562 return error;
563}
564
566 uint32_t file_permissions) {
567 if (!IsConnected())
568 return Status("Not connected.");
569 Status error =
570 m_gdb_client_up->SetFilePermissions(file_spec, file_permissions);
572 LLDB_LOGF(log,
573 "PlatformRemoteGDBServer::SetFilePermissions(path='%s', "
574 "file_permissions=%o) error = %u (%s)",
575 file_spec.GetPath().c_str(), file_permissions, error.GetError(),
576 error.AsCString());
577 return error;
578}
579
581 File::OpenOptions flags,
582 uint32_t mode,
583 Status &error) {
584 if (IsConnected())
585 return m_gdb_client_up->OpenFile(file_spec, flags, mode, error);
586 return LLDB_INVALID_UID;
587}
588
590 if (IsConnected())
591 return m_gdb_client_up->CloseFile(fd, error);
592 error = Status("Not connected.");
593 return false;
594}
595
598 if (IsConnected())
599 return m_gdb_client_up->GetFileSize(file_spec);
600 return LLDB_INVALID_UID;
601}
602
604 CompletionRequest &request, bool only_dir) {
605 if (IsConnected())
606 m_gdb_client_up->AutoCompleteDiskFileOrDirectory(request, only_dir);
607}
608
610 void *dst, uint64_t dst_len,
611 Status &error) {
612 if (IsConnected())
613 return m_gdb_client_up->ReadFile(fd, offset, dst, dst_len, error);
614 error = Status("Not connected.");
615 return 0;
616}
617
619 const void *src, uint64_t src_len,
620 Status &error) {
621 if (IsConnected())
622 return m_gdb_client_up->WriteFile(fd, offset, src, src_len, error);
623 error = Status("Not connected.");
624 return 0;
625}
626
628 const FileSpec &destination,
629 uint32_t uid, uint32_t gid) {
630 return Platform::PutFile(source, destination, uid, gid);
631}
632
634 const FileSpec &src, // The name of the link is in src
635 const FileSpec &dst) // The symlink points to dst
636{
637 if (!IsConnected())
638 return Status("Not connected.");
639 Status error = m_gdb_client_up->CreateSymlink(src, dst);
641 LLDB_LOGF(log,
642 "PlatformRemoteGDBServer::CreateSymlink(src='%s', dst='%s') "
643 "error = %u (%s)",
644 src.GetPath().c_str(), dst.GetPath().c_str(), error.GetError(),
645 error.AsCString());
646 return error;
647}
648
650 if (!IsConnected())
651 return Status("Not connected.");
652 Status error = m_gdb_client_up->Unlink(file_spec);
654 LLDB_LOGF(log, "PlatformRemoteGDBServer::Unlink(path='%s') error = %u (%s)",
655 file_spec.GetPath().c_str(), error.GetError(), error.AsCString());
656 return error;
657}
658
660 if (IsConnected())
661 return m_gdb_client_up->GetFileExists(file_spec);
662 return false;
663}
664
666 llvm::StringRef shell, llvm::StringRef command,
667 const FileSpec &
668 working_dir, // Pass empty FileSpec to use the current working directory
669 int *status_ptr, // Pass NULL if you don't want the process exit status
670 int *signo_ptr, // Pass NULL if you don't want the signal that caused the
671 // process to exit
672 std::string
673 *command_output, // Pass NULL if you don't want the command output
674 const Timeout<std::micro> &timeout) {
675 if (!IsConnected())
676 return Status("Not connected.");
677 return m_gdb_client_up->RunShellCommand(command, working_dir, status_ptr,
678 signo_ptr, command_output, timeout);
679}
680
682 m_trap_handlers.push_back(ConstString("_sigtramp"));
683}
684
686 if (!IsConnected())
688
690 return m_remote_signals_sp;
691
692 // If packet not implemented or JSON failed to parse, we'll guess the signal
693 // set based on the remote architecture.
695
697 auto result =
698 m_gdb_client_up->SendPacketAndWaitForResponse("jSignalsInfo", response);
699
700 if (result != decltype(result)::Success ||
701 response.GetResponseType() != response.eResponse)
702 return m_remote_signals_sp;
703
704 auto object_sp = StructuredData::ParseJSON(response.GetStringRef());
705 if (!object_sp || !object_sp->IsValid())
706 return m_remote_signals_sp;
707
708 auto array_sp = object_sp->GetAsArray();
709 if (!array_sp || !array_sp->IsValid())
710 return m_remote_signals_sp;
711
712 auto remote_signals_sp = std::make_shared<lldb_private::GDBRemoteSignals>();
713
714 bool done = array_sp->ForEach(
715 [&remote_signals_sp](StructuredData::Object *object) -> bool {
716 if (!object || !object->IsValid())
717 return false;
718
719 auto dict = object->GetAsDictionary();
720 if (!dict || !dict->IsValid())
721 return false;
722
723 // Signal number and signal name are required.
724 uint64_t signo;
725 if (!dict->GetValueForKeyAsInteger("signo", signo))
726 return false;
727
728 llvm::StringRef name;
729 if (!dict->GetValueForKeyAsString("name", name))
730 return false;
731
732 // We can live without short_name, description, etc.
733 bool suppress{false};
734 auto object_sp = dict->GetValueForKey("suppress");
735 if (object_sp && object_sp->IsValid())
736 suppress = object_sp->GetBooleanValue();
737
738 bool stop{false};
739 object_sp = dict->GetValueForKey("stop");
740 if (object_sp && object_sp->IsValid())
741 stop = object_sp->GetBooleanValue();
742
743 bool notify{false};
744 object_sp = dict->GetValueForKey("notify");
745 if (object_sp && object_sp->IsValid())
746 notify = object_sp->GetBooleanValue();
747
748 std::string description;
749 object_sp = dict->GetValueForKey("description");
750 if (object_sp && object_sp->IsValid())
751 description = std::string(object_sp->GetStringValue());
752
753 remote_signals_sp->AddSignal(signo, name.str().c_str(), suppress, stop,
754 notify, description.c_str());
755 return true;
756 });
757
758 if (done)
759 m_remote_signals_sp = std::move(remote_signals_sp);
760
761 return m_remote_signals_sp;
762}
763
765 const std::string &platform_scheme, const std::string &platform_hostname,
766 uint16_t port, const char *socket_name) {
767 const char *override_scheme =
768 getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_SCHEME");
769 const char *override_hostname =
770 getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME");
771 const char *port_offset_c_str =
772 getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET");
773 int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0;
774
775 return MakeUrl(override_scheme ? override_scheme : platform_scheme.c_str(),
776 override_hostname ? override_hostname
777 : platform_hostname.c_str(),
778 port + port_offset, socket_name);
779}
780
781std::string PlatformRemoteGDBServer::MakeUrl(const char *scheme,
782 const char *hostname,
783 uint16_t port, const char *path) {
784 StreamString result;
785 result.Printf("%s://[%s]", scheme, hostname);
786 if (port != 0)
787 result.Printf(":%u", port);
788 if (path)
789 result.Write(path, strlen(path));
790 return std::string(result.GetString());
791}
792
794 Status &error) {
795 std::vector<std::string> connection_urls;
796 GetPendingGdbServerList(connection_urls);
797
798 for (size_t i = 0; i < connection_urls.size(); ++i) {
799 ConnectProcess(connection_urls[i].c_str(), "gdb-remote", debugger, nullptr, error);
800 if (error.Fail())
801 return i; // We already connected to i process successfully
802 }
803 return connection_urls.size();
804}
805
807 std::vector<std::string> &connection_urls) {
808 std::vector<std::pair<uint16_t, std::string>> remote_servers;
809 if (!IsConnected())
810 return 0;
811 m_gdb_client_up->QueryGDBServer(remote_servers);
812 for (const auto &gdbserver : remote_servers) {
813 const char *socket_name_cstr =
814 gdbserver.second.empty() ? nullptr : gdbserver.second.c_str();
815 connection_urls.emplace_back(
817 gdbserver.first, socket_name_cstr));
818 }
819 return connection_urls.size();
820}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:344
static bool g_initialized
#define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName)
Definition: PluginManager.h:25
ResponseType GetResponseType() const
llvm::StringRef GetStringRef() const
An architecture specification class.
Definition: ArchSpec.h:31
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:450
bool TripleVendorWasSpecified() const
Definition: ArchSpec.h:353
bool TripleOSWasSpecified() const
Definition: ArchSpec.h:357
A command line argument class.
Definition: Args.h:33
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:116
void ReplaceArgumentAtIndex(size_t idx, llvm::StringRef arg_str, char quote_char='\0')
Replaces the argument value at index idx to arg_str if idx is a valid argument index.
Definition: Args.cpp:337
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition: Args.cpp:263
Class that manages the actual breakpoint that will be inserted into the running program.
"lldb/Utility/ArgCompletionRequest.h"
A uniqued constant string class.
Definition: ConstString.h:39
A class to manage flag bits.
Definition: Debugger.h:78
TargetList & GetTargetList()
Get accessor for the target list.
Definition: Debugger.h:201
A file utility class.
Definition: FileSpec.h:56
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:366
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
void Dump(Stream &strm) const
Definition: ModuleSpec.h:162
A plug-in interface definition class for debug platform that includes many platform abilities such as...
Definition: Platform.h:72
virtual FileSpec GetRemoteWorkingDirectory()
Definition: Platform.h:248
std::vector< ConstString > m_trap_handlers
Definition: Platform.h:926
static void Terminate()
Definition: Platform.cpp:139
llvm::VersionTuple m_os_version
Definition: Platform.h:910
virtual Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX)
Definition: Platform.cpp:1178
virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir)
Definition: Platform.cpp:737
virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Target *target, Status &error)
Definition: Platform.cpp:1752
static void Initialize()
Definition: Platform.cpp:137
std::string m_hostname
Definition: Platform.h:909
bool IsRemote() const
Definition: Platform.h:425
FileSpec m_working_dir
Definition: Platform.h:906
virtual const lldb::UnixSignalsSP & GetRemoteUnixSignals()
Definition: Platform.cpp:1673
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
lldb::ListenerSP GetListenerForProcess(Debugger &debugger)
Definition: Process.cpp:2793
lldb::ListenerSP GetHijackListener() const
Definition: ProcessInfo.h:107
void SetProcessID(lldb::pid_t pid)
Definition: ProcessInfo.h:69
FileSpec & GetExecutableFile()
Definition: ProcessInfo.h:42
lldb::ListenerSP GetListener() const
Definition: ProcessInfo.h:101
lldb::ListenerSP GetShadowListener() const
Definition: ProcessInfo.h:113
Environment & GetEnvironment()
Definition: ProcessInfo.h:87
ArchSpec & GetArchitecture()
Definition: ProcessInfo.h:61
const FileAction * GetFileActionAtIndex(size_t idx) const
const FileSpec & GetWorkingDirectory() const
An error handling class.
Definition: Status.h:44
const char * GetData() const
Definition: StreamString.h:43
llvm::StringRef GetString() const
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition: Stream.h:101
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
ObjectSP GetValueForKey(llvm::StringRef key) const
static ObjectSP ParseJSON(llvm::StringRef json_text)
Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles get_dependent_modules, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp)
Create a new Target.
const lldb::ProcessSP & CreateProcess(lldb::ListenerSP listener_sp, llvm::StringRef plugin_name, const FileSpec *crash_file, bool can_connect)
Definition: Target.cpp:207
static lldb::UnixSignalsSP Create(const ArchSpec &arch)
Definition: UnixSignals.cpp:33
lldb::user_id_t GetFileSize(const FileSpec &file_spec) override
std::unique_ptr< process_gdb_remote::GDBRemoteCommunicationClient > m_gdb_client_up
std::optional< std::string > GetRemoteOSKernelDescription() override
Status MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) override
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) override
Attach to an existing process by process name.
virtual size_t GetPendingGdbServerList(std::vector< std::string > &connection_urls)
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger, lldb_private::Status &error) override
Connect to all processes waiting for a debugger to attach.
Status RunShellCommand(llvm::StringRef shell, llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const lldb_private::Timeout< std::micro > &timeout) override
virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url)
Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *data, uint64_t len, Status &error) override
Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) override
virtual std::string MakeUrl(const char *scheme, const char *hostname, uint16_t port, const char *path)
Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr, FileSpec &local_file) override
Locate a file for a platform.
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *data_ptr, uint64_t len, Status &error) override
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override
bool CloseFile(lldb::user_id_t fd, Status &error) override
std::optional< std::string > DoGetGroupName(UserIDResolver::id_t uid) override
Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) override
bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override
Status LaunchProcess(ProcessLaunchInfo &launch_info) override
Launch a new process on a platform, not necessarily for debugging, it could be just for running the p...
std::string MakeGdbServerUrl(const std::string &platform_scheme, const std::string &platform_hostname, uint16_t port, const char *socket_name)
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) override
std::optional< std::string > DoGetUserName(UserIDResolver::id_t uid) override
void AutoCompleteDiskFileOrDirectory(CompletionRequest &request, bool only_dir) override
lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error) override
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override
Status KillProcess(const lldb::pid_t pid) override
Kill process on a platform.
lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, Status &error) override
Attach to an existing process using a process ID.
size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override
lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, Target &target, Status &error) override
Subclasses do not need to implement this function as it uses the Platform::LaunchProcess() followed b...
#define LLDB_INVALID_UID
Definition: lldb-defines.h:80
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:81
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition: Host.h:32
Definition: SBAddress.h:15
uint64_t pid_t
Definition: lldb-types.h:81
uint64_t user_id_t
Definition: lldb-types.h:80
static std::optional< URI > Parse(llvm::StringRef uri)
Definition: UriParser.cpp:28