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