mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 01:58:44 +08:00
[lldb] Use current execution context in SBDebugger
Use `GetSelectedExecutionContext()` instead of `GetCommandInterpreter().GetExecutionContext()` in `SBDebugger::GetInternalVariableValue/SBDebugger::SetInternalVariable`. The execution context in the command interpreter might be empty, if no commands has been executed yet (it is updated only when handling commands or completions -- e.g. https://github.com/llvm/llvm-project/blob/main/lldb/source/Interpreter/CommandInterpreter.cpp#L1855). Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D95761
This commit is contained in:
committed by
Raphael Isemann
parent
eefa8a9ff8
commit
754ab803b8
@@ -1278,8 +1278,7 @@ SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value,
|
||||
ConstString(debugger_instance_name)));
|
||||
Status error;
|
||||
if (debugger_sp) {
|
||||
ExecutionContext exe_ctx(
|
||||
debugger_sp->GetCommandInterpreter().GetExecutionContext());
|
||||
ExecutionContext exe_ctx(debugger_sp->GetSelectedExecutionContext());
|
||||
error = debugger_sp->SetPropertyValue(&exe_ctx, eVarSetOperationAssign,
|
||||
var_name, value);
|
||||
} else {
|
||||
@@ -1303,8 +1302,7 @@ SBDebugger::GetInternalVariableValue(const char *var_name,
|
||||
ConstString(debugger_instance_name)));
|
||||
Status error;
|
||||
if (debugger_sp) {
|
||||
ExecutionContext exe_ctx(
|
||||
debugger_sp->GetCommandInterpreter().GetExecutionContext());
|
||||
ExecutionContext exe_ctx(debugger_sp->GetSelectedExecutionContext());
|
||||
lldb::OptionValueSP value_sp(
|
||||
debugger_sp->GetPropertyValue(&exe_ctx, var_name, false, error));
|
||||
if (value_sp) {
|
||||
|
||||
@@ -43,3 +43,35 @@ class DebuggerAPITestCase(TestBase):
|
||||
target = lldb.SBTarget()
|
||||
self.assertFalse(target.IsValid())
|
||||
self.dbg.DeleteTarget(target)
|
||||
|
||||
@add_test_categories(['pyapi'])
|
||||
def test_debugger_internal_variables(self):
|
||||
debugger_name = self.dbg.GetInstanceName()
|
||||
|
||||
# Set a variable and check it was written successfully.
|
||||
error = lldb.SBDebugger.SetInternalVariable(
|
||||
'target.prefer-dynamic-value', 'no-dynamic-values', debugger_name)
|
||||
self.assertTrue(error.Success())
|
||||
ret = lldb.SBDebugger.GetInternalVariableValue(
|
||||
'target.prefer-dynamic-value', debugger_name)
|
||||
self.assertEqual(ret.GetSize(), 1)
|
||||
self.assertEqual(ret.GetStringAtIndex(0), 'no-dynamic-values')
|
||||
|
||||
# Set a variable with a different value.
|
||||
error = lldb.SBDebugger.SetInternalVariable(
|
||||
'target.prefer-dynamic-value', 'no-run-target', debugger_name)
|
||||
self.assertTrue(error.Success())
|
||||
ret = lldb.SBDebugger.GetInternalVariableValue(
|
||||
'target.prefer-dynamic-value', debugger_name)
|
||||
self.assertEqual(ret.GetSize(), 1)
|
||||
self.assertEqual(ret.GetStringAtIndex(0), 'no-run-target')
|
||||
|
||||
# Try setting invalid value, check for error.
|
||||
error = lldb.SBDebugger.SetInternalVariable(
|
||||
'target.prefer-dynamic-value', 'dummy-value', debugger_name)
|
||||
self.assertTrue(error.Fail())
|
||||
# Check that the value didn't change.
|
||||
ret = lldb.SBDebugger.GetInternalVariableValue(
|
||||
'target.prefer-dynamic-value', debugger_name)
|
||||
self.assertEqual(ret.GetSize(), 1)
|
||||
self.assertEqual(ret.GetStringAtIndex(0), 'no-run-target')
|
||||
|
||||
Reference in New Issue
Block a user