From fc3614024be76de935bf90b5f7e74db29d3fe25f Mon Sep 17 00:00:00 2001 From: John Dallaway Date: Thu, 30 Oct 2025 19:41:09 +0000 Subject: [PATCH] Handle var changed state following -var-assign --- src/MICmdCmdVar.cpp | 13 +++++++++++-- src/MICmnLLDBDebugSessionInfoVarObj.cpp | 22 +++++++++++++++++++--- src/MICmnLLDBDebugSessionInfoVarObj.h | 2 ++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/MICmdCmdVar.cpp b/src/MICmdCmdVar.cpp index db18799..0f58624 100644 --- a/src/MICmdCmdVar.cpp +++ b/src/MICmdCmdVar.cpp @@ -451,9 +451,14 @@ bool CMICmdCmdVarUpdate::Execute() { } lldb::SBValue &rValue = varObj.GetValue(); + const bool bVarChanged = varObj.ExchangeChanged(false); if (!ExamineSBValueForChange(rValue, m_bValueChanged)) return MIstatus::failure; + // SBValue changed state due to a -var-assign may have already been + // cleared so combine it with changed state held by the var object + m_bValueChanged |= bVarChanged; + if (!m_bValueChanged) { CMICmnLLDBDebugSessionInfo &rSessionInfo( CMICmnLLDBDebugSessionInfo::Instance()); @@ -747,10 +752,14 @@ bool CMICmdCmdVarAssign::Execute() { CMIUtilString strExpression(rExpression.Trim()); strExpression = strExpression.Trim('"'); lldb::SBValue &rValue(varObj.GetValue()); + CMIUtilString strOldValue(rValue.GetValue()); m_bOk = rValue.SetValueFromCString(strExpression.c_str()); - if (m_bOk) + if (m_bOk) { + CMIUtilString strNewValue(rValue.GetValue()); + const bool bVarChanged = !CMIUtilString::Compare(strOldValue, strNewValue); + varObj.ExchangeChanged(bVarChanged); varObj.UpdateValue(); - + } return MIstatus::success; } diff --git a/src/MICmnLLDBDebugSessionInfoVarObj.cpp b/src/MICmnLLDBDebugSessionInfoVarObj.cpp index a0f7753..868a486 100644 --- a/src/MICmnLLDBDebugSessionInfoVarObj.cpp +++ b/src/MICmnLLDBDebugSessionInfoVarObj.cpp @@ -36,7 +36,7 @@ CMICmnLLDBDebugSessionInfoVarObj::varFormat_e //-- CMICmnLLDBDebugSessionInfoVarObj::CMICmnLLDBDebugSessionInfoVarObj() : m_eVarFormat(eVarFormat_Natural), m_eVarType(eVarType_Internal), - m_eValObjKind(valObjKind_ec::eValObjKind_Other) { + m_eValObjKind(valObjKind_ec::eValObjKind_Other), m_bChanged(false) { // Do not call UpdateValue() in here as not necessary } @@ -56,7 +56,7 @@ CMICmnLLDBDebugSessionInfoVarObj::CMICmnLLDBDebugSessionInfoVarObj( const lldb::SBValue &vrValue, const valObjKind_ec eValObjKind) : m_eVarFormat(eVarFormat_Natural), m_eVarType(eVarType_Internal), m_eValObjKind(eValObjKind), m_strName(vrStrName), m_SBValue(vrValue), - m_strNameReal(vrStrNameReal) { + m_strNameReal(vrStrNameReal), m_bChanged(false) { UpdateValue(); } @@ -80,7 +80,7 @@ CMICmnLLDBDebugSessionInfoVarObj::CMICmnLLDBDebugSessionInfoVarObj( : m_eVarFormat(eVarFormat_Natural), m_eVarType(eVarType_Internal), m_eValObjKind(eValObjKind), m_strName(vrStrName), m_SBValue(vrValue), m_strNameReal(vrStrNameReal), - m_strVarObjParentName(vrStrVarObjParentName) { + m_strVarObjParentName(vrStrVarObjParentName), m_bChanged(false) { UpdateValue(); } @@ -159,6 +159,7 @@ void CMICmnLLDBDebugSessionInfoVarObj::CopyOther( m_strNameReal = vrOther.m_strNameReal; m_strFormattedValue = vrOther.m_strFormattedValue; m_strVarObjParentName = vrOther.m_strVarObjParentName; + m_bChanged = vrOther.m_bChanged; } //++ @@ -178,6 +179,7 @@ void CMICmnLLDBDebugSessionInfoVarObj::MoveOther( m_strNameReal = std::move(vrwOther.m_strNameReal); m_strFormattedValue = std::move(vrwOther.m_strFormattedValue); m_strVarObjParentName = std::move(vrwOther.m_strVarObjParentName); + m_bChanged = vrwOther.m_bChanged; vrwOther.m_eVarFormat = eVarFormat_Natural; vrwOther.m_eVarType = eVarType_Internal; @@ -187,6 +189,7 @@ void CMICmnLLDBDebugSessionInfoVarObj::MoveOther( vrwOther.m_strNameReal.clear(); vrwOther.m_strFormattedValue.clear(); vrwOther.m_strVarObjParentName.clear(); + vrwOther.m_bChanged = false; } //++ @@ -539,6 +542,19 @@ void CMICmnLLDBDebugSessionInfoVarObj::UpdateValue() { CMICmnLLDBDebugSessionInfoVarObj::VarObjUpdate(*this); } +//++ +// Details: Set the changed state of the var object. +// Type: Method. +// Args: bChanged - New changed state. +// Returns: m_bChanged - Previous changed state. +// Throws: None. +//-- +bool CMICmnLLDBDebugSessionInfoVarObj::ExchangeChanged(const bool bChanged) { + const bool bPreviousChanged = m_bChanged; + m_bChanged = bChanged; + return bPreviousChanged; +} + //++ // Details: Retrieve the enumeration type of the var object. // Type: Method. diff --git a/src/MICmnLLDBDebugSessionInfoVarObj.h b/src/MICmnLLDBDebugSessionInfoVarObj.h index 93b202f..820c9cd 100644 --- a/src/MICmnLLDBDebugSessionInfoVarObj.h +++ b/src/MICmnLLDBDebugSessionInfoVarObj.h @@ -106,6 +106,7 @@ class CMICmnLLDBDebugSessionInfoVarObj { const CMIUtilString &GetVarParentName() const; valObjKind_ec GetValObjKind() const; void UpdateValue(); + bool ExchangeChanged(const bool bChanged); // Overridden: public: @@ -148,6 +149,7 @@ class CMICmnLLDBDebugSessionInfoVarObj { CMIUtilString m_strNameReal; CMIUtilString m_strFormattedValue; CMIUtilString m_strVarObjParentName; + bool m_bChanged; // *** Update the copy move constructors and assignment operator *** };