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 addr_t 458 SBFrame::GetPC () const 459 { 460 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 461 addr_t addr = LLDB_INVALID_ADDRESS; 462 Mutex::Locker api_locker; 463 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 464 465 StackFrame *frame = NULL; 466 Target *target = exe_ctx.GetTargetPtr(); 467 Process *process = exe_ctx.GetProcessPtr(); 468 if (target && process) 469 { 470 Process::StopLocker stop_locker; 471 if (stop_locker.TryLock(&process->GetRunLock())) 472 { 473 frame = exe_ctx.GetFramePtr(); 474 if (frame) 475 { 476 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target); 477 } 478 else 479 { 480 if (log) 481 log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame."); 482 } 483 } 484 else 485 { 486 if (log) 487 log->Printf ("SBFrame::GetPC () => error: process is running"); 488 } 489 } 490 491 if (log) 492 log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64, 493 static_cast<void*>(frame), addr); 494 495 return addr; 496 } 497 498 bool 499 SBFrame::SetPC (addr_t new_pc) 500 { 501 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 502 bool ret_val = false; 503 Mutex::Locker api_locker; 504 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 505 506 StackFrame *frame = NULL; 507 Target *target = exe_ctx.GetTargetPtr(); 508 Process *process = exe_ctx.GetProcessPtr(); 509 if (target && process) 510 { 511 Process::StopLocker stop_locker; 512 if (stop_locker.TryLock(&process->GetRunLock())) 513 { 514 frame = exe_ctx.GetFramePtr(); 515 if (frame) 516 { 517 ret_val = frame->GetRegisterContext()->SetPC (new_pc); 518 } 519 else 520 { 521 if (log) 522 log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame."); 523 } 524 } 525 else 526 { 527 if (log) 528 log->Printf ("SBFrame::SetPC () => error: process is running"); 529 } 530 } 531 532 if (log) 533 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i", 534 static_cast<void*>(frame), new_pc, ret_val); 535 536 return ret_val; 537 } 538 539 addr_t 540 SBFrame::GetSP () const 541 { 542 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 543 addr_t addr = LLDB_INVALID_ADDRESS; 544 Mutex::Locker api_locker; 545 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 546 547 StackFrame *frame = NULL; 548 Target *target = exe_ctx.GetTargetPtr(); 549 Process *process = exe_ctx.GetProcessPtr(); 550 if (target && process) 551 { 552 Process::StopLocker stop_locker; 553 if (stop_locker.TryLock(&process->GetRunLock())) 554 { 555 frame = exe_ctx.GetFramePtr(); 556 if (frame) 557 { 558 addr = frame->GetRegisterContext()->GetSP(); 559 } 560 else 561 { 562 if (log) 563 log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame."); 564 } 565 } 566 else 567 { 568 if (log) 569 log->Printf ("SBFrame::GetSP () => error: process is running"); 570 } 571 } 572 if (log) 573 log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64, 574 static_cast<void*>(frame), addr); 575 576 return addr; 577 } 578 579 580 addr_t 581 SBFrame::GetFP () const 582 { 583 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 584 addr_t addr = LLDB_INVALID_ADDRESS; 585 Mutex::Locker api_locker; 586 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 587 588 StackFrame *frame = NULL; 589 Target *target = exe_ctx.GetTargetPtr(); 590 Process *process = exe_ctx.GetProcessPtr(); 591 if (target && process) 592 { 593 Process::StopLocker stop_locker; 594 if (stop_locker.TryLock(&process->GetRunLock())) 595 { 596 frame = exe_ctx.GetFramePtr(); 597 if (frame) 598 { 599 addr = frame->GetRegisterContext()->GetFP(); 600 } 601 else 602 { 603 if (log) 604 log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame."); 605 } 606 } 607 else 608 { 609 if (log) 610 log->Printf ("SBFrame::GetFP () => error: process is running"); 611 } 612 } 613 614 if (log) 615 log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64, 616 static_cast<void*>(frame), addr); 617 return addr; 618 } 619 620 621 SBAddress 622 SBFrame::GetPCAddress () const 623 { 624 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 625 SBAddress sb_addr; 626 Mutex::Locker api_locker; 627 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 628 629 StackFrame *frame = exe_ctx.GetFramePtr(); 630 Target *target = exe_ctx.GetTargetPtr(); 631 Process *process = exe_ctx.GetProcessPtr(); 632 if (target && process) 633 { 634 Process::StopLocker stop_locker; 635 if (stop_locker.TryLock(&process->GetRunLock())) 636 { 637 frame = exe_ctx.GetFramePtr(); 638 if (frame) 639 { 640 sb_addr.SetAddress (&frame->GetFrameCodeAddress()); 641 } 642 else 643 { 644 if (log) 645 log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame."); 646 } 647 } 648 else 649 { 650 if (log) 651 log->Printf ("SBFrame::GetPCAddress () => error: process is running"); 652 } 653 } 654 if (log) 655 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", 656 static_cast<void*>(frame), 657 static_cast<void*>(sb_addr.get())); 658 return sb_addr; 659 } 660 661 void 662 SBFrame::Clear() 663 { 664 m_opaque_sp->Clear(); 665 } 666 667 lldb::SBValue 668 SBFrame::GetValueForVariablePath (const char *var_path) 669 { 670 SBValue sb_value; 671 ExecutionContext exe_ctx(m_opaque_sp.get()); 672 StackFrame *frame = exe_ctx.GetFramePtr(); 673 Target *target = exe_ctx.GetTargetPtr(); 674 if (frame && target) 675 { 676 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 677 sb_value = GetValueForVariablePath (var_path, use_dynamic); 678 } 679 return sb_value; 680 } 681 682 lldb::SBValue 683 SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic) 684 { 685 SBValue sb_value; 686 Mutex::Locker api_locker; 687 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 688 if (var_path == NULL || var_path[0] == '\0') 689 { 690 if (log) 691 log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path."); 692 return sb_value; 693 } 694 695 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 696 697 StackFrame *frame = NULL; 698 Target *target = exe_ctx.GetTargetPtr(); 699 Process *process = exe_ctx.GetProcessPtr(); 700 if (target && process) 701 { 702 Process::StopLocker stop_locker; 703 if (stop_locker.TryLock(&process->GetRunLock())) 704 { 705 frame = exe_ctx.GetFramePtr(); 706 if (frame) 707 { 708 VariableSP var_sp; 709 Error error; 710 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path, 711 eNoDynamicValues, 712 StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess, 713 var_sp, 714 error)); 715 sb_value.SetSP(value_sp, use_dynamic); 716 } 717 else 718 { 719 if (log) 720 log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame."); 721 } 722 } 723 else 724 { 725 if (log) 726 log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running"); 727 } 728 } 729 return sb_value; 730 } 731 732 SBValue 733 SBFrame::FindVariable (const char *name) 734 { 735 SBValue value; 736 ExecutionContext exe_ctx(m_opaque_sp.get()); 737 StackFrame *frame = exe_ctx.GetFramePtr(); 738 Target *target = exe_ctx.GetTargetPtr(); 739 if (frame && target) 740 { 741 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 742 value = FindVariable (name, use_dynamic); 743 } 744 return value; 745 } 746 747 SBValue 748 SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) 749 { 750 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 751 VariableSP var_sp; 752 SBValue sb_value; 753 754 if (name == NULL || name[0] == '\0') 755 { 756 if (log) 757 log->Printf ("SBFrame::FindVariable called with empty name"); 758 return sb_value; 759 } 760 761 ValueObjectSP value_sp; 762 Mutex::Locker api_locker; 763 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 764 765 StackFrame *frame = NULL; 766 Target *target = exe_ctx.GetTargetPtr(); 767 Process *process = exe_ctx.GetProcessPtr(); 768 if (target && process) 769 { 770 Process::StopLocker stop_locker; 771 if (stop_locker.TryLock(&process->GetRunLock())) 772 { 773 frame = exe_ctx.GetFramePtr(); 774 if (frame) 775 { 776 VariableList variable_list; 777 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); 778 779 if (sc.block) 780 { 781 const bool can_create = true; 782 const bool get_parent_variables = true; 783 const bool stop_if_block_is_inlined_function = true; 784 785 if (sc.block->AppendVariables (can_create, 786 get_parent_variables, 787 stop_if_block_is_inlined_function, 788 &variable_list)) 789 { 790 var_sp = variable_list.FindVariable (ConstString(name)); 791 } 792 } 793 794 if (var_sp) 795 { 796 value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); 797 sb_value.SetSP(value_sp, use_dynamic); 798 } 799 } 800 else 801 { 802 if (log) 803 log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame."); 804 } 805 } 806 else 807 { 808 if (log) 809 log->Printf ("SBFrame::FindVariable () => error: process is running"); 810 } 811 } 812 813 if (log) 814 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", 815 static_cast<void*>(frame), name, 816 static_cast<void*>(value_sp.get())); 817 818 return sb_value; 819 } 820 821 SBValue 822 SBFrame::FindValue (const char *name, ValueType value_type) 823 { 824 SBValue value; 825 ExecutionContext exe_ctx(m_opaque_sp.get()); 826 StackFrame *frame = exe_ctx.GetFramePtr(); 827 Target *target = exe_ctx.GetTargetPtr(); 828 if (frame && target) 829 { 830 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 831 value = FindValue (name, value_type, use_dynamic); 832 } 833 return value; 834 } 835 836 SBValue 837 SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic) 838 { 839 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 840 SBValue sb_value; 841 842 if (name == NULL || name[0] == '\0') 843 { 844 if (log) 845 log->Printf ("SBFrame::FindValue called with empty name."); 846 return sb_value; 847 } 848 849 ValueObjectSP value_sp; 850 Mutex::Locker api_locker; 851 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 852 853 StackFrame *frame = NULL; 854 Target *target = exe_ctx.GetTargetPtr(); 855 Process *process = exe_ctx.GetProcessPtr(); 856 if (target && process) 857 { 858 Process::StopLocker stop_locker; 859 if (stop_locker.TryLock(&process->GetRunLock())) 860 { 861 frame = exe_ctx.GetFramePtr(); 862 if (frame) 863 { 864 VariableList variable_list; 865 866 switch (value_type) 867 { 868 case eValueTypeVariableGlobal: // global variable 869 case eValueTypeVariableStatic: // static variable 870 case eValueTypeVariableArgument: // function argument variables 871 case eValueTypeVariableLocal: // function local variables 872 { 873 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); 874 875 const bool can_create = true; 876 const bool get_parent_variables = true; 877 const bool stop_if_block_is_inlined_function = true; 878 879 if (sc.block && sc.block->AppendVariables (can_create, 880 get_parent_variables, 881 stop_if_block_is_inlined_function, 882 &variable_list)) 883 { 884 if (value_type == eValueTypeVariableGlobal) 885 { 886 const bool get_file_globals = true; 887 VariableList* frame_vars = frame->GetVariableList(get_file_globals); 888 if (frame_vars) 889 frame_vars->AppendVariablesIfUnique(variable_list); 890 } 891 ConstString const_name(name); 892 VariableSP variable_sp(variable_list.FindVariable(const_name,value_type)); 893 if (variable_sp) 894 { 895 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues); 896 sb_value.SetSP (value_sp, use_dynamic); 897 break; 898 } 899 } 900 } 901 break; 902 903 case eValueTypeRegister: // stack frame register value 904 { 905 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 906 if (reg_ctx) 907 { 908 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 909 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 910 { 911 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 912 if (reg_info && 913 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 914 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 915 { 916 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 917 sb_value.SetSP (value_sp); 918 break; 919 } 920 } 921 } 922 } 923 break; 924 925 case eValueTypeRegisterSet: // A collection of stack frame register values 926 { 927 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 928 if (reg_ctx) 929 { 930 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 931 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 932 { 933 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx); 934 if (reg_set && 935 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || 936 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) 937 { 938 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx); 939 sb_value.SetSP (value_sp); 940 break; 941 } 942 } 943 } 944 } 945 break; 946 947 case eValueTypeConstResult: // constant result variables 948 { 949 ConstString const_name(name); 950 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name)); 951 if (expr_var_sp) 952 { 953 value_sp = expr_var_sp->GetValueObject(); 954 sb_value.SetSP (value_sp, use_dynamic); 955 } 956 } 957 break; 958 959 default: 960 break; 961 } 962 } 963 else 964 { 965 if (log) 966 log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame."); 967 } 968 } 969 else 970 { 971 if (log) 972 log->Printf ("SBFrame::FindValue () => error: process is running"); 973 } 974 } 975 976 if (log) 977 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", 978 static_cast<void*>(frame), name, value_type, 979 static_cast<void*>(value_sp.get())); 980 981 return sb_value; 982 } 983 984 bool 985 SBFrame::IsEqual (const SBFrame &that) const 986 { 987 lldb::StackFrameSP this_sp = GetFrameSP(); 988 lldb::StackFrameSP that_sp = that.GetFrameSP(); 989 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID()); 990 } 991 992 bool 993 SBFrame::operator == (const SBFrame &rhs) const 994 { 995 return IsEqual(rhs); 996 } 997 998 bool 999 SBFrame::operator != (const SBFrame &rhs) const 1000 { 1001 return !IsEqual(rhs); 1002 } 1003 1004 SBThread 1005 SBFrame::GetThread () const 1006 { 1007 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1008 1009 ExecutionContext exe_ctx(m_opaque_sp.get()); 1010 ThreadSP thread_sp (exe_ctx.GetThreadSP()); 1011 SBThread sb_thread (thread_sp); 1012 1013 if (log) 1014 { 1015 SBStream sstr; 1016 sb_thread.GetDescription (sstr); 1017 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", 1018 static_cast<void*>(exe_ctx.GetFramePtr()), 1019 static_cast<void*>(thread_sp.get()), sstr.GetData()); 1020 } 1021 1022 return sb_thread; 1023 } 1024 1025 const char * 1026 SBFrame::Disassemble () const 1027 { 1028 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1029 const char *disassembly = NULL; 1030 Mutex::Locker api_locker; 1031 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1032 1033 StackFrame *frame = NULL; 1034 Target *target = exe_ctx.GetTargetPtr(); 1035 Process *process = exe_ctx.GetProcessPtr(); 1036 if (target && process) 1037 { 1038 Process::StopLocker stop_locker; 1039 if (stop_locker.TryLock(&process->GetRunLock())) 1040 { 1041 frame = exe_ctx.GetFramePtr(); 1042 if (frame) 1043 { 1044 disassembly = frame->Disassemble(); 1045 } 1046 else 1047 { 1048 if (log) 1049 log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame."); 1050 } 1051 } 1052 else 1053 { 1054 if (log) 1055 log->Printf ("SBFrame::Disassemble () => error: process is running"); 1056 } 1057 } 1058 1059 if (log) 1060 log->Printf ("SBFrame(%p)::Disassemble () => %s", 1061 static_cast<void*>(frame), disassembly); 1062 1063 return disassembly; 1064 } 1065 1066 1067 SBValueList 1068 SBFrame::GetVariables (bool arguments, 1069 bool locals, 1070 bool statics, 1071 bool in_scope_only) 1072 { 1073 SBValueList value_list; 1074 ExecutionContext exe_ctx(m_opaque_sp.get()); 1075 StackFrame *frame = exe_ctx.GetFramePtr(); 1076 Target *target = exe_ctx.GetTargetPtr(); 1077 if (frame && target) 1078 { 1079 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 1080 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false; 1081 1082 SBVariablesOptions options; 1083 options.SetIncludeArguments(arguments); 1084 options.SetIncludeLocals(locals); 1085 options.SetIncludeStatics(statics); 1086 options.SetInScopeOnly(in_scope_only); 1087 options.SetIncludeRuntimeSupportValues(include_runtime_support_values); 1088 options.SetUseDynamic(use_dynamic); 1089 1090 value_list = GetVariables (options); 1091 } 1092 return value_list; 1093 } 1094 1095 lldb::SBValueList 1096 SBFrame::GetVariables (bool arguments, 1097 bool locals, 1098 bool statics, 1099 bool in_scope_only, 1100 lldb::DynamicValueType use_dynamic) 1101 { 1102 ExecutionContext exe_ctx(m_opaque_sp.get()); 1103 Target *target = exe_ctx.GetTargetPtr(); 1104 const bool include_runtime_support_values = target ? target->GetDisplayRuntimeSupportValues() : false; 1105 SBVariablesOptions options; 1106 options.SetIncludeArguments(arguments); 1107 options.SetIncludeLocals(locals); 1108 options.SetIncludeStatics(statics); 1109 options.SetInScopeOnly(in_scope_only); 1110 options.SetIncludeRuntimeSupportValues(include_runtime_support_values); 1111 options.SetUseDynamic(use_dynamic); 1112 return GetVariables(options); 1113 } 1114 1115 SBValueList 1116 SBFrame::GetVariables (const lldb::SBVariablesOptions& options) 1117 { 1118 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1119 1120 SBValueList value_list; 1121 Mutex::Locker api_locker; 1122 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1123 1124 StackFrame *frame = NULL; 1125 Target *target = exe_ctx.GetTargetPtr(); 1126 1127 const bool statics = options.GetIncludeStatics(); 1128 const bool arguments = options.GetIncludeArguments(); 1129 const bool locals = options.GetIncludeLocals(); 1130 const bool in_scope_only = options.GetInScopeOnly(); 1131 const bool include_runtime_support_values = options.GetIncludeRuntimeSupportValues(); 1132 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic(); 1133 1134 if (log) 1135 log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i runtime=%i dynamic=%i)", 1136 arguments, locals, 1137 statics, in_scope_only, 1138 include_runtime_support_values, use_dynamic); 1139 1140 Process *process = exe_ctx.GetProcessPtr(); 1141 if (target && process) 1142 { 1143 Process::StopLocker stop_locker; 1144 if (stop_locker.TryLock(&process->GetRunLock())) 1145 { 1146 frame = exe_ctx.GetFramePtr(); 1147 if (frame) 1148 { 1149 size_t i; 1150 VariableList *variable_list = NULL; 1151 variable_list = frame->GetVariableList(true); 1152 if (variable_list) 1153 { 1154 const size_t num_variables = variable_list->GetSize(); 1155 if (num_variables) 1156 { 1157 for (i = 0; i < num_variables; ++i) 1158 { 1159 VariableSP variable_sp (variable_list->GetVariableAtIndex(i)); 1160 if (variable_sp) 1161 { 1162 bool add_variable = false; 1163 switch (variable_sp->GetScope()) 1164 { 1165 case eValueTypeVariableGlobal: 1166 case eValueTypeVariableStatic: 1167 add_variable = statics; 1168 break; 1169 1170 case eValueTypeVariableArgument: 1171 add_variable = arguments; 1172 break; 1173 1174 case eValueTypeVariableLocal: 1175 add_variable = locals; 1176 break; 1177 1178 default: 1179 break; 1180 } 1181 if (add_variable) 1182 { 1183 if (in_scope_only && !variable_sp->IsInScope(frame)) 1184 continue; 1185 1186 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues)); 1187 1188 if (false == include_runtime_support_values && 1189 valobj_sp && 1190 true == valobj_sp->IsRuntimeSupportValue()) 1191 continue; 1192 1193 SBValue value_sb; 1194 value_sb.SetSP(valobj_sp,use_dynamic); 1195 value_list.Append(value_sb); 1196 } 1197 } 1198 } 1199 } 1200 } 1201 } 1202 else 1203 { 1204 if (log) 1205 log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame."); 1206 } 1207 } 1208 else 1209 { 1210 if (log) 1211 log->Printf ("SBFrame::GetVariables () => error: process is running"); 1212 } 1213 } 1214 1215 if (log) 1216 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", 1217 static_cast<void*>(frame), 1218 static_cast<void*>(value_list.opaque_ptr())); 1219 1220 return value_list; 1221 } 1222 1223 SBValueList 1224 SBFrame::GetRegisters () 1225 { 1226 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1227 1228 SBValueList value_list; 1229 Mutex::Locker api_locker; 1230 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1231 1232 StackFrame *frame = NULL; 1233 Target *target = exe_ctx.GetTargetPtr(); 1234 Process *process = exe_ctx.GetProcessPtr(); 1235 if (target && process) 1236 { 1237 Process::StopLocker stop_locker; 1238 if (stop_locker.TryLock(&process->GetRunLock())) 1239 { 1240 frame = exe_ctx.GetFramePtr(); 1241 if (frame) 1242 { 1243 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 1244 if (reg_ctx) 1245 { 1246 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 1247 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 1248 { 1249 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx)); 1250 } 1251 } 1252 } 1253 else 1254 { 1255 if (log) 1256 log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame."); 1257 } 1258 } 1259 else 1260 { 1261 if (log) 1262 log->Printf ("SBFrame::GetRegisters () => error: process is running"); 1263 } 1264 } 1265 1266 if (log) 1267 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", 1268 static_cast<void*>(frame), 1269 static_cast<void*>(value_list.opaque_ptr())); 1270 1271 return value_list; 1272 } 1273 1274 SBValue 1275 SBFrame::FindRegister (const char *name) 1276 { 1277 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1278 1279 SBValue result; 1280 ValueObjectSP value_sp; 1281 Mutex::Locker api_locker; 1282 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1283 1284 StackFrame *frame = NULL; 1285 Target *target = exe_ctx.GetTargetPtr(); 1286 Process *process = exe_ctx.GetProcessPtr(); 1287 if (target && process) 1288 { 1289 Process::StopLocker stop_locker; 1290 if (stop_locker.TryLock(&process->GetRunLock())) 1291 { 1292 frame = exe_ctx.GetFramePtr(); 1293 if (frame) 1294 { 1295 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 1296 if (reg_ctx) 1297 { 1298 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 1299 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 1300 { 1301 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 1302 if (reg_info && 1303 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 1304 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 1305 { 1306 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 1307 result.SetSP (value_sp); 1308 break; 1309 } 1310 } 1311 } 1312 } 1313 else 1314 { 1315 if (log) 1316 log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame."); 1317 } 1318 } 1319 else 1320 { 1321 if (log) 1322 log->Printf ("SBFrame::FindRegister () => error: process is running"); 1323 } 1324 } 1325 1326 if (log) 1327 log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)", 1328 static_cast<void*>(frame), 1329 static_cast<void*>(value_sp.get())); 1330 1331 return result; 1332 } 1333 1334 bool 1335 SBFrame::GetDescription (SBStream &description) 1336 { 1337 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1338 Stream &strm = description.ref(); 1339 1340 Mutex::Locker api_locker; 1341 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1342 1343 StackFrame *frame; 1344 Target *target = exe_ctx.GetTargetPtr(); 1345 Process *process = exe_ctx.GetProcessPtr(); 1346 if (target && process) 1347 { 1348 Process::StopLocker stop_locker; 1349 if (stop_locker.TryLock(&process->GetRunLock())) 1350 { 1351 frame = exe_ctx.GetFramePtr(); 1352 if (frame) 1353 { 1354 frame->DumpUsingSettingsFormat (&strm); 1355 } 1356 else 1357 { 1358 if (log) 1359 log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame."); 1360 } 1361 } 1362 else 1363 { 1364 if (log) 1365 log->Printf ("SBFrame::GetDescription () => error: process is running"); 1366 } 1367 1368 } 1369 else 1370 strm.PutCString ("No value"); 1371 1372 return true; 1373 } 1374 1375 SBValue 1376 SBFrame::EvaluateExpression (const char *expr) 1377 { 1378 SBValue result; 1379 ExecutionContext exe_ctx(m_opaque_sp.get()); 1380 StackFrame *frame = exe_ctx.GetFramePtr(); 1381 Target *target = exe_ctx.GetTargetPtr(); 1382 if (frame && target) 1383 { 1384 SBExpressionOptions options; 1385 lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue(); 1386 options.SetFetchDynamicValue (fetch_dynamic_value); 1387 options.SetUnwindOnError (true); 1388 return EvaluateExpression (expr, options); 1389 } 1390 return result; 1391 } 1392 1393 SBValue 1394 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value) 1395 { 1396 SBExpressionOptions options; 1397 options.SetFetchDynamicValue (fetch_dynamic_value); 1398 options.SetUnwindOnError (true); 1399 return EvaluateExpression (expr, options); 1400 } 1401 1402 SBValue 1403 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error) 1404 { 1405 SBExpressionOptions options; 1406 options.SetFetchDynamicValue (fetch_dynamic_value); 1407 options.SetUnwindOnError (unwind_on_error); 1408 return EvaluateExpression (expr, options); 1409 } 1410 1411 lldb::SBValue 1412 SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options) 1413 { 1414 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1415 1416 Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 1417 1418 ExpressionResults exe_results = eExpressionSetupError; 1419 SBValue expr_result; 1420 1421 if (expr == NULL || expr[0] == '\0') 1422 { 1423 if (log) 1424 log->Printf ("SBFrame::EvaluateExpression called with an empty expression"); 1425 return expr_result; 1426 } 1427 1428 ValueObjectSP expr_value_sp; 1429 1430 Mutex::Locker api_locker; 1431 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1432 1433 if (log) 1434 log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr); 1435 1436 StackFrame *frame = NULL; 1437 Target *target = exe_ctx.GetTargetPtr(); 1438 Process *process = exe_ctx.GetProcessPtr(); 1439 1440 if (target && process) 1441 { 1442 Process::StopLocker stop_locker; 1443 if (stop_locker.TryLock(&process->GetRunLock())) 1444 { 1445 frame = exe_ctx.GetFramePtr(); 1446 if (frame) 1447 { 1448 if (target->GetDisplayExpressionsInCrashlogs()) 1449 { 1450 StreamString frame_description; 1451 frame->DumpUsingSettingsFormat (&frame_description); 1452 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", 1453 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str()); 1454 } 1455 1456 exe_results = target->EvaluateExpression (expr, 1457 frame, 1458 expr_value_sp, 1459 options.ref()); 1460 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); 1461 1462 if (target->GetDisplayExpressionsInCrashlogs()) 1463 Host::SetCrashDescription (NULL); 1464 } 1465 else 1466 { 1467 if (log) 1468 log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame."); 1469 } 1470 } 1471 else 1472 { 1473 if (log) 1474 log->Printf ("SBFrame::EvaluateExpression () => error: process is running"); 1475 } 1476 } 1477 1478 #ifndef LLDB_DISABLE_PYTHON 1479 if (expr_log) 1480 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **", 1481 expr_result.GetValue(), expr_result.GetSummary()); 1482 1483 if (log) 1484 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", 1485 static_cast<void*>(frame), expr, 1486 static_cast<void*>(expr_value_sp.get()), exe_results); 1487 #endif 1488 1489 return expr_result; 1490 } 1491 1492 bool 1493 SBFrame::IsInlined() 1494 { 1495 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1496 ExecutionContext exe_ctx(m_opaque_sp.get()); 1497 StackFrame *frame = NULL; 1498 Target *target = exe_ctx.GetTargetPtr(); 1499 Process *process = exe_ctx.GetProcessPtr(); 1500 if (target && process) 1501 { 1502 Process::StopLocker stop_locker; 1503 if (stop_locker.TryLock(&process->GetRunLock())) 1504 { 1505 frame = exe_ctx.GetFramePtr(); 1506 if (frame) 1507 { 1508 1509 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block; 1510 if (block) 1511 return block->GetContainingInlinedBlock () != NULL; 1512 } 1513 else 1514 { 1515 if (log) 1516 log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame."); 1517 } 1518 } 1519 else 1520 { 1521 if (log) 1522 log->Printf ("SBFrame::IsInlined () => error: process is running"); 1523 } 1524 1525 } 1526 return false; 1527 } 1528 1529 const char * 1530 SBFrame::GetFunctionName() 1531 { 1532 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1533 const char *name = NULL; 1534 ExecutionContext exe_ctx(m_opaque_sp.get()); 1535 StackFrame *frame = NULL; 1536 Target *target = exe_ctx.GetTargetPtr(); 1537 Process *process = exe_ctx.GetProcessPtr(); 1538 if (target && process) 1539 { 1540 Process::StopLocker stop_locker; 1541 if (stop_locker.TryLock(&process->GetRunLock())) 1542 { 1543 frame = exe_ctx.GetFramePtr(); 1544 if (frame) 1545 { 1546 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); 1547 if (sc.block) 1548 { 1549 Block *inlined_block = sc.block->GetContainingInlinedBlock (); 1550 if (inlined_block) 1551 { 1552 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo(); 1553 name = inlined_info->GetName().AsCString(); 1554 } 1555 } 1556 1557 if (name == NULL) 1558 { 1559 if (sc.function) 1560 name = sc.function->GetName().GetCString(); 1561 } 1562 1563 if (name == NULL) 1564 { 1565 if (sc.symbol) 1566 name = sc.symbol->GetName().GetCString(); 1567 } 1568 } 1569 else 1570 { 1571 if (log) 1572 log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame."); 1573 } 1574 } 1575 else 1576 { 1577 if (log) 1578 log->Printf ("SBFrame::GetFunctionName() => error: process is running"); 1579 1580 } 1581 } 1582 return name; 1583 } 1584 1585