[Lldb-commits] [lldb] r250780 - Added support to the expression command for dropping into the REPL at will.
Sean Callanan via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 19 17:55:21 PDT 2015
Author: spyffe
Date: Mon Oct 19 19:55:21 2015
New Revision: 250780
URL: http://llvm.org/viewvc/llvm-project?rev=250780&view=rev
Log:
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.
Modified:
lldb/trunk/source/Commands/CommandObjectExpression.cpp
lldb/trunk/source/Commands/CommandObjectExpression.h
Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=250780&r1=250779&r2=250780&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Mon Oct 19 19:55:21 2015
@@ -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::CommandObjectEx
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();
Modified: lldb/trunk/source/Commands/CommandObjectExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.h?rev=250780&r1=250779&r2=250780&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.h (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.h Mon Oct 19 19:55:21 2015
@@ -16,6 +16,7 @@
// Project includes
#include "lldb/Core/IOHandler.h"
#include "lldb/Interpreter/CommandObject.h"
+#include "lldb/Interpreter/OptionGroupBoolean.h"
#include "lldb/Interpreter/OptionGroupFormat.h"
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
#include "lldb/Target/ExecutionContext.h"
@@ -101,6 +102,7 @@ protected:
OptionGroupOptions m_option_group;
OptionGroupFormat m_format_options;
OptionGroupValueObjectDisplay m_varobj_options;
+ OptionGroupBoolean m_repl_option;
CommandOptions m_command_options;
uint32_t m_expr_line_count;
std::string m_expr_lines; // Multi-line expression support
More information about the lldb-commits
mailing list