Skip to content

Commit 2388bd7

Browse files
authored
Relax the checks for "stack-list-*" MI cmd (#46)
Relax the checks for "stack-list-*" MI cmd The "stack-list-*" MI commands were checking whether the thread was stopped. However, for state of some threads would not be stopped even when they clearly are. This was not an issue for non-MI commands since they don't check that the thread is stopped. This change relaxes the checks performed by the MI commands to match the ones by the non-MI commands.
1 parent f2acb1f commit 2388bd7

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

src/MICmdCmdStack.cpp

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@
3333

3434
#include <algorithm>
3535

36+
//++
37+
// Details: The check for the non-MI command "frame variable" validates that the
38+
// process is paused and the frame exists.
39+
// Type: Method.
40+
// Args: processState - the current process state.
41+
// threadInvalid - (R) Caller's m_bThreadInvalid member.
42+
// Return: MIstatus::success - Function succeeded.
43+
// MIstatus::failure - Function failed.
44+
// Throws: None.
45+
//--
46+
bool EnsureProcessIsPaused(lldb::StateType processState, bool &threadInvalid) {
47+
switch (processState) {
48+
case lldb::eStateInvalid:
49+
case lldb::eStateCrashed:
50+
threadInvalid = true;
51+
return MIstatus::failure;
52+
case lldb::eStateSuspended:
53+
case lldb::eStateStopped:
54+
break;
55+
default:
56+
threadInvalid = true;
57+
}
58+
59+
return MIstatus::success;
60+
}
61+
3662
//++
3763
// Details: CMICmdCmdStackInfoDepth constructor.
3864
// Type: Method.
@@ -519,20 +545,18 @@ bool CMICmdCmdStackListArguments::Execute() {
519545
CMICmnLLDBDebugSessionInfo &rSessionInfo(
520546
CMICmnLLDBDebugSessionInfo::Instance());
521547
lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
548+
549+
if (!EnsureProcessIsPaused(sbProcess.GetState(), m_bThreadInvalid)) {
550+
return MIstatus::failure;
551+
}
552+
522553
lldb::SBThread thread = (nThreadId != UINT64_MAX)
523554
? sbProcess.GetThreadByIndexID(nThreadId)
524555
: sbProcess.GetSelectedThread();
525-
m_bThreadInvalid = !thread.IsValid();
556+
m_bThreadInvalid |= !thread.IsValid();
526557
if (m_bThreadInvalid)
527558
return MIstatus::success;
528559

529-
const lldb::StopReason eStopReason = thread.GetStopReason();
530-
if ((eStopReason == lldb::eStopReasonNone) ||
531-
(eStopReason == lldb::eStopReasonInvalid)) {
532-
m_bThreadInvalid = true;
533-
return MIstatus::success;
534-
}
535-
536560
const MIuint nFrames = thread.GetNumFrames();
537561
if (nFrameLow >= nFrames) {
538562
// The low-frame is larger than the actual number of frames
@@ -857,20 +881,18 @@ bool CMICmdCmdStackListVariables::Execute() {
857881
CMICmnLLDBDebugSessionInfo &rSessionInfo(
858882
CMICmnLLDBDebugSessionInfo::Instance());
859883
lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
884+
885+
if (!EnsureProcessIsPaused(sbProcess.GetState(), m_bThreadInvalid)) {
886+
return MIstatus::failure;
887+
}
888+
860889
lldb::SBThread thread = (nThreadId != UINT64_MAX)
861890
? sbProcess.GetThreadByIndexID(nThreadId)
862891
: sbProcess.GetSelectedThread();
863-
m_bThreadInvalid = !thread.IsValid();
892+
m_bThreadInvalid |= !thread.IsValid();
864893
if (m_bThreadInvalid)
865894
return MIstatus::success;
866895

867-
const lldb::StopReason eStopReason = thread.GetStopReason();
868-
if ((eStopReason == lldb::eStopReasonNone) ||
869-
(eStopReason == lldb::eStopReasonInvalid)) {
870-
m_bThreadInvalid = true;
871-
return MIstatus::success;
872-
}
873-
874896
lldb::SBFrame frame = (nFrame != UINT64_MAX) ? thread.GetFrameAtIndex(nFrame)
875897
: thread.GetSelectedFrame();
876898

0 commit comments

Comments
 (0)