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