summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-04-11 00:24:49 +0000
committerGreg Clayton <gclayton@apple.com>2012-04-11 00:24:49 +0000
commit37a0a24a5fdc05e18770661b4ee13a91893dee1a (patch)
tree52098bf87fb35019b5b41d9af33dd508739a8bfb
parentad66de155bbdb01bc2e0ece769bf150203bd1a63 (diff)
downloadbcm5719-llvm-37a0a24a5fdc05e18770661b4ee13a91893dee1a.tar.gz
bcm5719-llvm-37a0a24a5fdc05e18770661b4ee13a91893dee1a.zip
No functionality changes, mostly cleanup.
Cleaned up the Mutex::Locker and the ReadWriteLock classes a bit. Also cleaned up the GDBRemoteCommunication class to not have so many packet functions. Used the "NoLock" versions of send/receive packet functions when possible for a bit of performance. llvm-svn: 154458
-rw-r--r--lldb/include/lldb/Host/Mutex.h5
-rw-r--r--lldb/include/lldb/Host/ReadWriteLock.h36
-rw-r--r--lldb/source/API/SBCommandInterpreter.cpp6
-rw-r--r--lldb/source/API/SBDebugger.cpp4
-rw-r--r--lldb/source/API/SBFunction.cpp2
-rw-r--r--lldb/source/API/SBInstruction.cpp6
-rw-r--r--lldb/source/API/SBSymbol.cpp2
-rw-r--r--lldb/source/Breakpoint/BreakpointList.cpp2
-rw-r--r--lldb/source/Breakpoint/WatchpointList.cpp2
-rw-r--r--lldb/source/Commands/CommandObjectTarget.cpp2
-rw-r--r--lldb/source/Core/Listener.cpp2
-rw-r--r--lldb/source/Core/ModuleList.cpp2
-rw-r--r--lldb/source/Host/common/Mutex.cpp42
-rw-r--r--lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp2
-rw-r--r--lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h2
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp33
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h21
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp68
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h6
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp26
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp8
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp15
22 files changed, 150 insertions, 144 deletions
diff --git a/lldb/include/lldb/Host/Mutex.h b/lldb/include/lldb/Host/Mutex.h
index b0943a9be29..f361ad7f471 100644
--- a/lldb/include/lldb/Host/Mutex.h
+++ b/lldb/include/lldb/Host/Mutex.h
@@ -105,7 +105,7 @@ public:
/// non-NULL.
//--------------------------------------------------------------
void
- Reset(pthread_mutex_t *mutex = NULL);
+ Lock (pthread_mutex_t *mutex);
//--------------------------------------------------------------
/// Change the contained mutex only if the mutex can be locked.
@@ -125,6 +125,9 @@ public:
bool
TryLock (pthread_mutex_t *mutex);
+ void
+ Unlock ();
+
protected:
//--------------------------------------------------------------
/// Member variables
diff --git a/lldb/include/lldb/Host/ReadWriteLock.h b/lldb/include/lldb/Host/ReadWriteLock.h
index 4652a98e827..b77bad41864 100644
--- a/lldb/include/lldb/Host/ReadWriteLock.h
+++ b/lldb/include/lldb/Host/ReadWriteLock.h
@@ -91,6 +91,13 @@ public:
{
}
+ ReadLocker (ReadWriteLock &lock) :
+ m_lock (NULL)
+ {
+ Lock(&lock);
+ }
+
+
ReadLocker (ReadWriteLock *lock) :
m_lock (NULL)
{
@@ -164,11 +171,17 @@ public:
m_lock (NULL)
{
}
-
+
+ WriteLocker (ReadWriteLock &lock) :
+ m_lock (NULL)
+ {
+ Lock(&lock);
+ }
+
WriteLocker (ReadWriteLock *lock) :
- m_lock (lock)
+ m_lock (NULL)
{
- Lock();
+ Lock(lock);
}
~WriteLocker()
@@ -177,17 +190,30 @@ public:
}
void
- Lock ()
+ Lock (ReadWriteLock *lock)
{
if (m_lock)
- m_lock->WriteLock();
+ {
+ if (m_lock == lock)
+ return; // We already have this lock locked
+ else
+ Unlock();
+ }
+ if (lock)
+ {
+ lock->WriteLock();
+ m_lock = lock;
+ }
}
void
Unlock ()
{
if (m_lock)
+ {
m_lock->WriteUnlock();
+ m_lock = NULL;
+ }
}
protected:
diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp
index 4593a594330..7dd4b2ecf90 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -93,7 +93,7 @@ SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnOb
TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
Mutex::Locker api_locker;
if (target_sp)
- api_locker.Reset(target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
m_opaque_ptr->HandleCommand (command_line, add_to_history, result.ref());
}
else
@@ -238,7 +238,7 @@ SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &resu
TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
Mutex::Locker api_locker;
if (target_sp)
- api_locker.Reset(target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
m_opaque_ptr->SourceInitFile (false, result.ref());
}
else
@@ -263,7 +263,7 @@ SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnOb
TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
Mutex::Locker api_locker;
if (target_sp)
- api_locker.Reset(target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
m_opaque_ptr->SourceInitFile (true, result.ref());
}
else
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 4c62ffb2c02..b052f77ff6e 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -308,7 +308,7 @@ SBDebugger::HandleCommand (const char *command)
TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
Mutex::Locker api_locker;
if (target_sp)
- api_locker.Reset(target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
SBCommandInterpreter sb_interpreter(GetCommandInterpreter ());
SBCommandReturnObject result;
@@ -830,7 +830,7 @@ SBDebugger::PushInputReader (SBInputReader &reader)
TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
Mutex::Locker api_locker;
if (target_sp)
- api_locker.Reset(target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
InputReaderSP reader_sp(*reader);
m_opaque_sp->PushInputReader (reader_sp);
}
diff --git a/lldb/source/API/SBFunction.cpp b/lldb/source/API/SBFunction.cpp
index d906e6e7af7..4f967b7d51a 100644
--- a/lldb/source/API/SBFunction.cpp
+++ b/lldb/source/API/SBFunction.cpp
@@ -130,7 +130,7 @@ SBFunction::GetInstructions (SBTarget target)
TargetSP target_sp (target.GetSP());
if (target_sp)
{
- api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
target_sp->CalculateExecutionContext (exe_ctx);
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
}
diff --git a/lldb/source/API/SBInstruction.cpp b/lldb/source/API/SBInstruction.cpp
index f384b5b97b4..c5561fd5c90 100644
--- a/lldb/source/API/SBInstruction.cpp
+++ b/lldb/source/API/SBInstruction.cpp
@@ -78,7 +78,7 @@ SBInstruction::GetMnemonic(SBTarget target)
TargetSP target_sp (target.GetSP());
if (target_sp)
{
- api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
target_sp->CalculateExecutionContext (exe_ctx);
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
}
@@ -97,7 +97,7 @@ SBInstruction::GetOperands(SBTarget target)
TargetSP target_sp (target.GetSP());
if (target_sp)
{
- api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
target_sp->CalculateExecutionContext (exe_ctx);
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
}
@@ -116,7 +116,7 @@ SBInstruction::GetComment(SBTarget target)
TargetSP target_sp (target.GetSP());
if (target_sp)
{
- api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
target_sp->CalculateExecutionContext (exe_ctx);
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
}
diff --git a/lldb/source/API/SBSymbol.cpp b/lldb/source/API/SBSymbol.cpp
index 9b82f368acd..89dff621dc9 100644
--- a/lldb/source/API/SBSymbol.cpp
+++ b/lldb/source/API/SBSymbol.cpp
@@ -126,7 +126,7 @@ SBSymbol::GetInstructions (SBTarget target)
TargetSP target_sp (target.GetSP());
if (target_sp)
{
- api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+ api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
target_sp->CalculateExecutionContext (exe_ctx);
}
if (m_opaque_ptr->ValueIsAddress())
diff --git a/lldb/source/Breakpoint/BreakpointList.cpp b/lldb/source/Breakpoint/BreakpointList.cpp
index 4c9fa065c5d..9ec6d8daec8 100644
--- a/lldb/source/Breakpoint/BreakpointList.cpp
+++ b/lldb/source/Breakpoint/BreakpointList.cpp
@@ -223,5 +223,5 @@ BreakpointList::ClearAllBreakpointSites ()
void
BreakpointList::GetListMutex (Mutex::Locker &locker)
{
- return locker.Reset (m_mutex.GetMutex());
+ return locker.Lock (m_mutex.GetMutex());
}
diff --git a/lldb/source/Breakpoint/WatchpointList.cpp b/lldb/source/Breakpoint/WatchpointList.cpp
index a3f2bbb57e5..f95265993ae 100644
--- a/lldb/source/Breakpoint/WatchpointList.cpp
+++ b/lldb/source/Breakpoint/WatchpointList.cpp
@@ -273,5 +273,5 @@ WatchpointList::RemoveAll ()
void
WatchpointList::GetListMutex (Mutex::Locker &locker)
{
- return locker.Reset (m_mutex.GetMutex());
+ return locker.Lock (m_mutex.GetMutex());
}
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index ec48de6960d..2c2ab436838 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -2839,7 +2839,7 @@ public:
if (use_global_module_list)
{
- locker.Reset (Module::GetAllocationModuleCollectionMutex()->GetMutex());
+ locker.Lock (Module::GetAllocationModuleCollectionMutex()->GetMutex());
num_modules = Module::GetNumberAllocatedModules();
}
else
diff --git a/lldb/source/Core/Listener.cpp b/lldb/source/Core/Listener.cpp
index 060d5e6b47b..6b1b95a59c6 100644
--- a/lldb/source/Core/Listener.cpp
+++ b/lldb/source/Core/Listener.cpp
@@ -303,7 +303,7 @@ Listener::FindNextEventInternal
// Unlock the event queue here. We've removed this event and are about to return
// it so it should be okay to get the next event off the queue here - and it might
// be useful to do that in the "DoOnRemoval".
- lock.Reset();
+ lock.Unlock();
event_sp->DoOnRemoval();
return true;
}
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 5e4f660dd28..e573555625e 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -118,7 +118,7 @@ ModuleList::RemoveOrphans (bool mandatory)
if (mandatory)
{
- locker.Reset (m_modules_mutex.GetMutex());
+ locker.Lock (m_modules_mutex.GetMutex());
}
else
{
diff --git a/lldb/source/Host/common/Mutex.cpp b/lldb/source/Host/common/Mutex.cpp
index 90045a31d6a..51b0d56e760 100644
--- a/lldb/source/Host/common/Mutex.cpp
+++ b/lldb/source/Host/common/Mutex.cpp
@@ -50,10 +50,9 @@ Mutex::Locker::Locker () :
// mutex owned by "m" and locks it.
//----------------------------------------------------------------------
Mutex::Locker::Locker (Mutex& m) :
- m_mutex_ptr(m.GetMutex())
+ m_mutex_ptr(NULL)
{
- if (m_mutex_ptr)
- Mutex::Lock (m_mutex_ptr);
+ Lock (m.GetMutex());
}
//----------------------------------------------------------------------
@@ -63,10 +62,10 @@ Mutex::Locker::Locker (Mutex& m) :
// mutex owned by "m" and locks it.
//----------------------------------------------------------------------
Mutex::Locker::Locker (Mutex* m) :
- m_mutex_ptr(m ? m->GetMutex() : NULL)
+ m_mutex_ptr(NULL)
{
- if (m_mutex_ptr)
- Mutex::Lock (m_mutex_ptr);
+ if (m)
+ Lock (m->GetMutex());
}
//----------------------------------------------------------------------
@@ -75,10 +74,10 @@ Mutex::Locker::Locker (Mutex* m) :
// This will create a scoped mutex locking object that locks "mutex"
//----------------------------------------------------------------------
Mutex::Locker::Locker (pthread_mutex_t *mutex_ptr) :
- m_mutex_ptr(mutex_ptr)
+ m_mutex_ptr (NULL)
{
if (m_mutex_ptr)
- Mutex::Lock (m_mutex_ptr);
+ Lock (m_mutex_ptr);
}
//----------------------------------------------------------------------
@@ -88,7 +87,7 @@ Mutex::Locker::Locker (pthread_mutex_t *mutex_ptr) :
//----------------------------------------------------------------------
Mutex::Locker::~Locker ()
{
- Reset();
+ Unlock();
}
//----------------------------------------------------------------------
@@ -96,18 +95,29 @@ Mutex::Locker::~Locker ()
// mutex) and lock the new "mutex" object if it is non-NULL.
//----------------------------------------------------------------------
void
-Mutex::Locker::Reset (pthread_mutex_t *mutex_ptr)
+Mutex::Locker::Lock (pthread_mutex_t *mutex_ptr)
{
// We already have this mutex locked or both are NULL...
if (m_mutex_ptr == mutex_ptr)
return;
- if (m_mutex_ptr)
- Mutex::Unlock (m_mutex_ptr);
+ Unlock ();
- m_mutex_ptr = mutex_ptr;
- if (m_mutex_ptr)
+ if (mutex_ptr)
+ {
+ m_mutex_ptr = mutex_ptr;
Mutex::Lock (m_mutex_ptr);
+ }
+}
+
+void
+Mutex::Locker::Unlock ()
+{
+ if (m_mutex_ptr)
+ {
+ Mutex::Unlock (m_mutex_ptr);
+ m_mutex_ptr = NULL;
+ }
}
bool
@@ -115,9 +125,9 @@ Mutex::Locker::TryLock (pthread_mutex_t *mutex_ptr)
{
// We already have this mutex locked!
if (m_mutex_ptr == mutex_ptr)
- return true;
+ return m_mutex_ptr != NULL;
- Reset ();
+ Unlock ();
if (mutex_ptr)
{
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
index 8fc3692c261..c1d9f955159 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
@@ -151,7 +151,7 @@ CommunicationKDP::SendRequestPacketNoLock (const PacketStreamType &request_packe
}
bool
-CommunicationKDP::TryLockSequenceMutex (Mutex::Locker& locker)
+CommunicationKDP::GetSequenceMutex (Mutex::Locker& locker)
{
return locker.TryLock (m_sequence_mutex.GetMutex());
}
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
index 728cddd995d..db1e02f605f 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
@@ -102,7 +102,7 @@ public:
uint32_t usec);
bool
- TryLockSequenceMutex(lldb_private::Mutex::Locker& locker);
+ GetSequenceMutex(lldb_private::Mutex::Locker& locker);
bool
CheckForPacket (const uint8_t *src,
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index caa70258e30..1535fd41260 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -158,21 +158,6 @@ GDBRemoteCommunication::SendNack ()
}
size_t
-GDBRemoteCommunication::SendPacket (lldb_private::StreamString &payload)
-{
- Mutex::Locker locker(m_sequence_mutex);
- const std::string &p (payload.GetString());
- return SendPacketNoLock (p.c_str(), p.size());
-}
-
-size_t
-GDBRemoteCommunication::SendPacket (const char *payload)
-{
- Mutex::Locker locker(m_sequence_mutex);
- return SendPacketNoLock (payload, ::strlen (payload));
-}
-
-size_t
GDBRemoteCommunication::SendPacket (const char *payload, size_t payload_length)
{
Mutex::Locker locker(m_sequence_mutex);
@@ -234,15 +219,20 @@ char
GDBRemoteCommunication::GetAck ()
{
StringExtractorGDBRemote packet;
- if (WaitForPacketWithTimeoutMicroSeconds (packet, GetPacketTimeoutInMicroSeconds ()) == 1)
+ if (WaitForPacketWithTimeoutMicroSecondsNoLock (packet, GetPacketTimeoutInMicroSeconds ()) == 1)
return packet.GetChar();
return 0;
}
bool
-GDBRemoteCommunication::TryLockSequenceMutex (Mutex::Locker& locker)
+GDBRemoteCommunication::GetSequenceMutex (Mutex::Locker& locker, uint32_t usec_timeout)
{
- return locker.TryLock (m_sequence_mutex.GetMutex());
+ if (usec_timeout == 0)
+ return locker.TryLock (m_sequence_mutex.GetMutex());
+
+ // Wait for the lock
+ locker.Lock (m_sequence_mutex.GetMutex());
+ return true;
}
@@ -253,13 +243,6 @@ GDBRemoteCommunication::WaitForNotRunningPrivate (const TimeValue *timeout_ptr)
}
size_t
-GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSeconds (StringExtractorGDBRemote &packet, uint32_t timeout_usec)
-{
- Mutex::Locker locker(m_sequence_mutex);
- return WaitForPacketWithTimeoutMicroSecondsNoLock (packet, timeout_usec);
-}
-
-size_t
GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractorGDBRemote &packet, uint32_t timeout_usec)
{
uint8_t buffer[8192];
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index d7986d5b278..ef0c1983898 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -45,21 +45,6 @@ public:
virtual
~GDBRemoteCommunication();
- size_t
- SendPacket (const char *payload);
-
- size_t
- SendPacket (const char *payload,
- size_t payload_length);
-
- size_t
- SendPacket (lldb_private::StreamString &response);
-
- // Wait for a packet within 'nsec' seconds
- size_t
- WaitForPacketWithTimeoutMicroSeconds (StringExtractorGDBRemote &response,
- uint32_t usec);
-
char
GetAck ();
@@ -74,7 +59,7 @@ public:
size_t payload_length);
bool
- TryLockSequenceMutex(lldb_private::Mutex::Locker& locker);
+ GetSequenceMutex (lldb_private::Mutex::Locker& locker, uint32_t usec_timeout);
bool
CheckForPacket (const uint8_t *src,
@@ -260,6 +245,10 @@ protected:
};
size_t
+ SendPacket (const char *payload,
+ size_t payload_length);
+
+ size_t
SendPacketNoLock (const char *payload,
size_t payload_length);
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 16a339c86c2..4efacd57eee 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -259,7 +259,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
Mutex::Locker locker;
LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
size_t response_len = 0;
- if (TryLockSequenceMutex (locker))
+ if (GetSequenceMutex (locker, 0))
{
if (SendPacketNoLock (payload, payload_length))
response_len = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ());
@@ -361,30 +361,6 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
return response_len;
}
-//template<typename _Tp>
-//class ScopedValueChanger
-//{
-//public:
-// // Take a value reference and the value to assign it to when this class
-// // instance goes out of scope.
-// ScopedValueChanger (_Tp &value_ref, _Tp value) :
-// m_value_ref (value_ref),
-// m_value (value)
-// {
-// }
-//
-// // This object is going out of scope, change the value pointed to by
-// // m_value_ref to the value we got during construction which was stored in
-// // m_value;
-// ~ScopedValueChanger ()
-// {
-// m_value_ref = m_value;
-// }
-//protected:
-// _Tp &m_value_ref; // A reference to the value we will change when this object destructs
-// _Tp m_value; // The value to assign to m_value_ref when this goes out of scope.
-//};
-
StateType
GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
(
@@ -415,7 +391,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
{
if (log)
log->Printf ("GDBRemoteCommunicationClient::%s () sending continue packet: %s", __FUNCTION__, continue_packet.c_str());
- if (SendPacket(continue_packet.c_str(), continue_packet.size()) == 0)
+ if (SendPacketNoLock(continue_packet.c_str(), continue_packet.size()) == 0)
state = eStateInvalid;
m_private_is_running.SetValue (true, eBroadcastAlways);
@@ -426,7 +402,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
if (log)
log->Printf ("GDBRemoteCommunicationClient::%s () WaitForPacket(%s)", __FUNCTION__, continue_packet.c_str());
- if (WaitForPacketWithTimeoutMicroSeconds (response, UINT32_MAX))
+ if (WaitForPacketWithTimeoutMicroSecondsNoLock(response, UINT32_MAX))
{
if (response.Empty())
state = eStateInvalid;
@@ -647,7 +623,7 @@ GDBRemoteCommunicationClient::SendAsyncSignal (int signo)
return false;
}
-// This function takes a mutex locker as a parameter in case the TryLockSequenceMutex
+// This function takes a mutex locker as a parameter in case the GetSequenceMutex
// actually succeeds. If it doesn't succeed in acquiring the sequence mutex
// (the expected result), then it will send the halt packet. If it does succeed
// then the caller that requested the interrupt will want to keep the sequence
@@ -672,7 +648,12 @@ GDBRemoteCommunicationClient::SendInterrupt
if (IsRunning())
{
// Only send an interrupt if our debugserver is running...
- if (TryLockSequenceMutex (locker) == false)
+ if (GetSequenceMutex (locker, 0))
+ {
+ if (log)
+ log->Printf ("SendInterrupt () - got sequence mutex without having to interrupt");
+ }
+ else
{
// Someone has the mutex locked waiting for a response or for the
// inferior to stop, so send the interrupt on the down low...
@@ -718,11 +699,6 @@ GDBRemoteCommunicationClient::SendInterrupt
}
return false;
}
- else
- {
- if (log)
- log->Printf ("SendInterrupt () - got sequence mutex without having to interrupt");
- }
}
else
{
@@ -1174,6 +1150,12 @@ GDBRemoteCommunicationClient::DeallocateMemory (addr_t addr)
return false;
}
+bool
+GDBRemoteCommunicationClient::Detach ()
+{
+ return SendPacket ("D", 1) > 0;
+}
+
Error
GDBRemoteCommunicationClient::GetMemoryRegionInfo (lldb::addr_t addr,
lldb_private::MemoryRegionInfo &region_info)
@@ -1861,7 +1843,7 @@ GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thr
Mutex::Locker locker;
thread_ids.clear();
- if (TryLockSequenceMutex (locker))
+ if (GetSequenceMutex (locker, 0))
{
sequence_mutex_unavailable = false;
StringExtractorGDBRemote response;
@@ -1894,3 +1876,19 @@ GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thr
}
return thread_ids.size();
}
+
+lldb::addr_t
+GDBRemoteCommunicationClient::GetShlibInfoAddr()
+{
+ if (!IsRunning())
+ {
+ StringExtractorGDBRemote response;
+ if (SendPacketAndWaitForResponse("qShlibInfoAddr", ::strlen ("qShlibInfoAddr"), response, false))
+ {
+ if (response.IsNormalResponse())
+ return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
+ }
+ }
+ return LLDB_INVALID_ADDRESS;
+}
+
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index c7ac21d83ad..4794021908c 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -199,6 +199,9 @@ public:
bool
DeallocateMemory (lldb::addr_t addr);
+ bool
+ Detach ();
+
lldb_private::Error
GetMemoryRegionInfo (lldb::addr_t addr,
lldb_private::MemoryRegionInfo &range_info);
@@ -232,6 +235,9 @@ public:
bool
GetHostname (std::string &s);
+ lldb::addr_t
+ GetShlibInfoAddr();
+
bool
GetSupportsThreadSuffix ();
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index 3fc97295a80..3f8677d1c7e 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -85,7 +85,7 @@ GDBRemoteCommunicationServer::GetPacketAndSendResponse (uint32_t timeout_usec,
bool &quit)
{
StringExtractorGDBRemote packet;
- if (WaitForPacketWithTimeoutMicroSeconds(packet, timeout_usec))
+ if (WaitForPacketWithTimeoutMicroSecondsNoLock (packet, timeout_usec))
{
const StringExtractorGDBRemote::ServerPacketType packet_type = packet.GetServerPacketType ();
switch (packet_type)
@@ -178,7 +178,7 @@ size_t
GDBRemoteCommunicationServer::SendUnimplementedResponse (const char *)
{
// TODO: Log the packet we aren't handling...
- return SendPacket ("");
+ return SendPacketNoLock ("", 0);
}
size_t
@@ -187,14 +187,14 @@ GDBRemoteCommunicationServer::SendErrorResponse (uint8_t err)
char packet[16];
int packet_len = ::snprintf (packet, sizeof(packet), "E%2.2x", err);
assert (packet_len < sizeof(packet));
- return SendPacket (packet, packet_len);
+ return SendPacketNoLock (packet, packet_len);
}
size_t
GDBRemoteCommunicationServer::SendOKResponse ()
{
- return SendPacket ("OK");
+ return SendPacketNoLock ("OK", 2);
}
bool
@@ -269,7 +269,7 @@ GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet
response.PutChar(';');
}
- return SendPacket (response) > 0;
+ return SendPacketNoLock (response.GetData(), response.GetSize()) > 0;
}
static void
@@ -308,7 +308,7 @@ GDBRemoteCommunicationServer::Handle_qProcessInfoPID (StringExtractorGDBRemote &
{
StreamString response;
CreateProcessInfoResponse (proc_info, response);
- return SendPacket (response);
+ return SendPacketNoLock (response.GetData(), response.GetSize());
}
}
return SendErrorResponse (1);
@@ -423,7 +423,7 @@ GDBRemoteCommunicationServer::Handle_qsProcessInfo (StringExtractorGDBRemote &pa
StreamString response;
CreateProcessInfoResponse (m_proc_infos.GetProcessInfoAtIndex(m_proc_infos_index), response);
++m_proc_infos_index;
- return SendPacket (response);
+ return SendPacketNoLock (response.GetData(), response.GetSize());
}
return SendErrorResponse (4);
}
@@ -441,7 +441,7 @@ GDBRemoteCommunicationServer::Handle_qUserName (StringExtractorGDBRemote &packet
{
StreamString response;
response.PutCStringAsRawHex8 (name.c_str());
- return SendPacket (response);
+ return SendPacketNoLock (response.GetData(), response.GetSize());
}
}
return SendErrorResponse (5);
@@ -461,7 +461,7 @@ GDBRemoteCommunicationServer::Handle_qGroupName (StringExtractorGDBRemote &packe
{
StreamString response;
response.PutCStringAsRawHex8 (name.c_str());
- return SendPacket (response);
+ return SendPacketNoLock (response.GetData(), response.GetSize());
}
}
return SendErrorResponse (6);
@@ -498,7 +498,7 @@ GDBRemoteCommunicationServer::Handle_qSpeedTest (StringExtractorGDBRemote &packe
bytes_left = 0;
}
}
- return SendPacket (response);
+ return SendPacketNoLock (response.GetData(), response.GetSize());
}
}
return SendErrorResponse (7);
@@ -657,7 +657,7 @@ GDBRemoteCommunicationServer::Handle_qC (StringExtractorGDBRemote &packet)
m_process_launch_info.Clear();
}
}
- return SendPacket (response);
+ return SendPacketNoLock (response.GetData(), response.GetSize());
}
bool
@@ -710,7 +710,7 @@ GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote
const int response_len = ::snprintf (response, sizeof(response), "pid:%llu;port:%u;", debugserver_pid, port);
assert (response_len < sizeof(response));
//m_port_to_pid_map[port] = debugserver_launch_info.GetProcessID();
- success = SendPacket (response, response_len) > 0;
+ success = SendPacketNoLock (response, response_len) > 0;
}
}
::unlink (unix_socket_name);
@@ -736,7 +736,7 @@ GDBRemoteCommunicationServer::Handle_qLaunchSuccess (StringExtractorGDBRemote &p
StreamString response;
response.PutChar('E');
response.PutCString(m_process_launch_error.AsCString("<unknown error>"));
- return SendPacket (response);
+ return SendPacketNoLock (response.GetData(), response.GetSize());
}
bool
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index 120caf3d7a7..33b74b42085 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -181,7 +181,7 @@ GDBRemoteRegisterContext::ReadRegisterBytes (const RegisterInfo *reg_info, DataE
if (!m_reg_valid[reg])
{
Mutex::Locker locker;
- if (gdb_comm.TryLockSequenceMutex (locker))
+ if (gdb_comm.GetSequenceMutex (locker, 0))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
@@ -331,7 +331,7 @@ GDBRemoteRegisterContext::WriteRegisterBytes (const lldb_private::RegisterInfo *
m_reg_data.GetByteOrder())) // dst byte order
{
Mutex::Locker locker;
- if (gdb_comm.TryLockSequenceMutex (locker))
+ if (gdb_comm.GetSequenceMutex (locker, 0))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
@@ -440,7 +440,7 @@ GDBRemoteRegisterContext::ReadAllRegisterValues (lldb::DataBufferSP &data_sp)
StringExtractorGDBRemote response;
Mutex::Locker locker;
- if (gdb_comm.TryLockSequenceMutex (locker))
+ if (gdb_comm.GetSequenceMutex (locker, 0))
{
char packet[32];
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
@@ -496,7 +496,7 @@ GDBRemoteRegisterContext::WriteAllRegisterValues (const lldb::DataBufferSP &data
StringExtractorGDBRemote response;
Mutex::Locker locker;
- if (gdb_comm.TryLockSequenceMutex (locker))
+ if (gdb_comm.GetSequenceMutex (locker, 0))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 035c6128db9..9b875012a6a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1621,10 +1621,10 @@ ProcessGDBRemote::DoDetach()
m_thread_list.DiscardThreadPlans();
- size_t response_size = m_gdb_comm.SendPacket ("D", 1);
+ bool success = m_gdb_comm.Detach ();
if (log)
{
- if (response_size)
+ if (success)
log->PutCString ("ProcessGDBRemote::DoDetach() detach packet sent successfully");
else
log->PutCString ("ProcessGDBRemote::DoDetach() detach packet send failed");
@@ -1691,16 +1691,7 @@ ProcessGDBRemote::IsAlive ()
addr_t
ProcessGDBRemote::GetImageInfoAddress()
{
- if (!m_gdb_comm.IsRunning())
- {
- StringExtractorGDBRemote response;
- if (m_gdb_comm.SendPacketAndWaitForResponse("qShlibInfoAddr", ::strlen ("qShlibInfoAddr"), response, false))
- {
- if (response.IsNormalResponse())
- return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
- }
- }
- return LLDB_INVALID_ADDRESS;
+ return m_gdb_comm.GetShlibInfoAddr();
}
//------------------------------------------------------------------
OpenPOWER on IntegriCloud