Skip to content

Commit

Permalink
Relax the checks for "stack-list-*" MI cmd (#46)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
WardenGnaw authored Dec 29, 2021
1 parent f2acb1f commit 2388bd7
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions src/MICmdCmdStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@

#include <algorithm>

//++
// Details: The check for the non-MI command "frame variable" validates that the
// process is paused and the frame exists.
// Type: Method.
// Args: processState - the current process state.
// threadInvalid - (R) Caller's m_bThreadInvalid member.
// Return: MIstatus::success - Function succeeded.
// MIstatus::failure - Function failed.
// Throws: None.
//--
bool EnsureProcessIsPaused(lldb::StateType processState, bool &threadInvalid) {
switch (processState) {
case lldb::eStateInvalid:
case lldb::eStateCrashed:
threadInvalid = true;
return MIstatus::failure;
case lldb::eStateSuspended:
case lldb::eStateStopped:
break;
default:
threadInvalid = true;
}

return MIstatus::success;
}

//++
// Details: CMICmdCmdStackInfoDepth constructor.
// Type: Method.
Expand Down Expand Up @@ -519,20 +545,18 @@ bool CMICmdCmdStackListArguments::Execute() {
CMICmnLLDBDebugSessionInfo &rSessionInfo(
CMICmnLLDBDebugSessionInfo::Instance());
lldb::SBProcess sbProcess = rSessionInfo.GetProcess();

if (!EnsureProcessIsPaused(sbProcess.GetState(), m_bThreadInvalid)) {
return MIstatus::failure;
}

lldb::SBThread thread = (nThreadId != UINT64_MAX)
? sbProcess.GetThreadByIndexID(nThreadId)
: sbProcess.GetSelectedThread();
m_bThreadInvalid = !thread.IsValid();
m_bThreadInvalid |= !thread.IsValid();
if (m_bThreadInvalid)
return MIstatus::success;

const lldb::StopReason eStopReason = thread.GetStopReason();
if ((eStopReason == lldb::eStopReasonNone) ||
(eStopReason == lldb::eStopReasonInvalid)) {
m_bThreadInvalid = true;
return MIstatus::success;
}

const MIuint nFrames = thread.GetNumFrames();
if (nFrameLow >= nFrames) {
// The low-frame is larger than the actual number of frames
Expand Down Expand Up @@ -857,20 +881,18 @@ bool CMICmdCmdStackListVariables::Execute() {
CMICmnLLDBDebugSessionInfo &rSessionInfo(
CMICmnLLDBDebugSessionInfo::Instance());
lldb::SBProcess sbProcess = rSessionInfo.GetProcess();

if (!EnsureProcessIsPaused(sbProcess.GetState(), m_bThreadInvalid)) {
return MIstatus::failure;
}

lldb::SBThread thread = (nThreadId != UINT64_MAX)
? sbProcess.GetThreadByIndexID(nThreadId)
: sbProcess.GetSelectedThread();
m_bThreadInvalid = !thread.IsValid();
m_bThreadInvalid |= !thread.IsValid();
if (m_bThreadInvalid)
return MIstatus::success;

const lldb::StopReason eStopReason = thread.GetStopReason();
if ((eStopReason == lldb::eStopReasonNone) ||
(eStopReason == lldb::eStopReasonInvalid)) {
m_bThreadInvalid = true;
return MIstatus::success;
}

lldb::SBFrame frame = (nFrame != UINT64_MAX) ? thread.GetFrameAtIndex(nFrame)
: thread.GetSelectedFrame();

Expand Down

0 comments on commit 2388bd7

Please sign in to comment.