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