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 // C Includes 11 // C++ Includes 12 #include <algorithm> 13 #include <set> 14 #include <string> 15 16 // Other libraries and framework includes 17 // Project includes 18 #include "lldb/API/SBFrame.h" 19 20 #include "lldb/lldb-types.h" 21 22 #include "lldb/Core/Address.h" 23 #include "lldb/Core/ConstString.h" 24 #include "lldb/Core/Log.h" 25 #include "lldb/Core/Stream.h" 26 #include "lldb/Core/StreamFile.h" 27 #include "lldb/Core/ValueObjectRegister.h" 28 #include "lldb/Core/ValueObjectVariable.h" 29 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" 30 #include "lldb/Expression/UserExpression.h" 31 #include "lldb/Host/Host.h" 32 #include "lldb/Symbol/Block.h" 33 #include "lldb/Symbol/Function.h" 34 #include "lldb/Symbol/Symbol.h" 35 #include "lldb/Symbol/SymbolContext.h" 36 #include "lldb/Symbol/VariableList.h" 37 #include "lldb/Symbol/Variable.h" 38 #include "lldb/Target/ExecutionContext.h" 39 #include "lldb/Target/Target.h" 40 #include "lldb/Target/Process.h" 41 #include "lldb/Target/RegisterContext.h" 42 #include "lldb/Target/StackFrame.h" 43 #include "lldb/Target/StackID.h" 44 #include "lldb/Target/Thread.h" 45 46 #include "lldb/API/SBDebugger.h" 47 #include "lldb/API/SBValue.h" 48 #include "lldb/API/SBAddress.h" 49 #include "lldb/API/SBExpressionOptions.h" 50 #include "lldb/API/SBStream.h" 51 #include "lldb/API/SBSymbolContext.h" 52 #include "lldb/API/SBThread.h" 53 #include "lldb/API/SBVariablesOptions.h" 54 55 using namespace lldb; 56 using namespace lldb_private; 57 58 SBFrame::SBFrame () : 59 m_opaque_sp (new ExecutionContextRef()) 60 { 61 } 62 63 SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) : 64 m_opaque_sp (new ExecutionContextRef (lldb_object_sp)) 65 { 66 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 67 68 if (log) 69 { 70 SBStream sstr; 71 GetDescription (sstr); 72 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s", 73 static_cast<void*>(lldb_object_sp.get()), 74 static_cast<void*>(lldb_object_sp.get()), sstr.GetData()); 75 } 76 } 77 78 SBFrame::SBFrame(const SBFrame &rhs) : 79 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp)) 80 { 81 } 82 83 SBFrame::~SBFrame() = default; 84 85 const SBFrame & 86 SBFrame::operator = (const SBFrame &rhs) 87 { 88 if (this != &rhs) 89 *m_opaque_sp = *rhs.m_opaque_sp; 90 return *this; 91 } 92 93 StackFrameSP 94 SBFrame::GetFrameSP() const 95 { 96 return (m_opaque_sp ? m_opaque_sp->GetFrameSP() : StackFrameSP()); 97 } 98 99 void 100 SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp) 101 { 102 return m_opaque_sp->SetFrameSP(lldb_object_sp); 103 } 104 105 bool 106 SBFrame::IsValid() const 107 { 108 std::unique_lock<std::recursive_mutex> lock; 109 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 110 111 Target *target = exe_ctx.GetTargetPtr(); 112 Process *process = exe_ctx.GetProcessPtr(); 113 if (target && process) 114 { 115 Process::StopLocker stop_locker; 116 if (stop_locker.TryLock(&process->GetRunLock())) 117 return GetFrameSP().get() != nullptr; 118 } 119 120 // Without a target & process we can't have a valid stack frame. 121 return false; 122 } 123 124 SBSymbolContext 125 SBFrame::GetSymbolContext (uint32_t resolve_scope) const 126 { 127 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 128 SBSymbolContext sb_sym_ctx; 129 std::unique_lock<std::recursive_mutex> lock; 130 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 131 132 StackFrame *frame = nullptr; 133 Target *target = exe_ctx.GetTargetPtr(); 134 Process *process = exe_ctx.GetProcessPtr(); 135 if (target && process) 136 { 137 Process::StopLocker stop_locker; 138 if (stop_locker.TryLock(&process->GetRunLock())) 139 { 140 frame = exe_ctx.GetFramePtr(); 141 if (frame) 142 { 143 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope)); 144 } 145 else 146 { 147 if (log) 148 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame."); 149 } 150 } 151 else 152 { 153 if (log) 154 log->Printf ("SBFrame::GetSymbolContext () => error: process is running"); 155 } 156 } 157 158 if (log) 159 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)", 160 static_cast<void*>(frame), resolve_scope, 161 static_cast<void*>(sb_sym_ctx.get())); 162 163 return sb_sym_ctx; 164 } 165 166 SBModule 167 SBFrame::GetModule () const 168 { 169 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 170 SBModule sb_module; 171 ModuleSP module_sp; 172 std::unique_lock<std::recursive_mutex> lock; 173 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 174 175 StackFrame *frame = nullptr; 176 Target *target = exe_ctx.GetTargetPtr(); 177 Process *process = exe_ctx.GetProcessPtr(); 178 if (target && process) 179 { 180 Process::StopLocker stop_locker; 181 if (stop_locker.TryLock(&process->GetRunLock())) 182 { 183 frame = exe_ctx.GetFramePtr(); 184 if (frame) 185 { 186 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp; 187 sb_module.SetSP (module_sp); 188 } 189 else 190 { 191 if (log) 192 log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame."); 193 } 194 } 195 else 196 { 197 if (log) 198 log->Printf ("SBFrame::GetModule () => error: process is running"); 199 } 200 } 201 202 if (log) 203 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", 204 static_cast<void*>(frame), 205 static_cast<void*>(module_sp.get())); 206 207 return sb_module; 208 } 209 210 SBCompileUnit 211 SBFrame::GetCompileUnit () const 212 { 213 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 214 SBCompileUnit sb_comp_unit; 215 std::unique_lock<std::recursive_mutex> lock; 216 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 217 218 StackFrame *frame = nullptr; 219 Target *target = exe_ctx.GetTargetPtr(); 220 Process *process = exe_ctx.GetProcessPtr(); 221 if (target && process) 222 { 223 Process::StopLocker stop_locker; 224 if (stop_locker.TryLock(&process->GetRunLock())) 225 { 226 frame = exe_ctx.GetFramePtr(); 227 if (frame) 228 { 229 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit); 230 } 231 else 232 { 233 if (log) 234 log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame."); 235 } 236 } 237 else 238 { 239 if (log) 240 log->Printf ("SBFrame::GetCompileUnit () => error: process is running"); 241 } 242 } 243 if (log) 244 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)", 245 static_cast<void*>(frame), 246 static_cast<void*>(sb_comp_unit.get())); 247 248 return sb_comp_unit; 249 } 250 251 SBFunction 252 SBFrame::GetFunction () const 253 { 254 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 255 SBFunction sb_function; 256 std::unique_lock<std::recursive_mutex> lock; 257 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 258 259 StackFrame *frame = nullptr; 260 Target *target = exe_ctx.GetTargetPtr(); 261 Process *process = exe_ctx.GetProcessPtr(); 262 if (target && process) 263 { 264 Process::StopLocker stop_locker; 265 if (stop_locker.TryLock(&process->GetRunLock())) 266 { 267 frame = exe_ctx.GetFramePtr(); 268 if (frame) 269 { 270 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function); 271 } 272 else 273 { 274 if (log) 275 log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame."); 276 } 277 } 278 else 279 { 280 if (log) 281 log->Printf ("SBFrame::GetFunction () => error: process is running"); 282 } 283 } 284 if (log) 285 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", 286 static_cast<void*>(frame), 287 static_cast<void*>(sb_function.get())); 288 289 return sb_function; 290 } 291 292 SBSymbol 293 SBFrame::GetSymbol () const 294 { 295 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 296 SBSymbol sb_symbol; 297 std::unique_lock<std::recursive_mutex> lock; 298 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 299 300 StackFrame *frame = nullptr; 301 Target *target = exe_ctx.GetTargetPtr(); 302 Process *process = exe_ctx.GetProcessPtr(); 303 if (target && process) 304 { 305 Process::StopLocker stop_locker; 306 if (stop_locker.TryLock(&process->GetRunLock())) 307 { 308 frame = exe_ctx.GetFramePtr(); 309 if (frame) 310 { 311 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol); 312 } 313 else 314 { 315 if (log) 316 log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame."); 317 } 318 } 319 else 320 { 321 if (log) 322 log->Printf ("SBFrame::GetSymbol () => error: process is running"); 323 } 324 } 325 if (log) 326 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", 327 static_cast<void*>(frame), 328 static_cast<void*>(sb_symbol.get())); 329 return sb_symbol; 330 } 331 332 SBBlock 333 SBFrame::GetBlock () const 334 { 335 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 336 SBBlock sb_block; 337 std::unique_lock<std::recursive_mutex> lock; 338 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 339 340 StackFrame *frame = nullptr; 341 Target *target = exe_ctx.GetTargetPtr(); 342 Process *process = exe_ctx.GetProcessPtr(); 343 if (target && process) 344 { 345 Process::StopLocker stop_locker; 346 if (stop_locker.TryLock(&process->GetRunLock())) 347 { 348 frame = exe_ctx.GetFramePtr(); 349 if (frame) 350 { 351 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block); 352 } 353 else 354 { 355 if (log) 356 log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame."); 357 } 358 } 359 else 360 { 361 if (log) 362 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running", 363 static_cast<void*>(frame)); 364 } 365 } 366 if (log) 367 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", 368 static_cast<void*>(frame), 369 static_cast<void*>(sb_block.GetPtr())); 370 return sb_block; 371 } 372 373 SBBlock 374 SBFrame::GetFrameBlock () const 375 { 376 SBBlock sb_block; 377 std::unique_lock<std::recursive_mutex> lock; 378 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 379 380 StackFrame *frame = nullptr; 381 Target *target = exe_ctx.GetTargetPtr(); 382 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 383 Process *process = exe_ctx.GetProcessPtr(); 384 if (target && process) 385 { 386 Process::StopLocker stop_locker; 387 if (stop_locker.TryLock(&process->GetRunLock())) 388 { 389 frame = exe_ctx.GetFramePtr(); 390 if (frame) 391 { 392 sb_block.SetPtr(frame->GetFrameBlock ()); 393 } 394 else 395 { 396 if (log) 397 log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame."); 398 } 399 } 400 else 401 { 402 if (log) 403 log->Printf ("SBFrame::GetFrameBlock () => error: process is running"); 404 } 405 } 406 if (log) 407 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", 408 static_cast<void*>(frame), 409 static_cast<void*>(sb_block.GetPtr())); 410 return sb_block; 411 } 412 413 SBLineEntry 414 SBFrame::GetLineEntry () const 415 { 416 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 417 SBLineEntry sb_line_entry; 418 std::unique_lock<std::recursive_mutex> lock; 419 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 420 421 StackFrame *frame = nullptr; 422 Target *target = exe_ctx.GetTargetPtr(); 423 Process *process = exe_ctx.GetProcessPtr(); 424 if (target && process) 425 { 426 Process::StopLocker stop_locker; 427 if (stop_locker.TryLock(&process->GetRunLock())) 428 { 429 frame = exe_ctx.GetFramePtr(); 430 if (frame) 431 { 432 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry); 433 } 434 else 435 { 436 if (log) 437 log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame."); 438 } 439 } 440 else 441 { 442 if (log) 443 log->Printf ("SBFrame::GetLineEntry () => error: process is running"); 444 } 445 } 446 if (log) 447 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", 448 static_cast<void*>(frame), 449 static_cast<void*>(sb_line_entry.get())); 450 return sb_line_entry; 451 } 452 453 uint32_t 454 SBFrame::GetFrameID () const 455 { 456 uint32_t frame_idx = UINT32_MAX; 457 458 std::unique_lock<std::recursive_mutex> lock; 459 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 460 461 StackFrame *frame = exe_ctx.GetFramePtr(); 462 if (frame) 463 frame_idx = frame->GetFrameIndex (); 464 465 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 466 if (log) 467 log->Printf ("SBFrame(%p)::GetFrameID () => %u", 468 static_cast<void*>(frame), frame_idx); 469 return frame_idx; 470 } 471 472 lldb::addr_t 473 SBFrame::GetCFA () const 474 { 475 std::unique_lock<std::recursive_mutex> lock; 476 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 477 478 StackFrame *frame = exe_ctx.GetFramePtr(); 479 if (frame) 480 return frame->GetStackID().GetCallFrameAddress(); 481 return LLDB_INVALID_ADDRESS; 482 } 483 484 addr_t 485 SBFrame::GetPC () const 486 { 487 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 488 addr_t addr = LLDB_INVALID_ADDRESS; 489 std::unique_lock<std::recursive_mutex> lock; 490 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 491 492 StackFrame *frame = nullptr; 493 Target *target = exe_ctx.GetTargetPtr(); 494 Process *process = exe_ctx.GetProcessPtr(); 495 if (target && process) 496 { 497 Process::StopLocker stop_locker; 498 if (stop_locker.TryLock(&process->GetRunLock())) 499 { 500 frame = exe_ctx.GetFramePtr(); 501 if (frame) 502 { 503 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target, eAddressClassCode); 504 } 505 else 506 { 507 if (log) 508 log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame."); 509 } 510 } 511 else 512 { 513 if (log) 514 log->Printf ("SBFrame::GetPC () => error: process is running"); 515 } 516 } 517 518 if (log) 519 log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64, 520 static_cast<void*>(frame), addr); 521 522 return addr; 523 } 524 525 bool 526 SBFrame::SetPC (addr_t new_pc) 527 { 528 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 529 bool ret_val = false; 530 std::unique_lock<std::recursive_mutex> lock; 531 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 532 533 StackFrame *frame = nullptr; 534 Target *target = exe_ctx.GetTargetPtr(); 535 Process *process = exe_ctx.GetProcessPtr(); 536 if (target && process) 537 { 538 Process::StopLocker stop_locker; 539 if (stop_locker.TryLock(&process->GetRunLock())) 540 { 541 frame = exe_ctx.GetFramePtr(); 542 if (frame) 543 { 544 ret_val = frame->GetRegisterContext()->SetPC (new_pc); 545 } 546 else 547 { 548 if (log) 549 log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame."); 550 } 551 } 552 else 553 { 554 if (log) 555 log->Printf ("SBFrame::SetPC () => error: process is running"); 556 } 557 } 558 559 if (log) 560 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i", 561 static_cast<void*>(frame), new_pc, ret_val); 562 563 return ret_val; 564 } 565 566 addr_t 567 SBFrame::GetSP () const 568 { 569 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 570 addr_t addr = LLDB_INVALID_ADDRESS; 571 std::unique_lock<std::recursive_mutex> lock; 572 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 573 574 StackFrame *frame = nullptr; 575 Target *target = exe_ctx.GetTargetPtr(); 576 Process *process = exe_ctx.GetProcessPtr(); 577 if (target && process) 578 { 579 Process::StopLocker stop_locker; 580 if (stop_locker.TryLock(&process->GetRunLock())) 581 { 582 frame = exe_ctx.GetFramePtr(); 583 if (frame) 584 { 585 addr = frame->GetRegisterContext()->GetSP(); 586 } 587 else 588 { 589 if (log) 590 log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame."); 591 } 592 } 593 else 594 { 595 if (log) 596 log->Printf ("SBFrame::GetSP () => error: process is running"); 597 } 598 } 599 if (log) 600 log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64, 601 static_cast<void*>(frame), addr); 602 603 return addr; 604 } 605 606 addr_t 607 SBFrame::GetFP () const 608 { 609 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 610 addr_t addr = LLDB_INVALID_ADDRESS; 611 std::unique_lock<std::recursive_mutex> lock; 612 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 613 614 StackFrame *frame = nullptr; 615 Target *target = exe_ctx.GetTargetPtr(); 616 Process *process = exe_ctx.GetProcessPtr(); 617 if (target && process) 618 { 619 Process::StopLocker stop_locker; 620 if (stop_locker.TryLock(&process->GetRunLock())) 621 { 622 frame = exe_ctx.GetFramePtr(); 623 if (frame) 624 { 625 addr = frame->GetRegisterContext()->GetFP(); 626 } 627 else 628 { 629 if (log) 630 log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame."); 631 } 632 } 633 else 634 { 635 if (log) 636 log->Printf ("SBFrame::GetFP () => error: process is running"); 637 } 638 } 639 640 if (log) 641 log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64, 642 static_cast<void*>(frame), addr); 643 return addr; 644 } 645 646 SBAddress 647 SBFrame::GetPCAddress () const 648 { 649 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 650 SBAddress sb_addr; 651 std::unique_lock<std::recursive_mutex> lock; 652 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 653 654 StackFrame *frame = exe_ctx.GetFramePtr(); 655 Target *target = exe_ctx.GetTargetPtr(); 656 Process *process = exe_ctx.GetProcessPtr(); 657 if (target && process) 658 { 659 Process::StopLocker stop_locker; 660 if (stop_locker.TryLock(&process->GetRunLock())) 661 { 662 frame = exe_ctx.GetFramePtr(); 663 if (frame) 664 { 665 sb_addr.SetAddress (&frame->GetFrameCodeAddress()); 666 } 667 else 668 { 669 if (log) 670 log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame."); 671 } 672 } 673 else 674 { 675 if (log) 676 log->Printf ("SBFrame::GetPCAddress () => error: process is running"); 677 } 678 } 679 if (log) 680 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", 681 static_cast<void*>(frame), 682 static_cast<void*>(sb_addr.get())); 683 return sb_addr; 684 } 685 686 void 687 SBFrame::Clear() 688 { 689 m_opaque_sp->Clear(); 690 } 691 692 lldb::SBValue 693 SBFrame::GetValueForVariablePath (const char *var_path) 694 { 695 SBValue sb_value; 696 std::unique_lock<std::recursive_mutex> lock; 697 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 698 699 StackFrame *frame = exe_ctx.GetFramePtr(); 700 Target *target = exe_ctx.GetTargetPtr(); 701 if (frame && target) 702 { 703 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 704 sb_value = GetValueForVariablePath (var_path, use_dynamic); 705 } 706 return sb_value; 707 } 708 709 lldb::SBValue 710 SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic) 711 { 712 SBValue sb_value; 713 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 714 if (var_path == nullptr || var_path[0] == '\0') 715 { 716 if (log) 717 log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path."); 718 return sb_value; 719 } 720 721 std::unique_lock<std::recursive_mutex> lock; 722 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 723 724 StackFrame *frame = nullptr; 725 Target *target = exe_ctx.GetTargetPtr(); 726 Process *process = exe_ctx.GetProcessPtr(); 727 if (target && process) 728 { 729 Process::StopLocker stop_locker; 730 if (stop_locker.TryLock(&process->GetRunLock())) 731 { 732 frame = exe_ctx.GetFramePtr(); 733 if (frame) 734 { 735 VariableSP var_sp; 736 Error error; 737 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path, 738 eNoDynamicValues, 739 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess, 740 var_sp, 741 error)); 742 sb_value.SetSP(value_sp, use_dynamic); 743 } 744 else 745 { 746 if (log) 747 log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame."); 748 } 749 } 750 else 751 { 752 if (log) 753 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running"); 754 } 755 } 756 return sb_value; 757 } 758 759 SBValue 760 SBFrame::FindVariable (const char *name) 761 { 762 SBValue value; 763 std::unique_lock<std::recursive_mutex> lock; 764 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 765 766 StackFrame *frame = exe_ctx.GetFramePtr(); 767 Target *target = exe_ctx.GetTargetPtr(); 768 if (frame && target) 769 { 770 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 771 value = FindVariable (name, use_dynamic); 772 } 773 return value; 774 } 775 776 SBValue 777 SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) 778 { 779 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 780 VariableSP var_sp; 781 SBValue sb_value; 782 783 if (name == nullptr || name[0] == '\0') 784 { 785 if (log) 786 log->Printf ("SBFrame::FindVariable called with empty name"); 787 return sb_value; 788 } 789 790 ValueObjectSP value_sp; 791 std::unique_lock<std::recursive_mutex> lock; 792 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 793 794 StackFrame *frame = nullptr; 795 Target *target = exe_ctx.GetTargetPtr(); 796 Process *process = exe_ctx.GetProcessPtr(); 797 if (target && process) 798 { 799 Process::StopLocker stop_locker; 800 if (stop_locker.TryLock(&process->GetRunLock())) 801 { 802 frame = exe_ctx.GetFramePtr(); 803 if (frame) 804 { 805 VariableList variable_list; 806 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); 807 808 if (sc.block) 809 { 810 const bool can_create = true; 811 const bool get_parent_variables = true; 812 const bool stop_if_block_is_inlined_function = true; 813 814 if (sc.block->AppendVariables (can_create, 815 get_parent_variables, 816 stop_if_block_is_inlined_function, 817 [frame](Variable* v) { return v->IsInScope(frame); }, 818 &variable_list)) 819 { 820 var_sp = variable_list.FindVariable (ConstString(name)); 821 } 822 } 823 824 if (var_sp) 825 { 826 value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); 827 sb_value.SetSP(value_sp, use_dynamic); 828 } 829 } 830 else 831 { 832 if (log) 833 log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame."); 834 } 835 } 836 else 837 { 838 if (log) 839 log->Printf ("SBFrame::FindVariable () => error: process is running"); 840 } 841 } 842 843 if (log) 844 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", 845 static_cast<void*>(frame), name, 846 static_cast<void*>(value_sp.get())); 847 848 return sb_value; 849 } 850 851 SBValue 852 SBFrame::FindValue (const char *name, ValueType value_type) 853 { 854 SBValue value; 855 std::unique_lock<std::recursive_mutex> lock; 856 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 857 858 StackFrame *frame = exe_ctx.GetFramePtr(); 859 Target *target = exe_ctx.GetTargetPtr(); 860 if (frame && target) 861 { 862 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 863 value = FindValue (name, value_type, use_dynamic); 864 } 865 return value; 866 } 867 868 SBValue 869 SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic) 870 { 871 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 872 SBValue sb_value; 873 874 if (name == nullptr || name[0] == '\0') 875 { 876 if (log) 877 log->Printf ("SBFrame::FindValue called with empty name."); 878 return sb_value; 879 } 880 881 ValueObjectSP value_sp; 882 std::unique_lock<std::recursive_mutex> lock; 883 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 884 885 StackFrame *frame = nullptr; 886 Target *target = exe_ctx.GetTargetPtr(); 887 Process *process = exe_ctx.GetProcessPtr(); 888 if (target && process) 889 { 890 Process::StopLocker stop_locker; 891 if (stop_locker.TryLock(&process->GetRunLock())) 892 { 893 frame = exe_ctx.GetFramePtr(); 894 if (frame) 895 { 896 VariableList variable_list; 897 898 switch (value_type) 899 { 900 case eValueTypeVariableGlobal: // global variable 901 case eValueTypeVariableStatic: // static variable 902 case eValueTypeVariableArgument: // function argument variables 903 case eValueTypeVariableLocal: // function local variables 904 { 905 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock)); 906 907 const bool can_create = true; 908 const bool get_parent_variables = true; 909 const bool stop_if_block_is_inlined_function = true; 910 911 if (sc.block) 912 sc.block->AppendVariables(can_create, 913 get_parent_variables, 914 stop_if_block_is_inlined_function, 915 [frame](Variable* v) { return v->IsInScope(frame); }, 916 &variable_list); 917 if (value_type == eValueTypeVariableGlobal) 918 { 919 const bool get_file_globals = true; 920 VariableList *frame_vars = frame->GetVariableList(get_file_globals); 921 if (frame_vars) 922 frame_vars->AppendVariablesIfUnique(variable_list); 923 } 924 ConstString const_name(name); 925 VariableSP variable_sp(variable_list.FindVariable(const_name, value_type)); 926 if (variable_sp) 927 { 928 value_sp = frame->GetValueObjectForFrameVariable(variable_sp, eNoDynamicValues); 929 sb_value.SetSP(value_sp, use_dynamic); 930 } 931 } 932 break; 933 934 case eValueTypeRegister: // stack frame register value 935 { 936 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 937 if (reg_ctx) 938 { 939 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 940 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 941 { 942 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 943 if (reg_info && 944 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 945 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 946 { 947 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 948 sb_value.SetSP (value_sp); 949 break; 950 } 951 } 952 } 953 } 954 break; 955 956 case eValueTypeRegisterSet: // A collection of stack frame register values 957 { 958 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 959 if (reg_ctx) 960 { 961 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 962 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 963 { 964 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx); 965 if (reg_set && 966 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || 967 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) 968 { 969 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx); 970 sb_value.SetSP (value_sp); 971 break; 972 } 973 } 974 } 975 } 976 break; 977 978 case eValueTypeConstResult: // constant result variables 979 { 980 ConstString const_name(name); 981 ExpressionVariableSP expr_var_sp (target->GetPersistentVariable (const_name)); 982 if (expr_var_sp) 983 { 984 value_sp = expr_var_sp->GetValueObject(); 985 sb_value.SetSP (value_sp, use_dynamic); 986 } 987 } 988 break; 989 990 default: 991 break; 992 } 993 } 994 else 995 { 996 if (log) 997 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame."); 998 } 999 } 1000 else 1001 { 1002 if (log) 1003 log->Printf ("SBFrame::FindValue () => error: process is running"); 1004 } 1005 } 1006 1007 if (log) 1008 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", 1009 static_cast<void*>(frame), name, value_type, 1010 static_cast<void*>(value_sp.get())); 1011 1012 return sb_value; 1013 } 1014 1015 bool 1016 SBFrame::IsEqual (const SBFrame &that) const 1017 { 1018 lldb::StackFrameSP this_sp = GetFrameSP(); 1019 lldb::StackFrameSP that_sp = that.GetFrameSP(); 1020 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID()); 1021 } 1022 1023 bool 1024 SBFrame::operator == (const SBFrame &rhs) const 1025 { 1026 return IsEqual(rhs); 1027 } 1028 1029 bool 1030 SBFrame::operator != (const SBFrame &rhs) const 1031 { 1032 return !IsEqual(rhs); 1033 } 1034 1035 SBThread 1036 SBFrame::GetThread () const 1037 { 1038 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1039 1040 std::unique_lock<std::recursive_mutex> lock; 1041 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1042 1043 ThreadSP thread_sp (exe_ctx.GetThreadSP()); 1044 SBThread sb_thread (thread_sp); 1045 1046 if (log) 1047 { 1048 SBStream sstr; 1049 sb_thread.GetDescription (sstr); 1050 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", 1051 static_cast<void*>(exe_ctx.GetFramePtr()), 1052 static_cast<void*>(thread_sp.get()), sstr.GetData()); 1053 } 1054 1055 return sb_thread; 1056 } 1057 1058 const char * 1059 SBFrame::Disassemble () const 1060 { 1061 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1062 const char *disassembly = nullptr; 1063 std::unique_lock<std::recursive_mutex> lock; 1064 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1065 1066 StackFrame *frame = nullptr; 1067 Target *target = exe_ctx.GetTargetPtr(); 1068 Process *process = exe_ctx.GetProcessPtr(); 1069 if (target && process) 1070 { 1071 Process::StopLocker stop_locker; 1072 if (stop_locker.TryLock(&process->GetRunLock())) 1073 { 1074 frame = exe_ctx.GetFramePtr(); 1075 if (frame) 1076 { 1077 disassembly = frame->Disassemble(); 1078 } 1079 else 1080 { 1081 if (log) 1082 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame."); 1083 } 1084 } 1085 else 1086 { 1087 if (log) 1088 log->Printf ("SBFrame::Disassemble () => error: process is running"); 1089 } 1090 } 1091 1092 if (log) 1093 log->Printf ("SBFrame(%p)::Disassemble () => %s", 1094 static_cast<void*>(frame), disassembly); 1095 1096 return disassembly; 1097 } 1098 1099 SBValueList 1100 SBFrame::GetVariables (bool arguments, 1101 bool locals, 1102 bool statics, 1103 bool in_scope_only) 1104 { 1105 SBValueList value_list; 1106 std::unique_lock<std::recursive_mutex> lock; 1107 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1108 1109 StackFrame *frame = exe_ctx.GetFramePtr(); 1110 Target *target = exe_ctx.GetTargetPtr(); 1111 if (frame && target) 1112 { 1113 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 1114 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false; 1115 1116 SBVariablesOptions options; 1117 options.SetIncludeArguments(arguments); 1118 options.SetIncludeLocals(locals); 1119 options.SetIncludeStatics(statics); 1120 options.SetInScopeOnly(in_scope_only); 1121 options.SetIncludeRuntimeSupportValues(include_runtime_support_values); 1122 options.SetUseDynamic(use_dynamic); 1123 1124 value_list = GetVariables (options); 1125 } 1126 return value_list; 1127 } 1128 1129 lldb::SBValueList 1130 SBFrame::GetVariables (bool arguments, 1131 bool locals, 1132 bool statics, 1133 bool in_scope_only, 1134 lldb::DynamicValueType use_dynamic) 1135 { 1136 std::unique_lock<std::recursive_mutex> lock; 1137 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1138 1139 Target *target = exe_ctx.GetTargetPtr(); 1140 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false; 1141 SBVariablesOptions options; 1142 options.SetIncludeArguments(arguments); 1143 options.SetIncludeLocals(locals); 1144 options.SetIncludeStatics(statics); 1145 options.SetInScopeOnly(in_scope_only); 1146 options.SetIncludeRuntimeSupportValues(include_runtime_support_values); 1147 options.SetUseDynamic(use_dynamic); 1148 return GetVariables(options); 1149 } 1150 1151 SBValueList 1152 SBFrame::GetVariables (const lldb::SBVariablesOptions& options) 1153 { 1154 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1155 1156 SBValueList value_list; 1157 std::unique_lock<std::recursive_mutex> lock; 1158 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1159 1160 StackFrame *frame = nullptr; 1161 Target *target = exe_ctx.GetTargetPtr(); 1162 1163 const bool statics = options.GetIncludeStatics(); 1164 const bool arguments = options.GetIncludeArguments(); 1165 const bool locals = options.GetIncludeLocals(); 1166 const bool in_scope_only = options.GetInScopeOnly(); 1167 const bool include_runtime_support_values = options.GetIncludeRuntimeSupportValues(); 1168 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic(); 1169 1170 if (log) 1171 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)", 1172 arguments, locals, 1173 statics, in_scope_only, 1174 include_runtime_support_values, use_dynamic); 1175 1176 std::set<VariableSP> variable_set; 1177 Process *process = exe_ctx.GetProcessPtr(); 1178 if (target && process) 1179 { 1180 Process::StopLocker stop_locker; 1181 if (stop_locker.TryLock(&process->GetRunLock())) 1182 { 1183 frame = exe_ctx.GetFramePtr(); 1184 if (frame) 1185 { 1186 size_t i; 1187 VariableList *variable_list = nullptr; 1188 variable_list = frame->GetVariableList(true); 1189 if (variable_list) 1190 { 1191 const size_t num_variables = variable_list->GetSize(); 1192 if (num_variables) 1193 { 1194 for (i = 0; i < num_variables; ++i) 1195 { 1196 VariableSP variable_sp (variable_list->GetVariableAtIndex(i)); 1197 if (variable_sp) 1198 { 1199 bool add_variable = false; 1200 switch (variable_sp->GetScope()) 1201 { 1202 case eValueTypeVariableGlobal: 1203 case eValueTypeVariableStatic: 1204 add_variable = statics; 1205 break; 1206 1207 case eValueTypeVariableArgument: 1208 add_variable = arguments; 1209 break; 1210 1211 case eValueTypeVariableLocal: 1212 add_variable = locals; 1213 break; 1214 1215 default: 1216 break; 1217 } 1218 if (add_variable) 1219 { 1220 // Only add variables once so we don't end up with duplicates 1221 if (variable_set.find(variable_sp) == variable_set.end()) 1222 variable_set.insert(variable_sp); 1223 else 1224 continue; 1225 1226 if (in_scope_only && !variable_sp->IsInScope(frame)) 1227 continue; 1228 1229 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues)); 1230 1231 if (!include_runtime_support_values && 1232 valobj_sp != nullptr && 1233 valobj_sp->IsRuntimeSupportValue()) 1234 continue; 1235 1236 SBValue value_sb; 1237 value_sb.SetSP(valobj_sp,use_dynamic); 1238 value_list.Append(value_sb); 1239 } 1240 } 1241 } 1242 } 1243 } 1244 } 1245 else 1246 { 1247 if (log) 1248 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame."); 1249 } 1250 } 1251 else 1252 { 1253 if (log) 1254 log->Printf ("SBFrame::GetVariables () => error: process is running"); 1255 } 1256 } 1257 1258 if (log) 1259 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", 1260 static_cast<void*>(frame), 1261 static_cast<void*>(value_list.opaque_ptr())); 1262 1263 return value_list; 1264 } 1265 1266 SBValueList 1267 SBFrame::GetRegisters () 1268 { 1269 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1270 1271 SBValueList value_list; 1272 std::unique_lock<std::recursive_mutex> lock; 1273 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1274 1275 StackFrame *frame = nullptr; 1276 Target *target = exe_ctx.GetTargetPtr(); 1277 Process *process = exe_ctx.GetProcessPtr(); 1278 if (target && process) 1279 { 1280 Process::StopLocker stop_locker; 1281 if (stop_locker.TryLock(&process->GetRunLock())) 1282 { 1283 frame = exe_ctx.GetFramePtr(); 1284 if (frame) 1285 { 1286 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 1287 if (reg_ctx) 1288 { 1289 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 1290 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 1291 { 1292 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx)); 1293 } 1294 } 1295 } 1296 else 1297 { 1298 if (log) 1299 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame."); 1300 } 1301 } 1302 else 1303 { 1304 if (log) 1305 log->Printf ("SBFrame::GetRegisters () => error: process is running"); 1306 } 1307 } 1308 1309 if (log) 1310 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", 1311 static_cast<void*>(frame), 1312 static_cast<void*>(value_list.opaque_ptr())); 1313 1314 return value_list; 1315 } 1316 1317 SBValue 1318 SBFrame::FindRegister (const char *name) 1319 { 1320 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1321 1322 SBValue result; 1323 ValueObjectSP value_sp; 1324 std::unique_lock<std::recursive_mutex> lock; 1325 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1326 1327 StackFrame *frame = nullptr; 1328 Target *target = exe_ctx.GetTargetPtr(); 1329 Process *process = exe_ctx.GetProcessPtr(); 1330 if (target && process) 1331 { 1332 Process::StopLocker stop_locker; 1333 if (stop_locker.TryLock(&process->GetRunLock())) 1334 { 1335 frame = exe_ctx.GetFramePtr(); 1336 if (frame) 1337 { 1338 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 1339 if (reg_ctx) 1340 { 1341 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 1342 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 1343 { 1344 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 1345 if (reg_info && 1346 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 1347 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 1348 { 1349 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 1350 result.SetSP (value_sp); 1351 break; 1352 } 1353 } 1354 } 1355 } 1356 else 1357 { 1358 if (log) 1359 log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame."); 1360 } 1361 } 1362 else 1363 { 1364 if (log) 1365 log->Printf ("SBFrame::FindRegister () => error: process is running"); 1366 } 1367 } 1368 1369 if (log) 1370 log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)", 1371 static_cast<void*>(frame), 1372 static_cast<void*>(value_sp.get())); 1373 1374 return result; 1375 } 1376 1377 bool 1378 SBFrame::GetDescription (SBStream &description) 1379 { 1380 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1381 Stream &strm = description.ref(); 1382 1383 std::unique_lock<std::recursive_mutex> lock; 1384 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1385 1386 StackFrame *frame; 1387 Target *target = exe_ctx.GetTargetPtr(); 1388 Process *process = exe_ctx.GetProcessPtr(); 1389 if (target && process) 1390 { 1391 Process::StopLocker stop_locker; 1392 if (stop_locker.TryLock(&process->GetRunLock())) 1393 { 1394 frame = exe_ctx.GetFramePtr(); 1395 if (frame) 1396 { 1397 frame->DumpUsingSettingsFormat (&strm); 1398 } 1399 else 1400 { 1401 if (log) 1402 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame."); 1403 } 1404 } 1405 else 1406 { 1407 if (log) 1408 log->Printf ("SBFrame::GetDescription () => error: process is running"); 1409 } 1410 1411 } 1412 else 1413 strm.PutCString ("No value"); 1414 1415 return true; 1416 } 1417 1418 SBValue 1419 SBFrame::EvaluateExpression (const char *expr) 1420 { 1421 SBValue result; 1422 std::unique_lock<std::recursive_mutex> lock; 1423 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1424 1425 StackFrame *frame = exe_ctx.GetFramePtr(); 1426 Target *target = exe_ctx.GetTargetPtr(); 1427 if (frame && target) 1428 { 1429 SBExpressionOptions options; 1430 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue(); 1431 options.SetFetchDynamicValue (fetch_dynamic_value); 1432 options.SetUnwindOnError (true); 1433 options.SetIgnoreBreakpoints (true); 1434 if (target->GetLanguage() != eLanguageTypeUnknown) 1435 options.SetLanguage(target->GetLanguage()); 1436 else 1437 options.SetLanguage(frame->GetLanguage()); 1438 return EvaluateExpression (expr, options); 1439 } 1440 return result; 1441 } 1442 1443 SBValue 1444 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value) 1445 { 1446 SBExpressionOptions options; 1447 options.SetFetchDynamicValue (fetch_dynamic_value); 1448 options.SetUnwindOnError (true); 1449 options.SetIgnoreBreakpoints (true); 1450 std::unique_lock<std::recursive_mutex> lock; 1451 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1452 1453 StackFrame *frame = exe_ctx.GetFramePtr(); 1454 Target *target = exe_ctx.GetTargetPtr(); 1455 if (target && target->GetLanguage() != eLanguageTypeUnknown) 1456 options.SetLanguage(target->GetLanguage()); 1457 else if (frame) 1458 options.SetLanguage(frame->GetLanguage()); 1459 return EvaluateExpression (expr, options); 1460 } 1461 1462 SBValue 1463 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error) 1464 { 1465 SBExpressionOptions options; 1466 std::unique_lock<std::recursive_mutex> lock; 1467 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1468 1469 options.SetFetchDynamicValue (fetch_dynamic_value); 1470 options.SetUnwindOnError (unwind_on_error); 1471 options.SetIgnoreBreakpoints (true); 1472 StackFrame *frame = exe_ctx.GetFramePtr(); 1473 Target *target = exe_ctx.GetTargetPtr(); 1474 if (target && target->GetLanguage() != eLanguageTypeUnknown) 1475 options.SetLanguage(target->GetLanguage()); 1476 else if (frame) 1477 options.SetLanguage(frame->GetLanguage()); 1478 return EvaluateExpression (expr, options); 1479 } 1480 1481 lldb::SBValue 1482 SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options) 1483 { 1484 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1485 1486 #ifndef LLDB_DISABLE_PYTHON 1487 Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 1488 #endif 1489 1490 ExpressionResults exe_results = eExpressionSetupError; 1491 SBValue expr_result; 1492 1493 if (expr == nullptr || expr[0] == '\0') 1494 { 1495 if (log) 1496 log->Printf ("SBFrame::EvaluateExpression called with an empty expression"); 1497 return expr_result; 1498 } 1499 1500 ValueObjectSP expr_value_sp; 1501 1502 std::unique_lock<std::recursive_mutex> lock; 1503 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1504 1505 if (log) 1506 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr); 1507 1508 StackFrame *frame = nullptr; 1509 Target *target = exe_ctx.GetTargetPtr(); 1510 Process *process = exe_ctx.GetProcessPtr(); 1511 1512 if (target && process) 1513 { 1514 Process::StopLocker stop_locker; 1515 if (stop_locker.TryLock(&process->GetRunLock())) 1516 { 1517 frame = exe_ctx.GetFramePtr(); 1518 if (frame) 1519 { 1520 if (target->GetDisplayExpressionsInCrashlogs()) 1521 { 1522 StreamString frame_description; 1523 frame->DumpUsingSettingsFormat (&frame_description); 1524 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", 1525 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str()); 1526 } 1527 1528 exe_results = target->EvaluateExpression (expr, 1529 frame, 1530 expr_value_sp, 1531 options.ref()); 1532 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); 1533 1534 if (target->GetDisplayExpressionsInCrashlogs()) 1535 Host::SetCrashDescription(nullptr); 1536 } 1537 else 1538 { 1539 if (log) 1540 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame."); 1541 } 1542 } 1543 else 1544 { 1545 if (log) 1546 log->Printf ("SBFrame::EvaluateExpression () => error: process is running"); 1547 } 1548 } 1549 1550 #ifndef LLDB_DISABLE_PYTHON 1551 if (expr_log) 1552 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **", 1553 expr_result.GetValue(), expr_result.GetSummary()); 1554 1555 if (log) 1556 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", 1557 static_cast<void*>(frame), expr, 1558 static_cast<void*>(expr_value_sp.get()), exe_results); 1559 #endif 1560 1561 return expr_result; 1562 } 1563 1564 bool 1565 SBFrame::IsInlined() 1566 { 1567 return static_cast<const SBFrame*>(this)->IsInlined(); 1568 } 1569 1570 bool 1571 SBFrame::IsInlined() const 1572 { 1573 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1574 std::unique_lock<std::recursive_mutex> lock; 1575 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1576 1577 StackFrame *frame = nullptr; 1578 Target *target = exe_ctx.GetTargetPtr(); 1579 Process *process = exe_ctx.GetProcessPtr(); 1580 if (target && process) 1581 { 1582 Process::StopLocker stop_locker; 1583 if (stop_locker.TryLock(&process->GetRunLock())) 1584 { 1585 frame = exe_ctx.GetFramePtr(); 1586 if (frame) 1587 { 1588 1589 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block; 1590 if (block) 1591 return block->GetContainingInlinedBlock() != nullptr; 1592 } 1593 else 1594 { 1595 if (log) 1596 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame."); 1597 } 1598 } 1599 else 1600 { 1601 if (log) 1602 log->Printf ("SBFrame::IsInlined () => error: process is running"); 1603 } 1604 1605 } 1606 return false; 1607 } 1608 1609 const char * 1610 SBFrame::GetFunctionName() 1611 { 1612 return static_cast<const SBFrame*>(this)->GetFunctionName(); 1613 } 1614 1615 const char * 1616 SBFrame::GetFunctionName() const 1617 { 1618 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1619 const char *name = nullptr; 1620 std::unique_lock<std::recursive_mutex> lock; 1621 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1622 1623 StackFrame *frame = nullptr; 1624 Target *target = exe_ctx.GetTargetPtr(); 1625 Process *process = exe_ctx.GetProcessPtr(); 1626 if (target && process) 1627 { 1628 Process::StopLocker stop_locker; 1629 if (stop_locker.TryLock(&process->GetRunLock())) 1630 { 1631 frame = exe_ctx.GetFramePtr(); 1632 if (frame) 1633 { 1634 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); 1635 if (sc.block) 1636 { 1637 Block *inlined_block = sc.block->GetContainingInlinedBlock (); 1638 if (inlined_block) 1639 { 1640 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo(); 1641 name = inlined_info->GetName(sc.function->GetLanguage()).AsCString(); 1642 } 1643 } 1644 1645 if (name == nullptr) 1646 { 1647 if (sc.function) 1648 name = sc.function->GetName().GetCString(); 1649 } 1650 1651 if (name == nullptr) 1652 { 1653 if (sc.symbol) 1654 name = sc.symbol->GetName().GetCString(); 1655 } 1656 } 1657 else 1658 { 1659 if (log) 1660 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame."); 1661 } 1662 } 1663 else 1664 { 1665 if (log) 1666 log->Printf ("SBFrame::GetFunctionName() => error: process is running"); 1667 1668 } 1669 } 1670 return name; 1671 } 1672 1673 const char * 1674 SBFrame::GetDisplayFunctionName() 1675 { 1676 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1677 const char *name = nullptr; 1678 1679 std::unique_lock<std::recursive_mutex> lock; 1680 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1681 1682 StackFrame *frame = nullptr; 1683 Target *target = exe_ctx.GetTargetPtr(); 1684 Process *process = exe_ctx.GetProcessPtr(); 1685 if (target && process) 1686 { 1687 Process::StopLocker stop_locker; 1688 if (stop_locker.TryLock(&process->GetRunLock())) 1689 { 1690 frame = exe_ctx.GetFramePtr(); 1691 if (frame) 1692 { 1693 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); 1694 if (sc.block) 1695 { 1696 Block *inlined_block = sc.block->GetContainingInlinedBlock (); 1697 if (inlined_block) 1698 { 1699 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo(); 1700 name = inlined_info->GetDisplayName(sc.function->GetLanguage()).AsCString(); 1701 } 1702 } 1703 1704 if (name == nullptr) 1705 { 1706 if (sc.function) 1707 name = sc.function->GetDisplayName().GetCString(); 1708 } 1709 1710 if (name == nullptr) 1711 { 1712 if (sc.symbol) 1713 name = sc.symbol->GetDisplayName().GetCString(); 1714 } 1715 } 1716 else 1717 { 1718 if (log) 1719 log->Printf ("SBFrame::GetDisplayFunctionName () => error: could not reconstruct frame object for this SBFrame."); 1720 } 1721 } 1722 else 1723 { 1724 if (log) 1725 log->Printf ("SBFrame::GetDisplayFunctionName() => error: process is running"); 1726 1727 } 1728 } 1729 return name; 1730 } 1731