diff options
author | Tatyana Krasnukha <21970096+tkrasnukha@users.noreply.github.com> | 2020-12-10 19:30:04 +0300 |
---|---|---|
committer | Tatyana Krasnukha <tatyana@synopsys.com> | 2020-12-12 16:40:59 +0300 |
commit | a01b26fb51c710a3a8ef88cc83b0701461f5b9ab (patch) | |
tree | 448aa6405f4bd8f98f14db61c21452ce368ff2c6 /lldb/source/Commands | |
parent | 7832d7e95ace589b2275bafe701ccb377a16b1b2 (diff) | |
download | llvm-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/Commands')
-rw-r--r-- | lldb/source/Commands/CommandObjectCommands.cpp | 14 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectExpression.cpp | 14 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectProcess.cpp | 1 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectRegexCommand.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectSettings.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectWatchpointCommand.cpp | 2 |
6 files changed, 11 insertions, 27 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 0c441dd..49d8e8a 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -134,15 +134,12 @@ protected: FileSpec cmd_file(command[0].ref()); FileSystem::Instance().Resolve(cmd_file); - ExecutionContext *exe_ctx = nullptr; // Just use the default context. + CommandInterpreterRunOptions options; // If any options were set, then use them if (m_options.m_stop_on_error.OptionWasSet() || m_options.m_silent_run.OptionWasSet() || m_options.m_stop_on_continue.OptionWasSet()) { - // Use user set settings - CommandInterpreterRunOptions options; - if (m_options.m_stop_on_continue.OptionWasSet()) options.SetStopOnContinue( m_options.m_stop_on_continue.GetCurrentValue()); @@ -159,14 +156,9 @@ protected: options.SetEchoCommands(m_interpreter.GetEchoCommands()); options.SetEchoCommentCommands(m_interpreter.GetEchoCommentCommands()); } - - m_interpreter.HandleCommandsFromFile(cmd_file, exe_ctx, options, result); - } else { - // No options were set, inherit any settings from nested "command source" - // commands, or set to sane default settings... - CommandInterpreterRunOptions options; - m_interpreter.HandleCommandsFromFile(cmd_file, exe_ctx, options, result); } + + m_interpreter.HandleCommandsFromFile(cmd_file, options, result); return result.Succeeded(); } diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 58eaa3f..c7866f9 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -292,18 +292,12 @@ void CommandObjectExpression::HandleCompletion(CompletionRequest &request) { options.SetAutoApplyFixIts(false); options.SetGenerateDebugInfo(false); - // We need a valid execution context with a frame pointer for this - // completion, so if we don't have one we should try to make a valid - // execution context. - if (m_interpreter.GetExecutionContext().GetFramePtr() == nullptr) - m_interpreter.UpdateExecutionContext(nullptr); - - // This didn't work, so let's get out before we start doing things that - // expect a valid frame pointer. - if (m_interpreter.GetExecutionContext().GetFramePtr() == nullptr) + ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); + + // Get out before we start doing things that expect a valid frame pointer. + if (exe_ctx.GetFramePtr() == nullptr) return; - ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); Target *exe_target = exe_ctx.GetTargetPtr(); Target &target = exe_target ? *exe_target : GetDummyTarget(); diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 1eef280..8beabed 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -380,7 +380,6 @@ protected: return false; } - m_interpreter.UpdateExecutionContext(nullptr); StreamString stream; const auto error = target->Attach(m_options.attach_info, &stream); if (error.Success()) { diff --git a/lldb/source/Commands/CommandObjectRegexCommand.cpp b/lldb/source/Commands/CommandObjectRegexCommand.cpp index 1bf29d3..dcd05a12 100644 --- a/lldb/source/Commands/CommandObjectRegexCommand.cpp +++ b/lldb/source/Commands/CommandObjectRegexCommand.cpp @@ -53,8 +53,8 @@ bool CommandObjectRegexCommand::DoExecute(llvm::StringRef command, // Pass in true for "no context switching". The command that called us // should have set up the context appropriately, we shouldn't have to // redo that. - return m_interpreter.HandleCommand( - new_command.c_str(), eLazyBoolCalculate, result, nullptr, true, true); + return m_interpreter.HandleCommand(new_command.c_str(), + eLazyBoolCalculate, result); } } result.SetStatus(eReturnStatusFailed); diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index 87e0352..d869377 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -469,14 +469,13 @@ protected: bool DoExecute(Args &command, CommandReturnObject &result) override { FileSpec file(m_options.m_filename); FileSystem::Instance().Resolve(file); - ExecutionContext clean_ctx; CommandInterpreterRunOptions options; options.SetAddToHistory(false); options.SetEchoCommands(false); options.SetPrintResults(true); options.SetPrintErrors(true); options.SetStopOnError(false); - m_interpreter.HandleCommandsFromFile(file, &clean_ctx, options, result); + m_interpreter.HandleCommandsFromFile(file, options, result); return result.Succeeded(); } diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp index fe3052a..3df17a0 100644 --- a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp @@ -301,7 +301,7 @@ are no syntax errors may indicate that a function was declared but never called. options.SetPrintErrors(true); options.SetAddToHistory(false); - debugger.GetCommandInterpreter().HandleCommands(commands, &exe_ctx, + debugger.GetCommandInterpreter().HandleCommands(commands, exe_ctx, options, result); result.GetImmediateOutputStream()->Flush(); result.GetImmediateErrorStream()->Flush(); |