[Lldb-commits] [lldb] 8f7c911 - [lldb][NFC] Refactor our option generation out of EvaluateExpression

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 6 18:33:16 PST 2020


Author: Raphael Isemann
Date: 2020-03-06T18:32:16-08:00
New Revision: 8f7c911b58813908da7fa99c7c1a8e7ca1a58213

URL: https://github.com/llvm/llvm-project/commit/8f7c911b58813908da7fa99c7c1a8e7ca1a58213
DIFF: https://github.com/llvm/llvm-project/commit/8f7c911b58813908da7fa99c7c1a8e7ca1a58213.diff

LOG: [lldb][NFC] Refactor our option generation out of EvaluateExpression

Added: 
    

Modified: 
    lldb/source/Commands/CommandObjectExpression.cpp
    lldb/source/Commands/CommandObjectExpression.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index fd01cece9ad0..388f9f0af66a 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -362,29 +362,13 @@ CanBeUsedForElementCountPrinting(ValueObject &valobj) {
   return Status();
 }
 
-bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
-                                                 Stream *output_stream,
-                                                 Stream *error_stream,
-                                                 CommandReturnObject *result) {
-  // Don't use m_exe_ctx as this might be called asynchronously after the
-  // command object DoExecute has finished when doing multi-line expression
-  // that use an input reader...
-  ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
-
-  Target *target = exe_ctx.GetTargetPtr();
-
-  if (!target)
-    target = &GetDummyTarget();
-
-  lldb::ValueObjectSP result_valobj_sp;
-  bool keep_in_memory = true;
-  StackFrame *frame = exe_ctx.GetFramePtr();
-
+EvaluateExpressionOptions
+CommandObjectExpression::GetEvalOptions(const Target &target) {
   EvaluateExpressionOptions options;
   options.SetCoerceToId(m_varobj_options.use_objc);
   options.SetUnwindOnError(m_command_options.unwind_on_error);
   options.SetIgnoreBreakpoints(m_command_options.ignore_breakpoints);
-  options.SetKeepInMemory(keep_in_memory);
+  options.SetKeepInMemory(true);
   options.SetUseDynamic(m_varobj_options.use_dynamic);
   options.SetTryAllThreads(m_command_options.try_all_threads);
   options.SetDebug(m_command_options.debug);
@@ -396,7 +380,7 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
 
   bool auto_apply_fixits;
   if (m_command_options.auto_apply_fixits == eLazyBoolCalculate)
-    auto_apply_fixits = target->GetEnableAutoApplyFixIts();
+    auto_apply_fixits = target.GetEnableAutoApplyFixIts();
   else
     auto_apply_fixits = m_command_options.auto_apply_fixits == eLazyBoolYes;
 
@@ -415,7 +399,27 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
     options.SetTimeout(std::chrono::microseconds(m_command_options.timeout));
   else
     options.SetTimeout(llvm::None);
+  return options;
+}
+
+bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
+                                                 Stream *output_stream,
+                                                 Stream *error_stream,
+                                                 CommandReturnObject *result) {
+  // Don't use m_exe_ctx as this might be called asynchronously after the
+  // command object DoExecute has finished when doing multi-line expression
+  // that use an input reader...
+  ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
+
+  Target *target = exe_ctx.GetTargetPtr();
+
+  if (!target)
+    target = &GetDummyTarget();
+
+  lldb::ValueObjectSP result_valobj_sp;
+  StackFrame *frame = exe_ctx.GetFramePtr();
 
+  const EvaluateExpressionOptions options = GetEvalOptions(*target);
   ExpressionResults success = target->EvaluateExpression(
       expr, frame, result_valobj_sp, options, &m_fixed_expression);
 

diff  --git a/lldb/source/Commands/CommandObjectExpression.h b/lldb/source/Commands/CommandObjectExpression.h
index 1564e22052ee..b3bee3ca0e8c 100644
--- a/lldb/source/Commands/CommandObjectExpression.h
+++ b/lldb/source/Commands/CommandObjectExpression.h
@@ -14,7 +14,9 @@
 #include "lldb/Interpreter/OptionGroupBoolean.h"
 #include "lldb/Interpreter/OptionGroupFormat.h"
 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
+#include "lldb/Target/Target.h"
 #include "lldb/lldb-private-enumerations.h"
+
 namespace lldb_private {
 
 class CommandObjectExpression : public CommandObjectRaw,
@@ -65,6 +67,10 @@ class CommandObjectExpression : public CommandObjectRaw,
 
   bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
 
+  /// Return the appropriate expression options used for evaluating the
+  /// expression in the given target.
+  EvaluateExpressionOptions GetEvalOptions(const Target &target);
+
   bool EvaluateExpression(llvm::StringRef expr, Stream *output_stream,
                           Stream *error_stream,
                           CommandReturnObject *result = nullptr);


        


More information about the lldb-commits mailing list