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 llvm::Expected<StringExtractorGDBRemote> launch_response =
368 m_gdb_client_up->LaunchProcess(args);
369 if (!launch_response) {
371 "Cannot launch '{0}': {1}", args.GetArgumentAtIndex(0),
372 llvm::fmt_consume(launch_response.takeError()));
373 return error;
374 }
375 }
376
377 const auto pid = m_gdb_client_up->GetCurrentProcessID(false);
378 if (pid != LLDB_INVALID_PROCESS_ID) {
379 launch_info.SetProcessID(pid);
380 LLDB_LOGF(log,
381 "PlatformRemoteGDBServer::%s() pid %" PRIu64
382 " launched successfully",
383 __FUNCTION__, pid);
384 } else {
385 LLDB_LOGF(log,
386 "PlatformRemoteGDBServer::%s() launch succeeded but we "
387 "didn't get a valid process id back!",
388 __FUNCTION__);
389 error = Status::FromErrorString("failed to get PID");
390 }
391 return error;
392}
393
395 if (!KillSpawnedProcess(pid))
397 "failed to kill remote spawned process");
398 return Status();
399}
400
403 Debugger &debugger, Target &target,
404 Status &error) {
405 lldb::ProcessSP process_sp;
406 if (IsRemote()) {
407 if (IsConnected()) {
408 lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
409 std::string connect_url;
410 if (!LaunchGDBServer(debugserver_pid, connect_url)) {
412 "unable to launch a GDB server on '%s'", GetHostname());
413 } else {
414 // By default, we always use the GDB remote debugger plug-in.
415 // Even when debugging locally, we are debugging remotely.
416 llvm::StringRef process_plugin = GetDefaultProcessPluginName();
417
418 // However, if a process plugin is specified by the attach info, we
419 // should honor it.
420 if (!launch_info.GetProcessPluginName().empty())
421 process_plugin = launch_info.GetProcessPluginName();
422
423 process_sp = target.CreateProcess(launch_info.GetListener(),
424 process_plugin, nullptr, true);
425
426 if (process_sp) {
427 process_sp->HijackProcessEvents(launch_info.GetHijackListener());
428 process_sp->SetShadowListener(launch_info.GetShadowListener());
429
430 error = process_sp->ConnectRemote(connect_url.c_str());
431 // Retry the connect remote one time...
432 if (error.Fail())
433 error = process_sp->ConnectRemote(connect_url.c_str());
434 if (error.Success())
435 error = process_sp->Launch(launch_info);
436 else if (debugserver_pid != LLDB_INVALID_PROCESS_ID) {
437 printf("error: connect remote failed (%s)\n", error.AsCString());
438 KillSpawnedProcess(debugserver_pid);
439 }
440 }
441 }
442 } else {
443 error = Status::FromErrorString("not connected to remote gdb server");
444 }
445 }
446 return process_sp;
447}
448
450 std::string &connect_url) {
451 assert(IsConnected());
452
454 llvm::Triple &remote_triple = remote_arch.GetTriple();
455
456 uint16_t port = 0;
457 std::string socket_name;
458 bool launch_result = false;
459 if (remote_triple.getVendor() == llvm::Triple::Apple &&
460 remote_triple.getOS() == llvm::Triple::IOS) {
461 // When remote debugging to iOS, we use a USB mux that always talks to
462 // localhost, so we will need the remote debugserver to accept connections
463 // only from localhost, no matter what our current hostname is
464 launch_result =
465 m_gdb_client_up->LaunchGDBServer("127.0.0.1", pid, port, socket_name);
466 } else {
467 // All other hosts should use their actual hostname
468 launch_result =
469 m_gdb_client_up->LaunchGDBServer(nullptr, pid, port, socket_name);
470 }
471
472 if (!launch_result)
473 return false;
474
475 connect_url =
477 (socket_name.empty()) ? nullptr : socket_name.c_str());
478 return true;
479}
480
482 assert(IsConnected());
483 return m_gdb_client_up->KillSpawnedProcess(pid);
484}
485
487 ProcessAttachInfo &attach_info, Debugger &debugger,
488 Target *target, // Can be NULL, if NULL create a new target, else use
489 // existing one
490 Status &error) {
491 lldb::ProcessSP process_sp;
492 if (IsRemote()) {
493 if (IsConnected()) {
494 lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
495 std::string connect_url;
496 if (!LaunchGDBServer(debugserver_pid, connect_url)) {
498 "unable to launch a GDB server on '%s'", GetHostname());
499 } else {
500 if (target == nullptr) {
501 TargetSP new_target_sp;
502
503 error = debugger.GetTargetList().CreateTarget(
504 debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
505 target = new_target_sp.get();
506 } else
507 error.Clear();
508
509 if (target && error.Success()) {
510 // By default, we always use the GDB remote debugger plug-in.
511 // Even when debugging locally, we are debugging remotely.
512 llvm::StringRef process_plugin = GetDefaultProcessPluginName();
513
514 // However, if a process plugin is specified by the attach info, we
515 // should honor it.
516 if (!attach_info.GetProcessPluginName().empty())
517 process_plugin = attach_info.GetProcessPluginName();
518
519 process_sp =
520 target->CreateProcess(attach_info.GetListenerForProcess(debugger),
521 process_plugin, nullptr, true);
522 if (process_sp) {
523 error = process_sp->ConnectRemote(connect_url.c_str());
524 if (error.Success()) {
525 ListenerSP listener_sp = attach_info.GetHijackListener();
526 if (listener_sp)
527 process_sp->HijackProcessEvents(listener_sp);
528 process_sp->SetShadowListener(attach_info.GetShadowListener());
529 error = process_sp->Attach(attach_info);
530 }
531
532 if (error.Fail() && debugserver_pid != LLDB_INVALID_PROCESS_ID) {
533 KillSpawnedProcess(debugserver_pid);
534 }
535 }
536 }
537 }
538 } else {
539 error = Status::FromErrorString("not connected to remote gdb server");
540 }
541 }
542 return process_sp;
543}
544
546 uint32_t mode) {
547 if (!IsConnected())
548 return Status::FromErrorStringWithFormat("Not connected.");
549 Status error = m_gdb_client_up->MakeDirectory(file_spec, mode);
551 LLDB_LOGF(log,
552 "PlatformRemoteGDBServer::MakeDirectory(path='%s', mode=%o) "
553 "error = %u (%s)",
554 file_spec.GetPath().c_str(), mode, error.GetError(),
555 error.AsCString());
556 return error;
557}
558
560 uint32_t &file_permissions) {
561 if (!IsConnected())
562 return Status::FromErrorStringWithFormat("Not connected.");
563 Status error =
564 m_gdb_client_up->GetFilePermissions(file_spec, file_permissions);
566 LLDB_LOGF(log,
567 "PlatformRemoteGDBServer::GetFilePermissions(path='%s', "
568 "file_permissions=%o) error = %u (%s)",
569 file_spec.GetPath().c_str(), file_permissions, error.GetError(),
570 error.AsCString());
571 return error;
572}
573
575 uint32_t file_permissions) {
576 if (!IsConnected())
577 return Status::FromErrorStringWithFormat("Not connected.");
578 Status error =
579 m_gdb_client_up->SetFilePermissions(file_spec, file_permissions);
581 LLDB_LOGF(log,
582 "PlatformRemoteGDBServer::SetFilePermissions(path='%s', "
583 "file_permissions=%o) error = %u (%s)",
584 file_spec.GetPath().c_str(), file_permissions, error.GetError(),
585 error.AsCString());
586 return error;
587}
588
590 File::OpenOptions flags,
591 uint32_t mode,
592 Status &error) {
593 if (IsConnected())
594 return m_gdb_client_up->OpenFile(file_spec, flags, mode, error);
595 return LLDB_INVALID_UID;
596}
597
599 if (IsConnected())
600 return m_gdb_client_up->CloseFile(fd, error);
601 error = Status::FromErrorStringWithFormat("Not connected.");
602 return false;
603}
604
607 if (IsConnected())
608 return m_gdb_client_up->GetFileSize(file_spec);
609 return LLDB_INVALID_UID;
610}
611
613 CompletionRequest &request, bool only_dir) {
614 if (IsConnected())
615 m_gdb_client_up->AutoCompleteDiskFileOrDirectory(request, only_dir);
616}
617
619 void *dst, uint64_t dst_len,
620 Status &error) {
621 if (IsConnected())
622 return m_gdb_client_up->ReadFile(fd, offset, dst, dst_len, error);
623 error = Status::FromErrorStringWithFormat("Not connected.");
624 return 0;
625}
626
628 const void *src, uint64_t src_len,
629 Status &error) {
630 if (IsConnected())
631 return m_gdb_client_up->WriteFile(fd, offset, src, src_len, error);
632 error = Status::FromErrorStringWithFormat("Not connected.");
633 return 0;
634}
635
637 const FileSpec &destination,
638 uint32_t uid, uint32_t gid) {
639 return Platform::PutFile(source, destination, uid, gid);
640}
641
643 const FileSpec &src, // The name of the link is in src
644 const FileSpec &dst) // The symlink points to dst
645{
646 if (!IsConnected())
647 return Status::FromErrorStringWithFormat("Not connected.");
648 Status error = m_gdb_client_up->CreateSymlink(src, dst);
650 LLDB_LOGF(log,
651 "PlatformRemoteGDBServer::CreateSymlink(src='%s', dst='%s') "
652 "error = %u (%s)",
653 src.GetPath().c_str(), dst.GetPath().c_str(), error.GetError(),
654 error.AsCString());
655 return error;
656}
657
659 if (!IsConnected())
660 return Status::FromErrorStringWithFormat("Not connected.");
661 Status error = m_gdb_client_up->Unlink(file_spec);
663 LLDB_LOGF(log, "PlatformRemoteGDBServer::Unlink(path='%s') error = %u (%s)",
664 file_spec.GetPath().c_str(), error.GetError(), error.AsCString());
665 return error;
666}
667
669 if (IsConnected())
670 return m_gdb_client_up->GetFileExists(file_spec);
671 return false;
672}
673
675 llvm::StringRef shell, llvm::StringRef command,
676 const FileSpec &
677 working_dir, // Pass empty FileSpec to use the current working directory
678 int *status_ptr, // Pass NULL if you don't want the process exit status
679 int *signo_ptr, // Pass NULL if you don't want the signal that caused the
680 // process to exit
681 std::string
682 *command_output, // Pass nullptr if you don't want the command output
683 std::string *separated_error_output, // Pass nullptr if you don't want the
684 // error output
685 const Timeout<std::micro> &timeout) {
686 if (!IsConnected())
687 return Status::FromErrorStringWithFormat("Not connected.");
688 return m_gdb_client_up->RunShellCommand(command, working_dir, status_ptr,
689 signo_ptr, command_output,
690 separated_error_output, timeout);
691}
692
693llvm::ErrorOr<llvm::MD5::MD5Result>
695 if (!IsConnected())
696 return std::make_error_code(std::errc::not_connected);
697
698 return m_gdb_client_up->CalculateMD5(file_spec);
699}
700
704
714
716 const std::string &platform_scheme, const std::string &platform_hostname,
717 uint16_t port, const char *socket_name) {
718 const char *override_scheme =
719 getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_SCHEME");
720 const char *override_hostname =
721 getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME");
722 const char *port_offset_c_str =
723 getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET");
724 int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0;
725
726 return MakeUrl(override_scheme ? override_scheme : platform_scheme.c_str(),
727 override_hostname ? override_hostname
728 : platform_hostname.c_str(),
729 port + port_offset, socket_name);
730}
731
732std::string PlatformRemoteGDBServer::MakeUrl(const char *scheme,
733 const char *hostname,
734 uint16_t port, const char *path) {
735 StreamString result;
736 result.Printf("%s://", scheme);
737 if (strlen(hostname) > 0)
738 result.Printf("[%s]", hostname);
739
740 if (port != 0)
741 result.Printf(":%u", port);
742 if (path)
743 result.Write(path, strlen(path));
744 return std::string(result.GetString());
745}
746
748 Status &error) {
749 std::vector<std::string> connection_urls;
750 GetPendingGdbServerList(connection_urls);
751
752 for (size_t i = 0; i < connection_urls.size(); ++i) {
753 ConnectProcess(connection_urls[i].c_str(), GetDefaultProcessPluginName(),
754 debugger, nullptr, error);
755 if (error.Fail())
756 return i; // We already connected to i process successfully
757 }
758 return connection_urls.size();
759}
760
762 std::vector<std::string> &connection_urls) {
763 std::vector<std::pair<uint16_t, std::string>> remote_servers;
764 if (!IsConnected())
765 return 0;
766 m_gdb_client_up->QueryGDBServer(remote_servers);
767 for (const auto &gdbserver : remote_servers) {
768 const char *socket_name_cstr =
769 gdbserver.second.empty() ? nullptr : gdbserver.second.c_str();
770 connection_urls.emplace_back(
772 gdbserver.first, socket_name_cstr));
773 }
774 return connection_urls.size();
775}
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:465
bool TripleVendorWasSpecified() const
Definition ArchSpec.h:380
bool TripleOSWasSpecified() const
Definition ArchSpec.h:384
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:106
TargetList & GetTargetList()
Get accessor for the target list.
Definition Debugger.h:230
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:3349
llvm::StringRef GetProcessPluginName() const
Definition Process.h:173
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:323
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