diff options
author | emaste <emaste@FreeBSD.org> | 2014-02-18 16:23:10 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2014-02-18 16:23:10 +0000 |
commit | 6beac4fcf9e5327f07c0fefd527180124438096a (patch) | |
tree | 95cb16075f0af1b3a05b9b84eb18dda8e6c903e9 /source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp | |
parent | f087960a1097db2a1ef14a88963f8785df239aaa (diff) | |
download | FreeBSD-src-6beac4fcf9e5327f07c0fefd527180124438096a.zip FreeBSD-src-6beac4fcf9e5327f07c0fefd527180124438096a.tar.gz |
Import lldb as of SVN r201577 (git 2bdc2f6)
(A number of files not required for the FreeBSD build have been removed.)
Sponsored by: DARPA, AFRL
Diffstat (limited to 'source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp')
-rw-r--r-- | source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp | 411 |
1 files changed, 304 insertions, 107 deletions
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 2690992..aa60ec1 100644 --- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -66,6 +66,9 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) : m_prepare_for_reg_writing_reply (eLazyBoolCalculate), m_supports_p (eLazyBoolCalculate), m_supports_QSaveRegisterState (eLazyBoolCalculate), + m_supports_qXfer_libraries_read (eLazyBoolCalculate), + m_supports_qXfer_libraries_svr4_read (eLazyBoolCalculate), + m_supports_augmented_libraries_svr4_read (eLazyBoolCalculate), m_supports_qProcessInfoPID (true), m_supports_qfProcessInfo (true), m_supports_qUserName (true), @@ -84,6 +87,7 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) : m_async_mutex (Mutex::eMutexTypeRecursive), m_async_packet_predicate (false), m_async_packet (), + m_async_result (PacketResult::Success), m_async_response (), m_async_signal (-1), m_thread_id_to_used_usec_map (), @@ -95,7 +99,8 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) : m_os_build (), m_os_kernel (), m_hostname (), - m_default_packet_timeout (0) + m_default_packet_timeout (0), + m_max_packet_size (0) { } @@ -117,6 +122,14 @@ GDBRemoteCommunicationClient::HandshakeWithServer (Error *error_ptr) // fail to send the handshake ack, there is no reason to continue... if (SendAck()) { + // Wait for any responses that might have been queued up in the remote + // GDB server and flush them all + StringExtractorGDBRemote response; + PacketResult packet_result = PacketResult::Success; + const uint32_t timeout_usec = 10 * 1000; // Wait for 10 ms for a response + while (packet_result == PacketResult::Success) + packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock (response, timeout_usec); + // The return value from QueryNoAckModeSupported() is true if the packet // was sent and _any_ response (including UNIMPLEMENTED) was received), // or false if no response was received. This quickly tells us if we have @@ -140,6 +153,46 @@ GDBRemoteCommunicationClient::HandshakeWithServer (Error *error_ptr) } bool +GDBRemoteCommunicationClient::GetAugmentedLibrariesSVR4ReadSupported () +{ + if (m_supports_augmented_libraries_svr4_read == eLazyBoolCalculate) + { + GetRemoteQSupported(); + } + return (m_supports_augmented_libraries_svr4_read == eLazyBoolYes); +} + +bool +GDBRemoteCommunicationClient::GetQXferLibrariesSVR4ReadSupported () +{ + if (m_supports_qXfer_libraries_svr4_read == eLazyBoolCalculate) + { + GetRemoteQSupported(); + } + return (m_supports_qXfer_libraries_svr4_read == eLazyBoolYes); +} + +bool +GDBRemoteCommunicationClient::GetQXferLibrariesReadSupported () +{ + if (m_supports_qXfer_libraries_read == eLazyBoolCalculate) + { + GetRemoteQSupported(); + } + return (m_supports_qXfer_libraries_read == eLazyBoolYes); +} + +uint64_t +GDBRemoteCommunicationClient::GetRemoteMaxPacketSize() +{ + if (m_max_packet_size == 0) + { + GetRemoteQSupported(); + } + return m_max_packet_size; +} + +bool GDBRemoteCommunicationClient::QueryNoAckModeSupported () { if (m_supports_not_sending_acks == eLazyBoolCalculate) @@ -148,7 +201,7 @@ GDBRemoteCommunicationClient::QueryNoAckModeSupported () m_supports_not_sending_acks = eLazyBoolNo; StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse("QStartNoAckMode", response, false)) + if (SendPacketAndWaitForResponse("QStartNoAckMode", response, false) == PacketResult::Success) { if (response.IsOKResponse()) { @@ -169,7 +222,7 @@ GDBRemoteCommunicationClient::GetListThreadsInStopReplySupported () m_supports_threads_in_stop_reply = eLazyBoolNo; StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse("QListThreadsInStopReply", response, false)) + if (SendPacketAndWaitForResponse("QListThreadsInStopReply", response, false) == PacketResult::Success) { if (response.IsOKResponse()) m_supports_threads_in_stop_reply = eLazyBoolYes; @@ -185,7 +238,7 @@ GDBRemoteCommunicationClient::GetVAttachOrWaitSupported () m_attach_or_wait_reply = eLazyBoolNo; StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse("qVAttachOrWaitSupported", response, false)) + if (SendPacketAndWaitForResponse("qVAttachOrWaitSupported", response, false) == PacketResult::Success) { if (response.IsOKResponse()) m_attach_or_wait_reply = eLazyBoolYes; @@ -205,7 +258,7 @@ GDBRemoteCommunicationClient::GetSyncThreadStateSupported () m_prepare_for_reg_writing_reply = eLazyBoolNo; StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse("qSyncThreadStateSupported", response, false)) + if (SendPacketAndWaitForResponse("qSyncThreadStateSupported", response, false) == PacketResult::Success) { if (response.IsOKResponse()) m_prepare_for_reg_writing_reply = eLazyBoolYes; @@ -236,6 +289,9 @@ GDBRemoteCommunicationClient::ResetDiscoverableSettings() m_supports_memory_region_info = eLazyBoolCalculate; m_prepare_for_reg_writing_reply = eLazyBoolCalculate; m_attach_or_wait_reply = eLazyBoolCalculate; + m_supports_qXfer_libraries_read = eLazyBoolCalculate; + m_supports_qXfer_libraries_svr4_read = eLazyBoolCalculate; + m_supports_augmented_libraries_svr4_read = eLazyBoolCalculate; m_supports_qProcessInfoPID = true; m_supports_qfProcessInfo = true; @@ -251,8 +307,50 @@ GDBRemoteCommunicationClient::ResetDiscoverableSettings() m_supports_QEnvironmentHexEncoded = true; m_host_arch.Clear(); m_process_arch.Clear(); + + m_max_packet_size = 0; } +void +GDBRemoteCommunicationClient::GetRemoteQSupported () +{ + // Clear out any capabilities we expect to see in the qSupported response + m_supports_qXfer_libraries_svr4_read = eLazyBoolNo; + m_supports_qXfer_libraries_read = eLazyBoolNo; + m_supports_augmented_libraries_svr4_read = eLazyBoolNo; + m_max_packet_size = UINT64_MAX; // It's supposed to always be there, but if not, we assume no limit + + StringExtractorGDBRemote response; + if (SendPacketAndWaitForResponse("qSupported", + response, + /*send_async=*/false) == PacketResult::Success) + { + const char *response_cstr = response.GetStringRef().c_str(); + if (::strstr (response_cstr, "qXfer:libraries-svr4:read+")) + m_supports_qXfer_libraries_svr4_read = eLazyBoolYes; + if (::strstr (response_cstr, "augmented-libraries-svr4-read")) + { + m_supports_qXfer_libraries_svr4_read = eLazyBoolYes; // implied + m_supports_augmented_libraries_svr4_read = eLazyBoolYes; + } + if (::strstr (response_cstr, "qXfer:libraries:read+")) + m_supports_qXfer_libraries_read = eLazyBoolYes; + + const char *packet_size_str = ::strstr (response_cstr, "PacketSize="); + if (packet_size_str) + { + StringExtractorGDBRemote packet_response(packet_size_str + strlen("PacketSize=")); + m_max_packet_size = packet_response.GetHexMaxU64(/*little_endian=*/false, UINT64_MAX); + if (m_max_packet_size == 0) + { + m_max_packet_size = UINT64_MAX; // Must have been a garbled response + Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); + if (log) + log->Printf ("Garbled PacketSize spec in qSupported response"); + } + } + } +} bool GDBRemoteCommunicationClient::GetThreadSuffixSupported () @@ -261,7 +359,7 @@ GDBRemoteCommunicationClient::GetThreadSuffixSupported () { StringExtractorGDBRemote response; m_supports_thread_suffix = eLazyBoolNo; - if (SendPacketAndWaitForResponse("QThreadSuffixSupported", response, false)) + if (SendPacketAndWaitForResponse("QThreadSuffixSupported", response, false) == PacketResult::Success) { if (response.IsOKResponse()) m_supports_thread_suffix = eLazyBoolYes; @@ -281,7 +379,7 @@ GDBRemoteCommunicationClient::GetVContSupported (char flavor) m_supports_vCont_C = eLazyBoolNo; m_supports_vCont_s = eLazyBoolNo; m_supports_vCont_S = eLazyBoolNo; - if (SendPacketAndWaitForResponse("vCont?", response, false)) + if (SendPacketAndWaitForResponse("vCont?", response, false) == PacketResult::Success) { const char *response_cstr = response.GetStringRef().c_str(); if (::strstr (response_cstr, ";c")) @@ -345,7 +443,7 @@ GDBRemoteCommunicationClient::GetpPacketSupported (lldb::tid_t tid) else snprintf(packet, sizeof(packet), "p0"); - if (SendPacketAndWaitForResponse(packet, response, false)) + if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success) { if (response.IsNormalResponse()) m_supports_p = eLazyBoolYes; @@ -354,7 +452,63 @@ GDBRemoteCommunicationClient::GetpPacketSupported (lldb::tid_t tid) return m_supports_p; } -size_t +GDBRemoteCommunicationClient::PacketResult +GDBRemoteCommunicationClient::SendPacketsAndConcatenateResponses +( + const char *payload_prefix, + std::string &response_string +) +{ + Mutex::Locker locker; + if (!GetSequenceMutex(locker, + "ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex")) + { + Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); + if (log) + log->Printf("error: failed to get packet sequence mutex, not sending packets with prefix '%s'", + payload_prefix); + return PacketResult::ErrorNoSequenceLock; + } + + response_string = ""; + std::string payload_prefix_str(payload_prefix); + unsigned int response_size = 0x1000; + if (response_size > GetRemoteMaxPacketSize()) { // May send qSupported packet + response_size = GetRemoteMaxPacketSize(); + } + + for (unsigned int offset = 0; true; offset += response_size) + { + StringExtractorGDBRemote this_response; + // Construct payload + char sizeDescriptor[128]; + snprintf(sizeDescriptor, sizeof(sizeDescriptor), "%x,%x", offset, response_size); + PacketResult result = SendPacketAndWaitForResponse((payload_prefix_str + sizeDescriptor).c_str(), + this_response, + /*send_async=*/false); + if (result != PacketResult::Success) + return result; + + const std::string &this_string = this_response.GetStringRef(); + + // Check for m or l as first character; l seems to mean this is the last chunk + char first_char = *this_string.c_str(); + if (first_char != 'm' && first_char != 'l') + { + return PacketResult::ErrorReplyInvalid; + } + // Skip past m or l + const char *s = this_string.c_str() + 1; + + // Concatenate the result so far + response_string += s; + if (first_char == 'l') + // We're done + return PacketResult::Success; + } +} + +GDBRemoteCommunicationClient::PacketResult GDBRemoteCommunicationClient::SendPacketAndWaitForResponse ( const char *payload, @@ -368,7 +522,18 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse send_async); } -size_t +GDBRemoteCommunicationClient::PacketResult +GDBRemoteCommunicationClient::SendPacketAndWaitForResponseNoLock (const char *payload, + size_t payload_length, + StringExtractorGDBRemote &response) +{ + PacketResult packet_result = SendPacketNoLock (payload, payload_length); + if (packet_result == PacketResult::Success) + packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ()); + return packet_result; +} + +GDBRemoteCommunicationClient::PacketResult GDBRemoteCommunicationClient::SendPacketAndWaitForResponse ( const char *payload, @@ -377,18 +542,13 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse bool send_async ) { + PacketResult packet_result = PacketResult::ErrorSendFailed; Mutex::Locker locker; Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); size_t response_len = 0; if (GetSequenceMutex (locker)) { - if (SendPacketNoLock (payload, payload_length)) - response_len = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ()); - else - { - if (log) - log->Printf("error: failed to send '%*s'", (int) payload_length, payload); - } + packet_result = SendPacketAndWaitForResponseNoLock (payload, payload_length, response); } else { @@ -424,6 +584,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse // Swap the response buffer to avoid malloc and string copy response.GetStringRef().swap (m_async_response.GetStringRef()); response_len = response.GetStringRef().size(); + packet_result = m_async_result; } else { @@ -456,13 +617,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse if (log) log->Printf ("async: got lock without sending interrupt"); // Send the packet normally since we got the lock - if (SendPacketNoLock (payload, payload_length)) - response_len = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ()); - else - { - if (log) - log->Printf("error: failed to send '%*s'", (int) payload_length, payload); - } + packet_result = SendPacketAndWaitForResponseNoLock (payload, payload_length, response); } } else @@ -483,12 +638,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse log->Printf("error: failed to get packet sequence mutex, not sending packet '%*s'", (int) payload_length, payload); } } - if (response_len == 0) - { - if (log) - log->Printf("error: failed to get response for '%*s'", (int) payload_length, payload); - } - return response_len; + return packet_result; } static const char *end_delimiter = "--end--;"; @@ -615,7 +765,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse { if (log) log->Printf ("GDBRemoteCommunicationClient::%s () sending continue packet: %s", __FUNCTION__, continue_packet.c_str()); - if (SendPacketNoLock(continue_packet.c_str(), continue_packet.size()) == 0) + if (SendPacketNoLock(continue_packet.c_str(), continue_packet.size()) != PacketResult::Success) state = eStateInvalid; m_private_is_running.SetValue (true, eBroadcastAlways); @@ -626,7 +776,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse if (log) log->Printf ("GDBRemoteCommunicationClient::%s () WaitForPacket(%s)", __FUNCTION__, continue_packet.c_str()); - if (WaitForPacketWithTimeoutMicroSecondsNoLock(response, UINT32_MAX)) + if (WaitForPacketWithTimeoutMicroSecondsNoLock(response, UINT32_MAX) == PacketResult::Success) { if (response.Empty()) state = eStateInvalid; @@ -683,7 +833,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse // packet to make sure it doesn't get in the way StringExtractorGDBRemote extra_stop_reply_packet; uint32_t timeout_usec = 1000; - if (WaitForPacketWithTimeoutMicroSecondsNoLock (extra_stop_reply_packet, timeout_usec)) + if (WaitForPacketWithTimeoutMicroSecondsNoLock (extra_stop_reply_packet, timeout_usec) == PacketResult::Success) { switch (extra_stop_reply_packet.GetChar()) { @@ -747,11 +897,12 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse Log * packet_log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS)); // We are supposed to send an asynchronous packet while - // we are running. + // we are running. m_async_response.Clear(); if (m_async_packet.empty()) { - if (packet_log) + m_async_result = PacketResult::ErrorSendFailed; + if (packet_log) packet_log->Printf ("async: error: empty async packet"); } @@ -760,10 +911,10 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse if (packet_log) packet_log->Printf ("async: sending packet"); - SendPacketAndWaitForResponse (&m_async_packet[0], - m_async_packet.size(), - m_async_response, - false); + m_async_result = SendPacketAndWaitForResponse (&m_async_packet[0], + m_async_packet.size(), + m_async_response, + false); } // Let the other thread that was trying to send the async // packet know that the packet has been sent and response is @@ -973,7 +1124,7 @@ lldb::pid_t GDBRemoteCommunicationClient::GetCurrentProcessID () { StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse("qC", strlen("qC"), response, false)) + if (SendPacketAndWaitForResponse("qC", strlen("qC"), response, false) == PacketResult::Success) { if (response.GetChar() == 'Q') if (response.GetChar() == 'C') @@ -987,7 +1138,7 @@ GDBRemoteCommunicationClient::GetLaunchSuccess (std::string &error_str) { error_str.clear(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse("qLaunchSuccess", strlen("qLaunchSuccess"), response, false)) + if (SendPacketAndWaitForResponse("qLaunchSuccess", strlen("qLaunchSuccess"), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return true; @@ -1050,7 +1201,7 @@ GDBRemoteCommunicationClient::SendArgumentsPacket (const ProcessLaunchInfo &laun } StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) + if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -1097,7 +1248,7 @@ GDBRemoteCommunicationClient::SendEnvironmentPacket (char const *name_equal_valu { packet.PutCString("QEnvironmentHexEncoded:"); packet.PutBytesAsRawHex8 (name_equal_value, strlen(name_equal_value)); - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) + if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -1113,7 +1264,7 @@ GDBRemoteCommunicationClient::SendEnvironmentPacket (char const *name_equal_valu else if (m_supports_QEnvironment) { packet.Printf("QEnvironment:%s", name_equal_value); - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) + if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -1136,7 +1287,7 @@ GDBRemoteCommunicationClient::SendLaunchArchPacket (char const *arch) StreamString packet; packet.Printf("QLaunchArch:%s", arch); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) + if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -1236,7 +1387,7 @@ GDBRemoteCommunicationClient::GetHostInfo (bool force) { m_qHostInfo_is_valid = eLazyBoolNo; StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse ("qHostInfo", response, false)) + if (SendPacketAndWaitForResponse ("qHostInfo", response, false) == PacketResult::Success) { if (response.IsNormalResponse()) { @@ -1248,6 +1399,7 @@ GDBRemoteCommunicationClient::GetHostInfo (bool force) std::string os_name; std::string vendor_name; std::string triple; + std::string distribution_id; uint32_t pointer_byte_size = 0; StringExtractor extractor; ByteOrder byte_order = eByteOrderInvalid; @@ -1281,6 +1433,13 @@ GDBRemoteCommunicationClient::GetHostInfo (bool force) extractor.GetHexByteString (triple); ++num_keys_decoded; } + else if (name.compare ("distribution_id") == 0) + { + extractor.GetStringRef ().swap (value); + extractor.SetFilePos (0); + extractor.GetHexByteString (distribution_id); + ++num_keys_decoded; + } else if (name.compare("os_build") == 0) { extractor.GetStringRef().swap(value); @@ -1455,7 +1614,9 @@ GDBRemoteCommunicationClient::GetHostInfo (bool force) { assert (byte_order == m_host_arch.GetByteOrder()); } - } + } + if (!distribution_id.empty ()) + m_host_arch.SetDistributionId (distribution_id.c_str ()); } } } @@ -1474,7 +1635,7 @@ GDBRemoteCommunicationClient::SendAttach char packet[64]; const int packet_len = ::snprintf (packet, sizeof(packet), "vAttach;%" PRIx64, pid); assert (packet_len < (int)sizeof(packet)); - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { if (response.IsErrorResponse()) return response.GetError(); @@ -1514,7 +1675,7 @@ GDBRemoteCommunicationClient::AllocateMemory (size_t size, uint32_t permissions) permissions & lldb::ePermissionsExecutable ? "x" : ""); assert (packet_len < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { if (!response.IsErrorResponse()) return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); @@ -1537,7 +1698,7 @@ GDBRemoteCommunicationClient::DeallocateMemory (addr_t addr) const int packet_len = ::snprintf(packet, sizeof(packet), "_m%" PRIx64, (uint64_t)addr); assert (packet_len < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { if (response.IsOKResponse()) return true; @@ -1563,7 +1724,7 @@ GDBRemoteCommunicationClient::Detach (bool keep_stopped) const int packet_len = ::snprintf(packet, sizeof(packet), "qSupportsDetachAndStayStopped:"); assert (packet_len < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { m_supports_detach_stay_stopped = eLazyBoolYes; } @@ -1580,15 +1741,15 @@ GDBRemoteCommunicationClient::Detach (bool keep_stopped) } else { - size_t num_sent = SendPacket ("D1", 2); - if (num_sent == 0) + PacketResult packet_result = SendPacket ("D1", 2); + if (packet_result != PacketResult::Success) error.SetErrorString ("Sending extended disconnect packet failed."); } } else { - size_t num_sent = SendPacket ("D", 1); - if (num_sent == 0) + PacketResult packet_result = SendPacket ("D", 1); + if (packet_result != PacketResult::Success) error.SetErrorString ("Sending disconnect packet failed."); } return error; @@ -1608,7 +1769,7 @@ GDBRemoteCommunicationClient::GetMemoryRegionInfo (lldb::addr_t addr, const int packet_len = ::snprintf(packet, sizeof(packet), "qMemoryRegionInfo:%" PRIx64, (uint64_t)addr); assert (packet_len < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { std::string name; std::string value; @@ -1711,7 +1872,7 @@ GDBRemoteCommunicationClient::GetWatchpointSupportInfo (uint32_t &num) const int packet_len = ::snprintf(packet, sizeof(packet), "qWatchpointSupportInfo:"); assert (packet_len < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { m_supports_watchpoint_support_info = eLazyBoolYes; std::string name; @@ -1773,7 +1934,7 @@ GDBRemoteCommunicationClient::SetSTDIN (char const *path) packet.PutBytesAsRawHex8(path, strlen(path)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) + if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -1795,7 +1956,7 @@ GDBRemoteCommunicationClient::SetSTDOUT (char const *path) packet.PutBytesAsRawHex8(path, strlen(path)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) + if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -1817,7 +1978,7 @@ GDBRemoteCommunicationClient::SetSTDERR (char const *path) packet.PutBytesAsRawHex8(path, strlen(path)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) + if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -1833,7 +1994,7 @@ bool GDBRemoteCommunicationClient::GetWorkingDir (std::string &cwd) { StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse ("qGetWorkingDir", response, false)) + if (SendPacketAndWaitForResponse ("qGetWorkingDir", response, false) == PacketResult::Success) { if (response.IsUnsupportedResponse()) return false; @@ -1855,7 +2016,7 @@ GDBRemoteCommunicationClient::SetWorkingDir (char const *path) packet.PutBytesAsRawHex8(path, strlen(path)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) + if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -1874,7 +2035,7 @@ GDBRemoteCommunicationClient::SetDisableASLR (bool enable) const int packet_len = ::snprintf (packet, sizeof (packet), "QSetDisableASLR:%i", enable ? 1 : 0); assert (packet_len < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -1893,6 +2054,11 @@ GDBRemoteCommunicationClient::DecodeProcessInfoResponse (StringExtractorGDBRemot std::string name; std::string value; StringExtractor extractor; + + uint32_t cpu = LLDB_INVALID_CPUTYPE; + uint32_t sub = 0; + std::string vendor; + std::string os_type; while (response.GetNameColonValue(name, value)) { @@ -1938,6 +2104,32 @@ GDBRemoteCommunicationClient::DecodeProcessInfoResponse (StringExtractorGDBRemot extractor.GetHexByteString (value); process_info.GetExecutableFile().SetFile (value.c_str(), false); } + else if (name.compare("cputype") == 0) + { + cpu = Args::StringToUInt32 (value.c_str(), LLDB_INVALID_CPUTYPE, 16); + } + else if (name.compare("cpusubtype") == 0) + { + sub = Args::StringToUInt32 (value.c_str(), 0, 16); + } + else if (name.compare("vendor") == 0) + { + vendor = value; + } + else if (name.compare("ostype") == 0) + { + os_type = value; + } + } + + if (cpu != LLDB_INVALID_CPUTYPE && !vendor.empty() && !os_type.empty()) + { + if (vendor == "apple") + { + process_info.GetArchitecture().SetArchitecture (eArchTypeMachO, cpu, sub); + process_info.GetArchitecture().GetTriple().setVendorName (llvm::StringRef (vendor)); + process_info.GetArchitecture().GetTriple().setOSName (llvm::StringRef (os_type)); + } } if (process_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) @@ -1957,7 +2149,7 @@ GDBRemoteCommunicationClient::GetProcessInfo (lldb::pid_t pid, ProcessInstanceIn const int packet_len = ::snprintf (packet, sizeof (packet), "qProcessInfoPID:%" PRIu64, pid); assert (packet_len < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { return DecodeProcessInfoResponse (response, process_info); } @@ -1981,7 +2173,7 @@ GDBRemoteCommunicationClient::GetCurrentProcessInfo () GetHostInfo (); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse ("qProcessInfo", response, false)) + if (SendPacketAndWaitForResponse ("qProcessInfo", response, false) == PacketResult::Success) { if (response.IsNormalResponse()) { @@ -2141,7 +2333,7 @@ GDBRemoteCommunicationClient::FindProcesses (const ProcessInstanceInfoMatch &mat } } StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) + if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { do { @@ -2151,7 +2343,7 @@ GDBRemoteCommunicationClient::FindProcesses (const ProcessInstanceInfoMatch &mat process_infos.Append(process_info); response.GetStringRef().clear(); response.SetFilePos(0); - } while (SendPacketAndWaitForResponse ("qsProcessInfo", strlen ("qsProcessInfo"), response, false)); + } while (SendPacketAndWaitForResponse ("qsProcessInfo", strlen ("qsProcessInfo"), response, false) == PacketResult::Success); } else { @@ -2172,7 +2364,7 @@ GDBRemoteCommunicationClient::GetUserName (uint32_t uid, std::string &name) const int packet_len = ::snprintf (packet, sizeof (packet), "qUserName:%i", uid); assert (packet_len < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { if (response.IsNormalResponse()) { @@ -2202,7 +2394,7 @@ GDBRemoteCommunicationClient::GetGroupName (uint32_t gid, std::string &name) const int packet_len = ::snprintf (packet, sizeof (packet), "qGroupName:%i", gid); assert (packet_len < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) { if (response.IsNormalResponse()) { @@ -2296,32 +2488,36 @@ GDBRemoteCommunicationClient::SendSpeedTestPacket (uint32_t send_size, uint32_t } StringExtractorGDBRemote response; - return SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) > 0; - return false; + return SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success; } uint16_t -GDBRemoteCommunicationClient::LaunchGDBserverAndGetPort (lldb::pid_t &pid) +GDBRemoteCommunicationClient::LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname) { pid = LLDB_INVALID_PROCESS_ID; StringExtractorGDBRemote response; StreamString stream; stream.PutCString("qLaunchGDBServer;"); std::string hostname; - if (Host::GetHostname (hostname)) - { - // Make the GDB server we launch only accept connections from this host - stream.Printf("host:%s;", hostname.c_str()); - } + if (remote_accept_hostname && remote_accept_hostname[0]) + hostname = remote_accept_hostname; else { - // Make the GDB server we launch accept connections from any host since we can't figure out the hostname - stream.Printf("host:*;"); + if (Host::GetHostname (hostname)) + { + // Make the GDB server we launch only accept connections from this host + stream.Printf("host:%s;", hostname.c_str()); + } + else + { + // Make the GDB server we launch accept connections from any host since we can't figure out the hostname + stream.Printf("host:*;"); + } } const char *packet = stream.GetData(); int packet_len = stream.GetSize(); - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { std::string name; std::string value; @@ -2347,7 +2543,7 @@ GDBRemoteCommunicationClient::KillSpawnedProcess (lldb::pid_t pid) int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.IsOKResponse()) return true; @@ -2369,7 +2565,7 @@ GDBRemoteCommunicationClient::SetCurrentThread (uint64_t tid) packet_len = ::snprintf (packet, sizeof(packet), "Hg%" PRIx64, tid); assert (packet_len + 1 < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.IsOKResponse()) { @@ -2395,7 +2591,7 @@ GDBRemoteCommunicationClient::SetCurrentThreadForRun (uint64_t tid) assert (packet_len + 1 < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.IsOKResponse()) { @@ -2409,7 +2605,7 @@ GDBRemoteCommunicationClient::SetCurrentThreadForRun (uint64_t tid) bool GDBRemoteCommunicationClient::GetStopReply (StringExtractorGDBRemote &response) { - if (SendPacketAndWaitForResponse("?", 1, response, false)) + if (SendPacketAndWaitForResponse("?", 1, response, false) == PacketResult::Success) return response.IsNormalResponse(); return false; } @@ -2422,7 +2618,7 @@ GDBRemoteCommunicationClient::GetThreadStopInfo (lldb::tid_t tid, StringExtracto char packet[256]; int packet_len = ::snprintf(packet, sizeof(packet), "qThreadStopInfo%" PRIx64, tid); assert (packet_len < (int)sizeof(packet)); - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.IsUnsupportedResponse()) m_supports_qThreadStopInfo = false; @@ -2463,7 +2659,7 @@ GDBRemoteCommunicationClient::SendGDBStoppointTypePacket (GDBStoppointType type, assert (packet_len + 1 < (int)sizeof(packet)); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, true)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, true) == PacketResult::Success) { if (response.IsOKResponse()) return 0; @@ -2497,9 +2693,10 @@ GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thr sequence_mutex_unavailable = false; StringExtractorGDBRemote response; - for (SendPacketNoLock ("qfThreadInfo", strlen("qfThreadInfo")) && WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ()); - response.IsNormalResponse(); - SendPacketNoLock ("qsThreadInfo", strlen("qsThreadInfo")) && WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ())) + PacketResult packet_result; + for (packet_result = SendPacketAndWaitForResponseNoLock ("qfThreadInfo", strlen("qfThreadInfo"), response); + packet_result == PacketResult::Success && response.IsNormalResponse(); + packet_result = SendPacketAndWaitForResponseNoLock ("qsThreadInfo", strlen("qsThreadInfo"), response)) { char ch = response.GetChar(); if (ch == 'l') @@ -2539,7 +2736,7 @@ GDBRemoteCommunicationClient::GetShlibInfoAddr() if (!IsRunning()) { StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse("qShlibInfoAddr", ::strlen ("qShlibInfoAddr"), response, false)) + if (SendPacketAndWaitForResponse("qShlibInfoAddr", ::strlen ("qShlibInfoAddr"), response, false) == PacketResult::Success) { if (response.IsNormalResponse()) return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); @@ -2569,7 +2766,7 @@ GDBRemoteCommunicationClient::RunShellCommand (const char *command, // const char *packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.GetChar() != 'F') return Error("malformed reply"); @@ -2608,7 +2805,7 @@ GDBRemoteCommunicationClient::MakeDirectory (const char *path, const char *packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { return Error(response.GetHexMaxU32(false, UINT32_MAX), eErrorTypePOSIX); } @@ -2628,7 +2825,7 @@ GDBRemoteCommunicationClient::SetFilePermissions (const char *path, const char *packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { return Error(response.GetHexMaxU32(false, UINT32_MAX), eErrorTypePOSIX); } @@ -2679,7 +2876,7 @@ GDBRemoteCommunicationClient::OpenFile (const lldb_private::FileSpec& file_spec, const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { return ParseHostIOPacketResponse (response, UINT64_MAX, error); } @@ -2695,7 +2892,7 @@ GDBRemoteCommunicationClient::CloseFile (lldb::user_id_t fd, const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { return ParseHostIOPacketResponse (response, -1, error) == 0; } @@ -2713,7 +2910,7 @@ GDBRemoteCommunicationClient::GetFileSize (const lldb_private::FileSpec& file_sp const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.GetChar() != 'F') return UINT64_MAX; @@ -2733,7 +2930,7 @@ GDBRemoteCommunicationClient::GetFilePermissions(const char *path, uint32_t &fil const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.GetChar() != 'F') { @@ -2780,7 +2977,7 @@ GDBRemoteCommunicationClient::ReadFile (lldb::user_id_t fd, const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.GetChar() != 'F') return 0; @@ -2819,7 +3016,7 @@ GDBRemoteCommunicationClient::WriteFile (lldb::user_id_t fd, const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.GetChar() != 'F') { @@ -2861,7 +3058,7 @@ GDBRemoteCommunicationClient::CreateSymlink (const char *src, const char *dst) const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.GetChar() == 'F') { @@ -2902,7 +3099,7 @@ GDBRemoteCommunicationClient::Unlink (const char *path) const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.GetChar() == 'F') { @@ -2942,7 +3139,7 @@ GDBRemoteCommunicationClient::GetFileExists (const lldb_private::FileSpec& file_ const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.GetChar() != 'F') return false; @@ -2966,7 +3163,7 @@ GDBRemoteCommunicationClient::CalculateMD5 (const lldb_private::FileSpec& file_s const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) + if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) { if (response.GetChar() != 'F') return false; @@ -2998,7 +3195,7 @@ GDBRemoteCommunicationClient::ReadRegister(lldb::tid_t tid, uint32_t reg, String else packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg); assert (packet_len < ((int)sizeof(packet) - 1)); - return SendPacketAndWaitForResponse(packet, response, false); + return SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success; } } return false; @@ -3024,7 +3221,7 @@ GDBRemoteCommunicationClient::ReadAllRegisters (lldb::tid_t tid, StringExtractor else packet_len = ::snprintf (packet, sizeof(packet), "g"); assert (packet_len < ((int)sizeof(packet) - 1)); - return SendPacketAndWaitForResponse(packet, response, false); + return SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success; } } return false; @@ -3051,7 +3248,7 @@ GDBRemoteCommunicationClient::SaveRegisterState (lldb::tid_t tid, uint32_t &save StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, response, false)) + if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success) { if (response.IsUnsupportedResponse()) { @@ -3094,7 +3291,7 @@ GDBRemoteCommunicationClient::RestoreRegisterState (lldb::tid_t tid, uint32_t sa StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet, response, false)) + if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success) { if (response.IsOKResponse()) { |