Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/STLExtras.h" |
| 14 | #include "llvm/ADT/StringRef.h" |
| 15 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | // Project includes |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 17 | #include "CommandObjectExpression.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Value.h" |
Jim Ingham | 6c68fb4 | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 19 | #include "lldb/Core/ValueObjectVariable.h" |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 20 | #include "lldb/DataFormatters/ValueObjectPrinter.h" |
Sean Callanan | 30e3397 | 2015-09-03 00:48:23 +0000 | [diff] [blame] | 21 | #include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 22 | #include "lldb/Expression/UserExpression.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Expression/DWARFExpression.h" |
Sean Callanan | f2bd5c3 | 2015-10-20 00:55:21 +0000 | [diff] [blame] | 24 | #include "lldb/Expression/REPL.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Host/Host.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 26 | #include "lldb/Host/StringConvert.h" |
Sean Callanan | ebf7707 | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 27 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 28 | #include "lldb/Interpreter/CommandInterpreter.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Interpreter/CommandReturnObject.h" |
Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Language.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | #include "lldb/Symbol/ObjectFile.h" |
| 32 | #include "lldb/Symbol/Variable.h" |
| 33 | #include "lldb/Target/Process.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 34 | #include "lldb/Target/StackFrame.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | #include "lldb/Target/Target.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 36 | #include "lldb/Target/Thread.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | |
| 38 | using namespace lldb; |
| 39 | using namespace lldb_private; |
| 40 | |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 41 | CommandObjectExpression::CommandOptions::CommandOptions () : |
| 42 | OptionGroup() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 46 | CommandObjectExpression::CommandOptions::~CommandOptions() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 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"}, |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 52 | { 0, nullptr, nullptr } |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 55 | OptionDefinition |
| 56 | CommandObjectExpression::CommandOptions::g_option_table[] = |
| 57 | { |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 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." }, |
Jim Ingham | 279b2e8 | 2016-06-28 01:33:03 +0000 | [diff] [blame] | 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." }, |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 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."}, |
Marianne Mailhot-Sarrasin | 3fe7158 | 2016-05-12 20:00:53 +0000 | [diff] [blame] | 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)."} |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 70 | uint32_t |
| 71 | CommandObjectExpression::CommandOptions::GetNumDefinitions () |
| 72 | { |
Saleem Abdulrasool | 2860695 | 2014-06-27 05:17:41 +0000 | [diff] [blame] | 73 | return llvm::array_lengthof(g_option_table); |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | Error |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 77 | CommandObjectExpression::CommandOptions::SetOptionValue (CommandInterpreter &interpreter, |
| 78 | uint32_t option_idx, |
| 79 | const char *option_arg) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | { |
| 81 | Error error; |
| 82 | |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 83 | const int short_option = g_option_table[option_idx].short_option; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | |
| 85 | switch (short_option) |
| 86 | { |
Dawn Perchik | 15663c5 | 2015-07-25 00:19:39 +0000 | [diff] [blame] | 87 | case 'l': |
Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 88 | language = Language::GetLanguageTypeFromString (option_arg); |
Dawn Perchik | 15663c5 | 2015-07-25 00:19:39 +0000 | [diff] [blame] | 89 | if (language == eLanguageTypeUnknown) |
| 90 | error.SetErrorStringWithFormat ("unknown language type: '%s' for expression", option_arg); |
| 91 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 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 | } |
Jim Ingham | 6c68fb4 | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 103 | break; |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 104 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 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 | } |
Marianne Mailhot-Sarrasin | 3fe7158 | 2016-05-12 20:00:53 +0000 | [diff] [blame] | 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 | |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 127 | case 't': |
| 128 | { |
| 129 | bool success; |
| 130 | uint32_t result; |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 131 | result = StringConvert::ToUInt32(option_arg, 0, 0, &success); |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 132 | if (success) |
| 133 | timeout = result; |
| 134 | else |
| 135 | error.SetErrorStringWithFormat ("invalid timeout setting \"%s\"", option_arg); |
| 136 | } |
| 137 | break; |
| 138 | |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 139 | case 'u': |
Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 140 | { |
| 141 | bool success; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 142 | bool tmp_value = Args::StringToBoolean(option_arg, true, &success); |
| 143 | if (success) |
| 144 | unwind_on_error = tmp_value; |
| 145 | else |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 146 | error.SetErrorStringWithFormat("could not convert \"%s\" to a boolean value.", option_arg); |
Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 147 | break; |
| 148 | } |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 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; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 160 | |
| 161 | case 'g': |
| 162 | debug = true; |
| 163 | unwind_on_error = false; |
| 164 | ignore_breakpoints = false; |
| 165 | break; |
Sean Callanan | 863fab6 | 2016-03-28 21:20:05 +0000 | [diff] [blame] | 166 | |
| 167 | case 'p': |
| 168 | top_level = true; |
| 169 | break; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 170 | |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 182 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 183 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 184 | break; |
| 185 | } |
| 186 | |
| 187 | return error; |
| 188 | } |
| 189 | |
| 190 | void |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 191 | CommandObjectExpression::CommandOptions::OptionParsingStarting (CommandInterpreter &interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 192 | { |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 193 | Process *process = interpreter.GetExecutionContext().GetProcessPtr(); |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 194 | if (process != nullptr) |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 195 | { |
| 196 | ignore_breakpoints = process->GetIgnoreBreakpointsInExpressions(); |
| 197 | unwind_on_error = process->GetUnwindOnErrorInExpressions(); |
| 198 | } |
| 199 | else |
| 200 | { |
Greg Clayton | fc03f8f | 2014-03-25 18:47:07 +0000 | [diff] [blame] | 201 | ignore_breakpoints = true; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 202 | unwind_on_error = true; |
| 203 | } |
| 204 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | show_summary = true; |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 206 | try_all_threads = true; |
| 207 | timeout = 0; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 208 | debug = false; |
Dawn Perchik | 15663c5 | 2015-07-25 00:19:39 +0000 | [diff] [blame] | 209 | language = eLanguageTypeUnknown; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 210 | m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityCompact; |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 211 | auto_apply_fixits = eLazyBoolCalculate; |
Sean Callanan | 863fab6 | 2016-03-28 21:20:05 +0000 | [diff] [blame] | 212 | top_level = false; |
Marianne Mailhot-Sarrasin | 3fe7158 | 2016-05-12 20:00:53 +0000 | [diff] [blame] | 213 | allow_jit = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 216 | const OptionDefinition* |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 217 | CommandObjectExpression::CommandOptions::GetDefinitions () |
| 218 | { |
| 219 | return g_option_table; |
| 220 | } |
| 221 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 222 | CommandObjectExpression::CommandObjectExpression(CommandInterpreter &interpreter) |
| 223 | : CommandObjectRaw( |
| 224 | interpreter, "expression", |
| 225 | "Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting.", |
| 226 | nullptr, eCommandProcessMustBePaused | eCommandTryTargetAPILock), |
| 227 | IOHandlerDelegate(IOHandlerDelegate::Completion::Expression), |
| 228 | m_option_group(interpreter), |
| 229 | m_format_options(eFormatDefault), |
| 230 | m_repl_option(LLDB_OPT_SET_1, false, "repl", 'r', "Drop into REPL", false, true), |
| 231 | m_command_options(), |
| 232 | m_expr_line_count(0), |
| 233 | m_expr_lines() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 234 | { |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 235 | SetHelpLong( |
| 236 | R"( |
| 237 | Timeouts: |
| 238 | |
| 239 | )" " If the expression can be evaluated statically (without running code) then it will be. \ |
| 240 | Otherwise, by default the expression will run on the current thread with a short timeout: \ |
| 241 | currently .25 seconds. If it doesn't return in that time, the evaluation will be interrupted \ |
| 242 | and resumed with all threads running. You can use the -a option to disable retrying on all \ |
| 243 | threads. You can use the -t option to set a shorter timeout." R"( |
| 244 | |
| 245 | User defined variables: |
| 246 | |
| 247 | )" " You can define your own variables for convenience or to be used in subsequent expressions. \ |
| 248 | You define them the same way you would define variables in C. If the first character of \ |
| 249 | your user defined variable is a $, then the variable's value will be available in future \ |
| 250 | expressions, otherwise it will just be available in the current expression." R"( |
| 251 | |
| 252 | Continuing evaluation after a breakpoint: |
| 253 | |
| 254 | )" " If the \"-i false\" option is used, and execution is interrupted by a breakpoint hit, once \ |
| 255 | you are done with your investigation, you can either remove the expression execution frames \ |
| 256 | from the stack with \"thread return -x\" or if you are still interested in the expression result \ |
| 257 | you can issue the \"continue\" command and the expression evaluation will complete and the \ |
| 258 | expression result will be available using the \"thread.completed-expression\" key in the thread \ |
| 259 | format." R"( |
| 260 | |
| 261 | Examples: |
| 262 | |
| 263 | expr my_struct->a = my_array[3] |
| 264 | expr -f bin -- (index * 8) + 5 |
| 265 | expr unsigned int $foo = 5 |
| 266 | expr char c[] = \"foo\"; c[0])" |
| 267 | ); |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 268 | |
| 269 | CommandArgumentEntry arg; |
| 270 | CommandArgumentData expression_arg; |
| 271 | |
| 272 | // Define the first (and only) variant of this arg. |
| 273 | expression_arg.arg_type = eArgTypeExpression; |
| 274 | expression_arg.arg_repetition = eArgRepeatPlain; |
| 275 | |
| 276 | // There is only one variant this argument could be; put it into the argument entry. |
| 277 | arg.push_back (expression_arg); |
| 278 | |
| 279 | // Push the data for the first argument into the m_arguments vector. |
| 280 | m_arguments.push_back (arg); |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 281 | |
Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 282 | // Add the "--format" and "--gdb-format" |
| 283 | m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1); |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 284 | m_option_group.Append (&m_command_options); |
Enrico Granata | b576bba | 2013-01-09 20:12:53 +0000 | [diff] [blame] | 285 | m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1 | LLDB_OPT_SET_2); |
Sean Callanan | f2bd5c3 | 2015-10-20 00:55:21 +0000 | [diff] [blame] | 286 | m_option_group.Append (&m_repl_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_3); |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 287 | m_option_group.Finalize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 290 | CommandObjectExpression::~CommandObjectExpression() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 291 | |
| 292 | Options * |
| 293 | CommandObjectExpression::GetOptions () |
| 294 | { |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 295 | return &m_option_group; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Enrico Granata | 520a422 | 2016-04-25 00:52:47 +0000 | [diff] [blame] | 298 | static lldb_private::Error |
| 299 | CanBeUsedForElementCountPrinting (ValueObject& valobj) |
| 300 | { |
| 301 | CompilerType type(valobj.GetCompilerType()); |
| 302 | CompilerType pointee; |
| 303 | if (!type.IsPointerType(&pointee)) |
| 304 | return Error("as it does not refer to a pointer"); |
| 305 | if (pointee.IsVoidType()) |
| 306 | return Error("as it refers to a pointer to void"); |
| 307 | return Error(); |
| 308 | } |
| 309 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | bool |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 311 | CommandObjectExpression::EvaluateExpression(const char *expr, |
| 312 | Stream *output_stream, |
| 313 | Stream *error_stream, |
| 314 | CommandReturnObject *result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 315 | { |
Greg Clayton | ba7b8e2 | 2013-01-26 23:54:29 +0000 | [diff] [blame] | 316 | // Don't use m_exe_ctx as this might be called asynchronously |
| 317 | // after the command object DoExecute has finished when doing |
| 318 | // multi-line expression that use an input reader... |
| 319 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
| 320 | |
| 321 | Target *target = exe_ctx.GetTargetPtr(); |
Sean Callanan | c0a6e06 | 2011-10-27 21:22:25 +0000 | [diff] [blame] | 322 | |
| 323 | if (!target) |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 324 | target = GetDummyTarget(); |
Sean Callanan | c0a6e06 | 2011-10-27 21:22:25 +0000 | [diff] [blame] | 325 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 326 | if (target) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 327 | { |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 328 | lldb::ValueObjectSP result_valobj_sp; |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 329 | bool keep_in_memory = true; |
Dawn Perchik | 009d110 | 2015-09-04 01:02:30 +0000 | [diff] [blame] | 330 | StackFrame *frame = exe_ctx.GetFramePtr(); |
Enrico Granata | b576bba | 2013-01-09 20:12:53 +0000 | [diff] [blame] | 331 | |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 332 | EvaluateExpressionOptions options; |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 333 | options.SetCoerceToId(m_varobj_options.use_objc); |
| 334 | options.SetUnwindOnError(m_command_options.unwind_on_error); |
| 335 | options.SetIgnoreBreakpoints (m_command_options.ignore_breakpoints); |
| 336 | options.SetKeepInMemory(keep_in_memory); |
| 337 | options.SetUseDynamic(m_varobj_options.use_dynamic); |
| 338 | options.SetTryAllThreads(m_command_options.try_all_threads); |
| 339 | options.SetDebug(m_command_options.debug); |
Dawn Perchik | 1bbaede | 2015-10-07 22:01:12 +0000 | [diff] [blame] | 340 | options.SetLanguage(m_command_options.language); |
Marianne Mailhot-Sarrasin | 3fe7158 | 2016-05-12 20:00:53 +0000 | [diff] [blame] | 341 | options.SetExecutionPolicy(m_command_options.allow_jit ? |
| 342 | EvaluateExpressionOptions::default_execution_policy : |
| 343 | lldb_private::eExecutionPolicyNever); |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 344 | |
| 345 | bool auto_apply_fixits; |
| 346 | if (m_command_options.auto_apply_fixits == eLazyBoolCalculate) |
| 347 | auto_apply_fixits = target->GetEnableAutoApplyFixIts(); |
| 348 | else |
| 349 | auto_apply_fixits = m_command_options.auto_apply_fixits == eLazyBoolYes ? true : false; |
| 350 | |
| 351 | options.SetAutoApplyFixIts(auto_apply_fixits); |
Sean Callanan | 863fab6 | 2016-03-28 21:20:05 +0000 | [diff] [blame] | 352 | |
| 353 | if (m_command_options.top_level) |
| 354 | options.SetExecutionPolicy(eExecutionPolicyTopLevel); |
Dawn Perchik | 15663c5 | 2015-07-25 00:19:39 +0000 | [diff] [blame] | 355 | |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 356 | // If there is any chance we are going to stop and want to see |
| 357 | // what went wrong with our expression, we should generate debug info |
| 358 | if (!m_command_options.ignore_breakpoints || |
| 359 | !m_command_options.unwind_on_error) |
| 360 | options.SetGenerateDebugInfo(true); |
| 361 | |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 362 | if (m_command_options.timeout > 0) |
| 363 | options.SetTimeoutUsec(m_command_options.timeout); |
Jim Ingham | 6f78f38 | 2014-01-17 20:09:23 +0000 | [diff] [blame] | 364 | else |
| 365 | options.SetTimeoutUsec(0); |
Arnaud A. de Grandmaison | 62e5f4d | 2014-03-22 20:23:26 +0000 | [diff] [blame] | 366 | |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 367 | ExpressionResults success = target->EvaluateExpression(expr, frame, result_valobj_sp, options, &m_fixed_expression); |
| 368 | |
| 369 | // We only tell you about the FixIt if we applied it. The compiler errors will suggest the FixIt if it parsed. |
| 370 | if (error_stream && !m_fixed_expression.empty() && target->GetEnableNotifyAboutFixIts()) |
| 371 | { |
| 372 | if (success == eExpressionCompleted) |
Jim Ingham | 279b2e8 | 2016-06-28 01:33:03 +0000 | [diff] [blame] | 373 | error_stream->Printf (" Fix-it applied, fixed expression was: \n %s\n", m_fixed_expression.c_str()); |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 374 | } |
Sean Callanan | 4b388c9 | 2013-07-30 19:54:09 +0000 | [diff] [blame] | 375 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 376 | if (result_valobj_sp) |
| 377 | { |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 378 | Format format = m_format_options.GetFormat(); |
| 379 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 380 | if (result_valobj_sp->GetError().Success()) |
| 381 | { |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 382 | if (format != eFormatVoid) |
| 383 | { |
| 384 | if (format != eFormatDefault) |
| 385 | result_valobj_sp->SetFormat (format); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 386 | |
Enrico Granata | 520a422 | 2016-04-25 00:52:47 +0000 | [diff] [blame] | 387 | if (m_varobj_options.elem_count > 0) |
| 388 | { |
| 389 | Error error(CanBeUsedForElementCountPrinting(*result_valobj_sp)); |
| 390 | if (error.Fail()) |
| 391 | { |
| 392 | result->AppendErrorWithFormat("expression cannot be used with --element-count %s\n", error.AsCString("")); |
| 393 | result->SetStatus(eReturnStatusFailed); |
| 394 | return false; |
| 395 | } |
| 396 | } |
| 397 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 398 | DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(m_command_options.m_verbosity,format)); |
Enrico Granata | 73e8c4d | 2015-10-07 02:36:35 +0000 | [diff] [blame] | 399 | options.SetVariableFormatDisplayLanguage(result_valobj_sp->GetPreferredDisplayLanguage()); |
Enrico Granata | b576bba | 2013-01-09 20:12:53 +0000 | [diff] [blame] | 400 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 401 | result_valobj_sp->Dump(*output_stream,options); |
| 402 | |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 403 | if (result) |
| 404 | result->SetStatus (eReturnStatusSuccessFinishResult); |
| 405 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 406 | } |
| 407 | else |
| 408 | { |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 409 | if (result_valobj_sp->GetError().GetError() == UserExpression::kNoResult) |
Greg Clayton | 5fd0590 | 2011-06-24 22:31:10 +0000 | [diff] [blame] | 410 | { |
Sean Callanan | bcf897f | 2012-08-09 18:18:47 +0000 | [diff] [blame] | 411 | if (format != eFormatVoid && m_interpreter.GetDebugger().GetNotifyVoid()) |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 412 | { |
Sean Callanan | bcf897f | 2012-08-09 18:18:47 +0000 | [diff] [blame] | 413 | error_stream->PutCString("(void)\n"); |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 414 | } |
Sean Callanan | bcf897f | 2012-08-09 18:18:47 +0000 | [diff] [blame] | 415 | |
| 416 | if (result) |
| 417 | result->SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | 5fd0590 | 2011-06-24 22:31:10 +0000 | [diff] [blame] | 418 | } |
| 419 | else |
| 420 | { |
Sean Callanan | bccce81 | 2011-08-23 21:20:51 +0000 | [diff] [blame] | 421 | const char *error_cstr = result_valobj_sp->GetError().AsCString(); |
| 422 | if (error_cstr && error_cstr[0]) |
| 423 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 424 | const size_t error_cstr_len = strlen (error_cstr); |
Sean Callanan | bccce81 | 2011-08-23 21:20:51 +0000 | [diff] [blame] | 425 | const bool ends_with_newline = error_cstr[error_cstr_len - 1] == '\n'; |
| 426 | if (strstr(error_cstr, "error:") != error_cstr) |
| 427 | error_stream->PutCString ("error: "); |
| 428 | error_stream->Write(error_cstr, error_cstr_len); |
| 429 | if (!ends_with_newline) |
| 430 | error_stream->EOL(); |
| 431 | } |
| 432 | else |
| 433 | { |
| 434 | error_stream->PutCString ("error: unknown error\n"); |
| 435 | } |
| 436 | |
| 437 | if (result) |
| 438 | result->SetStatus (eReturnStatusFailed); |
Greg Clayton | 5fd0590 | 2011-06-24 22:31:10 +0000 | [diff] [blame] | 439 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 442 | } |
| 443 | else |
| 444 | { |
Caroline Tice | 6e8dc33 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 445 | error_stream->Printf ("error: invalid execution context for expression\n"); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 446 | return false; |
Sean Callanan | ebf7707 | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 447 | } |
Sean Callanan | d1e5b43 | 2010-08-12 01:56:52 +0000 | [diff] [blame] | 448 | |
Sean Callanan | ebf7707 | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 449 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 452 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 453 | CommandObjectExpression::IOHandlerInputComplete (IOHandler &io_handler, std::string &line) |
| 454 | { |
| 455 | io_handler.SetIsDone(true); |
| 456 | // StreamSP output_stream = io_handler.GetDebugger().GetAsyncOutputStream(); |
| 457 | // StreamSP error_stream = io_handler.GetDebugger().GetAsyncErrorStream(); |
| 458 | StreamFileSP output_sp(io_handler.GetOutputStreamFile()); |
| 459 | StreamFileSP error_sp(io_handler.GetErrorStreamFile()); |
| 460 | |
| 461 | EvaluateExpression (line.c_str(), |
| 462 | output_sp.get(), |
| 463 | error_sp.get()); |
| 464 | if (output_sp) |
| 465 | output_sp->Flush(); |
| 466 | if (error_sp) |
| 467 | error_sp->Flush(); |
| 468 | } |
| 469 | |
Sean Callanan | f52c40c | 2016-05-09 21:13:27 +0000 | [diff] [blame] | 470 | bool |
| 471 | CommandObjectExpression::IOHandlerIsInputComplete (IOHandler &io_handler, |
| 472 | StringList &lines) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 473 | { |
Sean Callanan | f52c40c | 2016-05-09 21:13:27 +0000 | [diff] [blame] | 474 | // An empty lines is used to indicate the end of input |
| 475 | const size_t num_lines = lines.GetSize(); |
| 476 | if (num_lines > 0 && lines[num_lines - 1].empty()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 477 | { |
Sean Callanan | f52c40c | 2016-05-09 21:13:27 +0000 | [diff] [blame] | 478 | // Remove the last empty line from "lines" so it doesn't appear |
| 479 | // in our resulting input and return true to indicate we are done |
| 480 | // getting lines |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 481 | lines.PopBack(); |
Sean Callanan | f52c40c | 2016-05-09 21:13:27 +0000 | [diff] [blame] | 482 | return true; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 483 | } |
Sean Callanan | f52c40c | 2016-05-09 21:13:27 +0000 | [diff] [blame] | 484 | return false; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 487 | void |
| 488 | CommandObjectExpression::GetMultilineExpression () |
| 489 | { |
| 490 | m_expr_lines.clear(); |
| 491 | m_expr_line_count = 0; |
| 492 | |
| 493 | Debugger &debugger = GetCommandInterpreter().GetDebugger(); |
Kate Stone | e30f11d | 2014-11-17 19:06:59 +0000 | [diff] [blame] | 494 | bool color_prompt = debugger.GetUseColor(); |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 495 | const bool multiple_lines = true; // Get multiple lines |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 496 | IOHandlerSP io_handler_sp(new IOHandlerEditline(debugger, |
| 497 | IOHandler::Type::Expression, |
| 498 | "lldb-expr", // Name of input reader for history |
| 499 | nullptr, // No prompt |
| 500 | nullptr, // Continuation prompt |
| 501 | multiple_lines, |
| 502 | color_prompt, |
| 503 | 1, // Show line numbers starting at 1 |
| 504 | *this)); |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 505 | |
| 506 | StreamFileSP output_sp(io_handler_sp->GetOutputStreamFile()); |
| 507 | if (output_sp) |
| 508 | { |
| 509 | output_sp->PutCString("Enter expressions, then terminate with an empty line to evaluate:\n"); |
| 510 | output_sp->Flush(); |
| 511 | } |
| 512 | debugger.PushIOHandler(io_handler_sp); |
| 513 | } |
| 514 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 515 | bool |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 516 | CommandObjectExpression::DoExecute(const char *command, |
| 517 | CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 518 | { |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 519 | m_fixed_expression.clear(); |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 520 | m_option_group.NotifyOptionParsingStarting(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 521 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 522 | const char * expr = nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 523 | |
| 524 | if (command[0] == '\0') |
| 525 | { |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 526 | GetMultilineExpression (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 527 | return result.Succeeded(); |
| 528 | } |
| 529 | |
| 530 | if (command[0] == '-') |
| 531 | { |
| 532 | // We have some options and these options MUST end with --. |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 533 | const char *end_options = nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 534 | const char *s = command; |
| 535 | while (s && s[0]) |
| 536 | { |
| 537 | end_options = ::strstr (s, "--"); |
| 538 | if (end_options) |
| 539 | { |
| 540 | end_options += 2; // Get past the "--" |
| 541 | if (::isspace (end_options[0])) |
| 542 | { |
| 543 | expr = end_options; |
| 544 | while (::isspace (*expr)) |
| 545 | ++expr; |
| 546 | break; |
| 547 | } |
| 548 | } |
| 549 | s = end_options; |
| 550 | } |
| 551 | |
| 552 | if (end_options) |
| 553 | { |
Pavel Labath | 00b7f95 | 2015-03-02 12:46:22 +0000 | [diff] [blame] | 554 | Args args (llvm::StringRef(command, end_options - command)); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 555 | if (!ParseOptions (args, result)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 556 | return false; |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 557 | |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 558 | Error error (m_option_group.NotifyOptionParsingFinished()); |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 559 | if (error.Fail()) |
| 560 | { |
| 561 | result.AppendError (error.AsCString()); |
| 562 | result.SetStatus (eReturnStatusFailed); |
| 563 | return false; |
| 564 | } |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 565 | |
Sean Callanan | f2bd5c3 | 2015-10-20 00:55:21 +0000 | [diff] [blame] | 566 | if (m_repl_option.GetOptionValue().GetCurrentValue()) |
| 567 | { |
| 568 | Target *target = m_interpreter.GetExecutionContext().GetTargetPtr(); |
| 569 | if (target) |
| 570 | { |
| 571 | // Drop into REPL |
| 572 | m_expr_lines.clear(); |
| 573 | m_expr_line_count = 0; |
| 574 | |
| 575 | Debugger &debugger = target->GetDebugger(); |
| 576 | |
| 577 | // Check if the LLDB command interpreter is sitting on top of a REPL that |
| 578 | // launched it... |
| 579 | if (debugger.CheckTopIOHandlerTypes(IOHandler::Type::CommandInterpreter, IOHandler::Type::REPL)) |
| 580 | { |
| 581 | // the LLDB command interpreter is sitting on top of a REPL that launched it, |
| 582 | // so just say the command interpreter is done and fall back to the existing REPL |
| 583 | m_interpreter.GetIOHandler(false)->SetIsDone(true); |
| 584 | } |
| 585 | else |
| 586 | { |
| 587 | // We are launching the REPL on top of the current LLDB command interpreter, |
| 588 | // so just push one |
| 589 | bool initialize = false; |
| 590 | Error repl_error; |
| 591 | REPLSP repl_sp (target->GetREPL(repl_error, m_command_options.language, nullptr, false)); |
| 592 | |
| 593 | if (!repl_sp) |
| 594 | { |
| 595 | initialize = true; |
| 596 | repl_sp = target->GetREPL(repl_error, m_command_options.language, nullptr, true); |
| 597 | if (!repl_error.Success()) |
| 598 | { |
| 599 | result.SetError(repl_error); |
| 600 | return result.Succeeded(); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | if (repl_sp) |
| 605 | { |
| 606 | if (initialize) |
| 607 | { |
| 608 | repl_sp->SetCommandOptions(m_command_options); |
| 609 | repl_sp->SetFormatOptions(m_format_options); |
| 610 | repl_sp->SetValueObjectDisplayOptions(m_varobj_options); |
| 611 | } |
| 612 | |
| 613 | IOHandlerSP io_handler_sp (repl_sp->GetIOHandler()); |
| 614 | |
| 615 | io_handler_sp->SetIsDone(false); |
| 616 | |
| 617 | debugger.PushIOHandler(io_handler_sp); |
| 618 | } |
| 619 | else |
| 620 | { |
| 621 | repl_error.SetErrorStringWithFormat("Couldn't create a REPL for %s", Language::GetNameForLanguageType(m_command_options.language)); |
| 622 | result.SetError(repl_error); |
| 623 | return result.Succeeded(); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | } |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 628 | // No expression following options |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 629 | else if (expr == nullptr || expr[0] == '\0') |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 630 | { |
| 631 | GetMultilineExpression (); |
| 632 | return result.Succeeded(); |
| 633 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 637 | if (expr == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | expr = command; |
Sean Callanan | 16ad5fa | 2010-06-24 00:16:27 +0000 | [diff] [blame] | 639 | |
Caroline Tice | 6e8dc33 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 640 | if (EvaluateExpression (expr, &(result.GetOutputStream()), &(result.GetErrorStream()), &result)) |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 641 | { |
| 642 | Target *target = m_interpreter.GetExecutionContext().GetTargetPtr(); |
| 643 | if (!m_fixed_expression.empty() && target->GetEnableNotifyAboutFixIts()) |
| 644 | { |
| 645 | CommandHistory &history = m_interpreter.GetCommandHistory(); |
| 646 | // FIXME: Can we figure out what the user actually typed (e.g. some alias for expr???) |
| 647 | // If we can it would be nice to show that. |
| 648 | std::string fixed_command("expression "); |
| 649 | if (expr == command) |
| 650 | fixed_command.append(m_fixed_expression); |
| 651 | else |
| 652 | { |
| 653 | // Add in any options that might have been in the original command: |
| 654 | fixed_command.append(command, expr - command); |
| 655 | fixed_command.append(m_fixed_expression); |
| 656 | } |
| 657 | history.AppendString(fixed_command); |
| 658 | } |
Johnny Chen | fcd43b7 | 2010-08-13 00:42:30 +0000 | [diff] [blame] | 659 | return true; |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 660 | } |
Johnny Chen | fcd43b7 | 2010-08-13 00:42:30 +0000 | [diff] [blame] | 661 | |
| 662 | result.SetStatus (eReturnStatusFailed); |
| 663 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | } |