Add logic to MachThreadList::GetThreadID() for the use case of setting a watchpoint

(MachThreadList::EnableHardwareWatchpoint()) where the watchpoint is not associated
with a thread and the current thread, if set, is returned, otherwise we return the
first thread.

Plus minor change to RNBRemote::HandlePacket_z() to use the existing macros to check
the validity of break_id/watch_id.

llvm-svn: 139246
This commit is contained in:
Johnny Chen 2011-09-07 19:03:50 +00:00
parent 02f2f89a98
commit ec6a2d3160
2 changed files with 18 additions and 6 deletions

View File

@ -99,14 +99,26 @@ MachThreadList::GetThreadByID (nub_thread_t tid) const
PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
MachThreadSP thread_sp;
const size_t num_threads = m_threads.size();
for (size_t idx = 0; idx < num_threads; ++idx)
if (MachThread::ThreadIDIsValid(tid))
{
if (m_threads[idx]->ThreadID() == tid)
for (size_t idx = 0; idx < num_threads; ++idx)
{
thread_sp = m_threads[idx];
break;
if (m_threads[idx]->ThreadID() == tid)
{
thread_sp = m_threads[idx];
break;
}
}
}
else if (num_threads > 0)
{
// See DNBWatchpointSet() -> MachProcess::CreateWatchpoint() -> MachProcess::EnableWatchpoint()
// -> MachThreadList::EnableHardwareWatchpoint() for a use case of this branch.
if (m_current_thread)
thread_sp = m_current_thread;
else
thread_sp = m_threads[0];
}
return thread_sp;
}

View File

@ -2885,7 +2885,7 @@ RNBRemote::HandlePacket_z (const char *p)
// We do NOT already have a breakpoint at this address, So lets
// create one.
nub_break_t break_id = DNBBreakpointSet (pid, addr, byte_size, hardware);
if (break_id != INVALID_NUB_BREAK_ID)
if (NUB_BREAK_ID_IS_VALID(break_id))
{
// We successfully created a breakpoint, now lets full out
// a ref count structure with the breakID and add it to our
@ -2930,7 +2930,7 @@ RNBRemote::HandlePacket_z (const char *p)
// We do NOT already have a watchpoint at this address, So lets
// create one.
nub_watch_t watch_id = DNBWatchpointSet (pid, addr, byte_size, watch_flags, hardware);
if (watch_id != INVALID_NUB_WATCH_ID)
if (NUB_WATCH_ID_IS_VALID(watch_id))
{
// We successfully created a watchpoint, now lets full out
// a ref count structure with the watch_id and add it to our