xref: /llvm-project/lldb/source/Commands/CommandObjectExpression.cpp (revision ec67e73430889882861fb21a193f57cdf2c3a1d2)
1 //===-- CommandObjectExpression.cpp -----------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ADT/STLExtras.h"
10 #include "llvm/ADT/StringRef.h"
11 
12 #include "CommandObjectExpression.h"
13 #include "lldb/Core/Debugger.h"
14 #include "lldb/Core/Value.h"
15 #include "lldb/Core/ValueObjectVariable.h"
16 #include "lldb/DataFormatters/ValueObjectPrinter.h"
17 #include "lldb/Expression/DWARFExpression.h"
18 #include "lldb/Expression/REPL.h"
19 #include "lldb/Expression/UserExpression.h"
20 #include "lldb/Host/Host.h"
21 #include "lldb/Host/OptionParser.h"
22 #include "lldb/Interpreter/CommandInterpreter.h"
23 #include "lldb/Interpreter/CommandReturnObject.h"
24 #include "lldb/Interpreter/OptionArgParser.h"
25 #include "lldb/Symbol/ObjectFile.h"
26 #include "lldb/Symbol/Variable.h"
27 #include "lldb/Target/Language.h"
28 #include "lldb/Target/Process.h"
29 #include "lldb/Target/StackFrame.h"
30 #include "lldb/Target/Target.h"
31 #include "lldb/Target/Thread.h"
32 
33 using namespace lldb;
34 using namespace lldb_private;
35 
36 CommandObjectExpression::CommandOptions::CommandOptions() : OptionGroup() {}
37 
38 CommandObjectExpression::CommandOptions::~CommandOptions() = default;
39 
40 static constexpr OptionEnumValueElement g_description_verbosity_type[] = {
41     {eLanguageRuntimeDescriptionDisplayVerbosityCompact, "compact",
42      "Only show the description string"},
43     {eLanguageRuntimeDescriptionDisplayVerbosityFull, "full",
44      "Show the full output, including persistent variable's name and type"} };
45 
46 static constexpr OptionEnumValues DescriptionVerbosityTypes() {
47   return OptionEnumValues(g_description_verbosity_type);
48 }
49 
50 static constexpr OptionDefinition g_expression_options[] = {
51 #define LLDB_OPTIONS_expression
52 #include "CommandOptions.inc"
53 };
54 
55 Status CommandObjectExpression::CommandOptions::SetOptionValue(
56     uint32_t option_idx, llvm::StringRef option_arg,
57     ExecutionContext *execution_context) {
58   Status error;
59 
60   const int short_option = GetDefinitions()[option_idx].short_option;
61 
62   switch (short_option) {
63   case 'l':
64     language = Language::GetLanguageTypeFromString(option_arg);
65     if (language == eLanguageTypeUnknown)
66       error.SetErrorStringWithFormat(
67           "unknown language type: '%s' for expression",
68           option_arg.str().c_str());
69     break;
70 
71   case 'a': {
72     bool success;
73     bool result;
74     result = OptionArgParser::ToBoolean(option_arg, true, &success);
75     if (!success)
76       error.SetErrorStringWithFormat(
77           "invalid all-threads value setting: \"%s\"",
78           option_arg.str().c_str());
79     else
80       try_all_threads = result;
81   } break;
82 
83   case 'i': {
84     bool success;
85     bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
86     if (success)
87       ignore_breakpoints = tmp_value;
88     else
89       error.SetErrorStringWithFormat(
90           "could not convert \"%s\" to a boolean value.",
91           option_arg.str().c_str());
92     break;
93   }
94 
95   case 'j': {
96     bool success;
97     bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
98     if (success)
99       allow_jit = tmp_value;
100     else
101       error.SetErrorStringWithFormat(
102           "could not convert \"%s\" to a boolean value.",
103           option_arg.str().c_str());
104     break;
105   }
106 
107   case 't':
108     if (option_arg.getAsInteger(0, timeout)) {
109       timeout = 0;
110       error.SetErrorStringWithFormat("invalid timeout setting \"%s\"",
111                                      option_arg.str().c_str());
112     }
113     break;
114 
115   case 'u': {
116     bool success;
117     bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
118     if (success)
119       unwind_on_error = tmp_value;
120     else
121       error.SetErrorStringWithFormat(
122           "could not convert \"%s\" to a boolean value.",
123           option_arg.str().c_str());
124     break;
125   }
126 
127   case 'v':
128     if (option_arg.empty()) {
129       m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityFull;
130       break;
131     }
132     m_verbosity = (LanguageRuntimeDescriptionDisplayVerbosity)
133         OptionArgParser::ToOptionEnum(
134             option_arg, GetDefinitions()[option_idx].enum_values, 0, error);
135     if (!error.Success())
136       error.SetErrorStringWithFormat(
137           "unrecognized value for description-verbosity '%s'",
138           option_arg.str().c_str());
139     break;
140 
141   case 'g':
142     debug = true;
143     unwind_on_error = false;
144     ignore_breakpoints = false;
145     break;
146 
147   case 'p':
148     top_level = true;
149     break;
150 
151   case 'X': {
152     bool success;
153     bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
154     if (success)
155       auto_apply_fixits = tmp_value ? eLazyBoolYes : eLazyBoolNo;
156     else
157       error.SetErrorStringWithFormat(
158           "could not convert \"%s\" to a boolean value.",
159           option_arg.str().c_str());
160     break;
161   }
162 
163   default:
164     error.SetErrorStringWithFormat("invalid short option character '%c'",
165                                    short_option);
166     break;
167   }
168 
169   return error;
170 }
171 
172 void CommandObjectExpression::CommandOptions::OptionParsingStarting(
173     ExecutionContext *execution_context) {
174   auto process_sp =
175       execution_context ? execution_context->GetProcessSP() : ProcessSP();
176   if (process_sp) {
177     ignore_breakpoints = process_sp->GetIgnoreBreakpointsInExpressions();
178     unwind_on_error = process_sp->GetUnwindOnErrorInExpressions();
179   } else {
180     ignore_breakpoints = true;
181     unwind_on_error = true;
182   }
183 
184   show_summary = true;
185   try_all_threads = true;
186   timeout = 0;
187   debug = false;
188   language = eLanguageTypeUnknown;
189   m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityCompact;
190   auto_apply_fixits = eLazyBoolCalculate;
191   top_level = false;
192   allow_jit = true;
193 }
194 
195 llvm::ArrayRef<OptionDefinition>
196 CommandObjectExpression::CommandOptions::GetDefinitions() {
197   return llvm::makeArrayRef(g_expression_options);
198 }
199 
200 CommandObjectExpression::CommandObjectExpression(
201     CommandInterpreter &interpreter)
202     : CommandObjectRaw(
203           interpreter, "expression", "Evaluate an expression on the current "
204                                      "thread.  Displays any returned value "
205                                      "with LLDB's default formatting.",
206           "", eCommandProcessMustBePaused | eCommandTryTargetAPILock),
207       IOHandlerDelegate(IOHandlerDelegate::Completion::Expression),
208       m_option_group(), m_format_options(eFormatDefault),
209       m_repl_option(LLDB_OPT_SET_1, false, "repl", 'r', "Drop into REPL", false,
210                     true),
211       m_command_options(), m_expr_line_count(0), m_expr_lines() {
212   SetHelpLong(
213       R"(
214 Single and multi-line expressions:
215 
216 )"
217       "    The expression provided on the command line must be a complete expression \
218 with no newlines.  To evaluate a multi-line expression, \
219 hit a return after an empty expression, and lldb will enter the multi-line expression editor. \
220 Hit return on an empty line to end the multi-line expression."
221 
222       R"(
223 
224 Timeouts:
225 
226 )"
227       "    If the expression can be evaluated statically (without running code) then it will be.  \
228 Otherwise, by default the expression will run on the current thread with a short timeout: \
229 currently .25 seconds.  If it doesn't return in that time, the evaluation will be interrupted \
230 and resumed with all threads running.  You can use the -a option to disable retrying on all \
231 threads.  You can use the -t option to set a shorter timeout."
232       R"(
233 
234 User defined variables:
235 
236 )"
237       "    You can define your own variables for convenience or to be used in subsequent expressions.  \
238 You define them the same way you would define variables in C.  If the first character of \
239 your user defined variable is a $, then the variable's value will be available in future \
240 expressions, otherwise it will just be available in the current expression."
241       R"(
242 
243 Continuing evaluation after a breakpoint:
244 
245 )"
246       "    If the \"-i false\" option is used, and execution is interrupted by a breakpoint hit, once \
247 you are done with your investigation, you can either remove the expression execution frames \
248 from the stack with \"thread return -x\" or if you are still interested in the expression result \
249 you can issue the \"continue\" command and the expression evaluation will complete and the \
250 expression result will be available using the \"thread.completed-expression\" key in the thread \
251 format."
252 
253       R"(
254 
255 Examples:
256 
257     expr my_struct->a = my_array[3]
258     expr -f bin -- (index * 8) + 5
259     expr unsigned int $foo = 5
260     expr char c[] = \"foo\"; c[0])");
261 
262   CommandArgumentEntry arg;
263   CommandArgumentData expression_arg;
264 
265   // Define the first (and only) variant of this arg.
266   expression_arg.arg_type = eArgTypeExpression;
267   expression_arg.arg_repetition = eArgRepeatPlain;
268 
269   // There is only one variant this argument could be; put it into the argument
270   // entry.
271   arg.push_back(expression_arg);
272 
273   // Push the data for the first argument into the m_arguments vector.
274   m_arguments.push_back(arg);
275 
276   // Add the "--format" and "--gdb-format"
277   m_option_group.Append(&m_format_options,
278                         OptionGroupFormat::OPTION_GROUP_FORMAT |
279                             OptionGroupFormat::OPTION_GROUP_GDB_FMT,
280                         LLDB_OPT_SET_1);
281   m_option_group.Append(&m_command_options);
282   m_option_group.Append(&m_varobj_options, LLDB_OPT_SET_ALL,
283                         LLDB_OPT_SET_1 | LLDB_OPT_SET_2);
284   m_option_group.Append(&m_repl_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_3);
285   m_option_group.Finalize();
286 }
287 
288 CommandObjectExpression::~CommandObjectExpression() = default;
289 
290 Options *CommandObjectExpression::GetOptions() { return &m_option_group; }
291 
292 int CommandObjectExpression::HandleCompletion(CompletionRequest &request) {
293   EvaluateExpressionOptions options;
294   options.SetCoerceToId(m_varobj_options.use_objc);
295   options.SetLanguage(m_command_options.language);
296   options.SetExecutionPolicy(lldb_private::eExecutionPolicyNever);
297   options.SetAutoApplyFixIts(false);
298   options.SetGenerateDebugInfo(false);
299 
300   // We need a valid execution context with a frame pointer for this
301   // completion, so if we don't have one we should try to make a valid
302   // execution context.
303   if (m_interpreter.GetExecutionContext().GetFramePtr() == nullptr)
304     m_interpreter.UpdateExecutionContext(nullptr);
305 
306   // This didn't work, so let's get out before we start doing things that
307   // expect a valid frame pointer.
308   if (m_interpreter.GetExecutionContext().GetFramePtr() == nullptr)
309     return 0;
310 
311   ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
312 
313   Target *target = exe_ctx.GetTargetPtr();
314 
315   if (!target)
316     target = GetDummyTarget();
317 
318   if (!target)
319     return 0;
320 
321   unsigned cursor_pos = request.GetRawCursorPos();
322   llvm::StringRef code = request.GetRawLine();
323 
324   const std::size_t original_code_size = code.size();
325 
326   // Remove the first token which is 'expr' or some alias/abbreviation of that.
327   code = llvm::getToken(code).second.ltrim();
328   OptionsWithRaw args(code);
329   code = args.GetRawPart();
330 
331   // The position where the expression starts in the command line.
332   assert(original_code_size >= code.size());
333   std::size_t raw_start = original_code_size - code.size();
334 
335   // Check if the cursor is actually in the expression string, and if not, we
336   // exit.
337   // FIXME: We should complete the options here.
338   if (cursor_pos < raw_start)
339     return 0;
340 
341   // Make the cursor_pos again relative to the start of the code string.
342   assert(cursor_pos >= raw_start);
343   cursor_pos -= raw_start;
344 
345   auto language = exe_ctx.GetFrameRef().GetLanguage();
346 
347   Status error;
348   lldb::UserExpressionSP expr(target->GetUserExpressionForLanguage(
349       code, llvm::StringRef(), language, UserExpression::eResultTypeAny,
350       options, nullptr, error));
351   if (error.Fail())
352     return 0;
353 
354   expr->Complete(exe_ctx, request, cursor_pos);
355   return request.GetNumberOfMatches();
356 }
357 
358 static lldb_private::Status
359 CanBeUsedForElementCountPrinting(ValueObject &valobj) {
360   CompilerType type(valobj.GetCompilerType());
361   CompilerType pointee;
362   if (!type.IsPointerType(&pointee))
363     return Status("as it does not refer to a pointer");
364   if (pointee.IsVoidType())
365     return Status("as it refers to a pointer to void");
366   return Status();
367 }
368 
369 bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
370                                                  Stream *output_stream,
371                                                  Stream *error_stream,
372                                                  CommandReturnObject *result) {
373   // Don't use m_exe_ctx as this might be called asynchronously after the
374   // command object DoExecute has finished when doing multi-line expression
375   // that use an input reader...
376   ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
377 
378   Target *target = exe_ctx.GetTargetPtr();
379 
380   if (!target)
381     target = GetDummyTarget();
382 
383   if (target) {
384     lldb::ValueObjectSP result_valobj_sp;
385     bool keep_in_memory = true;
386     StackFrame *frame = exe_ctx.GetFramePtr();
387 
388     EvaluateExpressionOptions options;
389     options.SetCoerceToId(m_varobj_options.use_objc);
390     options.SetUnwindOnError(m_command_options.unwind_on_error);
391     options.SetIgnoreBreakpoints(m_command_options.ignore_breakpoints);
392     options.SetKeepInMemory(keep_in_memory);
393     options.SetUseDynamic(m_varobj_options.use_dynamic);
394     options.SetTryAllThreads(m_command_options.try_all_threads);
395     options.SetDebug(m_command_options.debug);
396     options.SetLanguage(m_command_options.language);
397     options.SetExecutionPolicy(
398         m_command_options.allow_jit
399             ? EvaluateExpressionOptions::default_execution_policy
400             : lldb_private::eExecutionPolicyNever);
401 
402     bool auto_apply_fixits;
403     if (m_command_options.auto_apply_fixits == eLazyBoolCalculate)
404       auto_apply_fixits = target->GetEnableAutoApplyFixIts();
405     else
406       auto_apply_fixits = m_command_options.auto_apply_fixits == eLazyBoolYes;
407 
408     options.SetAutoApplyFixIts(auto_apply_fixits);
409 
410     if (m_command_options.top_level)
411       options.SetExecutionPolicy(eExecutionPolicyTopLevel);
412 
413     // If there is any chance we are going to stop and want to see what went
414     // wrong with our expression, we should generate debug info
415     if (!m_command_options.ignore_breakpoints ||
416         !m_command_options.unwind_on_error)
417       options.SetGenerateDebugInfo(true);
418 
419     if (m_command_options.timeout > 0)
420       options.SetTimeout(std::chrono::microseconds(m_command_options.timeout));
421     else
422       options.SetTimeout(llvm::None);
423 
424     ExpressionResults success = target->EvaluateExpression(
425         expr, frame, result_valobj_sp, options, &m_fixed_expression);
426 
427     // We only tell you about the FixIt if we applied it.  The compiler errors
428     // will suggest the FixIt if it parsed.
429     if (error_stream && !m_fixed_expression.empty() &&
430         target->GetEnableNotifyAboutFixIts()) {
431       if (success == eExpressionCompleted)
432         error_stream->Printf(
433             "  Fix-it applied, fixed expression was: \n    %s\n",
434             m_fixed_expression.c_str());
435     }
436 
437     if (result_valobj_sp) {
438       Format format = m_format_options.GetFormat();
439 
440       if (result_valobj_sp->GetError().Success()) {
441         if (format != eFormatVoid) {
442           if (format != eFormatDefault)
443             result_valobj_sp->SetFormat(format);
444 
445           if (m_varobj_options.elem_count > 0) {
446             Status error(CanBeUsedForElementCountPrinting(*result_valobj_sp));
447             if (error.Fail()) {
448               result->AppendErrorWithFormat(
449                   "expression cannot be used with --element-count %s\n",
450                   error.AsCString(""));
451               result->SetStatus(eReturnStatusFailed);
452               return false;
453             }
454           }
455 
456           DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(
457               m_command_options.m_verbosity, format));
458           options.SetVariableFormatDisplayLanguage(
459               result_valobj_sp->GetPreferredDisplayLanguage());
460 
461           result_valobj_sp->Dump(*output_stream, options);
462 
463           if (result)
464             result->SetStatus(eReturnStatusSuccessFinishResult);
465         }
466       } else {
467         if (result_valobj_sp->GetError().GetError() ==
468             UserExpression::kNoResult) {
469           if (format != eFormatVoid && GetDebugger().GetNotifyVoid()) {
470             error_stream->PutCString("(void)\n");
471           }
472 
473           if (result)
474             result->SetStatus(eReturnStatusSuccessFinishResult);
475         } else {
476           const char *error_cstr = result_valobj_sp->GetError().AsCString();
477           if (error_cstr && error_cstr[0]) {
478             const size_t error_cstr_len = strlen(error_cstr);
479             const bool ends_with_newline =
480                 error_cstr[error_cstr_len - 1] == '\n';
481             if (strstr(error_cstr, "error:") != error_cstr)
482               error_stream->PutCString("error: ");
483             error_stream->Write(error_cstr, error_cstr_len);
484             if (!ends_with_newline)
485               error_stream->EOL();
486           } else {
487             error_stream->PutCString("error: unknown error\n");
488           }
489 
490           if (result)
491             result->SetStatus(eReturnStatusFailed);
492         }
493       }
494     }
495   } else {
496     error_stream->Printf("error: invalid execution context for expression\n");
497     return false;
498   }
499 
500   return true;
501 }
502 
503 void CommandObjectExpression::IOHandlerInputComplete(IOHandler &io_handler,
504                                                      std::string &line) {
505   io_handler.SetIsDone(true);
506   //    StreamSP output_stream =
507   //    io_handler.GetDebugger().GetAsyncOutputStream();
508   //    StreamSP error_stream = io_handler.GetDebugger().GetAsyncErrorStream();
509   StreamFileSP output_sp(io_handler.GetOutputStreamFile());
510   StreamFileSP error_sp(io_handler.GetErrorStreamFile());
511 
512   EvaluateExpression(line.c_str(), output_sp.get(), error_sp.get());
513   if (output_sp)
514     output_sp->Flush();
515   if (error_sp)
516     error_sp->Flush();
517 }
518 
519 bool CommandObjectExpression::IOHandlerIsInputComplete(IOHandler &io_handler,
520                                                        StringList &lines) {
521   // An empty lines is used to indicate the end of input
522   const size_t num_lines = lines.GetSize();
523   if (num_lines > 0 && lines[num_lines - 1].empty()) {
524     // Remove the last empty line from "lines" so it doesn't appear in our
525     // resulting input and return true to indicate we are done getting lines
526     lines.PopBack();
527     return true;
528   }
529   return false;
530 }
531 
532 void CommandObjectExpression::GetMultilineExpression() {
533   m_expr_lines.clear();
534   m_expr_line_count = 0;
535 
536   Debugger &debugger = GetCommandInterpreter().GetDebugger();
537   bool color_prompt = debugger.GetUseColor();
538   const bool multiple_lines = true; // Get multiple lines
539   IOHandlerSP io_handler_sp(
540       new IOHandlerEditline(debugger, IOHandler::Type::Expression,
541                             "lldb-expr", // Name of input reader for history
542                             llvm::StringRef(), // No prompt
543                             llvm::StringRef(), // Continuation prompt
544                             multiple_lines, color_prompt,
545                             1, // Show line numbers starting at 1
546                             *this, nullptr));
547 
548   StreamFileSP output_sp(io_handler_sp->GetOutputStreamFile());
549   if (output_sp) {
550     output_sp->PutCString(
551         "Enter expressions, then terminate with an empty line to evaluate:\n");
552     output_sp->Flush();
553   }
554   debugger.PushIOHandler(io_handler_sp);
555 }
556 
557 static EvaluateExpressionOptions
558 GetExprOptions(ExecutionContext &ctx,
559                CommandObjectExpression::CommandOptions command_options) {
560   command_options.OptionParsingStarting(&ctx);
561 
562   // Default certain settings for REPL regardless of the global settings.
563   command_options.unwind_on_error = false;
564   command_options.ignore_breakpoints = false;
565   command_options.debug = false;
566 
567   EvaluateExpressionOptions expr_options;
568   expr_options.SetUnwindOnError(command_options.unwind_on_error);
569   expr_options.SetIgnoreBreakpoints(command_options.ignore_breakpoints);
570   expr_options.SetTryAllThreads(command_options.try_all_threads);
571 
572   if (command_options.timeout > 0)
573     expr_options.SetTimeout(std::chrono::microseconds(command_options.timeout));
574   else
575     expr_options.SetTimeout(llvm::None);
576 
577   return expr_options;
578 }
579 
580 bool CommandObjectExpression::DoExecute(llvm::StringRef command,
581                                         CommandReturnObject &result) {
582   m_fixed_expression.clear();
583   auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
584   m_option_group.NotifyOptionParsingStarting(&exe_ctx);
585 
586   if (command.empty()) {
587     GetMultilineExpression();
588     return result.Succeeded();
589   }
590 
591   OptionsWithRaw args(command);
592   llvm::StringRef expr = args.GetRawPart();
593 
594   if (args.HasArgs()) {
595     if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group, exe_ctx))
596       return false;
597 
598     if (m_repl_option.GetOptionValue().GetCurrentValue()) {
599       Target *target = m_interpreter.GetExecutionContext().GetTargetPtr();
600       if (target) {
601         // Drop into REPL
602         m_expr_lines.clear();
603         m_expr_line_count = 0;
604 
605         Debugger &debugger = target->GetDebugger();
606 
607         // Check if the LLDB command interpreter is sitting on top of a REPL
608         // that launched it...
609         if (debugger.CheckTopIOHandlerTypes(IOHandler::Type::CommandInterpreter,
610                                             IOHandler::Type::REPL)) {
611           // the LLDB command interpreter is sitting on top of a REPL that
612           // launched it, so just say the command interpreter is done and
613           // fall back to the existing REPL
614           m_interpreter.GetIOHandler(false)->SetIsDone(true);
615         } else {
616           // We are launching the REPL on top of the current LLDB command
617           // interpreter, so just push one
618           bool initialize = false;
619           Status repl_error;
620           REPLSP repl_sp(target->GetREPL(repl_error, m_command_options.language,
621                                          nullptr, false));
622 
623           if (!repl_sp) {
624             initialize = true;
625             repl_sp = target->GetREPL(repl_error, m_command_options.language,
626                                       nullptr, true);
627             if (!repl_error.Success()) {
628               result.SetError(repl_error);
629               return result.Succeeded();
630             }
631           }
632 
633           if (repl_sp) {
634             if (initialize) {
635               repl_sp->SetEvaluateOptions(
636                   GetExprOptions(exe_ctx, m_command_options));
637               repl_sp->SetFormatOptions(m_format_options);
638               repl_sp->SetValueObjectDisplayOptions(m_varobj_options);
639             }
640 
641             IOHandlerSP io_handler_sp(repl_sp->GetIOHandler());
642 
643             io_handler_sp->SetIsDone(false);
644 
645             debugger.PushIOHandler(io_handler_sp);
646           } else {
647             repl_error.SetErrorStringWithFormat(
648                 "Couldn't create a REPL for %s",
649                 Language::GetNameForLanguageType(m_command_options.language));
650             result.SetError(repl_error);
651             return result.Succeeded();
652           }
653         }
654       }
655     }
656     // No expression following options
657     else if (expr.empty()) {
658       GetMultilineExpression();
659       return result.Succeeded();
660     }
661   }
662 
663   Target *target = GetSelectedOrDummyTarget();
664   if (EvaluateExpression(expr, &(result.GetOutputStream()),
665                          &(result.GetErrorStream()), &result)) {
666 
667     if (!m_fixed_expression.empty() && target->GetEnableNotifyAboutFixIts()) {
668       CommandHistory &history = m_interpreter.GetCommandHistory();
669       // FIXME: Can we figure out what the user actually typed (e.g. some alias
670       // for expr???)
671       // If we can it would be nice to show that.
672       std::string fixed_command("expression ");
673       if (args.HasArgs()) {
674         // Add in any options that might have been in the original command:
675         fixed_command.append(args.GetArgStringWithDelimiter());
676         fixed_command.append(m_fixed_expression);
677       } else
678         fixed_command.append(m_fixed_expression);
679       history.AppendString(fixed_command);
680     }
681     // Increment statistics to record this expression evaluation success.
682     target->IncrementStats(StatisticKind::ExpressionSuccessful);
683     return true;
684   }
685 
686   // Increment statistics to record this expression evaluation failure.
687   target->IncrementStats(StatisticKind::ExpressionFailure);
688   result.SetStatus(eReturnStatusFailed);
689   return false;
690 }
691