Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectFrame.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 "CommandObjectFrame.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Debugger.h" |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Module.h" |
| 18 | #include "lldb/Core/StreamFile.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Timer.h" |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Value.h" |
| 21 | #include "lldb/Core/ValueObject.h" |
| 22 | #include "lldb/Core/ValueObjectVariable.h" |
| 23 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 25 | #include "lldb/Interpreter/CommandReturnObject.h" |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 26 | #include "lldb/Interpreter/Options.h" |
| 27 | #include "lldb/Symbol/ClangASTType.h" |
| 28 | #include "lldb/Symbol/ClangASTContext.h" |
| 29 | #include "lldb/Symbol/ObjectFile.h" |
| 30 | #include "lldb/Symbol/SymbolContext.h" |
| 31 | #include "lldb/Symbol/Type.h" |
| 32 | #include "lldb/Symbol/Variable.h" |
| 33 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Target/Process.h" |
| 35 | #include "lldb/Target/StackFrame.h" |
| 36 | #include "lldb/Target/Thread.h" |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 37 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | |
| 39 | #include "CommandObjectThread.h" |
| 40 | |
| 41 | using namespace lldb; |
| 42 | using namespace lldb_private; |
| 43 | |
| 44 | #pragma mark CommandObjectFrameInfo |
| 45 | |
| 46 | //------------------------------------------------------------------------- |
| 47 | // CommandObjectFrameInfo |
| 48 | //------------------------------------------------------------------------- |
| 49 | |
| 50 | class CommandObjectFrameInfo : public CommandObject |
| 51 | { |
| 52 | public: |
| 53 | |
| 54 | CommandObjectFrameInfo () : |
| 55 | CommandObject ("frame info", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 56 | "List information about the currently selected frame in the current thread.", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | "frame info", |
| 58 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | ~CommandObjectFrameInfo () |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 67 | Execute (CommandInterpreter &interpreter, |
| 68 | Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | CommandReturnObject &result) |
| 70 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 71 | ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | if (exe_ctx.frame) |
| 73 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 74 | exe_ctx.frame->Dump (&result.GetOutputStream(), true, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | result.GetOutputStream().EOL(); |
| 76 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | result.AppendError ("no current frame"); |
| 81 | result.SetStatus (eReturnStatusFailed); |
| 82 | } |
| 83 | return result.Succeeded(); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | #pragma mark CommandObjectFrameSelect |
| 88 | |
| 89 | //------------------------------------------------------------------------- |
| 90 | // CommandObjectFrameSelect |
| 91 | //------------------------------------------------------------------------- |
| 92 | |
| 93 | class CommandObjectFrameSelect : public CommandObject |
| 94 | { |
| 95 | public: |
| 96 | |
| 97 | CommandObjectFrameSelect () : |
| 98 | CommandObject ("frame select", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 99 | //"Select the current frame by index in the current thread.", |
| 100 | "Select a frame by index from within the current thread and make it the current frame.", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 101 | "frame select <frame-index>", |
| 102 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
| 103 | { |
| 104 | } |
| 105 | |
| 106 | ~CommandObjectFrameSelect () |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 111 | Execute (CommandInterpreter &interpreter, |
| 112 | Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 113 | CommandReturnObject &result) |
| 114 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 115 | ExecutionContext exe_ctx (interpreter.GetDebugger().GetExecutionContext()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | if (exe_ctx.thread) |
| 117 | { |
| 118 | if (command.GetArgumentCount() == 1) |
| 119 | { |
| 120 | const char *frame_idx_cstr = command.GetArgumentAtIndex(0); |
| 121 | |
| 122 | const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount(); |
| 123 | const uint32_t frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0); |
| 124 | if (frame_idx < num_frames) |
| 125 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 126 | exe_ctx.thread->SetSelectedFrameByIndex (frame_idx); |
| 127 | exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 128 | |
| 129 | if (exe_ctx.frame) |
| 130 | { |
Jim Ingham | 74989e8 | 2010-08-30 19:44:40 +0000 | [diff] [blame] | 131 | bool already_shown = false; |
| 132 | SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry)); |
| 133 | if (interpreter.GetDebugger().UseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) |
| 134 | { |
| 135 | already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 136 | } |
| 137 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 138 | if (DisplayFrameForExecutionContext (exe_ctx.thread, |
| 139 | exe_ctx.frame, |
| 140 | interpreter, |
| 141 | result.GetOutputStream(), |
| 142 | true, |
Jim Ingham | 74989e8 | 2010-08-30 19:44:40 +0000 | [diff] [blame] | 143 | !already_shown, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | 3, |
| 145 | 3)) |
| 146 | { |
| 147 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 148 | return result.Succeeded(); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | if (frame_idx == UINT32_MAX) |
| 153 | result.AppendErrorWithFormat ("Invalid frame index: %s.\n", frame_idx_cstr); |
| 154 | else |
| 155 | result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx); |
| 156 | } |
| 157 | else |
| 158 | { |
| 159 | result.AppendError ("invalid arguments"); |
| 160 | result.AppendErrorWithFormat ("Usage: %s\n", m_cmd_syntax.c_str()); |
| 161 | } |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | result.AppendError ("no current thread"); |
| 166 | } |
| 167 | result.SetStatus (eReturnStatusFailed); |
| 168 | return false; |
| 169 | } |
| 170 | }; |
| 171 | |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 172 | #pragma mark CommandObjectFrameVariable |
| 173 | //---------------------------------------------------------------------- |
| 174 | // List images with associated information |
| 175 | //---------------------------------------------------------------------- |
| 176 | class CommandObjectFrameVariable : public CommandObject |
| 177 | { |
| 178 | public: |
| 179 | |
| 180 | class CommandOptions : public Options |
| 181 | { |
| 182 | public: |
| 183 | |
| 184 | CommandOptions () : |
| 185 | Options() |
| 186 | { |
| 187 | ResetOptionValues (); |
| 188 | } |
| 189 | |
| 190 | virtual |
| 191 | ~CommandOptions () |
| 192 | { |
| 193 | } |
| 194 | |
| 195 | virtual Error |
| 196 | SetOptionValue (int option_idx, const char *option_arg) |
| 197 | { |
| 198 | Error error; |
| 199 | bool success; |
| 200 | char short_option = (char) m_getopt_table[option_idx].val; |
| 201 | switch (short_option) |
| 202 | { |
| 203 | case 'o': use_objc = true; break; |
| 204 | case 'n': name = option_arg; break; |
| 205 | case 'r': use_regex = true; break; |
| 206 | case 'a': show_args = false; break; |
| 207 | case 'l': show_locals = false; break; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 208 | case 'g': show_globals = true; break; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 209 | case 't': show_types = false; break; |
| 210 | case 'y': show_summary = false; break; |
| 211 | case 'L': show_location= true; break; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 212 | case 'c': show_decl = true; break; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 213 | case 'D': debug = true; break; |
| 214 | case 'd': |
| 215 | max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success); |
| 216 | if (!success) |
| 217 | error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg); |
| 218 | break; |
| 219 | |
| 220 | case 'p': |
| 221 | ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success); |
| 222 | if (!success) |
| 223 | error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg); |
| 224 | break; |
| 225 | |
| 226 | case 'G': |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 227 | globals.push_back(ConstString (option_arg)); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 228 | break; |
| 229 | |
| 230 | case 's': |
| 231 | show_scope = true; |
| 232 | break; |
| 233 | |
| 234 | default: |
| 235 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 236 | break; |
| 237 | } |
| 238 | |
| 239 | return error; |
| 240 | } |
| 241 | |
| 242 | void |
| 243 | ResetOptionValues () |
| 244 | { |
| 245 | Options::ResetOptionValues(); |
| 246 | |
| 247 | name.clear(); |
| 248 | use_objc = false; |
| 249 | use_regex = false; |
| 250 | show_args = true; |
| 251 | show_locals = true; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 252 | show_globals = false; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 253 | show_types = true; |
| 254 | show_scope = false; |
| 255 | show_summary = true; |
| 256 | show_location = false; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 257 | show_decl = false; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 258 | debug = false; |
| 259 | max_depth = UINT32_MAX; |
| 260 | ptr_depth = 0; |
| 261 | globals.clear(); |
| 262 | } |
| 263 | |
| 264 | const lldb::OptionDefinition* |
| 265 | GetDefinitions () |
| 266 | { |
| 267 | return g_option_table; |
| 268 | } |
| 269 | |
| 270 | // Options table: Required for subclasses of Options. |
| 271 | |
| 272 | static lldb::OptionDefinition g_option_table[]; |
| 273 | std::string name; |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 274 | bool use_objc:1, |
| 275 | use_regex:1, |
| 276 | show_args:1, |
| 277 | show_locals:1, |
| 278 | show_globals:1, |
| 279 | show_types:1, |
| 280 | show_scope:1, |
| 281 | show_summary:1, |
| 282 | show_location:1, |
| 283 | show_decl:1, |
| 284 | debug:1; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 285 | uint32_t max_depth; // The depth to print when dumping concrete (not pointers) aggreate values |
| 286 | uint32_t ptr_depth; // The default depth that is dumped when we find pointers |
| 287 | std::vector<ConstString> globals; |
| 288 | // Instance variables to hold the values for command options. |
| 289 | }; |
| 290 | |
| 291 | CommandObjectFrameVariable () : |
| 292 | CommandObject ( |
| 293 | "frame variable", |
| 294 | "Show specified argument, local variable, static variable or global variable for the current frame. If none specified, list them all.", |
| 295 | "frame variable [<cmd-options>] [<var-name1> [<var-name2>...]]") |
| 296 | { |
| 297 | } |
| 298 | |
| 299 | virtual |
| 300 | ~CommandObjectFrameVariable () |
| 301 | { |
| 302 | } |
| 303 | |
| 304 | virtual |
| 305 | Options * |
| 306 | GetOptions () |
| 307 | { |
| 308 | return &m_options; |
| 309 | } |
| 310 | |
| 311 | void |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 312 | DumpValueObject (CommandReturnObject &result, |
| 313 | ExecutionContextScope *exe_scope, |
| 314 | ValueObject *valobj, |
| 315 | const char *root_valobj_name, |
| 316 | uint32_t ptr_depth, |
| 317 | uint32_t curr_depth, |
| 318 | uint32_t max_depth, |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 319 | bool use_objc, |
| 320 | bool scope_already_checked) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 321 | { |
| 322 | if (valobj) |
| 323 | { |
| 324 | Stream &s = result.GetOutputStream(); |
| 325 | |
| 326 | //const char *loc_cstr = valobj->GetLocationAsCString(); |
| 327 | if (m_options.show_location) |
| 328 | { |
| 329 | s.Printf("@ %s: ", valobj->GetLocationAsCString(exe_scope)); |
| 330 | } |
| 331 | if (m_options.debug) |
| 332 | s.Printf ("%p ValueObject{%u} ", valobj, valobj->GetID()); |
| 333 | |
| 334 | s.Indent(); |
| 335 | |
| 336 | if (m_options.show_types) |
| 337 | s.Printf("(%s) ", valobj->GetTypeName().AsCString()); |
| 338 | |
| 339 | const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString(""); |
| 340 | s.Printf ("%s = ", name_cstr); |
| 341 | |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 342 | if (!scope_already_checked && !valobj->IsInScope(exe_scope->CalculateStackFrame())) |
| 343 | { |
| 344 | s.PutCString("error: out of scope"); |
| 345 | return; |
| 346 | } |
| 347 | |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 348 | const char *val_cstr = valobj->GetValueAsCString(exe_scope); |
| 349 | const char *err_cstr = valobj->GetError().AsCString(); |
| 350 | |
| 351 | if (err_cstr) |
| 352 | { |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 353 | s.Printf ("error: %s", err_cstr); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 354 | } |
| 355 | else |
| 356 | { |
| 357 | const char *sum_cstr = valobj->GetSummaryAsCString(exe_scope); |
| 358 | |
| 359 | const bool is_aggregate = ClangASTContext::IsAggregateType (valobj->GetOpaqueClangQualType()); |
| 360 | |
| 361 | if (val_cstr) |
| 362 | s.PutCString(val_cstr); |
| 363 | |
| 364 | if (sum_cstr) |
| 365 | s.Printf(" %s", sum_cstr); |
| 366 | |
| 367 | if (use_objc) |
| 368 | { |
Jim Ingham | 4ae5196 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 369 | const char *object_desc = valobj->GetObjectDescription(exe_scope); |
| 370 | if (object_desc) |
| 371 | s.Printf("\n%s\n", object_desc); |
| 372 | else |
| 373 | s.Printf ("No description available.\n"); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 374 | return; |
| 375 | } |
| 376 | |
| 377 | |
| 378 | if (curr_depth < max_depth) |
| 379 | { |
| 380 | if (is_aggregate) |
| 381 | s.PutChar('{'); |
| 382 | |
| 383 | bool is_ptr_or_ref = ClangASTContext::IsPointerOrReferenceType (valobj->GetOpaqueClangQualType()); |
| 384 | |
| 385 | if (is_ptr_or_ref && ptr_depth == 0) |
| 386 | return; |
| 387 | |
| 388 | const uint32_t num_children = valobj->GetNumChildren(); |
| 389 | if (num_children) |
| 390 | { |
| 391 | s.IndentMore(); |
| 392 | for (uint32_t idx=0; idx<num_children; ++idx) |
| 393 | { |
| 394 | ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true)); |
| 395 | if (child_sp.get()) |
| 396 | { |
| 397 | s.EOL(); |
| 398 | DumpValueObject (result, |
| 399 | exe_scope, |
| 400 | child_sp.get(), |
| 401 | NULL, |
| 402 | is_ptr_or_ref ? ptr_depth - 1 : ptr_depth, |
| 403 | curr_depth + 1, |
| 404 | max_depth, |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 405 | false, |
| 406 | true); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 407 | if (idx + 1 < num_children) |
| 408 | s.PutChar(','); |
| 409 | } |
| 410 | } |
| 411 | s.IndentLess(); |
| 412 | } |
| 413 | if (is_aggregate) |
| 414 | { |
| 415 | s.EOL(); |
| 416 | s.Indent("}"); |
| 417 | } |
| 418 | } |
| 419 | else |
| 420 | { |
| 421 | if (is_aggregate) |
| 422 | { |
| 423 | s.PutCString("{...}"); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | virtual bool |
| 432 | Execute |
| 433 | ( |
| 434 | CommandInterpreter &interpreter, |
| 435 | Args& command, |
| 436 | CommandReturnObject &result |
| 437 | ) |
| 438 | { |
| 439 | ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext()); |
| 440 | if (exe_ctx.frame == NULL) |
| 441 | { |
| 442 | result.AppendError ("invalid frame"); |
| 443 | result.SetStatus (eReturnStatusFailed); |
| 444 | return false; |
| 445 | } |
| 446 | else |
| 447 | { |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 448 | Stream &s = result.GetOutputStream(); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 449 | |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 450 | bool get_file_globals = true; |
| 451 | VariableList *variable_list = exe_ctx.frame->GetVariableList (get_file_globals); |
| 452 | |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 453 | VariableSP var_sp; |
| 454 | ValueObjectSP valobj_sp; |
| 455 | //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList(); |
| 456 | const char *name_cstr = NULL; |
| 457 | size_t idx; |
| 458 | if (!m_options.globals.empty()) |
| 459 | { |
| 460 | uint32_t fail_count = 0; |
| 461 | if (exe_ctx.target) |
| 462 | { |
| 463 | const size_t num_globals = m_options.globals.size(); |
| 464 | for (idx = 0; idx < num_globals; ++idx) |
| 465 | { |
| 466 | VariableList global_var_list; |
| 467 | const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list); |
| 468 | |
| 469 | if (num_matching_globals == 0) |
| 470 | { |
| 471 | ++fail_count; |
| 472 | result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString()); |
| 473 | } |
| 474 | else |
| 475 | { |
| 476 | for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx) |
| 477 | { |
| 478 | var_sp = global_var_list.GetVariableAtIndex(global_idx); |
| 479 | if (var_sp) |
| 480 | { |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 481 | valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 482 | if (!valobj_sp) |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 483 | valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 484 | |
| 485 | if (valobj_sp) |
| 486 | { |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 487 | if (m_options.show_decl && var_sp->GetDeclaration ().GetFile()) |
| 488 | { |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 489 | var_sp->GetDeclaration ().DumpStopContext (&s, false); |
| 490 | s.PutCString (": "); |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 493 | DumpValueObject (result, |
| 494 | exe_ctx.frame, |
| 495 | valobj_sp.get(), |
| 496 | name_cstr, |
| 497 | m_options.ptr_depth, |
| 498 | 0, |
| 499 | m_options.max_depth, |
| 500 | m_options.use_objc, |
| 501 | false); |
| 502 | |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 503 | s.EOL(); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | if (fail_count) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 511 | result.SetStatus (eReturnStatusFailed); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 512 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 513 | else if (variable_list) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 514 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 515 | if (command.GetArgumentCount() > 0) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 516 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 517 | // If we have any args to the variable command, we will make |
| 518 | // variable objects from them... |
| 519 | for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 520 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 521 | uint32_t ptr_depth = m_options.ptr_depth; |
| 522 | // If first character is a '*', then show pointer contents |
| 523 | if (name_cstr[0] == '*') |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 524 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 525 | ++ptr_depth; |
| 526 | name_cstr++; // Skip the '*' |
| 527 | } |
| 528 | |
| 529 | std::string var_path (name_cstr); |
| 530 | size_t separator_idx = var_path.find_first_of(".-["); |
| 531 | |
| 532 | ConstString name_const_string; |
| 533 | if (separator_idx == std::string::npos) |
| 534 | name_const_string.SetCString (var_path.c_str()); |
| 535 | else |
| 536 | name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); |
| 537 | |
| 538 | var_sp = variable_list->FindVariable(name_const_string); |
| 539 | if (var_sp) |
| 540 | { |
| 541 | valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp); |
| 542 | |
| 543 | var_path.erase (0, name_const_string.GetLength ()); |
| 544 | // We are dumping at least one child |
| 545 | while (separator_idx != std::string::npos) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 546 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 547 | // Calculate the next separator index ahead of time |
| 548 | ValueObjectSP child_valobj_sp; |
| 549 | const char separator_type = var_path[0]; |
| 550 | switch (separator_type) |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 551 | { |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 552 | |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 553 | case '-': |
| 554 | if (var_path.size() >= 2 && var_path[1] != '>') |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 555 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 556 | result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n", |
| 557 | var_path.c_str()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 558 | var_path.clear(); |
| 559 | valobj_sp.reset(); |
| 560 | break; |
| 561 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 562 | var_path.erase (0, 1); // Remove the '-' |
| 563 | // Fall through |
| 564 | case '.': |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 565 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 566 | var_path.erase (0, 1); // Remove the '.' or '>' |
| 567 | separator_idx = var_path.find_first_of(".-["); |
| 568 | ConstString child_name; |
| 569 | if (separator_idx == std::string::npos) |
| 570 | child_name.SetCString (var_path.c_str()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 571 | else |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 572 | child_name.SetCStringWithLength(var_path.c_str(), separator_idx); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 573 | |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 574 | child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 575 | if (!child_valobj_sp) |
| 576 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 577 | result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n", |
| 578 | valobj_sp->GetName().AsCString(), |
| 579 | child_name.GetCString()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 580 | var_path.clear(); |
| 581 | valobj_sp.reset(); |
| 582 | break; |
| 583 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 584 | // Remove the child name from the path |
| 585 | var_path.erase(0, child_name.GetLength()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 586 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 587 | break; |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 588 | |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 589 | case '[': |
| 590 | // Array member access, or treating pointer as an array |
| 591 | if (var_path.size() > 2) // Need at least two brackets and a number |
| 592 | { |
| 593 | char *end = NULL; |
| 594 | int32_t child_index = ::strtol (&var_path[1], &end, 0); |
| 595 | if (end && *end == ']') |
| 596 | { |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 597 | |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 598 | if (valobj_sp->IsPointerType ()) |
| 599 | { |
| 600 | child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true); |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); |
| 605 | } |
| 606 | |
| 607 | if (!child_valobj_sp) |
| 608 | { |
| 609 | result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n", |
| 610 | child_index, |
| 611 | valobj_sp->GetName().AsCString()); |
| 612 | var_path.clear(); |
| 613 | valobj_sp.reset(); |
| 614 | break; |
| 615 | } |
| 616 | |
| 617 | // Erase the array member specification '[%i]' where %i is the array index |
| 618 | var_path.erase(0, (end - var_path.c_str()) + 1); |
| 619 | separator_idx = var_path.find_first_of(".-["); |
| 620 | |
| 621 | // Break out early from the switch since we were able to find the child member |
| 622 | break; |
| 623 | } |
| 624 | } |
| 625 | result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n", |
| 626 | valobj_sp->GetName().AsCString(), |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 627 | var_path.c_str()); |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 628 | var_path.clear(); |
| 629 | valobj_sp.reset(); |
| 630 | break; |
| 631 | |
| 632 | break; |
| 633 | |
| 634 | default: |
| 635 | result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n", |
| 636 | var_path.c_str()); |
| 637 | var_path.clear(); |
| 638 | valobj_sp.reset(); |
| 639 | separator_idx = std::string::npos; |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | if (child_valobj_sp) |
| 644 | valobj_sp = child_valobj_sp; |
| 645 | |
| 646 | if (var_path.empty()) |
| 647 | break; |
| 648 | |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 651 | if (valobj_sp) |
| 652 | { |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 653 | if (m_options.show_decl && var_sp->GetDeclaration ().GetFile()) |
| 654 | { |
| 655 | var_sp->GetDeclaration ().DumpStopContext (&s, false); |
| 656 | s.PutCString (": "); |
| 657 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 658 | |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 659 | DumpValueObject (result, |
| 660 | exe_ctx.frame, |
| 661 | valobj_sp.get(), |
| 662 | name_cstr, |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 663 | ptr_depth, |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 664 | 0, |
| 665 | m_options.max_depth, |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 666 | m_options.use_objc, |
| 667 | false); |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 668 | |
| 669 | s.EOL(); |
| 670 | } |
| 671 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 672 | else |
| 673 | { |
| 674 | result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr); |
| 675 | var_path.clear(); |
| 676 | } |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 677 | } |
| 678 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 679 | else |
| 680 | { |
| 681 | const uint32_t num_variables = variable_list->GetSize(); |
| 682 | |
| 683 | if (num_variables > 0) |
| 684 | { |
| 685 | for (uint32_t i=0; i<num_variables; i++) |
| 686 | { |
| 687 | VariableSP var_sp (variable_list->GetVariableAtIndex(i)); |
| 688 | bool dump_variable = true; |
| 689 | |
| 690 | switch (var_sp->GetScope()) |
| 691 | { |
| 692 | case eValueTypeVariableGlobal: |
| 693 | dump_variable = m_options.show_globals; |
| 694 | if (dump_variable && m_options.show_scope) |
| 695 | s.PutCString("GLOBAL: "); |
| 696 | break; |
| 697 | |
| 698 | case eValueTypeVariableStatic: |
| 699 | dump_variable = m_options.show_globals; |
| 700 | if (dump_variable && m_options.show_scope) |
| 701 | s.PutCString("STATIC: "); |
| 702 | break; |
| 703 | |
| 704 | case eValueTypeVariableArgument: |
| 705 | dump_variable = m_options.show_args; |
| 706 | if (dump_variable && m_options.show_scope) |
| 707 | s.PutCString(" ARG: "); |
| 708 | break; |
| 709 | |
| 710 | case eValueTypeVariableLocal: |
| 711 | dump_variable = m_options.show_locals; |
| 712 | if (dump_variable && m_options.show_scope) |
| 713 | s.PutCString(" LOCAL: "); |
| 714 | break; |
| 715 | |
| 716 | default: |
| 717 | break; |
| 718 | } |
| 719 | |
| 720 | if (dump_variable) |
| 721 | { |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 722 | |
| 723 | // Use the variable object code to make sure we are |
| 724 | // using the same APIs as the the public API will be |
| 725 | // using... |
| 726 | valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp); |
| 727 | if (valobj_sp) |
| 728 | { |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 729 | // When dumping all variables, don't print any variables |
| 730 | // that are not in scope to avoid extra unneeded output |
| 731 | if (valobj_sp->IsInScope (exe_ctx.frame)) |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 732 | { |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 733 | if (m_options.show_decl && var_sp->GetDeclaration ().GetFile()) |
| 734 | { |
| 735 | var_sp->GetDeclaration ().DumpStopContext (&s, false); |
| 736 | s.PutCString (": "); |
| 737 | } |
| 738 | DumpValueObject (result, |
| 739 | exe_ctx.frame, |
| 740 | valobj_sp.get(), |
| 741 | name_cstr, |
| 742 | m_options.ptr_depth, |
| 743 | 0, |
| 744 | m_options.max_depth, |
| 745 | m_options.use_objc, |
| 746 | true); |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 747 | |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame^] | 748 | s.EOL(); |
| 749 | } |
Greg Clayton | c0cf52d | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 756 | } |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 757 | } |
| 758 | return result.Succeeded(); |
| 759 | } |
| 760 | protected: |
| 761 | |
| 762 | CommandOptions m_options; |
| 763 | }; |
| 764 | |
| 765 | lldb::OptionDefinition |
| 766 | CommandObjectFrameVariable::CommandOptions::g_option_table[] = |
| 767 | { |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 768 | { LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, NULL, "Enable verbose debug information."}, |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 769 | { LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, "<count>", "Set the max recurse depth when dumping aggregate types (default is infinity)."}, |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 770 | { LLDB_OPT_SET_1, false, "show-globals",'g', no_argument, NULL, 0, NULL, "Show the current frame source file global and static variables."}, |
| 771 | { LLDB_OPT_SET_1, false, "find-global",'G', required_argument, NULL, 0, NULL, "Find a global variable by name (which might not be in the current stack frame source file)."}, |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 772 | { LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, NULL, "Show variable location information."}, |
Greg Clayton | aed5881 | 2010-09-13 02:37:44 +0000 | [diff] [blame] | 773 | { LLDB_OPT_SET_1, false, "show-declaration", 'c', no_argument, NULL, 0, NULL, "Show variable declaration information (source file and line where the variable was declared)."}, |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 774 | { LLDB_OPT_SET_1, false, "name", 'n', required_argument, NULL, 0, "<name>", "Lookup a variable by name or regex (--regex) for the current execution context."}, |
| 775 | { LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, NULL, "Omit function arguments."}, |
| 776 | { LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, NULL, "Omit local variables."}, |
| 777 | { LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, NULL, "Omit variable type names."}, |
| 778 | { LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, NULL, "Omit summary information."}, |
| 779 | { LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, NULL, "Show variable scope (argument, local, global, static)."}, |
| 780 | { LLDB_OPT_SET_1, false, "objc", 'o', no_argument, NULL, 0, NULL, "When looking up a variable by name (--name), print as an Objective-C object."}, |
| 781 | { LLDB_OPT_SET_1, false, "ptr-depth", 'p', required_argument, NULL, 0, "<count>", "The number of pointers to be traversed when dumping values (default is zero)."}, |
| 782 | { LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."}, |
| 783 | { 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL } |
| 784 | }; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 785 | #pragma mark CommandObjectMultiwordFrame |
| 786 | |
| 787 | //------------------------------------------------------------------------- |
| 788 | // CommandObjectMultiwordFrame |
| 789 | //------------------------------------------------------------------------- |
| 790 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 791 | CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) : |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 792 | CommandObjectMultiword ("frame", |
| 793 | "A set of commands for operating on the current thread's frames.", |
| 794 | "frame <subcommand> [<subcommand-options>]") |
| 795 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 796 | LoadSubCommand (interpreter, "info", CommandObjectSP (new CommandObjectFrameInfo ())); |
| 797 | LoadSubCommand (interpreter, "select", CommandObjectSP (new CommandObjectFrameSelect ())); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 798 | LoadSubCommand (interpreter, "variable", CommandObjectSP (new CommandObjectFrameVariable ())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame () |
| 802 | { |
| 803 | } |
| 804 | |