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