aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectExpression.cpp
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2015-10-20 00:55:21 +0000
committerSean Callanan <scallanan@apple.com>2015-10-20 00:55:21 +0000
commitf2bd5c3e225bde7576e421e09c03fb40c7268db5 (patch)
tree3cfdf75e92cea3f47f92e13387bea3f7f0e278e2 /lldb/source/Commands/CommandObjectExpression.cpp
parent61149b86c312fb7aa9122651e0fe0ebc3b6cedef (diff)
downloadllvm-f2bd5c3e225bde7576e421e09c03fb40c7268db5.zip
llvm-f2bd5c3e225bde7576e421e09c03fb40c7268db5.tar.gz
llvm-f2bd5c3e225bde7576e421e09c03fb40c7268db5.tar.bz2
Added support to the expression command for dropping into the REPL at will.
"expr -r" does this. It also returns to a REPL if the LLDB command interpreter is neseted inside it, for example in cases where a REPL command resulted in a breakpoint being hit or a crash. llvm-svn: 250780
Diffstat (limited to 'lldb/source/Commands/CommandObjectExpression.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectExpression.cpp67
1 files changed, 66 insertions, 1 deletions
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index ec23717c7..7f0b03b 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -19,6 +19,7 @@
#include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h"
#include "lldb/Expression/UserExpression.h"
#include "lldb/Expression/DWARFExpression.h"
+#include "lldb/Expression/REPL.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/StringConvert.h"
#include "lldb/Core/Debugger.h"
@@ -198,6 +199,7 @@ CommandObjectExpression::CommandObjectExpression (CommandInterpreter &interprete
IOHandlerDelegate (IOHandlerDelegate::Completion::Expression),
m_option_group (interpreter),
m_format_options (eFormatDefault),
+ m_repl_option (LLDB_OPT_SET_1, false, "repl", 'r', "Drop into REPL", false, true),
m_command_options (),
m_expr_line_count (0),
m_expr_lines ()
@@ -253,6 +255,7 @@ Examples:
m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1);
m_option_group.Append (&m_command_options);
m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1 | LLDB_OPT_SET_2);
+ m_option_group.Append (&m_repl_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_3);
m_option_group.Finalize();
}
@@ -502,8 +505,70 @@ CommandObjectExpression::DoExecute
return false;
}
+ if (m_repl_option.GetOptionValue().GetCurrentValue())
+ {
+ Target *target = m_interpreter.GetExecutionContext().GetTargetPtr();
+ if (target)
+ {
+ // Drop into REPL
+ m_expr_lines.clear();
+ m_expr_line_count = 0;
+
+ Debugger &debugger = target->GetDebugger();
+
+ // Check if the LLDB command interpreter is sitting on top of a REPL that
+ // launched it...
+ if (debugger.CheckTopIOHandlerTypes(IOHandler::Type::CommandInterpreter, IOHandler::Type::REPL))
+ {
+ // the LLDB command interpreter is sitting on top of a REPL that launched it,
+ // so just say the command interpreter is done and fall back to the existing REPL
+ m_interpreter.GetIOHandler(false)->SetIsDone(true);
+ }
+ else
+ {
+ // We are launching the REPL on top of the current LLDB command interpreter,
+ // so just push one
+ bool initialize = false;
+ Error repl_error;
+ REPLSP repl_sp (target->GetREPL(repl_error, m_command_options.language, nullptr, false));
+
+ if (!repl_sp)
+ {
+ initialize = true;
+ repl_sp = target->GetREPL(repl_error, m_command_options.language, nullptr, true);
+ if (!repl_error.Success())
+ {
+ result.SetError(repl_error);
+ return result.Succeeded();
+ }
+ }
+
+ if (repl_sp)
+ {
+ if (initialize)
+ {
+ repl_sp->SetCommandOptions(m_command_options);
+ repl_sp->SetFormatOptions(m_format_options);
+ repl_sp->SetValueObjectDisplayOptions(m_varobj_options);
+ }
+
+ IOHandlerSP io_handler_sp (repl_sp->GetIOHandler());
+
+ io_handler_sp->SetIsDone(false);
+
+ debugger.PushIOHandler(io_handler_sp);
+ }
+ else
+ {
+ repl_error.SetErrorStringWithFormat("Couldn't create a REPL for %s", Language::GetNameForLanguageType(m_command_options.language));
+ result.SetError(repl_error);
+ return result.Succeeded();
+ }
+ }
+ }
+ }
// No expression following options
- if (expr == NULL || expr[0] == '\0')
+ else if (expr == NULL || expr[0] == '\0')
{
GetMultilineExpression ();
return result.Succeeded();