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