diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
commit | cfca06d7963fa0909f90483b42a6d7d194d01e08 (patch) | |
tree | 209fb2a2d68f8f277793fc8df46c753d31bc853b /lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp | |
parent | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff) |
Notes
Diffstat (limited to 'lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp')
-rw-r--r-- | lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp | 96 |
1 files changed, 57 insertions, 39 deletions
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 1e62ddfe94fdb..21bf7f4ac46d3 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -1,4 +1,4 @@ -//===-- PlatformRemoteGDBServer.cpp -----------------------------*- C++ -*-===// +//===-- PlatformRemoteGDBServer.cpp ---------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -35,6 +35,8 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::platform_gdb_server; +LLDB_PLUGIN_DEFINE_ADV(PlatformRemoteGDBServer, PlatformGDB) + static bool g_initialized = false; void PlatformRemoteGDBServer::Initialize() { @@ -286,40 +288,55 @@ Status PlatformRemoteGDBServer::ConnectRemote(Args &args) { "execute 'platform disconnect' to close the " "current connection", GetHostname()); + return error; + } + + if (args.GetArgumentCount() != 1) { + error.SetErrorString( + "\"platform connect\" takes a single argument: <connect-url>"); + return error; + } + + const char *url = args.GetArgumentAtIndex(0); + if (!url) + return Status("URL is null."); + + int port; + llvm::StringRef scheme, hostname, pathname; + if (!UriParser::Parse(url, scheme, hostname, port, pathname)) + return Status("Invalid URL: %s", url); + + // We're going to reuse the hostname when we connect to the debugserver. + m_platform_scheme = std::string(scheme); + m_platform_hostname = std::string(hostname); + + m_gdb_client.SetConnection(std::make_unique<ConnectionFileDescriptor>()); + if (repro::Reproducer::Instance().IsReplaying()) { + error = m_gdb_replay_server.Connect(m_gdb_client); + if (error.Success()) + m_gdb_replay_server.StartAsyncThread(); } else { - if (args.GetArgumentCount() == 1) { - m_gdb_client.SetConnection(new ConnectionFileDescriptor()); - // we're going to reuse the hostname when we connect to the debugserver - int port; - std::string path; - const char *url = args.GetArgumentAtIndex(0); - if (!url) - return Status("URL is null."); - llvm::StringRef scheme, hostname, pathname; - if (!UriParser::Parse(url, scheme, hostname, port, pathname)) - return Status("Invalid URL: %s", url); - m_platform_scheme = scheme; - m_platform_hostname = hostname; - path = pathname; - - const ConnectionStatus status = m_gdb_client.Connect(url, &error); - if (status == eConnectionStatusSuccess) { - if (m_gdb_client.HandshakeWithServer(&error)) { - m_gdb_client.GetHostInfo(); - // If a working directory was set prior to connecting, send it down - // now - if (m_working_dir) - m_gdb_client.SetWorkingDir(m_working_dir); - } else { - m_gdb_client.Disconnect(); - if (error.Success()) - error.SetErrorString("handshake failed"); - } - } - } else { - error.SetErrorString( - "\"platform connect\" takes a single argument: <connect-url>"); + if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator()) { + repro::GDBRemoteProvider &provider = + g->GetOrCreate<repro::GDBRemoteProvider>(); + m_gdb_client.SetPacketRecorder(provider.GetNewPacketRecorder()); } + m_gdb_client.Connect(url, &error); + } + + if (error.Fail()) + return error; + + if (m_gdb_client.HandshakeWithServer(&error)) { + m_gdb_client.GetHostInfo(); + // If a working directory was set prior to connecting, send it down + // now. + if (m_working_dir) + m_gdb_client.SetWorkingDir(m_working_dir); + } else { + m_gdb_client.Disconnect(); + if (error.Success()) + error.SetErrorString("handshake failed"); } return error; } @@ -486,10 +503,10 @@ lldb::ProcessSP PlatformRemoteGDBServer::DebugProcess( "gdb-remote", nullptr); if (process_sp) { - error = process_sp->ConnectRemote(nullptr, connect_url.c_str()); + error = process_sp->ConnectRemote(connect_url.c_str()); // Retry the connect remote one time... if (error.Fail()) - error = process_sp->ConnectRemote(nullptr, connect_url.c_str()); + error = process_sp->ConnectRemote(connect_url.c_str()); if (error.Success()) error = process_sp->Launch(launch_info); else if (debugserver_pid != LLDB_INVALID_PROCESS_ID) { @@ -572,7 +589,7 @@ lldb::ProcessSP PlatformRemoteGDBServer::Attach( target->CreateProcess(attach_info.GetListenerForProcess(debugger), "gdb-remote", nullptr); if (process_sp) { - error = process_sp->ConnectRemote(nullptr, connect_url.c_str()); + error = process_sp->ConnectRemote(connect_url.c_str()); if (error.Success()) { ListenerSP listener_sp = attach_info.GetHijackListener(); if (listener_sp) @@ -725,7 +742,8 @@ const UnixSignalsSP &PlatformRemoteGDBServer::GetRemoteUnixSignals() { response.GetResponseType() != response.eResponse) return m_remote_signals_sp; - auto object_sp = StructuredData::ParseJSON(response.GetStringRef()); + auto object_sp = + StructuredData::ParseJSON(std::string(response.GetStringRef())); if (!object_sp || !object_sp->IsValid()) return m_remote_signals_sp; @@ -772,7 +790,7 @@ const UnixSignalsSP &PlatformRemoteGDBServer::GetRemoteUnixSignals() { std::string description{""}; object_sp = dict->GetValueForKey("description"); if (object_sp && object_sp->IsValid()) - description = object_sp->GetStringValue(); + description = std::string(object_sp->GetStringValue()); remote_signals_sp->AddSignal(signo, name.str().c_str(), suppress, stop, notify, description.c_str()); @@ -811,7 +829,7 @@ std::string PlatformRemoteGDBServer::MakeUrl(const char *scheme, result.Printf(":%u", port); if (path) result.Write(path, strlen(path)); - return result.GetString(); + return std::string(result.GetString()); } lldb::ProcessSP PlatformRemoteGDBServer::ConnectProcess( |