Skip to content

Commit cfea3bb

Browse files
igorkudrinkrishna2803
authored andcommitted
[lldb] Fix updating persistent variables without JIT (llvm#149642)
This patch fixes updating persistent variables when memory cannot be allocated in an inferior process: ``` > lldb -c test.core (lldb) expr int $i = 5 (lldb) expr $i = 55 (int) $0 = 55 (lldb) expr $i (int) $i = 5 ``` With this patch, the last command prints: ``` (int) $i = 55 ``` The issue was introduced in llvm#145599.
1 parent 2b91554 commit cfea3bb

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

lldb/source/Expression/Materializer.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,23 @@ class EntityPersistentVariable : public Materializer::Entity {
102102
m_persistent_variable_sp->GetName(), mem, eAddressTypeLoad,
103103
map.GetAddressByteSize());
104104

105-
if (m_persistent_variable_sp->m_flags &
106-
ExpressionVariable::EVKeepInTarget) {
107-
if (used_policy == IRMemoryMap::eAllocationPolicyMirror) {
105+
if (used_policy == IRMemoryMap::eAllocationPolicyMirror) {
106+
if (m_persistent_variable_sp->m_flags &
107+
ExpressionVariable::EVKeepInTarget) {
108108
// Clear the flag if the variable will never be deallocated.
109109
Status leak_error;
110110
map.Leak(mem, leak_error);
111111
m_persistent_variable_sp->m_flags &=
112112
~ExpressionVariable::EVNeedsAllocation;
113-
} else {
114-
// If the variable cannot be kept in target, clear this flag...
115-
m_persistent_variable_sp->m_flags &=
116-
~ExpressionVariable::EVKeepInTarget;
117-
// ...and set the flag to copy the value during dematerialization.
118-
m_persistent_variable_sp->m_flags |=
119-
ExpressionVariable::EVNeedsFreezeDry;
120113
}
114+
} else {
115+
// If we cannot allocate memory in the process,
116+
// - clear the 'EVKeepInTarget' flag to ensure that 'm_live_sp' is reset
117+
// during dematerialization,
118+
m_persistent_variable_sp->m_flags &= ~ExpressionVariable::EVKeepInTarget;
119+
// - set the 'EVNeedsFreezeDry' flag so that the value is copied to
120+
// 'm_frozen_sp' during dematerialization.
121+
m_persistent_variable_sp->m_flags |= ExpressionVariable::EVNeedsFreezeDry;
121122
}
122123

123124
// Write the contents of the variable to the area.

lldb/test/API/functionalities/postmortem/elf-core/expr/TestExpr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def test_persist_var(self):
3737
self.target.EvaluateExpression("int $my_int = 5")
3838
self.expect_expr("$my_int * 2", result_type="int", result_value="10")
3939

40+
# Try assigning the persistent variable a new value.
41+
self.target.EvaluateExpression("$my_int = 55")
42+
self.expect_expr("$my_int", result_type="int", result_value="55")
43+
4044
def test_context_object(self):
4145
"""Test expression evaluation in context of an object."""
4246

0 commit comments

Comments
 (0)