diff options
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp')
-rw-r--r-- | contrib/llvm-project/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp | 207 |
1 files changed, 89 insertions, 118 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/contrib/llvm-project/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 6e47e5b3e3d1..c6503129685a 100644 --- a/contrib/llvm-project/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/contrib/llvm-project/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -35,6 +35,7 @@ #include "lldb/Host/Config.h" #include "lldb/Utility/StringExtractorGDBRemote.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/JSON.h" @@ -69,10 +70,10 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient() m_supports_vFileSize(true), m_supports_vFileMode(true), m_supports_vFileExists(true), m_supports_vRun(true), - m_host_arch(), m_process_arch(), m_os_build(), m_os_kernel(), - m_hostname(), m_gdb_server_name(), m_default_packet_timeout(0), - m_qSupported_response(), m_supported_async_json_packets_sp(), - m_qXfer_memory_map() {} + m_host_arch(), m_host_distribution_id(), m_process_arch(), m_os_build(), + m_os_kernel(), m_hostname(), m_gdb_server_name(), + m_default_packet_timeout(0), m_qSupported_response(), + m_supported_async_json_packets_sp(), m_qXfer_memory_map() {} // Destructor GDBRemoteCommunicationClient::~GDBRemoteCommunicationClient() { @@ -307,6 +308,7 @@ void GDBRemoteCommunicationClient::ResetDiscoverableSettings(bool did_exec) { m_qSymbol_requests_done = false; m_supports_qModuleInfo = true; m_host_arch.Clear(); + m_host_distribution_id.clear(); m_os_version = llvm::VersionTuple(); m_os_build.clear(); m_os_kernel.clear(); @@ -549,8 +551,7 @@ StructuredData::ObjectSP GDBRemoteCommunicationClient::GetThreadsInfo() { if (response.IsUnsupportedResponse()) { m_supports_jThreadsInfo = false; } else if (!response.Empty()) { - object_sp = - StructuredData::ParseJSON(std::string(response.GetStringRef())); + object_sp = StructuredData::ParseJSON(response.GetStringRef()); } } } @@ -826,8 +827,12 @@ llvm::Error GDBRemoteCommunicationClient::LaunchProcess(const Args &args) { } int GDBRemoteCommunicationClient::SendEnvironment(const Environment &env) { - for (const auto &KV : env) { - int r = SendEnvironmentPacket(Environment::compose(KV).c_str()); + llvm::SmallVector<std::pair<llvm::StringRef, llvm::StringRef>, 0> vec; + for (const auto &kv : env) + vec.emplace_back(kv.first(), kv.second); + llvm::sort(vec, llvm::less_first()); + for (const auto &[k, v] : vec) { + int r = SendEnvironmentPacket((k + "=" + v).str().c_str()); if (r != 0) return r; } @@ -1207,7 +1212,6 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) { std::string environment; std::string vendor_name; std::string triple; - std::string distribution_id; uint32_t pointer_byte_size = 0; ByteOrder byte_order = eByteOrderInvalid; uint32_t num_keys_decoded = 0; @@ -1229,7 +1233,7 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) { ++num_keys_decoded; } else if (name.equals("distribution_id")) { StringExtractor extractor(value); - extractor.GetHexByteString(distribution_id); + extractor.GetHexByteString(m_host_distribution_id); ++num_keys_decoded; } else if (name.equals("os_build")) { StringExtractor extractor(value); @@ -1377,8 +1381,6 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) { m_host_arch.GetTriple().getTriple().c_str(), triple.c_str()); } - if (!distribution_id.empty()) - m_host_arch.SetDistributionId(distribution_id.c_str()); } } } @@ -1780,16 +1782,12 @@ Status GDBRemoteCommunicationClient::LoadQXferMemoryMap() { return error; } -Status GDBRemoteCommunicationClient::GetWatchpointSupportInfo(uint32_t &num) { - Status error; - +std::optional<uint32_t> GDBRemoteCommunicationClient::GetWatchpointSlotCount() { if (m_supports_watchpoint_support_info == eLazyBoolYes) { - num = m_num_supported_hardware_watchpoints; - return error; + return m_num_supported_hardware_watchpoints; } - // Set num to 0 first. - num = 0; + std::optional<uint32_t> num; if (m_supports_watchpoint_support_info != eLazyBoolNo) { StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse("qWatchpointSupportInfo:", response) == @@ -1797,15 +1795,13 @@ Status GDBRemoteCommunicationClient::GetWatchpointSupportInfo(uint32_t &num) { m_supports_watchpoint_support_info = eLazyBoolYes; llvm::StringRef name; llvm::StringRef value; - bool found_num_field = false; while (response.GetNameColonValue(name, value)) { if (name.equals("num")) { value.getAsInteger(0, m_num_supported_hardware_watchpoints); num = m_num_supported_hardware_watchpoints; - found_num_field = true; } } - if (!found_num_field) { + if (!num) { m_supports_watchpoint_support_info = eLazyBoolNo; } } else { @@ -1813,44 +1809,24 @@ Status GDBRemoteCommunicationClient::GetWatchpointSupportInfo(uint32_t &num) { } } - if (m_supports_watchpoint_support_info == eLazyBoolNo) { - error.SetErrorString("qWatchpointSupportInfo is not supported"); - } - return error; -} - -lldb_private::Status GDBRemoteCommunicationClient::GetWatchpointSupportInfo( - uint32_t &num, bool &after, const ArchSpec &arch) { - Status error(GetWatchpointSupportInfo(num)); - if (error.Success()) - error = GetWatchpointsTriggerAfterInstruction(after, arch); - return error; + return num; } -lldb_private::Status -GDBRemoteCommunicationClient::GetWatchpointsTriggerAfterInstruction( - bool &after, const ArchSpec &arch) { - Status error; - llvm::Triple triple = arch.GetTriple(); - - // we assume watchpoints will happen after running the relevant opcode and we - // only want to override this behavior if we have explicitly received a - // qHostInfo telling us otherwise - if (m_qHostInfo_is_valid != eLazyBoolYes) { - // On targets like MIPS and ppc64, watchpoint exceptions are always - // generated before the instruction is executed. The connected target may - // not support qHostInfo or qWatchpointSupportInfo packets. - after = !(triple.isMIPS() || triple.isPPC64()); - } else { - // For MIPS and ppc64, set m_watchpoints_trigger_after_instruction to - // eLazyBoolNo if it is not calculated before. - if (m_watchpoints_trigger_after_instruction == eLazyBoolCalculate && - (triple.isMIPS() || triple.isPPC64())) - m_watchpoints_trigger_after_instruction = eLazyBoolNo; +std::optional<bool> GDBRemoteCommunicationClient::GetWatchpointReportedAfter() { + if (m_qHostInfo_is_valid == eLazyBoolCalculate) + GetHostInfo(); - after = (m_watchpoints_trigger_after_instruction != eLazyBoolNo); + // Process determines this by target CPU, but allow for the + // remote stub to override it via the qHostInfo + // watchpoint_exceptions_received key, if it is present. + if (m_qHostInfo_is_valid == eLazyBoolYes) { + if (m_watchpoints_trigger_after_instruction == eLazyBoolNo) + return false; + if (m_watchpoints_trigger_after_instruction == eLazyBoolYes) + return true; } - return error; + + return std::nullopt; } int GDBRemoteCommunicationClient::SetSTDIN(const FileSpec &file_spec) { @@ -2619,6 +2595,9 @@ bool GDBRemoteCommunicationClient::LaunchGDBServer( if (SendPacketAndWaitForResponse(stream.GetString(), response) == PacketResult::Success) { + if (response.IsErrorResponse()) + return false; + llvm::StringRef name; llvm::StringRef value; while (response.GetNameColonValue(name, value)) { @@ -2646,7 +2625,7 @@ size_t GDBRemoteCommunicationClient::QueryGDBServer( return 0; StructuredData::ObjectSP data = - StructuredData::ParseJSON(std::string(response.GetStringRef())); + StructuredData::ParseJSON(response.GetStringRef()); if (!data) return 0; @@ -2662,7 +2641,7 @@ size_t GDBRemoteCommunicationClient::QueryGDBServer( uint16_t port = 0; if (StructuredData::ObjectSP port_osp = element->GetValueForKey(llvm::StringRef("port"))) - port = port_osp->GetIntegerValue(0); + port = port_osp->GetUnsignedIntegerValue(0); std::string socket_name; if (StructuredData::ObjectSP socket_name_osp = @@ -3894,7 +3873,7 @@ GDBRemoteCommunicationClient::GetModulesInfo( } StructuredData::ObjectSP response_object_sp = - StructuredData::ParseJSON(std::string(response.GetStringRef())); + StructuredData::ParseJSON(response.GetStringRef()); if (!response_object_sp) return std::nullopt; @@ -4057,52 +4036,45 @@ void GDBRemoteCommunicationClient::ServeSymbolLookups( lldb_private::SymbolContextList sc_list; process->GetTarget().GetImages().FindSymbolsWithNameAndType( ConstString(symbol_name), eSymbolTypeAny, sc_list); - if (!sc_list.IsEmpty()) { - const size_t num_scs = sc_list.GetSize(); - for (size_t sc_idx = 0; - sc_idx < num_scs && - symbol_load_addr == LLDB_INVALID_ADDRESS; - ++sc_idx) { - SymbolContext sc; - if (sc_list.GetContextAtIndex(sc_idx, sc)) { - if (sc.symbol) { - switch (sc.symbol->GetType()) { - case eSymbolTypeInvalid: - case eSymbolTypeAbsolute: - case eSymbolTypeUndefined: - case eSymbolTypeSourceFile: - case eSymbolTypeHeaderFile: - case eSymbolTypeObjectFile: - case eSymbolTypeCommonBlock: - case eSymbolTypeBlock: - case eSymbolTypeLocal: - case eSymbolTypeParam: - case eSymbolTypeVariable: - case eSymbolTypeVariableType: - case eSymbolTypeLineEntry: - case eSymbolTypeLineHeader: - case eSymbolTypeScopeBegin: - case eSymbolTypeScopeEnd: - case eSymbolTypeAdditional: - case eSymbolTypeCompiler: - case eSymbolTypeInstrumentation: - case eSymbolTypeTrampoline: - break; - - case eSymbolTypeCode: - case eSymbolTypeResolver: - case eSymbolTypeData: - case eSymbolTypeRuntime: - case eSymbolTypeException: - case eSymbolTypeObjCClass: - case eSymbolTypeObjCMetaClass: - case eSymbolTypeObjCIVar: - case eSymbolTypeReExported: - symbol_load_addr = - sc.symbol->GetLoadAddress(&process->GetTarget()); - break; - } - } + for (const SymbolContext &sc : sc_list) { + if (symbol_load_addr != LLDB_INVALID_ADDRESS) + break; + if (sc.symbol) { + switch (sc.symbol->GetType()) { + case eSymbolTypeInvalid: + case eSymbolTypeAbsolute: + case eSymbolTypeUndefined: + case eSymbolTypeSourceFile: + case eSymbolTypeHeaderFile: + case eSymbolTypeObjectFile: + case eSymbolTypeCommonBlock: + case eSymbolTypeBlock: + case eSymbolTypeLocal: + case eSymbolTypeParam: + case eSymbolTypeVariable: + case eSymbolTypeVariableType: + case eSymbolTypeLineEntry: + case eSymbolTypeLineHeader: + case eSymbolTypeScopeBegin: + case eSymbolTypeScopeEnd: + case eSymbolTypeAdditional: + case eSymbolTypeCompiler: + case eSymbolTypeInstrumentation: + case eSymbolTypeTrampoline: + break; + + case eSymbolTypeCode: + case eSymbolTypeResolver: + case eSymbolTypeData: + case eSymbolTypeRuntime: + case eSymbolTypeException: + case eSymbolTypeObjCClass: + case eSymbolTypeObjCMetaClass: + case eSymbolTypeObjCIVar: + case eSymbolTypeReExported: + symbol_load_addr = + sc.symbol->GetLoadAddress(&process->GetTarget()); + break; } } } @@ -4152,7 +4124,7 @@ GDBRemoteCommunicationClient::GetSupportedStructuredDataPlugins() { if (SendPacketAndWaitForResponse("qStructuredDataPlugins", response) == PacketResult::Success) { m_supported_async_json_packets_sp = - StructuredData::ParseJSON(std::string(response.GetStringRef())); + StructuredData::ParseJSON(response.GetStringRef()); if (m_supported_async_json_packets_sp && !m_supported_async_json_packets_sp->GetAsArray()) { // We were returned something other than a JSON array. This is @@ -4207,10 +4179,10 @@ Status GDBRemoteCommunicationClient::SendSignalsToIgnore( } Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData( - ConstString type_name, const StructuredData::ObjectSP &config_sp) { + llvm::StringRef type_name, const StructuredData::ObjectSP &config_sp) { Status error; - if (type_name.GetLength() == 0) { + if (type_name.empty()) { error.SetErrorString("invalid type_name argument"); return error; } @@ -4218,7 +4190,7 @@ Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData( // Build command: Configure{type_name}: serialized config data. StreamGDBRemote stream; stream.PutCString("QConfigure"); - stream.PutCString(type_name.GetStringRef()); + stream.PutCString(type_name); stream.PutChar(':'); if (config_sp) { // Gather the plain-text version of the configuration data. @@ -4237,21 +4209,20 @@ Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData( auto result = SendPacketAndWaitForResponse(stream.GetString(), response); if (result == PacketResult::Success) { // We failed if the config result comes back other than OK. - if (strcmp(response.GetStringRef().data(), "OK") == 0) { + if (response.GetStringRef() == "OK") { // Okay! error.Clear(); } else { - error.SetErrorStringWithFormat("configuring StructuredData feature " - "%s failed with error %s", - type_name.AsCString(), - response.GetStringRef().data()); + error.SetErrorStringWithFormatv( + "configuring StructuredData feature {0} failed with error {1}", + type_name, response.GetStringRef()); } } else { // Can we get more data here on the failure? - error.SetErrorStringWithFormat("configuring StructuredData feature %s " - "failed when sending packet: " - "PacketResult=%d", - type_name.AsCString(), (int)result); + error.SetErrorStringWithFormatv( + "configuring StructuredData feature {0} failed when sending packet: " + "PacketResult={1}", + type_name, (int)result); } return error; } |