10#include "lldb/Host/Config.h"
31#include "llvm/Support/FormatAdapters.h"
78 return "A platform that uses the GDB remote protocol as the communication "
99 const auto module_path = module_file_spec.
GetPath(
false);
102 !
m_gdb_client_up->GetModuleInfo(module_file_spec, arch, module_spec)) {
105 "PlatformRemoteGDBServer::%s - failed to get module info for %s:%s",
106 __FUNCTION__, module_path.c_str(),
113 module_spec.
Dump(stream);
115 "PlatformRemoteGDBServer::%s - got module info for (%s:%s) : %s",
116 __FUNCTION__, module_path.c_str(),
124 const UUID *uuid_ptr,
127 local_file = platform_file;
160std::optional<std::string>
180 "PlatformRemoteGDBServer::GetRemoteWorkingDirectory() -> '%s'",
181 working_dir.
GetPath().c_str());
194 LLDB_LOGF(log,
"PlatformRemoteGDBServer::SetRemoteWorkingDirectory('%s')",
195 working_dir.
GetPath().c_str());
209 "the platform is already connected to '%s', "
210 "execute 'platform disconnect' to close the "
211 "current connection",
216 "\"platform connect\" takes a single argument: <connect-url>");
222 std::optional<URI> parsed_url =
URI::Parse(url);
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);
240 if (client_up->HandshakeWithServer(&
error)) {
252 if (remote_arch.
GetTriple().isArch64Bit())
257 client_up->Disconnect();
279std::optional<std::string>
283 return std::move(name);
287std::optional<std::string>
291 return std::move(name);
314 LLDB_LOGF(log,
"PlatformRemoteGDBServer::%s() called", __FUNCTION__);
319 for (
decltype(num_file_actions) i = 0; i < num_file_actions; ++i) {
323 switch (file_action->GetFD()) {
350 const char *arch_triple = arch_spec.
GetTriple().str().c_str();
355 "PlatformRemoteGDBServer::%s() set launch architecture triple to '%s'",
356 __FUNCTION__, arch_triple ? arch_triple :
"<NULL>");
370 llvm::fmt_consume(std::move(err)));
379 "PlatformRemoteGDBServer::%s() pid %" PRIu64
380 " launched successfully",
384 "PlatformRemoteGDBServer::%s() launch succeeded but we "
385 "didn't get a valid process id back!",
395 "failed to kill remote spawned process");
407 std::string connect_url;
410 "unable to launch a GDB server on '%s'",
GetHostname());
422 process_plugin,
nullptr,
true);
428 error = process_sp->ConnectRemote(connect_url.c_str());
431 error = process_sp->ConnectRemote(connect_url.c_str());
433 error = process_sp->Launch(launch_info);
435 printf(
"error: connect remote failed (%s)\n",
error.AsCString());
448 std::string &connect_url) {
452 llvm::Triple &remote_triple = remote_arch.
GetTriple();
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) {
475 (socket_name.empty()) ?
nullptr : socket_name.c_str());
493 std::string connect_url;
496 "unable to launch a GDB server on '%s'",
GetHostname());
498 if (target ==
nullptr) {
503 target = new_target_sp.get();
507 if (target &&
error.Success()) {
519 process_plugin,
nullptr,
true);
521 error = process_sp->ConnectRemote(connect_url.c_str());
522 if (
error.Success()) {
525 process_sp->HijackProcessEvents(listener_sp);
527 error = process_sp->Attach(attach_info);
550 "PlatformRemoteGDBServer::MakeDirectory(path='%s', mode=%o) "
558 uint32_t &file_permissions) {
565 "PlatformRemoteGDBServer::GetFilePermissions(path='%s', "
566 "file_permissions=%o) error = %u (%s)",
567 file_spec.
GetPath().c_str(), file_permissions,
error.GetError(),
573 uint32_t file_permissions) {
580 "PlatformRemoteGDBServer::SetFilePermissions(path='%s', "
581 "file_permissions=%o) error = %u (%s)",
582 file_spec.
GetPath().c_str(), file_permissions,
error.GetError(),
617 void *dst, uint64_t dst_len,
626 const void *src, uint64_t src_len,
636 uint32_t uid, uint32_t gid) {
649 "PlatformRemoteGDBServer::CreateSymlink(src='%s', dst='%s') "
661 LLDB_LOGF(log,
"PlatformRemoteGDBServer::Unlink(path='%s') error = %u (%s)",
673 llvm::StringRef shell, llvm::StringRef command,
681 std::string *separated_error_output,
686 return m_gdb_client_up->RunShellCommand(command, working_dir, status_ptr,
687 signo_ptr, command_output,
688 separated_error_output, timeout);
691llvm::ErrorOr<llvm::MD5::MD5Result>
694 return std::make_error_code(std::errc::not_connected);
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;
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);
731 const char *hostname,
732 uint16_t port,
const char *path) {
734 result.
Printf(
"%s://", scheme);
735 if (strlen(hostname) > 0)
736 result.
Printf(
"[%s]", hostname);
739 result.
Printf(
":%u", port);
741 result.
Write(path, strlen(path));
747 std::vector<std::string> connection_urls;
750 for (
size_t i = 0; i < connection_urls.size(); ++i) {
752 debugger,
nullptr,
error);
756 return connection_urls.size();
760 std::vector<std::string> &connection_urls) {
761 std::vector<std::pair<uint16_t, std::string>> 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));
772 return connection_urls.size();
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
#define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName)
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool TripleVendorWasSpecified() const
bool TripleOSWasSpecified() const
A command line argument class.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
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.
const char * GetArgumentAtIndex(size_t idx) const
Gets the null-terminated C string argument pointer for the argument at index idx.
Class that manages the actual breakpoint that will be inserted into the running program.
"lldb/Utility/ArgCompletionRequest.h"
A class to manage flag bits.
TargetList & GetTargetList()
Get accessor for the target list.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
bool Test(ValueType bit) const
Test a single flag bit.
void Dump(Stream &strm) const
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
lldb::ListenerSP GetListenerForProcess(Debugger &debugger)
llvm::StringRef GetProcessPluginName() const
lldb::ListenerSP GetHijackListener() const
void SetProcessID(lldb::pid_t pid)
FileSpec & GetExecutableFile()
lldb::ListenerSP GetListener() const
lldb::ListenerSP GetShadowListener() const
Environment & GetEnvironment()
ArchSpec & GetArchitecture()
llvm::StringRef GetProcessPluginName() const
const FileAction * GetFileActionAtIndex(size_t idx) const
const FileSpec & GetWorkingDirectory() const
size_t GetNumFileActions() const
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
const char * GetData() const
llvm::StringRef GetString() const
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
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)
Represents UUID's of various sizes.
static lldb::UnixSignalsSP Create(const ArchSpec &arch)
static std::chrono::seconds GetPacketTimeout()
#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.
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
std::shared_ptr< lldb_private::UnixSignals > UnixSignalsSP
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Listener > ListenerSP
std::shared_ptr< lldb_private::Target > TargetSP
static std::optional< URI > Parse(llvm::StringRef uri)