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"
19#include "lldb/Host/Host.h"
20#include "lldb/Host/HostInfo.h"
21#include "lldb/Host/PosixApi.h"
22#include "lldb/Target/Process.h"
23#include "lldb/Target/Target.h"
26#include "lldb/Utility/Log.h"
28#include "lldb/Utility/Status.h"
31#include "llvm/Support/FormatAdapters.h"
32
35#include <optional>
36
37using namespace lldb;
38using namespace lldb_private;
40
42
43static bool g_initialized = false;
44
56
65
67 const ArchSpec *arch) {
68 bool create = force;
69 if (!create) {
70 create = !arch->TripleVendorWasSpecified() && !arch->TripleOSWasSpecified();
71 }
72 if (create)
74 return PlatformSP();
75}
76
78 return "A platform that uses the GDB remote protocol as the communication "
79 "transport.";
80}
81
83 if (m_platform_description.empty()) {
84 if (IsConnected()) {
85 // Send the get description packet
86 }
87 }
88
89 if (!m_platform_description.empty())
90 return m_platform_description.c_str();
91 return GetDescriptionStatic();
92}
93
95 const ArchSpec &arch,
96 ModuleSpec &module_spec) {
98
99 const auto module_path = module_file_spec.GetPath(false);
100
101 if (!m_gdb_client_up ||
102 !m_gdb_client_up->GetModuleInfo(module_file_spec, arch, module_spec)) {
103 LLDB_LOGF(
104 log,
105 "PlatformRemoteGDBServer::%s - failed to get module info for %s:%s",
106 __FUNCTION__, module_path.c_str(),
107 arch.GetTriple().getTriple().c_str());
108 return false;
109 }
110
111 if (log) {
112 StreamString stream;
113 module_spec.Dump(stream);
114 LLDB_LOGF(log,
115 "PlatformRemoteGDBServer::%s - got module info for (%s:%s) : %s",
116 __FUNCTION__, module_path.c_str(),
117 arch.GetTriple().getTriple().c_str(), stream.GetData());
118 }
119
120 return true;
121}
122
124 const UUID *uuid_ptr,
125 FileSpec &local_file) {
126 // Default to the local case
127 local_file = platform_file;
128 return Status();
129}
130
131/// Default Constructor
134
135/// Destructor.
136///
137/// The destructor is virtual since this class is designed to be
138/// inherited from by the plug-in instance.
140
142 Target &target, BreakpointSite *bp_site) {
143 // This isn't needed if the z/Z packets are supported in the GDB remote
144 // server. But we might need a packet to detect this.
145 return 0;
146}
147
149 if (m_gdb_client_up)
150 m_os_version = m_gdb_client_up->GetOSVersion();
151 return !m_os_version.empty();
152}
153
155 if (!m_gdb_client_up)
156 return std::nullopt;
157 return m_gdb_client_up->GetOSBuildString();
158}
159
160std::optional<std::string>
162 if (!m_gdb_client_up)
163 return std::nullopt;
164 return m_gdb_client_up->GetOSKernelDescription();
165}
166
167// Remote Platform subclasses need to override this function
169 if (!m_gdb_client_up)
170 return ArchSpec();
171 return m_gdb_client_up->GetSystemArchitecture();
172}
173
175 if (IsConnected()) {
177 FileSpec working_dir;
178 if (m_gdb_client_up->GetWorkingDir(working_dir) && log)
179 LLDB_LOGF(log,
180 "PlatformRemoteGDBServer::GetRemoteWorkingDirectory() -> '%s'",
181 working_dir.GetPath().c_str());
182 return working_dir;
183 } else {
185 }
186}
187
189 const FileSpec &working_dir) {
190 if (IsConnected()) {
191 // Clear the working directory it case it doesn't get set correctly. This
192 // will for use to re-read it
194 LLDB_LOGF(log, "PlatformRemoteGDBServer::SetRemoteWorkingDirectory('%s')",
195 working_dir.GetPath().c_str());
196 return m_gdb_client_up->SetWorkingDir(working_dir) == 0;
197 } else
198 return Platform::SetRemoteWorkingDirectory(working_dir);
199}
200
202 return m_gdb_client_up && m_gdb_client_up->IsConnected();
203}
204
207 if (IsConnected())
209 "the platform is already connected to '%s', "
210 "execute 'platform disconnect' to close the "
211 "current connection",
212 GetHostname());
213
214 if (args.GetArgumentCount() != 1)
216 "\"platform connect\" takes a single argument: <connect-url>");
217
218 const char *url = args.GetArgumentAtIndex(0);
219 if (!url)
220 return Status::FromErrorString("URL is null.");
221
222 std::optional<URI> parsed_url = URI::Parse(url);
223 if (!parsed_url)
224 return Status::FromErrorStringWithFormat("Invalid URL: %s", url);
225
226 // We're going to reuse the hostname when we connect to the debugserver.
227 m_platform_scheme = parsed_url->scheme.str();
228 m_platform_hostname = parsed_url->hostname.str();
229
230 auto client_up =
231 std::make_unique<process_gdb_remote::GDBRemoteCommunicationClient>();
232 client_up->SetPacketTimeout(
234 client_up->SetConnection(std::make_unique<ConnectionFileDescriptor>());
235 client_up->Connect(url, &error);
236
237 if (error.Fail())
238 return error;
239
240 if (client_up->HandshakeWithServer(&error)) {
241 m_gdb_client_up = std::move(client_up);
242 m_gdb_client_up->GetHostInfo();
243 // If a working directory was set prior to connecting, send it down
244 // now.
245 if (m_working_dir)
246 m_gdb_client_up->SetWorkingDir(m_working_dir);
247
249 ArchSpec remote_arch = m_gdb_client_up->GetSystemArchitecture();
250 if (remote_arch) {
251 m_supported_architectures.push_back(remote_arch);
252 if (remote_arch.GetTriple().isArch64Bit())
254 ArchSpec(remote_arch.GetTriple().get32BitArchVariant()));
255 }
256 } else {
257 client_up->Disconnect();
258 if (error.Success())
259 error = Status::FromErrorString("handshake failed");
260 }
261 return error;
262}
263
270
272 if (m_gdb_client_up)
273 m_gdb_client_up->GetHostname(m_hostname);
274 if (m_hostname.empty())
275 return nullptr;
276 return m_hostname.c_str();
277}
278
279std::optional<std::string>
281 std::string name;
282 if (m_gdb_client_up && m_gdb_client_up->GetUserName(uid, name))
283 return std::move(name);
284 return std::nullopt;
285}
286
287std::optional<std::string>
289 std::string name;
290 if (m_gdb_client_up && m_gdb_client_up->GetGroupName(gid, name))
291 return std::move(name);
292 return std::nullopt;
293}
294
296 const ProcessInstanceInfoMatch &match_info,
297 ProcessInstanceInfoList &process_infos) {
298 if (m_gdb_client_up)
299 return m_gdb_client_up->FindProcesses(match_info, process_infos);
300 return 0;
301}
302
304 lldb::pid_t pid, ProcessInstanceInfo &process_info) {
305 if (m_gdb_client_up)
306 return m_gdb_client_up->GetProcessInfo(pid, process_info);
307 return false;
308}
309
313
314 LLDB_LOGF(log, "PlatformRemoteGDBServer::%s() called", __FUNCTION__);
315
316 if (!IsConnected())
317 return Status::FromErrorStringWithFormat("Not connected.");
318 auto num_file_actions = launch_info.GetNumFileActions();
319 for (decltype(num_file_actions) i = 0; i < num_file_actions; ++i) {
320 const auto file_action = launch_info.GetFileActionAtIndex(i);
321 if (file_action->GetAction() != FileAction::eFileActionOpen)
322 continue;
323 switch (file_action->GetFD()) {
324 case STDIN_FILENO:
325 m_gdb_client_up->SetSTDIN(file_action->GetFileSpec());
326 break;
327 case STDOUT_FILENO:
328 m_gdb_client_up->SetSTDOUT(file_action->GetFileSpec());
329 break;
330 case STDERR_FILENO:
331 m_gdb_client_up->SetSTDERR(file_action->GetFileSpec());
332 break;
333 }
334 }
335
336 m_gdb_client_up->SetDisableASLR(
337 launch_info.GetFlags().Test(eLaunchFlagDisableASLR));
338 m_gdb_client_up->SetDetachOnError(
339 launch_info.GetFlags().Test(eLaunchFlagDetachOnError));
340
341 FileSpec working_dir = launch_info.GetWorkingDirectory();
342 if (working_dir) {
343 m_gdb_client_up->SetWorkingDir(working_dir);
344 }
345
346 // Send the environment and the program + arguments after we connect
347 m_gdb_client_up->SendEnvironment(launch_info.GetEnvironment());
348
349 ArchSpec arch_spec = launch_info.GetArchitecture();
350 const char *arch_triple = arch_spec.GetTriple().str().c_str();
351
352 m_gdb_client_up->SendLaunchArchPacket(arch_triple);
353 LLDB_LOGF(
354 log,
355 "PlatformRemoteGDBServer::%s() set launch architecture triple to '%s'",
356 __FUNCTION__, arch_triple ? arch_triple : "<NULL>");
357
358 {
359 // Scope for the scoped timeout object
361 *m_gdb_client_up, std::chrono::seconds(5));
362 // Since we can't send argv0 separate from the executable path, we need to
363 // make sure to use the actual executable path found in the launch_info...
364 Args args = launch_info.GetArguments();
365 if (FileSpec exe_file = launch_info.GetExecutableFile())
366 args.ReplaceArgumentAtIndex(0, exe_file.GetPath(false));
367 if (llvm::Error err = m_gdb_client_up->LaunchProcess(args)) {
369 "Cannot launch '{0}': {1}", args.GetArgumentAtIndex(0),
370 llvm::fmt_consume(std::move(err)));
371 return error;
372 }
373 }
374
375 const auto pid = m_gdb_client_up->GetCurrentProcessID(false);
376 if (pid != LLDB_INVALID_PROCESS_ID) {
377 launch_info.SetProcessID(pid);
378 LLDB_LOGF(log,
379 "PlatformRemoteGDBServer::%s() pid %" PRIu64
380 " launched successfully",
381 __FUNCTION__, pid);
382 } else {
383 LLDB_LOGF(log,
384 "PlatformRemoteGDBServer::%s() launch succeeded but we "
385 "didn't get a valid process id back!",
386 __FUNCTION__);
387 error = Status::FromErrorString("failed to get PID");
388 }
389 return error;
390}
391
393 if (!KillSpawnedProcess(pid))
395 "failed to kill remote spawned process");
396 return Status();
397}
398
401 Debugger &debugger, Target &target,
402 Status &error) {
403 lldb::ProcessSP process_sp;
404 if (IsRemote()) {
405 if (IsConnected()) {
406 lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
407 std::string connect_url;
408 if (!LaunchGDBServer(debugserver_pid, connect_url)) {
410 "unable to launch a GDB server on '%s'", GetHostname());
411 } else {
412 // By default, we always use the GDB remote debugger plug-in.
413 // Even when debugging locally, we are debugging remotely.
414 llvm::StringRef process_plugin = GetDefaultProcessPluginName();
415
416 // However, if a process plugin is specified by the attach info, we
417 // should honor it.
418 if (!launch_info.GetProcessPluginName().empty())
419 process_plugin = launch_info.GetProcessPluginName();
420
421 process_sp = target.CreateProcess(launch_info.GetListener(),
422 process_plugin, 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 = Status::FromErrorString("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)) {
496 "unable to launch a GDB server on '%s'", 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 // By default, we always use the GDB remote debugger plug-in.
509 // Even when debugging locally, we are debugging remotely.
510 llvm::StringRef process_plugin = GetDefaultProcessPluginName();
511
512 // However, if a process plugin is specified by the attach info, we
513 // should honor it.
514 if (!attach_info.GetProcessPluginName().empty())
515 process_plugin = attach_info.GetProcessPluginName();
516
517 process_sp =
518 target->CreateProcess(attach_info.GetListenerForProcess(debugger),
519 process_plugin, nullptr, true);
520 if (process_sp) {
521 error = process_sp->ConnectRemote(connect_url.c_str());
522 if (error.Success()) {
523 ListenerSP listener_sp = attach_info.GetHijackListener();
524 if (listener_sp)
525 process_sp->HijackProcessEvents(listener_sp);
526 process_sp->SetShadowListener(attach_info.GetShadowListener());
527 error = process_sp->Attach(attach_info);
528 }
529
530 if (error.Fail() && debugserver_pid != LLDB_INVALID_PROCESS_ID) {
531 KillSpawnedProcess(debugserver_pid);
532 }
533 }
534 }
535 }
536 } else {
537 error = Status::FromErrorString("not connected to remote gdb server");
538 }
539 }
540 return process_sp;
541}
542
544 uint32_t mode) {
545 if (!IsConnected())
546 return Status::FromErrorStringWithFormat("Not connected.");
547 Status error = m_gdb_client_up->MakeDirectory(file_spec, mode);
549 LLDB_LOGF(log,
550 "PlatformRemoteGDBServer::MakeDirectory(path='%s', mode=%o) "
551 "error = %u (%s)",
552 file_spec.GetPath().c_str(), mode, error.GetError(),
553 error.AsCString());
554 return error;
555}
556
558 uint32_t &file_permissions) {
559 if (!IsConnected())
560 return Status::FromErrorStringWithFormat("Not connected.");
561 Status error =
562 m_gdb_client_up->GetFilePermissions(file_spec, file_permissions);
564 LLDB_LOGF(log,
565 "PlatformRemoteGDBServer::GetFilePermissions(path='%s', "
566 "file_permissions=%o) error = %u (%s)",
567 file_spec.GetPath().c_str(), file_permissions, error.GetError(),
568 error.AsCString());
569 return error;
570}
571
573 uint32_t file_permissions) {
574 if (!IsConnected())
575 return Status::FromErrorStringWithFormat("Not connected.");
576 Status error =
577 m_gdb_client_up->SetFilePermissions(file_spec, file_permissions);
579 LLDB_LOGF(log,
580 "PlatformRemoteGDBServer::SetFilePermissions(path='%s', "
581 "file_permissions=%o) error = %u (%s)",
582 file_spec.GetPath().c_str(), file_permissions, error.GetError(),
583 error.AsCString());
584 return error;
585}
586
588 File::OpenOptions flags,
589 uint32_t mode,
590 Status &error) {
591 if (IsConnected())
592 return m_gdb_client_up->OpenFile(file_spec, flags, mode, error);
593 return LLDB_INVALID_UID;
594}
595
597 if (IsConnected())
598 return m_gdb_client_up->CloseFile(fd, error);
599 error = Status::FromErrorStringWithFormat("Not connected.");
600 return false;
601}
602
605 if (IsConnected())
606 return m_gdb_client_up->GetFileSize(file_spec);
607 return LLDB_INVALID_UID;
608}
609
611 CompletionRequest &request, bool only_dir) {
612 if (IsConnected())
613 m_gdb_client_up->AutoCompleteDiskFileOrDirectory(request, only_dir);
614}
615
617 void *dst, uint64_t dst_len,
618 Status &error) {
619 if (IsConnected())
620 return m_gdb_client_up->ReadFile(fd, offset, dst, dst_len, error);
621 error = Status::FromErrorStringWithFormat("Not connected.");
622 return 0;
623}
624
626 const void *src, uint64_t src_len,
627 Status &error) {
628 if (IsConnected())
629 return m_gdb_client_up->WriteFile(fd, offset, src, src_len, error);
630 error = Status::FromErrorStringWithFormat("Not connected.");
631 return 0;
632}
633
635 const FileSpec &destination,
636 uint32_t uid, uint32_t gid) {
637 return Platform::PutFile(source, destination, uid, gid);
638}
639
641 const FileSpec &src, // The name of the link is in src
642 const FileSpec &dst) // The symlink points to dst
643{
644 if (!IsConnected())
645 return Status::FromErrorStringWithFormat("Not connected.");
646 Status error = m_gdb_client_up->CreateSymlink(src, dst);
648 LLDB_LOGF(log,
649 "PlatformRemoteGDBServer::CreateSymlink(src='%s', dst='%s') "
650 "error = %u (%s)",
651 src.GetPath().c_str(), dst.GetPath().c_str(), error.GetError(),
652 error.AsCString());
653 return error;
654}
655
657 if (!IsConnected())
658 return Status::FromErrorStringWithFormat("Not connected.");
659 Status error = m_gdb_client_up->Unlink(file_spec);
661 LLDB_LOGF(log, "PlatformRemoteGDBServer::Unlink(path='%s') error = %u (%s)",
662 file_spec.GetPath().c_str(), error.GetError(), error.AsCString());
663 return error;
664}
665
667 if (IsConnected())
668 return m_gdb_client_up->GetFileExists(file_spec);
669 return false;
670}
671
673 llvm::StringRef shell, llvm::StringRef command,
674 const FileSpec &
675 working_dir, // Pass empty FileSpec to use the current working directory
676 int *status_ptr, // Pass NULL if you don't want the process exit status
677 int *signo_ptr, // Pass NULL if you don't want the signal that caused the
678 // process to exit
679 std::string
680 *command_output, // Pass nullptr if you don't want the command output
681 std::string *separated_error_output, // Pass nullptr if you don't want the
682 // error output
683 const Timeout<std::micro> &timeout) {
684 if (!IsConnected())
685 return Status::FromErrorStringWithFormat("Not connected.");
686 return m_gdb_client_up->RunShellCommand(command, working_dir, status_ptr,
687 signo_ptr, command_output,
688 separated_error_output, timeout);
689}
690
691llvm::ErrorOr<llvm::MD5::MD5Result>
693 if (!IsConnected())
694 return std::make_error_code(std::errc::not_connected);
695
696 return m_gdb_client_up->CalculateMD5(file_spec);
697}
698
702
712
714 const std::string &platform_scheme, const std::string &platform_hostname,
715 uint16_t port, const char *socket_name) {
716 const char *override_scheme =
717 getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_SCHEME");
718 const char *override_hostname =
719 getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME");
720 const char *port_offset_c_str =
721 getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET");
722 int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0;
723
724 return MakeUrl(override_scheme ? override_scheme : platform_scheme.c_str(),
725 override_hostname ? override_hostname
726 : platform_hostname.c_str(),
727 port + port_offset, socket_name);
728}
729
730std::string PlatformRemoteGDBServer::MakeUrl(const char *scheme,
731 const char *hostname,
732 uint16_t port, const char *path) {
733 StreamString result;
734 result.Printf("%s://", scheme);
735 if (strlen(hostname) > 0)
736 result.Printf("[%s]", hostname);
737
738 if (port != 0)
739 result.Printf(":%u", port);
740 if (path)
741 result.Write(path, strlen(path));
742 return std::string(result.GetString());
743}
744
746 Status &error) {
747 std::vector<std::string> connection_urls;
748 GetPendingGdbServerList(connection_urls);
749
750 for (size_t i = 0; i < connection_urls.size(); ++i) {
751 ConnectProcess(connection_urls[i].c_str(), GetDefaultProcessPluginName(),
752 debugger, nullptr, error);
753 if (error.Fail())
754 return i; // We already connected to i process successfully
755 }
756 return connection_urls.size();
757}
758
760 std::vector<std::string> &connection_urls) {
761 std::vector<std::pair<uint16_t, std::string>> remote_servers;
762 if (!IsConnected())
763 return 0;
764 m_gdb_client_up->QueryGDBServer(remote_servers);
765 for (const auto &gdbserver : remote_servers) {
766 const char *socket_name_cstr =
767 gdbserver.second.empty() ? nullptr : gdbserver.second.c_str();
768 connection_urls.emplace_back(
770 gdbserver.first, socket_name_cstr));
771 }
772 return connection_urls.size();
773}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:389
static bool g_initialized
#define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName)
An architecture specification class.
Definition ArchSpec.h:32
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:547
bool TripleVendorWasSpecified() const
Definition ArchSpec.h:460
bool TripleOSWasSpecified() const
Definition ArchSpec.h:464
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:120
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:347
const char * GetArgumentAtIndex(size_t idx) const
Gets the null-terminated C string argument pointer for the argument at index idx.
Definition Args.cpp:273
Class that manages the actual breakpoint that will be inserted into the running program.
"lldb/Utility/ArgCompletionRequest.h"
A class to manage flag bits.
Definition Debugger.h:103
TargetList & GetTargetList()
Get accessor for the target list.
Definition Debugger.h:223
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:380
bool Test(ValueType bit) const
Test a single flag bit.
Definition Flags.h:96
void Dump(Stream &strm) const
Definition ModuleSpec.h:200
virtual FileSpec GetRemoteWorkingDirectory()
Definition Platform.h:241
static void Terminate()
Definition Platform.cpp:154
llvm::VersionTuple m_os_version
Definition Platform.h:1074
virtual Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX)
Platform(bool is_host_platform)
Default Constructor.
Definition Platform.cpp:339
virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir)
Definition Platform.cpp:809
virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Target *target, Status &error)
static void Initialize()
Definition Platform.cpp:152
std::string m_hostname
Definition Platform.h:1073
bool IsRemote() const
Definition Platform.h:560
virtual const lldb::UnixSignalsSP & GetRemoteUnixSignals()
std::vector< std::string > m_trap_handlers
Definition Platform.h:1089
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:3231
llvm::StringRef GetProcessPluginName() const
Definition Process.h:172
lldb::ListenerSP GetHijackListener() const
void SetProcessID(lldb::pid_t pid)
Definition ProcessInfo.h:68
FileSpec & GetExecutableFile()
Definition ProcessInfo.h:41
lldb::ListenerSP GetListener() const
lldb::ListenerSP GetShadowListener() const
Environment & GetEnvironment()
Definition ProcessInfo.h:86
ArchSpec & GetArchitecture()
Definition ProcessInfo.h:60
llvm::StringRef GetProcessPluginName() const
const FileAction * GetFileActionAtIndex(size_t idx) const
const FileSpec & GetWorkingDirectory() const
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
const char * GetData() const
llvm::StringRef GetString() const
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition Stream.h:111
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
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:319
Represents UUID's of various sizes.
Definition UUID.h:27
static lldb::UnixSignalsSP Create(const ArchSpec &arch)
lldb::user_id_t GetFileSize(const FileSpec &file_spec) override
Status RunShellCommand(llvm::StringRef shell, llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, std::string *separated_error_outputerror_output, const lldb_private::Timeout< std::micro > &timeout) override
std::unique_ptr< process_gdb_remote::GDBRemoteCommunicationClient > m_gdb_client_up
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)
llvm::ErrorOr< llvm::MD5::MD5Result > CalculateMD5(const FileSpec &file_spec) override
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.
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
#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.
Definition Log.h:338
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition Host.h:32
std::shared_ptr< lldb_private::UnixSignals > UnixSignalsSP
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Process > ProcessSP
uint64_t pid_t
Definition lldb-types.h:84
std::shared_ptr< lldb_private::Listener > ListenerSP
uint64_t user_id_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Target > TargetSP
static std::optional< URI > Parse(llvm::StringRef uri)
Definition UriParser.cpp:28