summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2011-01-18 19:36:39 +0000
committerGreg Clayton <gclayton@apple.com>2011-01-18 19:36:39 +0000
commitc4e411ffc09a77abe9957f83827fc1745d7e0408 (patch)
tree78a1107cecd93fdb0cda97b735d5ff23751f2c4a /lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
parent4dc73fa075db86bc6a07d755d972e9f8ad7336cc (diff)
downloadbcm5719-llvm-c4e411ffc09a77abe9957f83827fc1745d7e0408.tar.gz
bcm5719-llvm-c4e411ffc09a77abe9957f83827fc1745d7e0408.zip
Thread safety changes in debugserver and also in the process GDB remote plugin.
I added support for asking if the GDB remote server supports thread suffixes for packets that should be thread specific (register read/write packets) because the way the GDB remote protocol does it right now is to have a notion of a current thread for register and memory reads/writes (set via the "$Hg%x" packet) and a current thread for running ("$Hc%x"). Now we ask the remote GDB server if it supports adding the thread ID to the register packets and we enable that feature in LLDB if supported. This stops us from having to send a bunch of packets that update the current thread ID to some value which is prone to error, or extra packets. llvm-svn: 123762
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp54
1 files changed, 42 insertions, 12 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index eaf91eb98b1..2c00b9a8431 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -217,15 +217,19 @@ GDBRemoteRegisterContext::ReadRegisterBytes (uint32_t reg, DataExtractor &data)
Mutex::Locker locker;
if (gdb_comm.GetSequenceMutex (locker))
{
- if (GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID()))
+ const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
+ if (thread_suffix_supported || GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID()))
{
- char packet[32];
+ char packet[64];
StringExtractorGDBRemote response;
- int packet_len;
+ int packet_len = 0;
if (m_read_all_at_once)
{
// Get all registers in one packet
- packet_len = ::snprintf (packet, sizeof(packet), "g");
+ if (thread_suffix_supported)
+ packet_len = ::snprintf (packet, sizeof(packet), "g;thread:%4.4x;", m_thread.GetID());
+ else
+ packet_len = ::snprintf (packet, sizeof(packet), "g");
assert (packet_len < (sizeof(packet) - 1));
if (gdb_comm.SendPacketAndWaitForResponse(packet, response, 1, false))
{
@@ -237,7 +241,10 @@ GDBRemoteRegisterContext::ReadRegisterBytes (uint32_t reg, DataExtractor &data)
else
{
// Get each register individually
- packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg);
+ if (thread_suffix_supported)
+ packet_len = ::snprintf (packet, sizeof(packet), "p%x;thread:%4.4x;", reg, m_thread.GetID());
+ else
+ packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg);
assert (packet_len < (sizeof(packet) - 1));
if (gdb_comm.SendPacketAndWaitForResponse(packet, response, 1, false))
PrivateSetRegisterValue (reg, response);
@@ -319,7 +326,8 @@ GDBRemoteRegisterContext::WriteRegisterBytes (uint32_t reg, DataExtractor &data,
Mutex::Locker locker;
if (gdb_comm.GetSequenceMutex (locker))
{
- if (GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID()))
+ const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
+ if (thread_suffix_supported || GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID()))
{
uint32_t offset, end_offset;
StreamString packet;
@@ -336,6 +344,9 @@ GDBRemoteRegisterContext::WriteRegisterBytes (uint32_t reg, DataExtractor &data,
eByteOrderHost,
eByteOrderHost);
+ if (thread_suffix_supported)
+ packet.Printf (";thread:%4.4x;", m_thread.GetID());
+
// Invalidate all register values
InvalidateIfNeeded (true);
@@ -361,6 +372,9 @@ GDBRemoteRegisterContext::WriteRegisterBytes (uint32_t reg, DataExtractor &data,
eByteOrderHost,
eByteOrderHost);
+ if (thread_suffix_supported)
+ packet.Printf (";thread:%4.4x;", m_thread.GetID());
+
// Invalidate just this register
m_reg_valid[reg] = false;
if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(),
@@ -391,16 +405,31 @@ GDBRemoteRegisterContext::ReadAllRegisterValues (lldb::DataBufferSP &data_sp)
Mutex::Locker locker;
if (gdb_comm.GetSequenceMutex (locker))
{
- if (GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID()))
+ char packet[32];
+ const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
+ if (thread_suffix_supported || GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID()))
{
- if (gdb_comm.SendPacketAndWaitForResponse("g", response, 1, false))
+ int packet_len = 0;
+ if (thread_suffix_supported)
+ packet_len = ::snprintf (packet, sizeof(packet), "g;thread:%4.4x", m_thread.GetID());
+ else
+ packet_len = ::snprintf (packet, sizeof(packet), "g");
+ assert (packet_len < (sizeof(packet) - 1));
+
+ if (gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, 1, false))
{
if (response.IsErrorPacket())
return false;
-
+
response.GetStringRef().insert(0, 1, 'G');
- data_sp.reset (new DataBufferHeap(response.GetStringRef().c_str(),
- response.GetStringRef().size()));
+ if (thread_suffix_supported)
+ {
+ char thread_id_cstr[64];
+ ::snprintf (thread_id_cstr, sizeof(thread_id_cstr), ";thread:%4.4x;", m_thread.GetID());
+ response.GetStringRef().append (thread_id_cstr);
+ }
+ data_sp.reset (new DataBufferHeap (response.GetStringRef().c_str(),
+ response.GetStringRef().size()));
return true;
}
}
@@ -419,7 +448,8 @@ GDBRemoteRegisterContext::WriteAllRegisterValues (const lldb::DataBufferSP &data
Mutex::Locker locker;
if (gdb_comm.GetSequenceMutex (locker))
{
- if (GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID()))
+ const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
+ if (thread_suffix_supported || GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID()))
{
if (gdb_comm.SendPacketAndWaitForResponse((const char *)data_sp->GetBytes(),
data_sp->GetByteSize(),
OpenPOWER on IntegriCloud