aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/API/SBCommandInterpreter.cpp
diff options
context:
space:
mode:
authorTatyana Krasnukha <21970096+tkrasnukha@users.noreply.github.com>2020-12-10 19:30:04 +0300
committerTatyana Krasnukha <tatyana@synopsys.com>2020-12-12 16:40:59 +0300
commita01b26fb51c710a3a8ef88cc83b0701461f5b9ab (patch)
tree448aa6405f4bd8f98f14db61c21452ce368ff2c6 /lldb/source/API/SBCommandInterpreter.cpp
parent7832d7e95ace589b2275bafe701ccb377a16b1b2 (diff)
downloadllvm-a01b26fb51c710a3a8ef88cc83b0701461f5b9ab.zip
llvm-a01b26fb51c710a3a8ef88cc83b0701461f5b9ab.tar.gz
llvm-a01b26fb51c710a3a8ef88cc83b0701461f5b9ab.tar.bz2
[lldb] Make CommandInterpreter's execution context the same as debugger's one.
Currently, the interpreter's context is not updated until a command is executed. This has resulted in the behavior of SB-interface functions and some commands depends on previous user actions. The interpreter's context can stay uninitialized, point to a currently selected target, or point to one of previously selected targets. This patch removes any usages of CommandInterpreter::UpdateExecutionContext. CommandInterpreter::HandleCommand* functions still may override context temporarily, but now they always restore it before exiting. CommandInterpreter saves overriden contexts to the stack, that makes nesting commands possible. Added test reproduces one of the issues. Without this fix, the last assertion fails because interpreter's execution context is empty until running "target list", so, the value of the global property was updated instead of process's local instance. Differential Revision: https://reviews.llvm.org/D92164
Diffstat (limited to 'lldb/source/API/SBCommandInterpreter.cpp')
-rw-r--r--lldb/source/API/SBCommandInterpreter.cpp37
1 files changed, 16 insertions, 21 deletions
diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp
index 31e7da8..d28bc41 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -171,27 +171,23 @@ lldb::ReturnStatus SBCommandInterpreter::HandleCommand(
lldb::SBCommandReturnObject &, bool),
command_line, override_context, result, add_to_history);
-
- ExecutionContext ctx, *ctx_ptr;
- if (override_context.get()) {
- ctx = override_context.get()->Lock(true);
- ctx_ptr = &ctx;
- } else
- ctx_ptr = nullptr;
-
result.Clear();
if (command_line && IsValid()) {
result.ref().SetInteractive(false);
- m_opaque_ptr->HandleCommand(command_line,
- add_to_history ? eLazyBoolYes : eLazyBoolNo,
- result.ref(), ctx_ptr);
+ auto do_add_to_history = add_to_history ? eLazyBoolYes : eLazyBoolNo;
+ if (override_context.get())
+ m_opaque_ptr->HandleCommand(command_line, do_add_to_history,
+ override_context.get()->Lock(true),
+ result.ref());
+ else
+ m_opaque_ptr->HandleCommand(command_line, do_add_to_history,
+ result.ref());
} else {
result->AppendError(
"SBCommandInterpreter or the command line is not valid");
result->SetStatus(eReturnStatusFailed);
}
-
return result.GetStatus();
}
@@ -219,15 +215,14 @@ void SBCommandInterpreter::HandleCommandsFromFile(
}
FileSpec tmp_spec = file.ref();
- ExecutionContext ctx, *ctx_ptr;
- if (override_context.get()) {
- ctx = override_context.get()->Lock(true);
- ctx_ptr = &ctx;
- } else
- ctx_ptr = nullptr;
-
- m_opaque_ptr->HandleCommandsFromFile(tmp_spec, ctx_ptr, options.ref(),
- result.ref());
+ if (override_context.get())
+ m_opaque_ptr->HandleCommandsFromFile(tmp_spec,
+ override_context.get()->Lock(true),
+ options.ref(),
+ result.ref());
+
+ else
+ m_opaque_ptr->HandleCommandsFromFile(tmp_spec, options.ref(), result.ref());
}
int SBCommandInterpreter::HandleCompletion(