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