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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "CommandObjectExpression.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
| 17 | // Project includes |
Sean Callanan | ebf7707 | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Value.h" |
Jim Ingham | 6c68fb4 | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 20 | #include "lldb/Core/ValueObjectVariable.h" |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 21 | #include "lldb/DataFormatters/ValueObjectPrinter.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Expression/ClangExpressionVariable.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 23 | #include "lldb/Expression/ClangUserExpression.h" |
Stephen Wilson | ebb84b2 | 2010-07-23 21:47:22 +0000 | [diff] [blame] | 24 | #include "lldb/Expression/ClangFunction.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Expression/DWARFExpression.h" |
| 26 | #include "lldb/Host/Host.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 | 6c68fb4 | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 30 | #include "lldb/Target/ObjCLanguageRuntime.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" |
Sean Callanan | ebf7707 | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/StringRef.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | |
| 39 | using namespace lldb; |
| 40 | using namespace lldb_private; |
| 41 | |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 42 | CommandObjectExpression::CommandOptions::CommandOptions () : |
| 43 | OptionGroup() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | |
| 48 | CommandObjectExpression::CommandOptions::~CommandOptions () |
| 49 | { |
| 50 | } |
| 51 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 52 | static OptionEnumValueElement g_description_verbosity_type[] = |
| 53 | { |
| 54 | { eLanguageRuntimeDescriptionDisplayVerbosityCompact, "compact", "Only show the description string"}, |
| 55 | { eLanguageRuntimeDescriptionDisplayVerbosityFull, "full", "Show the full output, including persistent variable's name and type"}, |
| 56 | { 0, NULL, NULL } |
| 57 | }; |
| 58 | |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 59 | OptionDefinition |
| 60 | CommandObjectExpression::CommandOptions::g_option_table[] = |
| 61 | { |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 62 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "all-threads", 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "Should we run all threads if the execution doesn't complete on one thread."}, |
| 63 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "ignore-breakpoints", 'i', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "Ignore breakpoint hits while running expressions"}, |
| 64 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "timeout", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeUnsignedInteger, "Timeout value (in microseconds) for running the expression."}, |
| 65 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "unwind-on-error", 'u', OptionParser::eRequiredArgument, NULL, 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)."}, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 66 | { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "debug", 'g', OptionParser::eNoArgument , NULL, 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)."}, |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 67 | { LLDB_OPT_SET_1, false, "description-verbosity", 'v', OptionParser::eOptionalArgument, g_description_verbosity_type, 0, eArgTypeDescriptionVerbosity, "How verbose should the output of this expression be, if the object description is asked for."}, |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | |
| 71 | uint32_t |
| 72 | CommandObjectExpression::CommandOptions::GetNumDefinitions () |
| 73 | { |
| 74 | return sizeof(g_option_table)/sizeof(OptionDefinition); |
| 75 | } |
| 76 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | Error |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 78 | CommandObjectExpression::CommandOptions::SetOptionValue (CommandInterpreter &interpreter, |
| 79 | uint32_t option_idx, |
| 80 | const char *option_arg) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | { |
| 82 | Error error; |
| 83 | |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 84 | const int short_option = g_option_table[option_idx].short_option; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | |
| 86 | switch (short_option) |
| 87 | { |
Caroline Tice | 3f4c09c | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 88 | //case 'l': |
| 89 | //if (language.SetLanguageFromCString (option_arg) == false) |
| 90 | //{ |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 91 | // error.SetErrorStringWithFormat("invalid language option argument '%s'", option_arg); |
Caroline Tice | 3f4c09c | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 92 | //} |
| 93 | //break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 94 | |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 95 | case 'a': |
| 96 | { |
| 97 | bool success; |
| 98 | bool result; |
| 99 | result = Args::StringToBoolean(option_arg, true, &success); |
| 100 | if (!success) |
| 101 | error.SetErrorStringWithFormat("invalid all-threads value setting: \"%s\"", option_arg); |
| 102 | else |
| 103 | try_all_threads = result; |
| 104 | } |
Jim Ingham | 6c68fb4 | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 105 | break; |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 106 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 107 | case 'i': |
| 108 | { |
| 109 | bool success; |
| 110 | bool tmp_value = Args::StringToBoolean(option_arg, true, &success); |
| 111 | if (success) |
| 112 | ignore_breakpoints = tmp_value; |
| 113 | else |
| 114 | error.SetErrorStringWithFormat("could not convert \"%s\" to a boolean value.", option_arg); |
| 115 | break; |
| 116 | } |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 117 | case 't': |
| 118 | { |
| 119 | bool success; |
| 120 | uint32_t result; |
| 121 | result = Args::StringToUInt32(option_arg, 0, 0, &success); |
| 122 | if (success) |
| 123 | timeout = result; |
| 124 | else |
| 125 | error.SetErrorStringWithFormat ("invalid timeout setting \"%s\"", option_arg); |
| 126 | } |
| 127 | break; |
| 128 | |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 129 | case 'u': |
Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 130 | { |
| 131 | bool success; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 132 | bool tmp_value = Args::StringToBoolean(option_arg, true, &success); |
| 133 | if (success) |
| 134 | unwind_on_error = tmp_value; |
| 135 | else |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 136 | error.SetErrorStringWithFormat("could not convert \"%s\" to a boolean value.", option_arg); |
Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 137 | break; |
| 138 | } |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 139 | |
| 140 | case 'v': |
| 141 | if (!option_arg) |
| 142 | { |
| 143 | m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityFull; |
| 144 | break; |
| 145 | } |
| 146 | m_verbosity = (LanguageRuntimeDescriptionDisplayVerbosity) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); |
| 147 | if (!error.Success()) |
| 148 | error.SetErrorStringWithFormat ("unrecognized value for description-verbosity '%s'", option_arg); |
| 149 | break; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 150 | |
| 151 | case 'g': |
| 152 | debug = true; |
| 153 | unwind_on_error = false; |
| 154 | ignore_breakpoints = false; |
| 155 | break; |
| 156 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 158 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | break; |
| 160 | } |
| 161 | |
| 162 | return error; |
| 163 | } |
| 164 | |
| 165 | void |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 166 | CommandObjectExpression::CommandOptions::OptionParsingStarting (CommandInterpreter &interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | { |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 168 | Process *process = interpreter.GetExecutionContext().GetProcessPtr(); |
| 169 | if (process != NULL) |
| 170 | { |
| 171 | ignore_breakpoints = process->GetIgnoreBreakpointsInExpressions(); |
| 172 | unwind_on_error = process->GetUnwindOnErrorInExpressions(); |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | ignore_breakpoints = false; |
| 177 | unwind_on_error = true; |
| 178 | } |
| 179 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 180 | show_summary = true; |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 181 | try_all_threads = true; |
| 182 | timeout = 0; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 183 | debug = false; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 184 | m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityCompact; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 187 | const OptionDefinition* |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | CommandObjectExpression::CommandOptions::GetDefinitions () |
| 189 | { |
| 190 | return g_option_table; |
| 191 | } |
| 192 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 193 | CommandObjectExpression::CommandObjectExpression (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 194 | CommandObjectRaw (interpreter, |
| 195 | "expression", |
Jim Ingham | 5c48d5c | 2012-10-25 18:11:24 +0000 | [diff] [blame] | 196 | "Evaluate a C/ObjC/C++ expression in the current program context, using user defined variables and variables currently in scope.", |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 197 | NULL, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 198 | eFlagProcessMustBePaused | eFlagTryTargetAPILock), |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 199 | IOHandlerDelegate (IOHandlerDelegate::Completion::Expression), |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 200 | m_option_group (interpreter), |
| 201 | m_format_options (eFormatDefault), |
| 202 | m_command_options (), |
Johnny Chen | f7edb1c | 2010-09-30 18:30:25 +0000 | [diff] [blame] | 203 | m_expr_line_count (0), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 204 | m_expr_lines () |
| 205 | { |
| 206 | SetHelpLong( |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 207 | "Timeouts:\n\ |
| 208 | If the expression can be evaluated statically (without runnning code) then it will be.\n\ |
| 209 | Otherwise, by default the expression will run on the current thread with a short timeout:\n\ |
| 210 | currently .25 seconds. If it doesn't return in that time, the evaluation will be interrupted\n\ |
| 211 | and resumed with all threads running. You can use the -a option to disable retrying on all\n\ |
| 212 | threads. You can use the -t option to set a shorter timeout.\n\ |
Jim Ingham | 5c48d5c | 2012-10-25 18:11:24 +0000 | [diff] [blame] | 213 | \n\ |
| 214 | User defined variables:\n\ |
| 215 | You can define your own variables for convenience or to be used in subsequent expressions.\n\ |
| 216 | You define them the same way you would define variables in C. If the first character of \n\ |
| 217 | your user defined variable is a $, then the variable's value will be available in future\n\ |
| 218 | expressions, otherwise it will just be available in the current expression.\n\ |
| 219 | \n\ |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 220 | Examples: \n\ |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | \n\ |
| 222 | expr my_struct->a = my_array[3] \n\ |
| 223 | expr -f bin -- (index * 8) + 5 \n\ |
Jim Ingham | 5c48d5c | 2012-10-25 18:11:24 +0000 | [diff] [blame] | 224 | expr unsigned int $foo = 5\n\ |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | expr char c[] = \"foo\"; c[0]\n"); |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 226 | |
| 227 | CommandArgumentEntry arg; |
| 228 | CommandArgumentData expression_arg; |
| 229 | |
| 230 | // Define the first (and only) variant of this arg. |
| 231 | expression_arg.arg_type = eArgTypeExpression; |
| 232 | expression_arg.arg_repetition = eArgRepeatPlain; |
| 233 | |
| 234 | // There is only one variant this argument could be; put it into the argument entry. |
| 235 | arg.push_back (expression_arg); |
| 236 | |
| 237 | // Push the data for the first argument into the m_arguments vector. |
| 238 | m_arguments.push_back (arg); |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 239 | |
Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 240 | // Add the "--format" and "--gdb-format" |
| 241 | 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] | 242 | m_option_group.Append (&m_command_options); |
Enrico Granata | b576bba | 2013-01-09 20:12:53 +0000 | [diff] [blame] | 243 | m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1 | LLDB_OPT_SET_2); |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 244 | m_option_group.Finalize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | CommandObjectExpression::~CommandObjectExpression () |
| 248 | { |
| 249 | } |
| 250 | |
| 251 | Options * |
| 252 | CommandObjectExpression::GetOptions () |
| 253 | { |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 254 | return &m_option_group; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 257 | bool |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 258 | CommandObjectExpression::EvaluateExpression |
| 259 | ( |
| 260 | const char *expr, |
Caroline Tice | 6e8dc33 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 261 | Stream *output_stream, |
| 262 | Stream *error_stream, |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 263 | CommandReturnObject *result |
| 264 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | { |
Greg Clayton | ba7b8e2 | 2013-01-26 23:54:29 +0000 | [diff] [blame] | 266 | // Don't use m_exe_ctx as this might be called asynchronously |
| 267 | // after the command object DoExecute has finished when doing |
| 268 | // multi-line expression that use an input reader... |
| 269 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
| 270 | |
| 271 | Target *target = exe_ctx.GetTargetPtr(); |
Sean Callanan | c0a6e06 | 2011-10-27 21:22:25 +0000 | [diff] [blame] | 272 | |
| 273 | if (!target) |
| 274 | target = Host::GetDummyTarget(m_interpreter.GetDebugger()).get(); |
| 275 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 276 | if (target) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 277 | { |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 278 | lldb::ValueObjectSP result_valobj_sp; |
Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 279 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 280 | ExecutionResults exe_results; |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 281 | |
| 282 | bool keep_in_memory = true; |
Enrico Granata | b576bba | 2013-01-09 20:12:53 +0000 | [diff] [blame] | 283 | |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 284 | EvaluateExpressionOptions options; |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 285 | options.SetCoerceToId(m_varobj_options.use_objc); |
| 286 | options.SetUnwindOnError(m_command_options.unwind_on_error); |
| 287 | options.SetIgnoreBreakpoints (m_command_options.ignore_breakpoints); |
| 288 | options.SetKeepInMemory(keep_in_memory); |
| 289 | options.SetUseDynamic(m_varobj_options.use_dynamic); |
| 290 | options.SetTryAllThreads(m_command_options.try_all_threads); |
| 291 | options.SetDebug(m_command_options.debug); |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 292 | |
| 293 | if (m_command_options.timeout > 0) |
| 294 | options.SetTimeoutUsec(m_command_options.timeout); |
Jim Ingham | 6f78f38 | 2014-01-17 20:09:23 +0000 | [diff] [blame] | 295 | else |
| 296 | options.SetTimeoutUsec(0); |
Enrico Granata | d4439aa | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 297 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 298 | exe_results = target->EvaluateExpression (expr, |
Greg Clayton | ba7b8e2 | 2013-01-26 23:54:29 +0000 | [diff] [blame] | 299 | exe_ctx.GetFramePtr(), |
Enrico Granata | 3372f58 | 2012-07-16 23:10:35 +0000 | [diff] [blame] | 300 | result_valobj_sp, |
Enrico Granata | d4439aa | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 301 | options); |
Sean Callanan | 4b388c9 | 2013-07-30 19:54:09 +0000 | [diff] [blame] | 302 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 303 | if (result_valobj_sp) |
| 304 | { |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 305 | Format format = m_format_options.GetFormat(); |
| 306 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 307 | if (result_valobj_sp->GetError().Success()) |
| 308 | { |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 309 | if (format != eFormatVoid) |
| 310 | { |
| 311 | if (format != eFormatDefault) |
| 312 | result_valobj_sp->SetFormat (format); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 313 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 314 | DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(m_command_options.m_verbosity,format)); |
Enrico Granata | b576bba | 2013-01-09 20:12:53 +0000 | [diff] [blame] | 315 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 316 | result_valobj_sp->Dump(*output_stream,options); |
| 317 | |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 318 | if (result) |
| 319 | result->SetStatus (eReturnStatusSuccessFinishResult); |
| 320 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 321 | } |
| 322 | else |
| 323 | { |
Sean Callanan | bccce81 | 2011-08-23 21:20:51 +0000 | [diff] [blame] | 324 | if (result_valobj_sp->GetError().GetError() == ClangUserExpression::kNoResult) |
Greg Clayton | 5fd0590 | 2011-06-24 22:31:10 +0000 | [diff] [blame] | 325 | { |
Sean Callanan | bcf897f | 2012-08-09 18:18:47 +0000 | [diff] [blame] | 326 | if (format != eFormatVoid && m_interpreter.GetDebugger().GetNotifyVoid()) |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 327 | { |
Sean Callanan | bcf897f | 2012-08-09 18:18:47 +0000 | [diff] [blame] | 328 | error_stream->PutCString("(void)\n"); |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 329 | } |
Sean Callanan | bcf897f | 2012-08-09 18:18:47 +0000 | [diff] [blame] | 330 | |
| 331 | if (result) |
| 332 | result->SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | 5fd0590 | 2011-06-24 22:31:10 +0000 | [diff] [blame] | 333 | } |
| 334 | else |
| 335 | { |
Sean Callanan | bccce81 | 2011-08-23 21:20:51 +0000 | [diff] [blame] | 336 | const char *error_cstr = result_valobj_sp->GetError().AsCString(); |
| 337 | if (error_cstr && error_cstr[0]) |
| 338 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 339 | const size_t error_cstr_len = strlen (error_cstr); |
Sean Callanan | bccce81 | 2011-08-23 21:20:51 +0000 | [diff] [blame] | 340 | const bool ends_with_newline = error_cstr[error_cstr_len - 1] == '\n'; |
| 341 | if (strstr(error_cstr, "error:") != error_cstr) |
| 342 | error_stream->PutCString ("error: "); |
| 343 | error_stream->Write(error_cstr, error_cstr_len); |
| 344 | if (!ends_with_newline) |
| 345 | error_stream->EOL(); |
| 346 | } |
| 347 | else |
| 348 | { |
| 349 | error_stream->PutCString ("error: unknown error\n"); |
| 350 | } |
| 351 | |
| 352 | if (result) |
| 353 | result->SetStatus (eReturnStatusFailed); |
Greg Clayton | 5fd0590 | 2011-06-24 22:31:10 +0000 | [diff] [blame] | 354 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 355 | } |
| 356 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 357 | } |
| 358 | else |
| 359 | { |
Caroline Tice | 6e8dc33 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 360 | error_stream->Printf ("error: invalid execution context for expression\n"); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 361 | return false; |
Sean Callanan | ebf7707 | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 362 | } |
Sean Callanan | d1e5b43 | 2010-08-12 01:56:52 +0000 | [diff] [blame] | 363 | |
Sean Callanan | ebf7707 | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 364 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 367 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 368 | CommandObjectExpression::IOHandlerInputComplete (IOHandler &io_handler, std::string &line) |
| 369 | { |
| 370 | io_handler.SetIsDone(true); |
| 371 | // StreamSP output_stream = io_handler.GetDebugger().GetAsyncOutputStream(); |
| 372 | // StreamSP error_stream = io_handler.GetDebugger().GetAsyncErrorStream(); |
| 373 | StreamFileSP output_sp(io_handler.GetOutputStreamFile()); |
| 374 | StreamFileSP error_sp(io_handler.GetErrorStreamFile()); |
| 375 | |
| 376 | EvaluateExpression (line.c_str(), |
| 377 | output_sp.get(), |
| 378 | error_sp.get()); |
| 379 | if (output_sp) |
| 380 | output_sp->Flush(); |
| 381 | if (error_sp) |
| 382 | error_sp->Flush(); |
| 383 | } |
| 384 | |
| 385 | LineStatus |
| 386 | CommandObjectExpression::IOHandlerLinesUpdated (IOHandler &io_handler, |
| 387 | StringList &lines, |
| 388 | uint32_t line_idx, |
| 389 | Error &error) |
| 390 | { |
| 391 | if (line_idx == UINT32_MAX) |
| 392 | { |
| 393 | // Remove the last line from "lines" so it doesn't appear |
| 394 | // in our final expression |
| 395 | lines.PopBack(); |
| 396 | error.Clear(); |
| 397 | return LineStatus::Done; |
| 398 | } |
| 399 | else if (line_idx + 1 == lines.GetSize()) |
| 400 | { |
| 401 | // The last line was edited, if this line is empty, then we are done |
| 402 | // getting our multiple lines. |
| 403 | if (lines[line_idx].empty()) |
| 404 | return LineStatus::Done; |
| 405 | } |
| 406 | return LineStatus::Success; |
| 407 | } |
| 408 | |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 409 | void |
| 410 | CommandObjectExpression::GetMultilineExpression () |
| 411 | { |
| 412 | m_expr_lines.clear(); |
| 413 | m_expr_line_count = 0; |
| 414 | |
| 415 | Debugger &debugger = GetCommandInterpreter().GetDebugger(); |
| 416 | const bool multiple_lines = true; // Get multiple lines |
| 417 | IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger, |
| 418 | "lldb-expr", // Name of input reader for history |
| 419 | NULL, // No prompt |
| 420 | multiple_lines, |
| 421 | 1, // Show line numbers starting at 1 |
| 422 | *this)); |
| 423 | |
| 424 | StreamFileSP output_sp(io_handler_sp->GetOutputStreamFile()); |
| 425 | if (output_sp) |
| 426 | { |
| 427 | output_sp->PutCString("Enter expressions, then terminate with an empty line to evaluate:\n"); |
| 428 | output_sp->Flush(); |
| 429 | } |
| 430 | debugger.PushIOHandler(io_handler_sp); |
| 431 | } |
| 432 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 433 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 434 | CommandObjectExpression::DoExecute |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | ( |
| 436 | const char *command, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 437 | CommandReturnObject &result |
| 438 | ) |
| 439 | { |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 440 | m_option_group.NotifyOptionParsingStarting(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 441 | |
| 442 | const char * expr = NULL; |
| 443 | |
| 444 | if (command[0] == '\0') |
| 445 | { |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 446 | GetMultilineExpression (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | return result.Succeeded(); |
| 448 | } |
| 449 | |
| 450 | if (command[0] == '-') |
| 451 | { |
| 452 | // We have some options and these options MUST end with --. |
| 453 | const char *end_options = NULL; |
| 454 | const char *s = command; |
| 455 | while (s && s[0]) |
| 456 | { |
| 457 | end_options = ::strstr (s, "--"); |
| 458 | if (end_options) |
| 459 | { |
| 460 | end_options += 2; // Get past the "--" |
| 461 | if (::isspace (end_options[0])) |
| 462 | { |
| 463 | expr = end_options; |
| 464 | while (::isspace (*expr)) |
| 465 | ++expr; |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | s = end_options; |
| 470 | } |
| 471 | |
| 472 | if (end_options) |
| 473 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 474 | Args args (command, end_options - command); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 475 | if (!ParseOptions (args, result)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | return false; |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 477 | |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 478 | Error error (m_option_group.NotifyOptionParsingFinished()); |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 479 | if (error.Fail()) |
| 480 | { |
| 481 | result.AppendError (error.AsCString()); |
| 482 | result.SetStatus (eReturnStatusFailed); |
| 483 | return false; |
| 484 | } |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 485 | |
| 486 | // No expression following options |
Greg Clayton | 05da458c | 2014-03-13 23:48:40 +0000 | [diff] [blame] | 487 | if (expr == NULL || expr[0] == '\0') |
Greg Clayton | cf28a8b | 2014-03-13 23:42:30 +0000 | [diff] [blame] | 488 | { |
| 489 | GetMultilineExpression (); |
| 490 | return result.Succeeded(); |
| 491 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 495 | if (expr == NULL) |
| 496 | expr = command; |
Sean Callanan | 16ad5fa | 2010-06-24 00:16:27 +0000 | [diff] [blame] | 497 | |
Caroline Tice | 6e8dc33 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 498 | if (EvaluateExpression (expr, &(result.GetOutputStream()), &(result.GetErrorStream()), &result)) |
Johnny Chen | fcd43b7 | 2010-08-13 00:42:30 +0000 | [diff] [blame] | 499 | return true; |
| 500 | |
| 501 | result.SetStatus (eReturnStatusFailed); |
| 502 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 503 | } |
| 504 | |