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