Remove Dbg::IsSuspended, which was checking the wrong thing.
It was also unnecessarily racy.
Change-Id: I9d59ac81ffb5b178ca9d2a00d895a272321adec9
diff --git a/src/debugger.cc b/src/debugger.cc
index deef322..85ebf66 100644
--- a/src/debugger.cc
+++ b/src/debugger.cc
@@ -1494,19 +1494,6 @@
return JDWP::ERR_NONE;
}
-JDWP::JdwpError Dbg::IsSuspended(JDWP::ObjectId thread_id, bool& result) {
- ScopedObjectAccess soa(Thread::Current());
- MutexLock mu(soa.Self(), *Locks::thread_list_lock_);
- Thread* thread;
- JDWP::JdwpError error = DecodeThread(soa, thread_id, thread);
- if (error != JDWP::ERR_NONE) {
- return error;
- }
- MutexLock mu2(soa.Self(), *Locks::thread_suspend_count_lock_);
- result = thread->IsSuspended();
- return JDWP::ERR_NONE;
-}
-
void Dbg::GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids) {
class ThreadListVisitor {
public:
@@ -1609,6 +1596,11 @@
return visitor.depth;
}
+static bool IsSuspendedForDebugger(ScopedObjectAccessUnchecked& soa, Thread* thread) {
+ MutexLock mu(soa.Self(), *Locks::thread_suspend_count_lock_);
+ return thread->IsSuspended() && thread->GetDebugSuspendCount() > 0;
+}
+
JDWP::JdwpError Dbg::GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result) {
ScopedObjectAccess soa(Thread::Current());
MutexLock mu(soa.Self(), *Locks::thread_list_lock_);
@@ -1617,6 +1609,9 @@
if (error != JDWP::ERR_NONE) {
return error;
}
+ if (!IsSuspendedForDebugger(soa, thread)) {
+ return JDWP::ERR_THREAD_NOT_SUSPENDED;
+ }
result = GetStackDepth(thread);
return JDWP::ERR_NONE;
}
@@ -1662,7 +1657,6 @@
JDWP::ExpandBuf* buf_;
};
- // Caller already checked thread is suspended.
ScopedObjectAccessUnchecked soa(Thread::Current());
MutexLock mu(soa.Self(), *Locks::thread_list_lock_);
Thread* thread;
@@ -1670,6 +1664,9 @@
if (error != JDWP::ERR_NONE) {
return error;
}
+ if (!IsSuspendedForDebugger(soa, thread)) {
+ return JDWP::ERR_THREAD_NOT_SUSPENDED;
+ }
GetFrameVisitor visitor(thread->GetManagedStack(), thread->GetInstrumentationStack(),
start_frame, frame_count, buf);
visitor.WalkStack();