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 case eValueTypeVariableThreadLocal: // thread local variables 905 { 906 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock)); 907 908 const bool can_create = true; 909 const bool get_parent_variables = true; 910 const bool stop_if_block_is_inlined_function = true; 911 912 if (sc.block) 913 sc.block->AppendVariables(can_create, get_parent_variables, stop_if_block_is_inlined_function, 914 [frame](Variable *v) { return v->IsInScope(frame); }, &variable_list); 915 if (value_type == eValueTypeVariableGlobal) 916 { 917 const bool get_file_globals = true; 918 VariableList *frame_vars = frame->GetVariableList(get_file_globals); 919 if (frame_vars) 920 frame_vars->AppendVariablesIfUnique(variable_list); 921 } 922 ConstString const_name(name); 923 VariableSP variable_sp(variable_list.FindVariable(const_name, value_type)); 924 if (variable_sp) 925 { 926 value_sp = frame->GetValueObjectForFrameVariable(variable_sp, eNoDynamicValues); 927 sb_value.SetSP(value_sp, use_dynamic); 928 } 929 } 930 break; 931 932 case eValueTypeRegister: // stack frame register value 933 { 934 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 935 if (reg_ctx) 936 { 937 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 938 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 939 { 940 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 941 if (reg_info && 942 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 943 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 944 { 945 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 946 sb_value.SetSP (value_sp); 947 break; 948 } 949 } 950 } 951 } 952 break; 953 954 case eValueTypeRegisterSet: // A collection of stack frame register values 955 { 956 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 957 if (reg_ctx) 958 { 959 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 960 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 961 { 962 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx); 963 if (reg_set && 964 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || 965 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) 966 { 967 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx); 968 sb_value.SetSP (value_sp); 969 break; 970 } 971 } 972 } 973 } 974 break; 975 976 case eValueTypeConstResult: // constant result variables 977 { 978 ConstString const_name(name); 979 ExpressionVariableSP expr_var_sp (target->GetPersistentVariable (const_name)); 980 if (expr_var_sp) 981 { 982 value_sp = expr_var_sp->GetValueObject(); 983 sb_value.SetSP (value_sp, use_dynamic); 984 } 985 } 986 break; 987 988 default: 989 break; 990 } 991 } 992 else 993 { 994 if (log) 995 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame."); 996 } 997 } 998 else 999 { 1000 if (log) 1001 log->Printf ("SBFrame::FindValue () => error: process is running"); 1002 } 1003 } 1004 1005 if (log) 1006 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", 1007 static_cast<void*>(frame), name, value_type, 1008 static_cast<void*>(value_sp.get())); 1009 1010 return sb_value; 1011 } 1012 1013 bool 1014 SBFrame::IsEqual (const SBFrame &that) const 1015 { 1016 lldb::StackFrameSP this_sp = GetFrameSP(); 1017 lldb::StackFrameSP that_sp = that.GetFrameSP(); 1018 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID()); 1019 } 1020 1021 bool 1022 SBFrame::operator == (const SBFrame &rhs) const 1023 { 1024 return IsEqual(rhs); 1025 } 1026 1027 bool 1028 SBFrame::operator != (const SBFrame &rhs) const 1029 { 1030 return !IsEqual(rhs); 1031 } 1032 1033 SBThread 1034 SBFrame::GetThread () const 1035 { 1036 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1037 1038 std::unique_lock<std::recursive_mutex> lock; 1039 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1040 1041 ThreadSP thread_sp (exe_ctx.GetThreadSP()); 1042 SBThread sb_thread (thread_sp); 1043 1044 if (log) 1045 { 1046 SBStream sstr; 1047 sb_thread.GetDescription (sstr); 1048 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", 1049 static_cast<void*>(exe_ctx.GetFramePtr()), 1050 static_cast<void*>(thread_sp.get()), sstr.GetData()); 1051 } 1052 1053 return sb_thread; 1054 } 1055 1056 const char * 1057 SBFrame::Disassemble () const 1058 { 1059 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1060 const char *disassembly = nullptr; 1061 std::unique_lock<std::recursive_mutex> lock; 1062 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1063 1064 StackFrame *frame = nullptr; 1065 Target *target = exe_ctx.GetTargetPtr(); 1066 Process *process = exe_ctx.GetProcessPtr(); 1067 if (target && process) 1068 { 1069 Process::StopLocker stop_locker; 1070 if (stop_locker.TryLock(&process->GetRunLock())) 1071 { 1072 frame = exe_ctx.GetFramePtr(); 1073 if (frame) 1074 { 1075 disassembly = frame->Disassemble(); 1076 } 1077 else 1078 { 1079 if (log) 1080 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame."); 1081 } 1082 } 1083 else 1084 { 1085 if (log) 1086 log->Printf ("SBFrame::Disassemble () => error: process is running"); 1087 } 1088 } 1089 1090 if (log) 1091 log->Printf ("SBFrame(%p)::Disassemble () => %s", 1092 static_cast<void*>(frame), disassembly); 1093 1094 return disassembly; 1095 } 1096 1097 SBValueList 1098 SBFrame::GetVariables (bool arguments, 1099 bool locals, 1100 bool statics, 1101 bool in_scope_only) 1102 { 1103 SBValueList value_list; 1104 std::unique_lock<std::recursive_mutex> lock; 1105 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1106 1107 StackFrame *frame = exe_ctx.GetFramePtr(); 1108 Target *target = exe_ctx.GetTargetPtr(); 1109 if (frame && target) 1110 { 1111 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 1112 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false; 1113 1114 SBVariablesOptions options; 1115 options.SetIncludeArguments(arguments); 1116 options.SetIncludeLocals(locals); 1117 options.SetIncludeStatics(statics); 1118 options.SetInScopeOnly(in_scope_only); 1119 options.SetIncludeRuntimeSupportValues(include_runtime_support_values); 1120 options.SetUseDynamic(use_dynamic); 1121 1122 value_list = GetVariables (options); 1123 } 1124 return value_list; 1125 } 1126 1127 lldb::SBValueList 1128 SBFrame::GetVariables (bool arguments, 1129 bool locals, 1130 bool statics, 1131 bool in_scope_only, 1132 lldb::DynamicValueType use_dynamic) 1133 { 1134 std::unique_lock<std::recursive_mutex> lock; 1135 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1136 1137 Target *target = exe_ctx.GetTargetPtr(); 1138 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false; 1139 SBVariablesOptions options; 1140 options.SetIncludeArguments(arguments); 1141 options.SetIncludeLocals(locals); 1142 options.SetIncludeStatics(statics); 1143 options.SetInScopeOnly(in_scope_only); 1144 options.SetIncludeRuntimeSupportValues(include_runtime_support_values); 1145 options.SetUseDynamic(use_dynamic); 1146 return GetVariables(options); 1147 } 1148 1149 SBValueList 1150 SBFrame::GetVariables (const lldb::SBVariablesOptions& options) 1151 { 1152 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1153 1154 SBValueList value_list; 1155 std::unique_lock<std::recursive_mutex> lock; 1156 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1157 1158 StackFrame *frame = nullptr; 1159 Target *target = exe_ctx.GetTargetPtr(); 1160 1161 const bool statics = options.GetIncludeStatics(); 1162 const bool arguments = options.GetIncludeArguments(); 1163 const bool locals = options.GetIncludeLocals(); 1164 const bool in_scope_only = options.GetInScopeOnly(); 1165 const bool include_runtime_support_values = options.GetIncludeRuntimeSupportValues(); 1166 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic(); 1167 1168 if (log) 1169 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)", 1170 arguments, locals, 1171 statics, in_scope_only, 1172 include_runtime_support_values, use_dynamic); 1173 1174 std::set<VariableSP> variable_set; 1175 Process *process = exe_ctx.GetProcessPtr(); 1176 if (target && process) 1177 { 1178 Process::StopLocker stop_locker; 1179 if (stop_locker.TryLock(&process->GetRunLock())) 1180 { 1181 frame = exe_ctx.GetFramePtr(); 1182 if (frame) 1183 { 1184 size_t i; 1185 VariableList *variable_list = nullptr; 1186 variable_list = frame->GetVariableList(true); 1187 if (variable_list) 1188 { 1189 const size_t num_variables = variable_list->GetSize(); 1190 if (num_variables) 1191 { 1192 for (i = 0; i < num_variables; ++i) 1193 { 1194 VariableSP variable_sp (variable_list->GetVariableAtIndex(i)); 1195 if (variable_sp) 1196 { 1197 bool add_variable = false; 1198 switch (variable_sp->GetScope()) 1199 { 1200 case eValueTypeVariableGlobal: 1201 case eValueTypeVariableStatic: 1202 case eValueTypeVariableThreadLocal: 1203 add_variable = statics; 1204 break; 1205 1206 case eValueTypeVariableArgument: 1207 add_variable = arguments; 1208 break; 1209 1210 case eValueTypeVariableLocal: 1211 add_variable = locals; 1212 break; 1213 1214 default: 1215 break; 1216 } 1217 if (add_variable) 1218 { 1219 // Only add variables once so we don't end up with duplicates 1220 if (variable_set.find(variable_sp) == variable_set.end()) 1221 variable_set.insert(variable_sp); 1222 else 1223 continue; 1224 1225 if (in_scope_only && !variable_sp->IsInScope(frame)) 1226 continue; 1227 1228 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues)); 1229 1230 if (!include_runtime_support_values && 1231 valobj_sp != nullptr && 1232 valobj_sp->IsRuntimeSupportValue()) 1233 continue; 1234 1235 SBValue value_sb; 1236 value_sb.SetSP(valobj_sp,use_dynamic); 1237 value_list.Append(value_sb); 1238 } 1239 } 1240 } 1241 } 1242 } 1243 } 1244 else 1245 { 1246 if (log) 1247 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame."); 1248 } 1249 } 1250 else 1251 { 1252 if (log) 1253 log->Printf ("SBFrame::GetVariables () => error: process is running"); 1254 } 1255 } 1256 1257 if (log) 1258 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", 1259 static_cast<void*>(frame), 1260 static_cast<void*>(value_list.opaque_ptr())); 1261 1262 return value_list; 1263 } 1264 1265 SBValueList 1266 SBFrame::GetRegisters () 1267 { 1268 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1269 1270 SBValueList value_list; 1271 std::unique_lock<std::recursive_mutex> lock; 1272 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1273 1274 StackFrame *frame = nullptr; 1275 Target *target = exe_ctx.GetTargetPtr(); 1276 Process *process = exe_ctx.GetProcessPtr(); 1277 if (target && process) 1278 { 1279 Process::StopLocker stop_locker; 1280 if (stop_locker.TryLock(&process->GetRunLock())) 1281 { 1282 frame = exe_ctx.GetFramePtr(); 1283 if (frame) 1284 { 1285 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 1286 if (reg_ctx) 1287 { 1288 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 1289 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 1290 { 1291 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx)); 1292 } 1293 } 1294 } 1295 else 1296 { 1297 if (log) 1298 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame."); 1299 } 1300 } 1301 else 1302 { 1303 if (log) 1304 log->Printf ("SBFrame::GetRegisters () => error: process is running"); 1305 } 1306 } 1307 1308 if (log) 1309 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", 1310 static_cast<void*>(frame), 1311 static_cast<void*>(value_list.opaque_ptr())); 1312 1313 return value_list; 1314 } 1315 1316 SBValue 1317 SBFrame::FindRegister (const char *name) 1318 { 1319 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1320 1321 SBValue result; 1322 ValueObjectSP value_sp; 1323 std::unique_lock<std::recursive_mutex> lock; 1324 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1325 1326 StackFrame *frame = nullptr; 1327 Target *target = exe_ctx.GetTargetPtr(); 1328 Process *process = exe_ctx.GetProcessPtr(); 1329 if (target && process) 1330 { 1331 Process::StopLocker stop_locker; 1332 if (stop_locker.TryLock(&process->GetRunLock())) 1333 { 1334 frame = exe_ctx.GetFramePtr(); 1335 if (frame) 1336 { 1337 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 1338 if (reg_ctx) 1339 { 1340 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 1341 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 1342 { 1343 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 1344 if (reg_info && 1345 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 1346 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 1347 { 1348 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 1349 result.SetSP (value_sp); 1350 break; 1351 } 1352 } 1353 } 1354 } 1355 else 1356 { 1357 if (log) 1358 log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame."); 1359 } 1360 } 1361 else 1362 { 1363 if (log) 1364 log->Printf ("SBFrame::FindRegister () => error: process is running"); 1365 } 1366 } 1367 1368 if (log) 1369 log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)", 1370 static_cast<void*>(frame), 1371 static_cast<void*>(value_sp.get())); 1372 1373 return result; 1374 } 1375 1376 bool 1377 SBFrame::GetDescription (SBStream &description) 1378 { 1379 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1380 Stream &strm = description.ref(); 1381 1382 std::unique_lock<std::recursive_mutex> lock; 1383 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1384 1385 StackFrame *frame; 1386 Target *target = exe_ctx.GetTargetPtr(); 1387 Process *process = exe_ctx.GetProcessPtr(); 1388 if (target && process) 1389 { 1390 Process::StopLocker stop_locker; 1391 if (stop_locker.TryLock(&process->GetRunLock())) 1392 { 1393 frame = exe_ctx.GetFramePtr(); 1394 if (frame) 1395 { 1396 frame->DumpUsingSettingsFormat (&strm); 1397 } 1398 else 1399 { 1400 if (log) 1401 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame."); 1402 } 1403 } 1404 else 1405 { 1406 if (log) 1407 log->Printf ("SBFrame::GetDescription () => error: process is running"); 1408 } 1409 1410 } 1411 else 1412 strm.PutCString ("No value"); 1413 1414 return true; 1415 } 1416 1417 SBValue 1418 SBFrame::EvaluateExpression (const char *expr) 1419 { 1420 SBValue result; 1421 std::unique_lock<std::recursive_mutex> lock; 1422 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1423 1424 StackFrame *frame = exe_ctx.GetFramePtr(); 1425 Target *target = exe_ctx.GetTargetPtr(); 1426 if (frame && target) 1427 { 1428 SBExpressionOptions options; 1429 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue(); 1430 options.SetFetchDynamicValue (fetch_dynamic_value); 1431 options.SetUnwindOnError (true); 1432 options.SetIgnoreBreakpoints (true); 1433 if (target->GetLanguage() != eLanguageTypeUnknown) 1434 options.SetLanguage(target->GetLanguage()); 1435 else 1436 options.SetLanguage(frame->GetLanguage()); 1437 return EvaluateExpression (expr, options); 1438 } 1439 return result; 1440 } 1441 1442 SBValue 1443 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value) 1444 { 1445 SBExpressionOptions options; 1446 options.SetFetchDynamicValue (fetch_dynamic_value); 1447 options.SetUnwindOnError (true); 1448 options.SetIgnoreBreakpoints (true); 1449 std::unique_lock<std::recursive_mutex> lock; 1450 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1451 1452 StackFrame *frame = exe_ctx.GetFramePtr(); 1453 Target *target = exe_ctx.GetTargetPtr(); 1454 if (target && target->GetLanguage() != eLanguageTypeUnknown) 1455 options.SetLanguage(target->GetLanguage()); 1456 else if (frame) 1457 options.SetLanguage(frame->GetLanguage()); 1458 return EvaluateExpression (expr, options); 1459 } 1460 1461 SBValue 1462 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error) 1463 { 1464 SBExpressionOptions options; 1465 std::unique_lock<std::recursive_mutex> lock; 1466 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1467 1468 options.SetFetchDynamicValue (fetch_dynamic_value); 1469 options.SetUnwindOnError (unwind_on_error); 1470 options.SetIgnoreBreakpoints (true); 1471 StackFrame *frame = exe_ctx.GetFramePtr(); 1472 Target *target = exe_ctx.GetTargetPtr(); 1473 if (target && target->GetLanguage() != eLanguageTypeUnknown) 1474 options.SetLanguage(target->GetLanguage()); 1475 else if (frame) 1476 options.SetLanguage(frame->GetLanguage()); 1477 return EvaluateExpression (expr, options); 1478 } 1479 1480 lldb::SBValue 1481 SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options) 1482 { 1483 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1484 1485 #ifndef LLDB_DISABLE_PYTHON 1486 Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 1487 #endif 1488 1489 ExpressionResults exe_results = eExpressionSetupError; 1490 SBValue expr_result; 1491 1492 if (expr == nullptr || expr[0] == '\0') 1493 { 1494 if (log) 1495 log->Printf ("SBFrame::EvaluateExpression called with an empty expression"); 1496 return expr_result; 1497 } 1498 1499 ValueObjectSP expr_value_sp; 1500 1501 std::unique_lock<std::recursive_mutex> lock; 1502 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1503 1504 if (log) 1505 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr); 1506 1507 StackFrame *frame = nullptr; 1508 Target *target = exe_ctx.GetTargetPtr(); 1509 Process *process = exe_ctx.GetProcessPtr(); 1510 1511 if (target && process) 1512 { 1513 Process::StopLocker stop_locker; 1514 if (stop_locker.TryLock(&process->GetRunLock())) 1515 { 1516 frame = exe_ctx.GetFramePtr(); 1517 if (frame) 1518 { 1519 if (target->GetDisplayExpressionsInCrashlogs()) 1520 { 1521 StreamString frame_description; 1522 frame->DumpUsingSettingsFormat (&frame_description); 1523 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", 1524 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str()); 1525 } 1526 1527 exe_results = target->EvaluateExpression (expr, 1528 frame, 1529 expr_value_sp, 1530 options.ref()); 1531 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); 1532 1533 if (target->GetDisplayExpressionsInCrashlogs()) 1534 Host::SetCrashDescription(nullptr); 1535 } 1536 else 1537 { 1538 if (log) 1539 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame."); 1540 } 1541 } 1542 else 1543 { 1544 if (log) 1545 log->Printf ("SBFrame::EvaluateExpression () => error: process is running"); 1546 } 1547 } 1548 1549 #ifndef LLDB_DISABLE_PYTHON 1550 if (expr_log) 1551 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **", 1552 expr_result.GetValue(), expr_result.GetSummary()); 1553 1554 if (log) 1555 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", 1556 static_cast<void*>(frame), expr, 1557 static_cast<void*>(expr_value_sp.get()), exe_results); 1558 #endif 1559 1560 return expr_result; 1561 } 1562 1563 bool 1564 SBFrame::IsInlined() 1565 { 1566 return static_cast<const SBFrame*>(this)->IsInlined(); 1567 } 1568 1569 bool 1570 SBFrame::IsInlined() const 1571 { 1572 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1573 std::unique_lock<std::recursive_mutex> lock; 1574 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1575 1576 StackFrame *frame = nullptr; 1577 Target *target = exe_ctx.GetTargetPtr(); 1578 Process *process = exe_ctx.GetProcessPtr(); 1579 if (target && process) 1580 { 1581 Process::StopLocker stop_locker; 1582 if (stop_locker.TryLock(&process->GetRunLock())) 1583 { 1584 frame = exe_ctx.GetFramePtr(); 1585 if (frame) 1586 { 1587 1588 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block; 1589 if (block) 1590 return block->GetContainingInlinedBlock() != nullptr; 1591 } 1592 else 1593 { 1594 if (log) 1595 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame."); 1596 } 1597 } 1598 else 1599 { 1600 if (log) 1601 log->Printf ("SBFrame::IsInlined () => error: process is running"); 1602 } 1603 1604 } 1605 return false; 1606 } 1607 1608 const char * 1609 SBFrame::GetFunctionName() 1610 { 1611 return static_cast<const SBFrame*>(this)->GetFunctionName(); 1612 } 1613 1614 const char * 1615 SBFrame::GetFunctionName() const 1616 { 1617 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1618 const char *name = nullptr; 1619 std::unique_lock<std::recursive_mutex> lock; 1620 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1621 1622 StackFrame *frame = nullptr; 1623 Target *target = exe_ctx.GetTargetPtr(); 1624 Process *process = exe_ctx.GetProcessPtr(); 1625 if (target && process) 1626 { 1627 Process::StopLocker stop_locker; 1628 if (stop_locker.TryLock(&process->GetRunLock())) 1629 { 1630 frame = exe_ctx.GetFramePtr(); 1631 if (frame) 1632 { 1633 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); 1634 if (sc.block) 1635 { 1636 Block *inlined_block = sc.block->GetContainingInlinedBlock (); 1637 if (inlined_block) 1638 { 1639 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo(); 1640 name = inlined_info->GetName(sc.function->GetLanguage()).AsCString(); 1641 } 1642 } 1643 1644 if (name == nullptr) 1645 { 1646 if (sc.function) 1647 name = sc.function->GetName().GetCString(); 1648 } 1649 1650 if (name == nullptr) 1651 { 1652 if (sc.symbol) 1653 name = sc.symbol->GetName().GetCString(); 1654 } 1655 } 1656 else 1657 { 1658 if (log) 1659 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame."); 1660 } 1661 } 1662 else 1663 { 1664 if (log) 1665 log->Printf ("SBFrame::GetFunctionName() => error: process is running"); 1666 1667 } 1668 } 1669 return name; 1670 } 1671 1672 const char * 1673 SBFrame::GetDisplayFunctionName() 1674 { 1675 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1676 const char *name = nullptr; 1677 1678 std::unique_lock<std::recursive_mutex> lock; 1679 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1680 1681 StackFrame *frame = nullptr; 1682 Target *target = exe_ctx.GetTargetPtr(); 1683 Process *process = exe_ctx.GetProcessPtr(); 1684 if (target && process) 1685 { 1686 Process::StopLocker stop_locker; 1687 if (stop_locker.TryLock(&process->GetRunLock())) 1688 { 1689 frame = exe_ctx.GetFramePtr(); 1690 if (frame) 1691 { 1692 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); 1693 if (sc.block) 1694 { 1695 Block *inlined_block = sc.block->GetContainingInlinedBlock (); 1696 if (inlined_block) 1697 { 1698 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo(); 1699 name = inlined_info->GetDisplayName(sc.function->GetLanguage()).AsCString(); 1700 } 1701 } 1702 1703 if (name == nullptr) 1704 { 1705 if (sc.function) 1706 name = sc.function->GetDisplayName().GetCString(); 1707 } 1708 1709 if (name == nullptr) 1710 { 1711 if (sc.symbol) 1712 name = sc.symbol->GetDisplayName().GetCString(); 1713 } 1714 } 1715 else 1716 { 1717 if (log) 1718 log->Printf ("SBFrame::GetDisplayFunctionName () => error: could not reconstruct frame object for this SBFrame."); 1719 } 1720 } 1721 else 1722 { 1723 if (log) 1724 log->Printf ("SBFrame::GetDisplayFunctionName() => error: process is running"); 1725 1726 } 1727 } 1728 return name; 1729 } 1730