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