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; |
| 208 | case 'g': show_globals = false; break; |
| 209 | case 't': show_types = false; break; |
| 210 | case 'y': show_summary = false; break; |
| 211 | case 'L': show_location= true; break; |
| 212 | case 'D': debug = true; break; |
| 213 | case 'd': |
| 214 | max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success); |
| 215 | if (!success) |
| 216 | error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg); |
| 217 | break; |
| 218 | |
| 219 | case 'p': |
| 220 | ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success); |
| 221 | if (!success) |
| 222 | error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg); |
| 223 | break; |
| 224 | |
| 225 | case 'G': |
| 226 | { |
| 227 | ConstString const_string (option_arg); |
| 228 | globals.push_back(const_string); |
| 229 | } |
| 230 | break; |
| 231 | |
| 232 | case 's': |
| 233 | show_scope = true; |
| 234 | break; |
| 235 | |
| 236 | default: |
| 237 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 238 | break; |
| 239 | } |
| 240 | |
| 241 | return error; |
| 242 | } |
| 243 | |
| 244 | void |
| 245 | ResetOptionValues () |
| 246 | { |
| 247 | Options::ResetOptionValues(); |
| 248 | |
| 249 | name.clear(); |
| 250 | use_objc = false; |
| 251 | use_regex = false; |
| 252 | show_args = true; |
| 253 | show_locals = true; |
| 254 | show_globals = true; |
| 255 | show_types = true; |
| 256 | show_scope = false; |
| 257 | show_summary = true; |
| 258 | show_location = false; |
| 259 | debug = false; |
| 260 | max_depth = UINT32_MAX; |
| 261 | ptr_depth = 0; |
| 262 | globals.clear(); |
| 263 | } |
| 264 | |
| 265 | const lldb::OptionDefinition* |
| 266 | GetDefinitions () |
| 267 | { |
| 268 | return g_option_table; |
| 269 | } |
| 270 | |
| 271 | // Options table: Required for subclasses of Options. |
| 272 | |
| 273 | static lldb::OptionDefinition g_option_table[]; |
| 274 | std::string name; |
| 275 | bool use_objc; |
| 276 | bool use_regex; |
| 277 | bool show_args; |
| 278 | bool show_locals; |
| 279 | bool show_globals; |
| 280 | bool show_types; |
| 281 | bool show_scope; // local/arg/global/static |
| 282 | bool show_summary; |
| 283 | bool show_location; |
| 284 | bool debug; |
| 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 |
| 312 | DumpVariable (CommandReturnObject &result, ExecutionContext *exe_ctx, Variable *variable) |
| 313 | { |
| 314 | if (variable) |
| 315 | { |
| 316 | Stream &s = result.GetOutputStream(); |
| 317 | DWARFExpression &expr = variable->LocationExpression(); |
| 318 | Value expr_result; |
| 319 | Error expr_error; |
| 320 | Type *variable_type = variable->GetType(); |
| 321 | bool expr_success = expr.Evaluate(exe_ctx, NULL, NULL, expr_result, &expr_error); |
| 322 | |
| 323 | if (m_options.debug) |
| 324 | s.Printf ("Variable{0x%8.8x}: ", variable->GetID()); |
| 325 | |
| 326 | if (!expr_success) |
| 327 | s.Printf ("%s = ERROR: %s\n", variable->GetName().AsCString(NULL), expr_error.AsCString()); |
| 328 | else |
| 329 | { |
| 330 | Value::ValueType expr_value_type = expr_result.GetValueType(); |
| 331 | switch (expr_value_type) |
| 332 | { |
| 333 | case Value::eValueTypeScalar: |
| 334 | s.Printf ("%s = ", variable->GetName().AsCString(NULL)); |
| 335 | if (variable_type) |
| 336 | { |
| 337 | DataExtractor data; |
| 338 | if (expr_result.ResolveValue (exe_ctx, NULL).GetData (data)) |
| 339 | variable_type->DumpValue (exe_ctx, &s, data, 0, m_options.show_types, m_options.show_summary, m_options.debug); |
| 340 | } |
| 341 | break; |
| 342 | |
| 343 | case Value::eValueTypeFileAddress: |
| 344 | case Value::eValueTypeLoadAddress: |
| 345 | case Value::eValueTypeHostAddress: |
| 346 | { |
| 347 | s.Printf ("%s = ", variable->GetName().AsCString(NULL)); |
| 348 | lldb::addr_t addr = LLDB_INVALID_ADDRESS; |
| 349 | lldb::AddressType addr_type = eAddressTypeLoad; |
| 350 | |
| 351 | if (expr_value_type == Value::eValueTypeFileAddress) |
| 352 | { |
| 353 | lldb::addr_t file_addr = expr_result.ResolveValue (exe_ctx, NULL).ULongLong(LLDB_INVALID_ADDRESS); |
| 354 | SymbolContext var_sc; |
| 355 | variable->CalculateSymbolContext(&var_sc); |
| 356 | if (var_sc.module_sp) |
| 357 | { |
| 358 | ObjectFile *objfile = var_sc.module_sp->GetObjectFile(); |
| 359 | if (objfile) |
| 360 | { |
| 361 | Address so_addr(file_addr, objfile->GetSectionList()); |
| 362 | addr = so_addr.GetLoadAddress(exe_ctx->process); |
| 363 | } |
| 364 | if (addr == LLDB_INVALID_ADDRESS) |
| 365 | { |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 366 | result.GetErrorStream().Printf ("error: %s is not loaded\n", |
| 367 | var_sc.module_sp->GetFileSpec().GetFilename().AsCString()); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | else |
| 371 | { |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 372 | result.GetErrorStream().Printf ("error: unable to resolve the variable address 0x%llx\n", file_addr); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | else |
| 376 | { |
| 377 | if (expr_value_type == Value::eValueTypeHostAddress) |
| 378 | addr_type = eAddressTypeHost; |
| 379 | addr = expr_result.ResolveValue (exe_ctx, NULL).ULongLong(LLDB_INVALID_ADDRESS); |
| 380 | } |
| 381 | |
| 382 | if (addr != LLDB_INVALID_ADDRESS) |
| 383 | { |
| 384 | if (m_options.debug) |
| 385 | s.Printf("@ 0x%8.8llx, value = ", addr); |
| 386 | variable_type->DumpValueInMemory (exe_ctx, &s, addr, addr_type, m_options.show_types, m_options.show_summary, m_options.debug); |
| 387 | } |
| 388 | } |
| 389 | break; |
| 390 | } |
| 391 | s.EOL(); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | void |
| 397 | DumpValueObject (CommandReturnObject &result, |
| 398 | ExecutionContextScope *exe_scope, |
| 399 | ValueObject *valobj, |
| 400 | const char *root_valobj_name, |
| 401 | uint32_t ptr_depth, |
| 402 | uint32_t curr_depth, |
| 403 | uint32_t max_depth, |
| 404 | bool use_objc) |
| 405 | { |
| 406 | if (valobj) |
| 407 | { |
| 408 | Stream &s = result.GetOutputStream(); |
| 409 | |
| 410 | //const char *loc_cstr = valobj->GetLocationAsCString(); |
| 411 | if (m_options.show_location) |
| 412 | { |
| 413 | s.Printf("@ %s: ", valobj->GetLocationAsCString(exe_scope)); |
| 414 | } |
| 415 | if (m_options.debug) |
| 416 | s.Printf ("%p ValueObject{%u} ", valobj, valobj->GetID()); |
| 417 | |
| 418 | s.Indent(); |
| 419 | |
| 420 | if (m_options.show_types) |
| 421 | s.Printf("(%s) ", valobj->GetTypeName().AsCString()); |
| 422 | |
| 423 | const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString(""); |
| 424 | s.Printf ("%s = ", name_cstr); |
| 425 | |
| 426 | const char *val_cstr = valobj->GetValueAsCString(exe_scope); |
| 427 | const char *err_cstr = valobj->GetError().AsCString(); |
| 428 | |
| 429 | if (err_cstr) |
| 430 | { |
| 431 | s.Printf ("error: %s\n", err_cstr); |
| 432 | } |
| 433 | else |
| 434 | { |
| 435 | const char *sum_cstr = valobj->GetSummaryAsCString(exe_scope); |
| 436 | |
| 437 | const bool is_aggregate = ClangASTContext::IsAggregateType (valobj->GetOpaqueClangQualType()); |
| 438 | |
| 439 | if (val_cstr) |
| 440 | s.PutCString(val_cstr); |
| 441 | |
| 442 | if (sum_cstr) |
| 443 | s.Printf(" %s", sum_cstr); |
| 444 | |
| 445 | if (use_objc) |
| 446 | { |
Jim Ingham | 4ae5196 | 2010-09-10 23:12:17 +0000 | [diff] [blame^] | 447 | const char *object_desc = valobj->GetObjectDescription(exe_scope); |
| 448 | if (object_desc) |
| 449 | s.Printf("\n%s\n", object_desc); |
| 450 | else |
| 451 | s.Printf ("No description available.\n"); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 452 | return; |
| 453 | } |
| 454 | |
| 455 | |
| 456 | if (curr_depth < max_depth) |
| 457 | { |
| 458 | if (is_aggregate) |
| 459 | s.PutChar('{'); |
| 460 | |
| 461 | bool is_ptr_or_ref = ClangASTContext::IsPointerOrReferenceType (valobj->GetOpaqueClangQualType()); |
| 462 | |
| 463 | if (is_ptr_or_ref && ptr_depth == 0) |
| 464 | return; |
| 465 | |
| 466 | const uint32_t num_children = valobj->GetNumChildren(); |
| 467 | if (num_children) |
| 468 | { |
| 469 | s.IndentMore(); |
| 470 | for (uint32_t idx=0; idx<num_children; ++idx) |
| 471 | { |
| 472 | ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true)); |
| 473 | if (child_sp.get()) |
| 474 | { |
| 475 | s.EOL(); |
| 476 | DumpValueObject (result, |
| 477 | exe_scope, |
| 478 | child_sp.get(), |
| 479 | NULL, |
| 480 | is_ptr_or_ref ? ptr_depth - 1 : ptr_depth, |
| 481 | curr_depth + 1, |
| 482 | max_depth, |
| 483 | false); |
| 484 | if (idx + 1 < num_children) |
| 485 | s.PutChar(','); |
| 486 | } |
| 487 | } |
| 488 | s.IndentLess(); |
| 489 | } |
| 490 | if (is_aggregate) |
| 491 | { |
| 492 | s.EOL(); |
| 493 | s.Indent("}"); |
| 494 | } |
| 495 | } |
| 496 | else |
| 497 | { |
| 498 | if (is_aggregate) |
| 499 | { |
| 500 | s.PutCString("{...}"); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | virtual bool |
| 509 | Execute |
| 510 | ( |
| 511 | CommandInterpreter &interpreter, |
| 512 | Args& command, |
| 513 | CommandReturnObject &result |
| 514 | ) |
| 515 | { |
| 516 | ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext()); |
| 517 | if (exe_ctx.frame == NULL) |
| 518 | { |
| 519 | result.AppendError ("invalid frame"); |
| 520 | result.SetStatus (eReturnStatusFailed); |
| 521 | return false; |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | VariableList variable_list; |
| 526 | |
| 527 | bool show_inlined = true; // TODO: Get this from the process |
| 528 | SymbolContext frame_sc = exe_ctx.frame->GetSymbolContext (eSymbolContextEverything); |
| 529 | if (exe_ctx.frame && frame_sc.block) |
| 530 | frame_sc.block->AppendVariables(true, true, show_inlined, &variable_list); |
| 531 | VariableSP var_sp; |
| 532 | ValueObjectSP valobj_sp; |
| 533 | //ValueObjectList &valobj_list = exe_ctx.frame->GetValueObjectList(); |
| 534 | const char *name_cstr = NULL; |
| 535 | size_t idx; |
| 536 | if (!m_options.globals.empty()) |
| 537 | { |
| 538 | uint32_t fail_count = 0; |
| 539 | if (exe_ctx.target) |
| 540 | { |
| 541 | const size_t num_globals = m_options.globals.size(); |
| 542 | for (idx = 0; idx < num_globals; ++idx) |
| 543 | { |
| 544 | VariableList global_var_list; |
| 545 | const uint32_t num_matching_globals = exe_ctx.target->GetImages().FindGlobalVariables (m_options.globals[idx], true, UINT32_MAX, global_var_list); |
| 546 | |
| 547 | if (num_matching_globals == 0) |
| 548 | { |
| 549 | ++fail_count; |
| 550 | result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", m_options.globals[idx].AsCString()); |
| 551 | } |
| 552 | else |
| 553 | { |
| 554 | for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx) |
| 555 | { |
| 556 | var_sp = global_var_list.GetVariableAtIndex(global_idx); |
| 557 | if (var_sp) |
| 558 | { |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 559 | valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 560 | if (!valobj_sp) |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 561 | valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 562 | |
| 563 | if (valobj_sp) |
| 564 | { |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 565 | DumpValueObject (result, exe_ctx.frame, valobj_sp.get(), name_cstr, m_options.ptr_depth, 0, m_options.max_depth, false); |
| 566 | result.GetOutputStream().EOL(); |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | if (fail_count) |
| 574 | { |
| 575 | result.SetStatus (eReturnStatusFailed); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | if (command.GetArgumentCount() > 0) |
| 580 | { |
| 581 | // If we have any args to the variable command, we will make |
| 582 | // variable objects from them... |
| 583 | for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx) |
| 584 | { |
| 585 | uint32_t ptr_depth = m_options.ptr_depth; |
| 586 | // If first character is a '*', then show pointer contents |
| 587 | if (name_cstr[0] == '*') |
| 588 | { |
| 589 | ++ptr_depth; |
| 590 | name_cstr++; // Skip the '*' |
| 591 | } |
| 592 | |
| 593 | std::string var_path (name_cstr); |
| 594 | size_t separator_idx = var_path.find_first_of(".-["); |
| 595 | |
| 596 | ConstString name_const_string; |
| 597 | if (separator_idx == std::string::npos) |
| 598 | name_const_string.SetCString (var_path.c_str()); |
| 599 | else |
| 600 | name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); |
| 601 | |
| 602 | var_sp = variable_list.FindVariable(name_const_string); |
| 603 | if (var_sp) |
| 604 | { |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 605 | valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 606 | |
| 607 | var_path.erase (0, name_const_string.GetLength ()); |
| 608 | // We are dumping at least one child |
| 609 | while (separator_idx != std::string::npos) |
| 610 | { |
| 611 | // Calculate the next separator index ahead of time |
| 612 | ValueObjectSP child_valobj_sp; |
| 613 | const char separator_type = var_path[0]; |
| 614 | switch (separator_type) |
| 615 | { |
| 616 | |
| 617 | case '-': |
| 618 | if (var_path.size() >= 2 && var_path[1] != '>') |
| 619 | { |
| 620 | result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n", |
| 621 | var_path.c_str()); |
| 622 | var_path.clear(); |
| 623 | valobj_sp.reset(); |
| 624 | break; |
| 625 | } |
| 626 | var_path.erase (0, 1); // Remove the '-' |
| 627 | // Fall through |
| 628 | case '.': |
| 629 | { |
| 630 | var_path.erase (0, 1); // Remove the '.' or '>' |
| 631 | separator_idx = var_path.find_first_of(".-["); |
| 632 | ConstString child_name; |
| 633 | if (separator_idx == std::string::npos) |
| 634 | child_name.SetCString (var_path.c_str()); |
| 635 | else |
| 636 | child_name.SetCStringWithLength(var_path.c_str(), separator_idx); |
| 637 | |
| 638 | child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); |
| 639 | if (!child_valobj_sp) |
| 640 | { |
| 641 | result.GetErrorStream().Printf ("error: can't find child of '%s' named '%s'\n", |
| 642 | valobj_sp->GetName().AsCString(), |
| 643 | child_name.GetCString()); |
| 644 | var_path.clear(); |
| 645 | valobj_sp.reset(); |
| 646 | break; |
| 647 | } |
| 648 | // Remove the child name from the path |
| 649 | var_path.erase(0, child_name.GetLength()); |
| 650 | } |
| 651 | break; |
| 652 | |
| 653 | case '[': |
| 654 | // Array member access, or treating pointer as an array |
| 655 | if (var_path.size() > 2) // Need at least two brackets and a number |
| 656 | { |
| 657 | char *end = NULL; |
| 658 | int32_t child_index = ::strtol (&var_path[1], &end, 0); |
| 659 | if (end && *end == ']') |
| 660 | { |
| 661 | |
| 662 | if (valobj_sp->IsPointerType ()) |
| 663 | { |
| 664 | child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true); |
| 665 | } |
| 666 | else |
| 667 | { |
| 668 | child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); |
| 669 | } |
| 670 | |
| 671 | if (!child_valobj_sp) |
| 672 | { |
| 673 | result.GetErrorStream().Printf ("error: invalid array index %u in '%s'\n", |
| 674 | child_index, |
| 675 | valobj_sp->GetName().AsCString()); |
| 676 | var_path.clear(); |
| 677 | valobj_sp.reset(); |
| 678 | break; |
| 679 | } |
| 680 | |
| 681 | // Erase the array member specification '[%i]' where %i is the array index |
| 682 | var_path.erase(0, (end - var_path.c_str()) + 1); |
| 683 | separator_idx = var_path.find_first_of(".-["); |
| 684 | |
| 685 | // Break out early from the switch since we were able to find the child member |
| 686 | break; |
| 687 | } |
| 688 | } |
| 689 | result.GetErrorStream().Printf ("error: invalid array member specification for '%s' starting at '%s'\n", |
| 690 | valobj_sp->GetName().AsCString(), |
| 691 | var_path.c_str()); |
| 692 | var_path.clear(); |
| 693 | valobj_sp.reset(); |
| 694 | break; |
| 695 | |
| 696 | break; |
| 697 | |
| 698 | default: |
| 699 | result.GetErrorStream().Printf ("error: invalid character in variable path starting at '%s'\n", |
| 700 | var_path.c_str()); |
| 701 | var_path.clear(); |
| 702 | valobj_sp.reset(); |
| 703 | separator_idx = std::string::npos; |
| 704 | break; |
| 705 | } |
| 706 | |
| 707 | if (child_valobj_sp) |
| 708 | valobj_sp = child_valobj_sp; |
| 709 | |
| 710 | if (var_path.empty()) |
| 711 | break; |
| 712 | |
| 713 | } |
| 714 | |
| 715 | if (valobj_sp) |
| 716 | { |
| 717 | DumpValueObject (result, exe_ctx.frame, valobj_sp.get(), name_cstr, ptr_depth, 0, m_options.max_depth, m_options.use_objc); |
| 718 | result.GetOutputStream().EOL(); |
| 719 | } |
| 720 | } |
| 721 | else |
| 722 | { |
| 723 | result.GetErrorStream().Printf ("error: unable to find any variables named '%s'\n", name_cstr); |
| 724 | var_path.clear(); |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | |
| 731 | if (m_options.show_globals) |
| 732 | { |
| 733 | if (frame_sc.comp_unit) |
| 734 | { |
| 735 | variable_list.AddVariables (frame_sc.comp_unit->GetVariableList(true).get()); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | const uint32_t num_variables = variable_list.GetSize(); |
| 740 | |
| 741 | if (num_variables > 0) |
| 742 | { |
| 743 | for (uint32_t i=0; i<num_variables; i++) |
| 744 | { |
| 745 | Variable *variable = variable_list.GetVariableAtIndex(i).get(); |
| 746 | bool dump_variable = true; |
| 747 | |
| 748 | switch (variable->GetScope()) |
| 749 | { |
| 750 | case eValueTypeVariableGlobal: |
| 751 | dump_variable = m_options.show_globals; |
| 752 | if (dump_variable && m_options.show_scope) |
| 753 | result.GetOutputStream().PutCString("GLOBAL: "); |
| 754 | break; |
| 755 | |
| 756 | case eValueTypeVariableStatic: |
| 757 | dump_variable = m_options.show_globals; |
| 758 | if (dump_variable && m_options.show_scope) |
| 759 | result.GetOutputStream().PutCString("STATIC: "); |
| 760 | break; |
| 761 | |
| 762 | case eValueTypeVariableArgument: |
| 763 | dump_variable = m_options.show_args; |
| 764 | if (dump_variable && m_options.show_scope) |
| 765 | result.GetOutputStream().PutCString(" ARG: "); |
| 766 | break; |
| 767 | |
| 768 | case eValueTypeVariableLocal: |
| 769 | dump_variable = m_options.show_locals; |
| 770 | if (dump_variable && m_options.show_scope) |
| 771 | result.GetOutputStream().PutCString(" LOCAL: "); |
| 772 | break; |
| 773 | |
| 774 | default: |
| 775 | break; |
| 776 | } |
| 777 | |
| 778 | if (dump_variable) |
| 779 | DumpVariable (result, &exe_ctx, variable); |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 784 | } |
| 785 | return result.Succeeded(); |
| 786 | } |
| 787 | protected: |
| 788 | |
| 789 | CommandOptions m_options; |
| 790 | }; |
| 791 | |
| 792 | lldb::OptionDefinition |
| 793 | CommandObjectFrameVariable::CommandOptions::g_option_table[] = |
| 794 | { |
| 795 | { LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, NULL, "Show verbose debug information."}, |
| 796 | { LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, "<count>", "Set the max recurse depth when dumping aggregate types (default is infinity)."}, |
| 797 | { LLDB_OPT_SET_1, false, "globals", 'g', no_argument, NULL, 0, NULL, "List global and static variables for the current stack frame source file."}, |
| 798 | { LLDB_OPT_SET_1, false, "global", 'G', required_argument, NULL, 0, NULL, "Find a global variable by name (which might not be in the current stack frame source file)."}, |
| 799 | { LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, NULL, "Show variable location information."}, |
| 800 | { 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."}, |
| 801 | { LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, NULL, "Omit function arguments."}, |
| 802 | { LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, NULL, "Omit local variables."}, |
| 803 | { LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, NULL, "Omit variable type names."}, |
| 804 | { LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, NULL, "Omit summary information."}, |
| 805 | { LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, NULL, "Show variable scope (argument, local, global, static)."}, |
| 806 | { 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."}, |
| 807 | { 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)."}, |
| 808 | { LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."}, |
| 809 | { 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL } |
| 810 | }; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | #pragma mark CommandObjectMultiwordFrame |
| 812 | |
| 813 | //------------------------------------------------------------------------- |
| 814 | // CommandObjectMultiwordFrame |
| 815 | //------------------------------------------------------------------------- |
| 816 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 817 | CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) : |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 818 | CommandObjectMultiword ("frame", |
| 819 | "A set of commands for operating on the current thread's frames.", |
| 820 | "frame <subcommand> [<subcommand-options>]") |
| 821 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 822 | LoadSubCommand (interpreter, "info", CommandObjectSP (new CommandObjectFrameInfo ())); |
| 823 | LoadSubCommand (interpreter, "select", CommandObjectSP (new CommandObjectFrameSelect ())); |
Jim Ingham | 537926c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 824 | LoadSubCommand (interpreter, "variable", CommandObjectSP (new CommandObjectFrameVariable ())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame () |
| 828 | { |
| 829 | } |
| 830 | |