1 //===-- SBFrame.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 "lldb/API/SBFrame.h" 11 12 #include <string> 13 #include <algorithm> 14 15 #include "lldb/lldb-types.h" 16 17 #include "lldb/Core/Address.h" 18 #include "lldb/Core/ConstString.h" 19 #include "lldb/Core/Log.h" 20 #include "lldb/Core/Stream.h" 21 #include "lldb/Core/StreamFile.h" 22 #include "lldb/Core/ValueObjectRegister.h" 23 #include "lldb/Core/ValueObjectVariable.h" 24 #include "lldb/Expression/ClangUserExpression.h" 25 #include "lldb/Host/Host.h" 26 #include "lldb/Symbol/Block.h" 27 #include "lldb/Symbol/Function.h" 28 #include "lldb/Symbol/Symbol.h" 29 #include "lldb/Symbol/SymbolContext.h" 30 #include "lldb/Symbol/VariableList.h" 31 #include "lldb/Symbol/Variable.h" 32 #include "lldb/Target/ExecutionContext.h" 33 #include "lldb/Target/Target.h" 34 #include "lldb/Target/Process.h" 35 #include "lldb/Target/RegisterContext.h" 36 #include "lldb/Target/StackFrame.h" 37 #include "lldb/Target/StackID.h" 38 #include "lldb/Target/Thread.h" 39 40 #include "lldb/API/SBDebugger.h" 41 #include "lldb/API/SBValue.h" 42 #include "lldb/API/SBAddress.h" 43 #include "lldb/API/SBStream.h" 44 #include "lldb/API/SBSymbolContext.h" 45 #include "lldb/API/SBThread.h" 46 47 using namespace lldb; 48 using namespace lldb_private; 49 50 51 SBFrame::SBFrame () : 52 m_opaque_sp (new ExecutionContextRef()) 53 { 54 } 55 56 SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) : 57 m_opaque_sp (new ExecutionContextRef (lldb_object_sp)) 58 { 59 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 60 61 if (log) 62 { 63 SBStream sstr; 64 GetDescription (sstr); 65 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s", 66 lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData()); 67 68 } 69 } 70 71 SBFrame::SBFrame(const SBFrame &rhs) : 72 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp)) 73 { 74 } 75 76 const SBFrame & 77 SBFrame::operator = (const SBFrame &rhs) 78 { 79 if (this != &rhs) 80 *m_opaque_sp = *rhs.m_opaque_sp; 81 return *this; 82 } 83 84 SBFrame::~SBFrame() 85 { 86 } 87 88 StackFrameSP 89 SBFrame::GetFrameSP() const 90 { 91 if (m_opaque_sp) 92 return m_opaque_sp->GetFrameSP(); 93 return StackFrameSP(); 94 } 95 96 void 97 SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp) 98 { 99 return m_opaque_sp->SetFrameSP(lldb_object_sp); 100 } 101 102 bool 103 SBFrame::IsValid() const 104 { 105 return GetFrameSP().get() != NULL; 106 } 107 108 SBSymbolContext 109 SBFrame::GetSymbolContext (uint32_t resolve_scope) const 110 { 111 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 112 SBSymbolContext sb_sym_ctx; 113 Mutex::Locker api_locker; 114 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 115 116 StackFrame *frame = exe_ctx.GetFramePtr(); 117 Target *target = exe_ctx.GetTargetPtr(); 118 if (frame && target) 119 { 120 Process::StopLocker stop_locker; 121 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 122 { 123 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope)); 124 } 125 else 126 { 127 if (log) 128 log->Printf ("SBFrame(%p)::GetSymbolContext () => error: process is running", frame); 129 } 130 } 131 132 if (log) 133 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)", 134 frame, resolve_scope, sb_sym_ctx.get()); 135 136 return sb_sym_ctx; 137 } 138 139 SBModule 140 SBFrame::GetModule () const 141 { 142 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 143 SBModule sb_module; 144 ModuleSP module_sp; 145 Mutex::Locker api_locker; 146 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 147 148 StackFrame *frame = exe_ctx.GetFramePtr(); 149 Target *target = exe_ctx.GetTargetPtr(); 150 if (frame && target) 151 { 152 Process::StopLocker stop_locker; 153 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 154 { 155 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp; 156 sb_module.SetSP (module_sp); 157 } 158 else 159 { 160 if (log) 161 log->Printf ("SBFrame(%p)::GetModule () => error: process is running", frame); 162 } 163 } 164 165 if (log) 166 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", 167 frame, module_sp.get()); 168 169 return sb_module; 170 } 171 172 SBCompileUnit 173 SBFrame::GetCompileUnit () const 174 { 175 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 176 SBCompileUnit sb_comp_unit; 177 Mutex::Locker api_locker; 178 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 179 180 StackFrame *frame = exe_ctx.GetFramePtr(); 181 Target *target = exe_ctx.GetTargetPtr(); 182 if (frame && target) 183 { 184 Process::StopLocker stop_locker; 185 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 186 { 187 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit); 188 } 189 else 190 { 191 if (log) 192 log->Printf ("SBFrame(%p)::GetCompileUnit () => error: process is running", frame); 193 } 194 } 195 if (log) 196 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)", 197 frame, sb_comp_unit.get()); 198 199 return sb_comp_unit; 200 } 201 202 SBFunction 203 SBFrame::GetFunction () const 204 { 205 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 206 SBFunction sb_function; 207 Mutex::Locker api_locker; 208 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 209 210 StackFrame *frame = exe_ctx.GetFramePtr(); 211 Target *target = exe_ctx.GetTargetPtr(); 212 if (frame && target) 213 { 214 Process::StopLocker stop_locker; 215 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 216 { 217 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function); 218 } 219 else 220 { 221 if (log) 222 log->Printf ("SBFrame(%p)::GetFunction () => error: process is running", frame); 223 } 224 } 225 if (log) 226 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", 227 frame, sb_function.get()); 228 229 return sb_function; 230 } 231 232 SBSymbol 233 SBFrame::GetSymbol () const 234 { 235 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 236 SBSymbol sb_symbol; 237 Mutex::Locker api_locker; 238 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 239 240 StackFrame *frame = exe_ctx.GetFramePtr(); 241 Target *target = exe_ctx.GetTargetPtr(); 242 if (frame && target) 243 { 244 Process::StopLocker stop_locker; 245 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 246 { 247 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol); 248 } 249 else 250 { 251 if (log) 252 log->Printf ("SBFrame(%p)::GetSymbol () => error: process is running", frame); 253 } 254 } 255 if (log) 256 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", 257 frame, sb_symbol.get()); 258 return sb_symbol; 259 } 260 261 SBBlock 262 SBFrame::GetBlock () const 263 { 264 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 265 SBBlock sb_block; 266 Mutex::Locker api_locker; 267 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 268 269 StackFrame *frame = exe_ctx.GetFramePtr(); 270 Target *target = exe_ctx.GetTargetPtr(); 271 if (frame && target) 272 { 273 Process::StopLocker stop_locker; 274 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 275 { 276 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block); 277 } 278 else 279 { 280 if (log) 281 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running", frame); 282 } 283 } 284 if (log) 285 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", 286 frame, sb_block.GetPtr()); 287 return sb_block; 288 } 289 290 SBBlock 291 SBFrame::GetFrameBlock () const 292 { 293 SBBlock sb_block; 294 Mutex::Locker api_locker; 295 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 296 297 StackFrame *frame = exe_ctx.GetFramePtr(); 298 Target *target = exe_ctx.GetTargetPtr(); 299 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 300 if (frame && target) 301 { 302 Process::StopLocker stop_locker; 303 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 304 { 305 sb_block.SetPtr(frame->GetFrameBlock ()); 306 } 307 else 308 { 309 if (log) 310 log->Printf ("SBFrame(%p)::GetFrameBlock () => error: process is running", frame); 311 } 312 } 313 if (log) 314 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", 315 frame, sb_block.GetPtr()); 316 return sb_block; 317 } 318 319 SBLineEntry 320 SBFrame::GetLineEntry () const 321 { 322 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 323 SBLineEntry sb_line_entry; 324 Mutex::Locker api_locker; 325 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 326 327 StackFrame *frame = exe_ctx.GetFramePtr(); 328 Target *target = exe_ctx.GetTargetPtr(); 329 if (frame && target) 330 { 331 Process::StopLocker stop_locker; 332 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 333 { 334 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry); 335 } 336 else 337 { 338 if (log) 339 log->Printf ("SBFrame(%p)::GetLineEntry () => error: process is running", frame); 340 } 341 } 342 if (log) 343 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", 344 frame, sb_line_entry.get()); 345 return sb_line_entry; 346 } 347 348 uint32_t 349 SBFrame::GetFrameID () const 350 { 351 uint32_t frame_idx = UINT32_MAX; 352 353 ExecutionContext exe_ctx(m_opaque_sp.get()); 354 StackFrame *frame = exe_ctx.GetFramePtr(); 355 if (frame) 356 frame_idx = frame->GetFrameIndex (); 357 358 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 359 if (log) 360 log->Printf ("SBFrame(%p)::GetFrameID () => %u", 361 frame, frame_idx); 362 return frame_idx; 363 } 364 365 addr_t 366 SBFrame::GetPC () const 367 { 368 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 369 addr_t addr = LLDB_INVALID_ADDRESS; 370 Mutex::Locker api_locker; 371 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 372 373 StackFrame *frame = exe_ctx.GetFramePtr(); 374 Target *target = exe_ctx.GetTargetPtr(); 375 if (frame && target) 376 { 377 Process::StopLocker stop_locker; 378 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 379 { 380 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target); 381 } 382 else 383 { 384 if (log) 385 log->Printf ("SBFrame(%p)::GetPC () => error: process is running", frame); 386 } 387 } 388 389 if (log) 390 log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame, addr); 391 392 return addr; 393 } 394 395 bool 396 SBFrame::SetPC (addr_t new_pc) 397 { 398 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 399 bool ret_val = false; 400 Mutex::Locker api_locker; 401 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 402 403 StackFrame *frame = exe_ctx.GetFramePtr(); 404 Target *target = exe_ctx.GetTargetPtr(); 405 if (frame && target) 406 { 407 Process::StopLocker stop_locker; 408 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 409 { 410 ret_val = frame->GetRegisterContext()->SetPC (new_pc); 411 } 412 else 413 { 414 if (log) 415 log->Printf ("SBFrame(%p)::SetPC () => error: process is running", frame); 416 } 417 } 418 419 if (log) 420 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i", 421 frame, new_pc, ret_val); 422 423 return ret_val; 424 } 425 426 addr_t 427 SBFrame::GetSP () const 428 { 429 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 430 addr_t addr = LLDB_INVALID_ADDRESS; 431 Mutex::Locker api_locker; 432 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 433 434 StackFrame *frame = exe_ctx.GetFramePtr(); 435 Target *target = exe_ctx.GetTargetPtr(); 436 if (frame && target) 437 { 438 Process::StopLocker stop_locker; 439 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 440 { 441 addr = frame->GetRegisterContext()->GetSP(); 442 } 443 else 444 { 445 if (log) 446 log->Printf ("SBFrame(%p)::GetSP () => error: process is running", frame); 447 } 448 } 449 if (log) 450 log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame, addr); 451 452 return addr; 453 } 454 455 456 addr_t 457 SBFrame::GetFP () const 458 { 459 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 460 addr_t addr = LLDB_INVALID_ADDRESS; 461 Mutex::Locker api_locker; 462 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 463 464 StackFrame *frame = exe_ctx.GetFramePtr(); 465 Target *target = exe_ctx.GetTargetPtr(); 466 if (frame && target) 467 { 468 Process::StopLocker stop_locker; 469 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 470 { 471 addr = frame->GetRegisterContext()->GetFP(); 472 } 473 else 474 { 475 if (log) 476 log->Printf ("SBFrame(%p)::GetFP () => error: process is running", frame); 477 } 478 } 479 480 if (log) 481 log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame, addr); 482 return addr; 483 } 484 485 486 SBAddress 487 SBFrame::GetPCAddress () const 488 { 489 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 490 SBAddress sb_addr; 491 Mutex::Locker api_locker; 492 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 493 494 StackFrame *frame = exe_ctx.GetFramePtr(); 495 Target *target = exe_ctx.GetTargetPtr(); 496 if (frame && target) 497 { 498 Process::StopLocker stop_locker; 499 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 500 { 501 sb_addr.SetAddress (&frame->GetFrameCodeAddress()); 502 } 503 else 504 { 505 if (log) 506 log->Printf ("SBFrame(%p)::GetPCAddress () => error: process is running", frame); 507 } 508 } 509 if (log) 510 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get()); 511 return sb_addr; 512 } 513 514 void 515 SBFrame::Clear() 516 { 517 m_opaque_sp->Clear(); 518 } 519 520 lldb::SBValue 521 SBFrame::GetValueForVariablePath (const char *var_path) 522 { 523 SBValue sb_value; 524 ExecutionContext exe_ctx(m_opaque_sp.get()); 525 StackFrame *frame = exe_ctx.GetFramePtr(); 526 Target *target = exe_ctx.GetTargetPtr(); 527 if (frame && target) 528 { 529 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 530 sb_value = GetValueForVariablePath (var_path, use_dynamic); 531 } 532 return sb_value; 533 } 534 535 lldb::SBValue 536 SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic) 537 { 538 SBValue sb_value; 539 Mutex::Locker api_locker; 540 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 541 542 StackFrame *frame = exe_ctx.GetFramePtr(); 543 Target *target = exe_ctx.GetTargetPtr(); 544 if (frame && target && var_path && var_path[0]) 545 { 546 Process::StopLocker stop_locker; 547 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 548 { 549 VariableSP var_sp; 550 Error error; 551 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path, 552 use_dynamic, 553 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess, 554 var_sp, 555 error)); 556 sb_value.SetSP(value_sp); 557 } 558 else 559 { 560 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 561 if (log) 562 log->Printf ("SBFrame(%p)::GetValueForVariablePath () => error: process is running", frame); 563 } 564 } 565 return sb_value; 566 } 567 568 SBValue 569 SBFrame::FindVariable (const char *name) 570 { 571 SBValue value; 572 ExecutionContext exe_ctx(m_opaque_sp.get()); 573 StackFrame *frame = exe_ctx.GetFramePtr(); 574 Target *target = exe_ctx.GetTargetPtr(); 575 if (frame && target) 576 { 577 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 578 value = FindVariable (name, use_dynamic); 579 } 580 return value; 581 } 582 583 584 SBValue 585 SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) 586 { 587 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 588 VariableSP var_sp; 589 SBValue sb_value; 590 ValueObjectSP value_sp; 591 Mutex::Locker api_locker; 592 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 593 594 StackFrame *frame = exe_ctx.GetFramePtr(); 595 Target *target = exe_ctx.GetTargetPtr(); 596 if (frame && target && name && name[0]) 597 { 598 Process::StopLocker stop_locker; 599 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 600 { 601 VariableList variable_list; 602 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); 603 604 if (sc.block) 605 { 606 const bool can_create = true; 607 const bool get_parent_variables = true; 608 const bool stop_if_block_is_inlined_function = true; 609 610 if (sc.block->AppendVariables (can_create, 611 get_parent_variables, 612 stop_if_block_is_inlined_function, 613 &variable_list)) 614 { 615 var_sp = variable_list.FindVariable (ConstString(name)); 616 } 617 } 618 619 if (var_sp) 620 { 621 value_sp = frame->GetValueObjectForFrameVariable(var_sp, use_dynamic); 622 sb_value.SetSP(value_sp); 623 } 624 } 625 else 626 { 627 if (log) 628 log->Printf ("SBFrame(%p)::FindVariable () => error: process is running", frame); 629 } 630 } 631 632 if (log) 633 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", 634 frame, name, value_sp.get()); 635 636 return sb_value; 637 } 638 639 SBValue 640 SBFrame::FindValue (const char *name, ValueType value_type) 641 { 642 SBValue value; 643 ExecutionContext exe_ctx(m_opaque_sp.get()); 644 StackFrame *frame = exe_ctx.GetFramePtr(); 645 Target *target = exe_ctx.GetTargetPtr(); 646 if (frame && target) 647 { 648 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 649 value = FindValue (name, value_type, use_dynamic); 650 } 651 return value; 652 } 653 654 SBValue 655 SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic) 656 { 657 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 658 SBValue sb_value; 659 ValueObjectSP value_sp; 660 Mutex::Locker api_locker; 661 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 662 663 StackFrame *frame = exe_ctx.GetFramePtr(); 664 Target *target = exe_ctx.GetTargetPtr(); 665 if (frame && target && name && name[0]) 666 { 667 Process::StopLocker stop_locker; 668 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 669 { 670 switch (value_type) 671 { 672 case eValueTypeVariableGlobal: // global variable 673 case eValueTypeVariableStatic: // static variable 674 case eValueTypeVariableArgument: // function argument variables 675 case eValueTypeVariableLocal: // function local variables 676 { 677 VariableList *variable_list = frame->GetVariableList(true); 678 679 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); 680 681 const bool can_create = true; 682 const bool get_parent_variables = true; 683 const bool stop_if_block_is_inlined_function = true; 684 685 if (sc.block && sc.block->AppendVariables (can_create, 686 get_parent_variables, 687 stop_if_block_is_inlined_function, 688 variable_list)) 689 { 690 ConstString const_name(name); 691 const uint32_t num_variables = variable_list->GetSize(); 692 for (uint32_t i = 0; i < num_variables; ++i) 693 { 694 VariableSP variable_sp (variable_list->GetVariableAtIndex(i)); 695 if (variable_sp && 696 variable_sp->GetScope() == value_type && 697 variable_sp->GetName() == const_name) 698 { 699 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic); 700 sb_value.SetSP (value_sp); 701 break; 702 } 703 } 704 } 705 } 706 break; 707 708 case eValueTypeRegister: // stack frame register value 709 { 710 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 711 if (reg_ctx) 712 { 713 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 714 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 715 { 716 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 717 if (reg_info && 718 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 719 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 720 { 721 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 722 sb_value.SetSP (value_sp); 723 break; 724 } 725 } 726 } 727 } 728 break; 729 730 case eValueTypeRegisterSet: // A collection of stack frame register values 731 { 732 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 733 if (reg_ctx) 734 { 735 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 736 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 737 { 738 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx); 739 if (reg_set && 740 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || 741 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) 742 { 743 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx); 744 sb_value.SetSP (value_sp); 745 break; 746 } 747 } 748 } 749 } 750 break; 751 752 case eValueTypeConstResult: // constant result variables 753 { 754 ConstString const_name(name); 755 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name)); 756 if (expr_var_sp) 757 { 758 value_sp = expr_var_sp->GetValueObject(); 759 sb_value.SetSP (value_sp); 760 } 761 } 762 break; 763 764 default: 765 break; 766 } 767 } 768 else 769 { 770 if (log) 771 log->Printf ("SBFrame(%p)::FindValue () => error: process is running", frame); 772 } 773 } 774 775 if (log) 776 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", 777 frame, name, value_type, value_sp.get()); 778 779 780 return sb_value; 781 } 782 783 bool 784 SBFrame::IsEqual (const SBFrame &that) const 785 { 786 lldb::StackFrameSP this_sp = GetFrameSP(); 787 lldb::StackFrameSP that_sp = that.GetFrameSP(); 788 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID()); 789 } 790 791 bool 792 SBFrame::operator == (const SBFrame &rhs) const 793 { 794 return IsEqual(rhs); 795 } 796 797 bool 798 SBFrame::operator != (const SBFrame &rhs) const 799 { 800 return !IsEqual(rhs); 801 } 802 803 SBThread 804 SBFrame::GetThread () const 805 { 806 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 807 808 ExecutionContext exe_ctx(m_opaque_sp.get()); 809 ThreadSP thread_sp (exe_ctx.GetThreadSP()); 810 SBThread sb_thread (thread_sp); 811 812 if (log) 813 { 814 SBStream sstr; 815 sb_thread.GetDescription (sstr); 816 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", 817 exe_ctx.GetFramePtr(), 818 thread_sp.get(), 819 sstr.GetData()); 820 } 821 822 return sb_thread; 823 } 824 825 const char * 826 SBFrame::Disassemble () const 827 { 828 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 829 const char *disassembly = NULL; 830 Mutex::Locker api_locker; 831 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 832 833 StackFrame *frame = exe_ctx.GetFramePtr(); 834 Target *target = exe_ctx.GetTargetPtr(); 835 if (frame && target) 836 { 837 Process::StopLocker stop_locker; 838 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 839 { 840 disassembly = frame->Disassemble(); 841 } 842 else 843 { 844 if (log) 845 log->Printf ("SBFrame(%p)::Disassemble () => error: process is running", frame); 846 } 847 } 848 849 if (log) 850 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly); 851 852 return disassembly; 853 } 854 855 856 SBValueList 857 SBFrame::GetVariables (bool arguments, 858 bool locals, 859 bool statics, 860 bool in_scope_only) 861 { 862 SBValueList value_list; 863 ExecutionContext exe_ctx(m_opaque_sp.get()); 864 StackFrame *frame = exe_ctx.GetFramePtr(); 865 Target *target = exe_ctx.GetTargetPtr(); 866 if (frame && target) 867 { 868 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 869 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic); 870 } 871 return value_list; 872 } 873 874 SBValueList 875 SBFrame::GetVariables (bool arguments, 876 bool locals, 877 bool statics, 878 bool in_scope_only, 879 lldb::DynamicValueType use_dynamic) 880 { 881 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 882 883 SBValueList value_list; 884 Mutex::Locker api_locker; 885 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 886 887 StackFrame *frame = exe_ctx.GetFramePtr(); 888 Target *target = exe_ctx.GetTargetPtr(); 889 890 if (log) 891 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)", 892 frame, 893 arguments, 894 locals, 895 statics, 896 in_scope_only); 897 898 if (frame && target) 899 { 900 Process::StopLocker stop_locker; 901 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 902 { 903 904 size_t i; 905 VariableList *variable_list = NULL; 906 variable_list = frame->GetVariableList(true); 907 if (variable_list) 908 { 909 const size_t num_variables = variable_list->GetSize(); 910 if (num_variables) 911 { 912 for (i = 0; i < num_variables; ++i) 913 { 914 VariableSP variable_sp (variable_list->GetVariableAtIndex(i)); 915 if (variable_sp) 916 { 917 bool add_variable = false; 918 switch (variable_sp->GetScope()) 919 { 920 case eValueTypeVariableGlobal: 921 case eValueTypeVariableStatic: 922 add_variable = statics; 923 break; 924 925 case eValueTypeVariableArgument: 926 add_variable = arguments; 927 break; 928 929 case eValueTypeVariableLocal: 930 add_variable = locals; 931 break; 932 933 default: 934 break; 935 } 936 if (add_variable) 937 { 938 if (in_scope_only && !variable_sp->IsInScope(frame)) 939 continue; 940 941 value_list.Append(frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic)); 942 } 943 } 944 } 945 } 946 } 947 } 948 else 949 { 950 if (log) 951 log->Printf ("SBFrame(%p)::GetVariables () => error: process is running", frame); 952 } 953 } 954 955 if (log) 956 { 957 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame, 958 value_list.get()); 959 } 960 961 return value_list; 962 } 963 964 SBValueList 965 SBFrame::GetRegisters () 966 { 967 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 968 969 SBValueList value_list; 970 Mutex::Locker api_locker; 971 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 972 973 StackFrame *frame = exe_ctx.GetFramePtr(); 974 Target *target = exe_ctx.GetTargetPtr(); 975 if (frame && target) 976 { 977 Process::StopLocker stop_locker; 978 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 979 { 980 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 981 if (reg_ctx) 982 { 983 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 984 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 985 { 986 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx)); 987 } 988 } 989 } 990 else 991 { 992 if (log) 993 log->Printf ("SBFrame(%p)::GetRegisters () => error: process is running", frame); 994 } 995 } 996 997 if (log) 998 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", frame, value_list.get()); 999 1000 return value_list; 1001 } 1002 1003 bool 1004 SBFrame::GetDescription (SBStream &description) 1005 { 1006 Stream &strm = description.ref(); 1007 1008 Mutex::Locker api_locker; 1009 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1010 1011 StackFrame *frame = exe_ctx.GetFramePtr(); 1012 Target *target = exe_ctx.GetTargetPtr(); 1013 if (frame && target) 1014 { 1015 Process::StopLocker stop_locker; 1016 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 1017 { 1018 frame->DumpUsingSettingsFormat (&strm); 1019 } 1020 else 1021 { 1022 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1023 if (log) 1024 log->Printf ("SBFrame(%p)::GetDescription () => error: process is running", frame); 1025 } 1026 1027 } 1028 else 1029 strm.PutCString ("No value"); 1030 1031 return true; 1032 } 1033 1034 SBValue 1035 SBFrame::EvaluateExpression (const char *expr) 1036 { 1037 SBValue result; 1038 ExecutionContext exe_ctx(m_opaque_sp.get()); 1039 StackFrame *frame = exe_ctx.GetFramePtr(); 1040 Target *target = exe_ctx.GetTargetPtr(); 1041 if (frame && target) 1042 { 1043 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 1044 result = EvaluateExpression (expr, use_dynamic); 1045 } 1046 return result; 1047 } 1048 1049 SBValue 1050 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value) 1051 { 1052 return EvaluateExpression (expr, fetch_dynamic_value, true); 1053 } 1054 1055 SBValue 1056 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error) 1057 { 1058 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1059 1060 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 1061 1062 ExecutionResults exe_results = eExecutionSetupError; 1063 SBValue expr_result; 1064 ValueObjectSP expr_value_sp; 1065 1066 Mutex::Locker api_locker; 1067 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1068 1069 StackFrame *frame = exe_ctx.GetFramePtr(); 1070 Target *target = exe_ctx.GetTargetPtr(); 1071 if (log) 1072 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame, expr); 1073 1074 if (frame && target) 1075 { 1076 Process::StopLocker stop_locker; 1077 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 1078 { 1079 #ifdef LLDB_CONFIGURATION_DEBUG 1080 StreamString frame_description; 1081 frame->DumpUsingSettingsFormat (&frame_description); 1082 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", 1083 expr, fetch_dynamic_value, frame_description.GetString().c_str()); 1084 #endif 1085 Target::EvaluateExpressionOptions options; 1086 options.SetUnwindOnError(unwind_on_error) 1087 .SetUseDynamic(fetch_dynamic_value); 1088 1089 exe_results = target->EvaluateExpression (expr, 1090 frame, 1091 expr_value_sp, 1092 options); 1093 expr_result.SetSP(expr_value_sp); 1094 #ifdef LLDB_CONFIGURATION_DEBUG 1095 Host::SetCrashDescription (NULL); 1096 #endif 1097 } 1098 else 1099 { 1100 if (log) 1101 log->Printf ("SBFrame(%p)::EvaluateExpression () => error: process is running", frame); 1102 } 1103 } 1104 1105 #ifndef LLDB_DISABLE_PYTHON 1106 if (expr_log) 1107 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **", 1108 expr_result.GetValue(), 1109 expr_result.GetSummary()); 1110 1111 if (log) 1112 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", 1113 frame, 1114 expr, 1115 expr_value_sp.get(), 1116 exe_results); 1117 #endif 1118 1119 return expr_result; 1120 } 1121 1122 bool 1123 SBFrame::IsInlined() 1124 { 1125 ExecutionContext exe_ctx(m_opaque_sp.get()); 1126 StackFrame *frame = exe_ctx.GetFramePtr(); 1127 Target *target = exe_ctx.GetTargetPtr(); 1128 if (frame && target) 1129 { 1130 Process::StopLocker stop_locker; 1131 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 1132 { 1133 1134 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block; 1135 if (block) 1136 return block->GetContainingInlinedBlock () != NULL; 1137 } 1138 else 1139 { 1140 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1141 if (log) 1142 log->Printf ("SBFrame(%p)::IsInlined () => error: process is running", frame); 1143 } 1144 1145 } 1146 return false; 1147 } 1148 1149 const char * 1150 SBFrame::GetFunctionName() 1151 { 1152 const char *name = NULL; 1153 ExecutionContext exe_ctx(m_opaque_sp.get()); 1154 StackFrame *frame = exe_ctx.GetFramePtr(); 1155 Target *target = exe_ctx.GetTargetPtr(); 1156 if (frame && target) 1157 { 1158 Process::StopLocker stop_locker; 1159 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 1160 { 1161 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); 1162 if (sc.block) 1163 { 1164 Block *inlined_block = sc.block->GetContainingInlinedBlock (); 1165 if (inlined_block) 1166 { 1167 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo(); 1168 name = inlined_info->GetName().AsCString(); 1169 } 1170 } 1171 1172 if (name == NULL) 1173 { 1174 if (sc.function) 1175 name = sc.function->GetName().GetCString(); 1176 } 1177 1178 if (name == NULL) 1179 { 1180 if (sc.symbol) 1181 name = sc.symbol->GetName().GetCString(); 1182 } 1183 } 1184 else 1185 { 1186 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1187 if (log) 1188 log->Printf ("SBFrame(%p)::GetFunctionName() => error: process is running", frame); 1189 1190 } 1191 } 1192 return name; 1193 } 1194 1195