diff options
author | Todd Fiala <todd.fiala@gmail.com> | 2014-05-07 19:28:21 +0000 |
---|---|---|
committer | Todd Fiala <todd.fiala@gmail.com> | 2014-05-07 19:28:21 +0000 |
commit | 9f72b3a1ce3099e646771990825c5bf2017bfbfc (patch) | |
tree | 6abb4ab73447f0459ddffebf4cd2a48b282b0103 /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp | |
parent | dda7f8cfd0f2b89f5a8c27d02dedf92e1751daa0 (diff) | |
download | bcm5719-llvm-9f72b3a1ce3099e646771990825c5bf2017bfbfc.tar.gz bcm5719-llvm-9f72b3a1ce3099e646771990825c5bf2017bfbfc.zip |
Modify debugserver to follow gdb remote $qC protocol definition.
$qC from debugserver now returns the current thread's thread-id (and, like $?, will set a current thread if one is not already selected). Previously it was returning the current process id.
lldb will now query $qProcessInfo to retrieve the process id. The process id is now cached lazily and reset like other cached values. Retrieval of the process id will fall back to the old $qC method for vendor==Apple and os==iOS if the qProcessInfo retrieval fails.
Added a gdb remote protocol-level test to verify that $qProcessInfo reports a valid process id after launching a process, while the process is in the initial stopped state. Verifies the given process id is a currently valid process on host OSes for which we know how to check (MacOSX, Linux, {Free/Net}BSD). Ignores the live process check for OSes where we don't know how to do this. (I saw no portable way to do this in stock Python without pulling in other libs).
llvm-svn: 208241
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 0b642733414..30004202186 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -57,6 +57,7 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) : m_supports_vCont_s (eLazyBoolCalculate), m_supports_vCont_S (eLazyBoolCalculate), m_qHostInfo_is_valid (eLazyBoolCalculate), + m_curr_pid_is_valid (eLazyBoolCalculate), m_qProcessInfo_is_valid (eLazyBoolCalculate), m_qGDBServerVersion_is_valid (eLazyBoolCalculate), m_supports_alloc_dealloc_memory (eLazyBoolCalculate), @@ -86,6 +87,7 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) : m_supports_z4 (true), m_supports_QEnvironment (true), m_supports_QEnvironmentHexEncoded (true), + m_curr_pid (LLDB_INVALID_PROCESS_ID), m_curr_tid (LLDB_INVALID_THREAD_ID), m_curr_tid_run (LLDB_INVALID_THREAD_ID), m_num_supported_hardware_watchpoints (0), @@ -308,6 +310,7 @@ GDBRemoteCommunicationClient::ResetDiscoverableSettings() m_supports_x = eLazyBoolCalculate; m_supports_QSaveRegisterState = eLazyBoolCalculate; m_qHostInfo_is_valid = eLazyBoolCalculate; + m_curr_pid_is_valid = eLazyBoolCalculate; m_qProcessInfo_is_valid = eLazyBoolCalculate; m_qGDBServerVersion_is_valid = eLazyBoolCalculate; m_supports_alloc_dealloc_memory = eLazyBoolCalculate; @@ -1178,13 +1181,43 @@ GDBRemoteCommunicationClient::SendInterrupt lldb::pid_t GDBRemoteCommunicationClient::GetCurrentProcessID () { - StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse("qC", strlen("qC"), response, false) == PacketResult::Success) + if (m_curr_pid_is_valid == eLazyBoolYes) + return m_curr_pid; + + // First try to retrieve the pid via the qProcessInfo request. + GetCurrentProcessInfo (); + if (m_curr_pid_is_valid == eLazyBoolYes) + { + // We really got it. + return m_curr_pid; + } + else { - if (response.GetChar() == 'Q') - if (response.GetChar() == 'C') - return response.GetHexMaxU32 (false, LLDB_INVALID_PROCESS_ID); + // For Apple iOS targets, go back and ask the qC packet for its result. In earlier iterations of debugserver, $qC returned + // the process id of the current process. + const llvm::Triple &triple = GetProcessArchitecture().GetTriple(); + if ((triple.getVendor() == llvm::Triple::Apple) && + (triple.getOS() == llvm::Triple::IOS)) + { + StringExtractorGDBRemote response; + if (SendPacketAndWaitForResponse("qC", strlen("qC"), response, false) == PacketResult::Success) + { + if (response.GetChar() == 'Q') + { + if (response.GetChar() == 'C') + { + m_curr_pid = response.GetHexMaxU32 (false, LLDB_INVALID_PROCESS_ID); + if (m_curr_pid != LLDB_INVALID_PROCESS_ID) + { + m_curr_pid_is_valid = eLazyBoolYes; + return m_curr_pid; + } + } + } + } + } } + return LLDB_INVALID_PROCESS_ID; } @@ -2346,6 +2379,7 @@ GDBRemoteCommunicationClient::GetCurrentProcessInfo () StringExtractor extractor; ByteOrder byte_order = eByteOrderInvalid; uint32_t num_keys_decoded = 0; + lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; while (response.GetNameColonValue(name, value)) { if (name.compare("cputype") == 0) @@ -2388,9 +2422,20 @@ GDBRemoteCommunicationClient::GetCurrentProcessInfo () if (pointer_byte_size != 0) ++num_keys_decoded; } + else if (name.compare("pid") == 0) + { + pid = Args::StringToUInt64(value.c_str(), 0, 16); + if (pid != LLDB_INVALID_PROCESS_ID) + ++num_keys_decoded; + } } if (num_keys_decoded > 0) m_qProcessInfo_is_valid = eLazyBoolYes; + if (pid != LLDB_INVALID_PROCESS_ID) + { + m_curr_pid_is_valid = eLazyBoolYes; + m_curr_pid = pid; + } if (cpu != LLDB_INVALID_CPUTYPE && !os_name.empty() && !vendor_name.empty()) { m_process_arch.SetArchitecture (eArchTypeMachO, cpu, sub); |