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