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