Chris Lattner | 24943d2 | 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 | |
| 10 | #include "CommandObjectExpression.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Value.h" |
| 18 | #include "lldb/Core/InputReader.h" |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 19 | #include "lldb/Core/ValueObjectVariable.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Expression/ClangExpressionVariable.h" |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 21 | #include "lldb/Expression/ClangUserExpression.h" |
Stephen Wilson | 63c468c | 2010-07-23 21:47:22 +0000 | [diff] [blame] | 22 | #include "lldb/Expression/ClangFunction.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Expression/DWARFExpression.h" |
| 24 | #include "lldb/Host/Host.h" |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 25 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 26 | #include "lldb/Interpreter/CommandInterpreter.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Interpreter/CommandReturnObject.h" |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 28 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Symbol/ObjectFile.h" |
| 30 | #include "lldb/Symbol/Variable.h" |
| 31 | #include "lldb/Target/Process.h" |
| 32 | #include "lldb/Target/StackFrame.h" |
| 33 | #include "lldb/Target/Target.h" |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 34 | #include "lldb/Target/Thread.h" |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/StringRef.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | |
| 37 | using namespace lldb; |
| 38 | using namespace lldb_private; |
| 39 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 40 | CommandObjectExpression::CommandOptions::CommandOptions (CommandInterpreter &interpreter) : |
Johnny Chen | 9335643 | 2011-04-08 22:39:17 +0000 | [diff] [blame] | 41 | Options(interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | { |
| 43 | // Keep only one place to reset the values to their defaults |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 44 | OptionParsingStarting(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | |
| 48 | CommandObjectExpression::CommandOptions::~CommandOptions () |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 53 | CommandObjectExpression::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | { |
| 55 | Error error; |
| 56 | |
| 57 | char short_option = (char) m_getopt_table[option_idx].val; |
| 58 | |
| 59 | switch (short_option) |
| 60 | { |
Caroline Tice | c1ad82e | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 61 | //case 'l': |
| 62 | //if (language.SetLanguageFromCString (option_arg) == false) |
| 63 | //{ |
| 64 | // error.SetErrorStringWithFormat("Invalid language option argument '%s'.\n", option_arg); |
| 65 | //} |
| 66 | //break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | |
| 68 | case 'g': |
| 69 | debug = true; |
| 70 | break; |
| 71 | |
| 72 | case 'f': |
Greg Clayton | 56bbdaf | 2011-04-28 20:55:26 +0000 | [diff] [blame] | 73 | error = Args::StringToFormat(option_arg, format, NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | break; |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 75 | |
| 76 | case 'o': |
| 77 | print_object = true; |
| 78 | break; |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 79 | |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 80 | case 'd': |
| 81 | { |
| 82 | bool success; |
| 83 | bool result; |
| 84 | result = Args::StringToBoolean(option_arg, true, &success); |
| 85 | if (!success) |
| 86 | error.SetErrorStringWithFormat("Invalid dynamic value setting: \"%s\".\n", option_arg); |
| 87 | else |
| 88 | { |
| 89 | if (result) |
Greg Clayton | 82f0746 | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 90 | use_dynamic = eLazyBoolYes; |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 91 | else |
| 92 | use_dynamic = eLazyBoolNo; |
| 93 | } |
| 94 | } |
| 95 | break; |
| 96 | |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 97 | case 'u': |
| 98 | bool success; |
| 99 | unwind_on_error = Args::StringToBoolean(option_arg, true, &success); |
| 100 | if (!success) |
| 101 | error.SetErrorStringWithFormat("Could not convert \"%s\" to a boolean value.", option_arg); |
| 102 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | |
| 104 | default: |
| 105 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 106 | break; |
| 107 | } |
| 108 | |
| 109 | return error; |
| 110 | } |
| 111 | |
| 112 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 113 | CommandObjectExpression::CommandOptions::OptionParsingStarting () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | { |
Caroline Tice | c1ad82e | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 115 | //language.Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | debug = false; |
| 117 | format = eFormatDefault; |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 118 | print_object = false; |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 119 | use_dynamic = eLazyBoolCalculate; |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 120 | unwind_on_error = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | show_types = true; |
| 122 | show_summary = true; |
| 123 | } |
| 124 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 125 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 126 | CommandObjectExpression::CommandOptions::GetDefinitions () |
| 127 | { |
| 128 | return g_option_table; |
| 129 | } |
| 130 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 131 | CommandObjectExpression::CommandObjectExpression (CommandInterpreter &interpreter) : |
| 132 | CommandObject (interpreter, |
| 133 | "expression", |
Johnny Chen | 106a737 | 2010-09-30 18:16:58 +0000 | [diff] [blame] | 134 | "Evaluate a C/ObjC/C++ expression in the current program context, using variables currently in scope.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 135 | NULL), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 136 | m_options (interpreter), |
Johnny Chen | cc112ac | 2010-09-30 18:30:25 +0000 | [diff] [blame] | 137 | m_expr_line_count (0), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 138 | m_expr_lines () |
| 139 | { |
| 140 | SetHelpLong( |
| 141 | "Examples: \n\ |
| 142 | \n\ |
| 143 | expr my_struct->a = my_array[3] \n\ |
| 144 | expr -f bin -- (index * 8) + 5 \n\ |
| 145 | expr char c[] = \"foo\"; c[0]\n"); |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 146 | |
| 147 | CommandArgumentEntry arg; |
| 148 | CommandArgumentData expression_arg; |
| 149 | |
| 150 | // Define the first (and only) variant of this arg. |
| 151 | expression_arg.arg_type = eArgTypeExpression; |
| 152 | expression_arg.arg_repetition = eArgRepeatPlain; |
| 153 | |
| 154 | // There is only one variant this argument could be; put it into the argument entry. |
| 155 | arg.push_back (expression_arg); |
| 156 | |
| 157 | // Push the data for the first argument into the m_arguments vector. |
| 158 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | CommandObjectExpression::~CommandObjectExpression () |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | Options * |
| 166 | CommandObjectExpression::GetOptions () |
| 167 | { |
| 168 | return &m_options; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | bool |
| 173 | CommandObjectExpression::Execute |
| 174 | ( |
| 175 | Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 176 | CommandReturnObject &result |
| 177 | ) |
| 178 | { |
| 179 | return false; |
| 180 | } |
| 181 | |
| 182 | |
| 183 | size_t |
| 184 | CommandObjectExpression::MultiLineExpressionCallback |
| 185 | ( |
| 186 | void *baton, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 187 | InputReader &reader, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | lldb::InputReaderAction notification, |
| 189 | const char *bytes, |
| 190 | size_t bytes_len |
| 191 | ) |
| 192 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 193 | CommandObjectExpression *cmd_object_expr = (CommandObjectExpression *) baton; |
Caroline Tice | 892fadd | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 194 | bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode(); |
| 195 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 196 | switch (notification) |
| 197 | { |
| 198 | case eInputReaderActivate: |
Caroline Tice | 892fadd | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 199 | if (!batch_mode) |
Caroline Tice | 2b5e4e6 | 2011-06-15 19:35:17 +0000 | [diff] [blame] | 200 | { |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 201 | StreamSP async_strm_sp(reader.GetDebugger().GetAsyncOutputStream()); |
| 202 | if (async_strm_sp) |
| 203 | { |
| 204 | async_strm_sp->PutCString("Enter expressions, then terminate with an empty line to evaluate:\n"); |
| 205 | async_strm_sp->Flush(); |
| 206 | } |
Caroline Tice | 2b5e4e6 | 2011-06-15 19:35:17 +0000 | [diff] [blame] | 207 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 208 | // Fall through |
| 209 | case eInputReaderReactivate: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 210 | break; |
| 211 | |
| 212 | case eInputReaderDeactivate: |
| 213 | break; |
| 214 | |
Caroline Tice | 4a34808 | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 215 | case eInputReaderAsynchronousOutputWritten: |
| 216 | break; |
| 217 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 218 | case eInputReaderGotToken: |
| 219 | ++cmd_object_expr->m_expr_line_count; |
| 220 | if (bytes && bytes_len) |
| 221 | { |
| 222 | cmd_object_expr->m_expr_lines.append (bytes, bytes_len + 1); |
| 223 | } |
| 224 | |
| 225 | if (bytes_len == 0) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 226 | reader.SetIsDone(true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 227 | break; |
| 228 | |
Caroline Tice | c4f55fe | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 229 | case eInputReaderInterrupt: |
| 230 | cmd_object_expr->m_expr_lines.clear(); |
| 231 | reader.SetIsDone (true); |
Caroline Tice | 892fadd | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 232 | if (!batch_mode) |
Caroline Tice | 2b5e4e6 | 2011-06-15 19:35:17 +0000 | [diff] [blame] | 233 | { |
Greg Clayton | 234981a | 2011-07-20 03:41:06 +0000 | [diff] [blame] | 234 | StreamSP async_strm_sp (reader.GetDebugger().GetAsyncOutputStream()); |
| 235 | if (async_strm_sp) |
| 236 | { |
| 237 | async_strm_sp->PutCString("Expression evaluation cancelled.\n"); |
| 238 | async_strm_sp->Flush(); |
| 239 | } |
Caroline Tice | 2b5e4e6 | 2011-06-15 19:35:17 +0000 | [diff] [blame] | 240 | } |
Caroline Tice | c4f55fe | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 241 | break; |
| 242 | |
| 243 | case eInputReaderEndOfFile: |
| 244 | reader.SetIsDone (true); |
| 245 | break; |
| 246 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 247 | case eInputReaderDone: |
Caroline Tice | c4f55fe | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 248 | if (cmd_object_expr->m_expr_lines.size() > 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | { |
Caroline Tice | 87e1f77 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 250 | StreamSP output_stream = reader.GetDebugger().GetAsyncOutputStream(); |
| 251 | StreamSP error_stream = reader.GetDebugger().GetAsyncErrorStream(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | cmd_object_expr->EvaluateExpression (cmd_object_expr->m_expr_lines.c_str(), |
Caroline Tice | 87e1f77 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 253 | output_stream.get(), |
| 254 | error_stream.get()); |
| 255 | output_stream->Flush(); |
| 256 | error_stream->Flush(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 257 | } |
| 258 | break; |
| 259 | } |
| 260 | |
| 261 | return bytes_len; |
| 262 | } |
| 263 | |
| 264 | bool |
Greg Clayton | 66ed2fb | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 265 | CommandObjectExpression::EvaluateExpression |
| 266 | ( |
| 267 | const char *expr, |
Caroline Tice | 87e1f77 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 268 | Stream *output_stream, |
| 269 | Stream *error_stream, |
Greg Clayton | 66ed2fb | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 270 | CommandReturnObject *result |
| 271 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 272 | { |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 273 | if (m_exe_ctx.target) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 274 | { |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 275 | lldb::ValueObjectSP result_valobj_sp; |
Greg Clayton | 11730f3 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 276 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 277 | ExecutionResults exe_results; |
Sean Callanan | 6a92553 | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 278 | |
| 279 | bool keep_in_memory = true; |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 280 | lldb::DynamicValueType use_dynamic; |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 281 | // If use dynamic is not set, get it from the target: |
| 282 | switch (m_options.use_dynamic) |
| 283 | { |
| 284 | case eLazyBoolCalculate: |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 285 | use_dynamic = m_exe_ctx.target->GetPreferDynamicValue(); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 286 | break; |
| 287 | case eLazyBoolYes: |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 288 | use_dynamic = lldb::eDynamicCanRunTarget; |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 289 | break; |
| 290 | case eLazyBoolNo: |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 291 | use_dynamic = lldb::eNoDynamicValues; |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 292 | break; |
| 293 | } |
Sean Callanan | 6a92553 | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 294 | |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 295 | exe_results = m_exe_ctx.target->EvaluateExpression(expr, m_exe_ctx.frame, m_options.unwind_on_error, keep_in_memory, use_dynamic, result_valobj_sp); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 296 | |
| 297 | if (exe_results == eExecutionInterrupted && !m_options.unwind_on_error) |
Jim Ingham | 360f53f | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 298 | { |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 299 | uint32_t start_frame = 0; |
| 300 | uint32_t num_frames = 1; |
| 301 | uint32_t num_frames_with_source = 0; |
Jim Ingham | 360f53f | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 302 | if (m_exe_ctx.thread) |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 303 | { |
| 304 | m_exe_ctx.thread->GetStatus (result->GetOutputStream(), |
| 305 | start_frame, |
| 306 | num_frames, |
| 307 | num_frames_with_source); |
| 308 | } |
| 309 | else if (m_exe_ctx.process) |
| 310 | { |
| 311 | bool only_threads_with_stop_reason = true; |
| 312 | m_exe_ctx.process->GetThreadStatus (result->GetOutputStream(), |
| 313 | only_threads_with_stop_reason, |
| 314 | start_frame, |
| 315 | num_frames, |
| 316 | num_frames_with_source); |
| 317 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | if (result_valobj_sp) |
| 321 | { |
| 322 | if (result_valobj_sp->GetError().Success()) |
| 323 | { |
| 324 | if (m_options.format != eFormatDefault) |
| 325 | result_valobj_sp->SetFormat (m_options.format); |
| 326 | |
Caroline Tice | 87e1f77 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 327 | ValueObject::DumpValueObject (*(output_stream), |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 328 | result_valobj_sp.get(), // Variable object to dump |
| 329 | result_valobj_sp->GetName().GetCString(),// Root object name |
| 330 | 0, // Pointer depth to traverse (zero means stop at pointers) |
| 331 | 0, // Current depth, this is the top most, so zero... |
| 332 | UINT32_MAX, // Max depth to go when dumping concrete types, dump everything... |
| 333 | m_options.show_types, // Show types when dumping? |
| 334 | false, // Show locations of variables, no since this is a host address which we don't care to see |
| 335 | m_options.print_object, // Print the objective C object? |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 336 | use_dynamic, |
Enrico Granata | e4e3e2c | 2011-07-22 00:16:08 +0000 | [diff] [blame^] | 337 | true, // Use synthetic children if available |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 338 | true, // Scope is already checked. Const results are always in scope. |
Enrico Granata | 7f163b3 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 339 | false, // Don't flatten output |
| 340 | 0); // Always use summaries (you might want an option --no-summary like there is for frame variable) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 341 | if (result) |
| 342 | result->SetStatus (eReturnStatusSuccessFinishResult); |
| 343 | } |
| 344 | else |
| 345 | { |
Greg Clayton | fe1b47d | 2011-06-24 22:31:10 +0000 | [diff] [blame] | 346 | const char *error_cstr = result_valobj_sp->GetError().AsCString(); |
| 347 | if (error_cstr && error_cstr[0]) |
| 348 | { |
| 349 | int error_cstr_len = strlen (error_cstr); |
| 350 | const bool ends_with_newline = error_cstr[error_cstr_len - 1] == '\n'; |
| 351 | if (strstr(error_cstr, "error:") != error_cstr) |
| 352 | error_stream->PutCString ("error: "); |
| 353 | error_stream->Write(error_cstr, error_cstr_len); |
| 354 | if (!ends_with_newline) |
| 355 | error_stream->EOL(); |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | error_stream->PutCString ("error: unknown error\n"); |
| 360 | } |
| 361 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 362 | if (result) |
| 363 | result->SetStatus (eReturnStatusFailed); |
Jim Ingham | 360f53f | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 364 | } |
| 365 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 366 | } |
| 367 | else |
| 368 | { |
Caroline Tice | 87e1f77 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 369 | error_stream->Printf ("error: invalid execution context for expression\n"); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 370 | return false; |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 371 | } |
Sean Callanan | 82b74c8 | 2010-08-12 01:56:52 +0000 | [diff] [blame] | 372 | |
Sean Callanan | 841026f | 2010-07-23 00:16:21 +0000 | [diff] [blame] | 373 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | bool |
| 377 | CommandObjectExpression::ExecuteRawCommandString |
| 378 | ( |
| 379 | const char *command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 380 | CommandReturnObject &result |
| 381 | ) |
| 382 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 383 | m_exe_ctx = m_interpreter.GetExecutionContext(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 384 | |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 385 | m_options.NotifyOptionParsingStarting(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 386 | |
| 387 | const char * expr = NULL; |
| 388 | |
| 389 | if (command[0] == '\0') |
| 390 | { |
| 391 | m_expr_lines.clear(); |
| 392 | m_expr_line_count = 0; |
| 393 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 394 | InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 395 | if (reader_sp) |
| 396 | { |
| 397 | Error err (reader_sp->Initialize (CommandObjectExpression::MultiLineExpressionCallback, |
| 398 | this, // baton |
| 399 | eInputReaderGranularityLine, // token size, to pass to callback function |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 400 | NULL, // end token |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | NULL, // prompt |
| 402 | true)); // echo input |
| 403 | if (err.Success()) |
| 404 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 405 | m_interpreter.GetDebugger().PushInputReader (reader_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 406 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 407 | } |
| 408 | else |
| 409 | { |
| 410 | result.AppendError (err.AsCString()); |
| 411 | result.SetStatus (eReturnStatusFailed); |
| 412 | } |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | result.AppendError("out of memory"); |
| 417 | result.SetStatus (eReturnStatusFailed); |
| 418 | } |
| 419 | return result.Succeeded(); |
| 420 | } |
| 421 | |
| 422 | if (command[0] == '-') |
| 423 | { |
| 424 | // We have some options and these options MUST end with --. |
| 425 | const char *end_options = NULL; |
| 426 | const char *s = command; |
| 427 | while (s && s[0]) |
| 428 | { |
| 429 | end_options = ::strstr (s, "--"); |
| 430 | if (end_options) |
| 431 | { |
| 432 | end_options += 2; // Get past the "--" |
| 433 | if (::isspace (end_options[0])) |
| 434 | { |
| 435 | expr = end_options; |
| 436 | while (::isspace (*expr)) |
| 437 | ++expr; |
| 438 | break; |
| 439 | } |
| 440 | } |
| 441 | s = end_options; |
| 442 | } |
| 443 | |
| 444 | if (end_options) |
| 445 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 446 | Args args (command, end_options - command); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 447 | if (!ParseOptions (args, result)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 448 | return false; |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 449 | |
| 450 | Error error (m_options.NotifyOptionParsingFinished()); |
| 451 | if (error.Fail()) |
| 452 | { |
| 453 | result.AppendError (error.AsCString()); |
| 454 | result.SetStatus (eReturnStatusFailed); |
| 455 | return false; |
| 456 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 460 | if (expr == NULL) |
| 461 | expr = command; |
Sean Callanan | 46b6249 | 2010-06-24 00:16:27 +0000 | [diff] [blame] | 462 | |
Caroline Tice | 87e1f77 | 2011-06-13 20:20:29 +0000 | [diff] [blame] | 463 | if (EvaluateExpression (expr, &(result.GetOutputStream()), &(result.GetErrorStream()), &result)) |
Johnny Chen | 0deefc7 | 2010-08-13 00:42:30 +0000 | [diff] [blame] | 464 | return true; |
| 465 | |
| 466 | result.SetStatus (eReturnStatusFailed); |
| 467 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 470 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 471 | CommandObjectExpression::CommandOptions::g_option_table[] = |
| 472 | { |
Johnny Chen | 2bc9eb3 | 2011-07-19 19:48:13 +0000 | [diff] [blame] | 473 | //{ LLDB_OPT_SET_ALL, false, "language", 'l', required_argument, NULL, 0, "[c|c++|objc|objc++]", "Sets the language to use when parsing the expression."}, |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 474 | //{ LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]", "Specify the format that the expression output should use."}, |
Johnny Chen | 2bc9eb3 | 2011-07-19 19:48:13 +0000 | [diff] [blame] | 475 | { LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, eArgTypeExprFormat, "Specify the format that the expression output should use."}, |
| 476 | { LLDB_OPT_SET_2, false, "object-description", 'o', no_argument, NULL, 0, eArgTypeNone, "Print the object description of the value resulting from the expression."}, |
| 477 | { LLDB_OPT_SET_2, false, "dynamic-value", 'd', required_argument, NULL, 0, eArgTypeBoolean, "Upcast the value resulting from the expression to its dynamic type if available."}, |
| 478 | { LLDB_OPT_SET_ALL, false, "unwind-on-error", 'u', required_argument, NULL, 0, eArgTypeBoolean, "Clean up program state if the expression causes a crash, breakpoint hit or signal."}, |
| 479 | { LLDB_OPT_SET_ALL, false, "debug", 'g', no_argument, NULL, 0, eArgTypeNone, "Enable verbose debug logging of the expression parsing and evaluation."}, |
| 480 | { LLDB_OPT_SET_ALL, false, "use-ir", 'i', no_argument, NULL, 0, eArgTypeNone, "[Temporary] Instructs the expression evaluator to use IR instead of ASTs."}, |
| 481 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 482 | }; |
| 483 | |