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/SymbolContext.h" 28 #include "lldb/Symbol/VariableList.h" 29 #include "lldb/Symbol/Variable.h" 30 #include "lldb/Target/ExecutionContext.h" 31 #include "lldb/Target/Target.h" 32 #include "lldb/Target/Process.h" 33 #include "lldb/Target/RegisterContext.h" 34 #include "lldb/Target/StackFrame.h" 35 #include "lldb/Target/StackID.h" 36 #include "lldb/Target/Thread.h" 37 38 #include "lldb/API/SBDebugger.h" 39 #include "lldb/API/SBValue.h" 40 #include "lldb/API/SBAddress.h" 41 #include "lldb/API/SBStream.h" 42 #include "lldb/API/SBSymbolContext.h" 43 #include "lldb/API/SBThread.h" 44 45 using namespace lldb; 46 using namespace lldb_private; 47 48 49 SBFrame::SBFrame () : 50 m_opaque_sp (new ExecutionContextRef()) 51 { 52 } 53 54 SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) : 55 m_opaque_sp (new ExecutionContextRef (lldb_object_sp)) 56 { 57 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 58 59 if (log) 60 { 61 SBStream sstr; 62 GetDescription (sstr); 63 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s", 64 lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData()); 65 66 } 67 } 68 69 SBFrame::SBFrame(const SBFrame &rhs) : 70 m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp)) 71 { 72 } 73 74 const SBFrame & 75 SBFrame::operator = (const SBFrame &rhs) 76 { 77 if (this != &rhs) 78 *m_opaque_sp = *rhs.m_opaque_sp; 79 return *this; 80 } 81 82 SBFrame::~SBFrame() 83 { 84 } 85 86 StackFrameSP 87 SBFrame::GetFrameSP() const 88 { 89 return m_opaque_sp->GetFrameSP(); 90 } 91 92 void 93 SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp) 94 { 95 return m_opaque_sp->SetFrameSP(lldb_object_sp); 96 } 97 98 bool 99 SBFrame::IsValid() const 100 { 101 return GetFrameSP().get() != NULL; 102 } 103 104 SBSymbolContext 105 SBFrame::GetSymbolContext (uint32_t resolve_scope) const 106 { 107 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 108 SBSymbolContext sb_sym_ctx; 109 ExecutionContext exe_ctx(m_opaque_sp.get()); 110 StackFrame *frame = exe_ctx.GetFramePtr(); 111 Target *target = exe_ctx.GetTargetPtr(); 112 if (frame && target) 113 { 114 Process::StopLocker stop_locker; 115 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 116 { 117 Mutex::Locker api_locker (target->GetAPIMutex()); 118 sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope)); 119 } 120 else 121 { 122 if (log) 123 log->Printf ("SBFrame(%p)::GetSymbolContext () => error: process is running", frame); 124 } 125 } 126 127 if (log) 128 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)", 129 frame, resolve_scope, sb_sym_ctx.get()); 130 131 return sb_sym_ctx; 132 } 133 134 SBModule 135 SBFrame::GetModule () const 136 { 137 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 138 SBModule sb_module; 139 ModuleSP module_sp; 140 ExecutionContext exe_ctx(m_opaque_sp.get()); 141 StackFrame *frame = exe_ctx.GetFramePtr(); 142 Target *target = exe_ctx.GetTargetPtr(); 143 if (frame && target) 144 { 145 Process::StopLocker stop_locker; 146 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 147 { 148 Mutex::Locker api_locker (target->GetAPIMutex()); 149 module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp; 150 sb_module.SetSP (module_sp); 151 } 152 else 153 { 154 if (log) 155 log->Printf ("SBFrame(%p)::GetModule () => error: process is running", frame); 156 } 157 } 158 159 if (log) 160 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", 161 frame, module_sp.get()); 162 163 return sb_module; 164 } 165 166 SBCompileUnit 167 SBFrame::GetCompileUnit () const 168 { 169 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 170 SBCompileUnit sb_comp_unit; 171 ExecutionContext exe_ctx(m_opaque_sp.get()); 172 StackFrame *frame = exe_ctx.GetFramePtr(); 173 Target *target = exe_ctx.GetTargetPtr(); 174 if (frame && target) 175 { 176 Process::StopLocker stop_locker; 177 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 178 { 179 Mutex::Locker api_locker (target->GetAPIMutex()); 180 sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit); 181 } 182 else 183 { 184 if (log) 185 log->Printf ("SBFrame(%p)::GetCompileUnit () => error: process is running", frame); 186 } 187 } 188 if (log) 189 log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)", 190 frame, sb_comp_unit.get()); 191 192 return sb_comp_unit; 193 } 194 195 SBFunction 196 SBFrame::GetFunction () const 197 { 198 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 199 SBFunction sb_function; 200 ExecutionContext exe_ctx(m_opaque_sp.get()); 201 StackFrame *frame = exe_ctx.GetFramePtr(); 202 Target *target = exe_ctx.GetTargetPtr(); 203 if (frame && target) 204 { 205 Process::StopLocker stop_locker; 206 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 207 { 208 Mutex::Locker api_locker (target->GetAPIMutex()); 209 sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function); 210 } 211 else 212 { 213 if (log) 214 log->Printf ("SBFrame(%p)::GetFunction () => error: process is running", frame); 215 } 216 } 217 if (log) 218 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", 219 frame, sb_function.get()); 220 221 return sb_function; 222 } 223 224 SBSymbol 225 SBFrame::GetSymbol () const 226 { 227 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 228 SBSymbol sb_symbol; 229 ExecutionContext exe_ctx(m_opaque_sp.get()); 230 StackFrame *frame = exe_ctx.GetFramePtr(); 231 Target *target = exe_ctx.GetTargetPtr(); 232 if (frame && target) 233 { 234 Process::StopLocker stop_locker; 235 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 236 { 237 Mutex::Locker api_locker (target->GetAPIMutex()); 238 sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol); 239 } 240 else 241 { 242 if (log) 243 log->Printf ("SBFrame(%p)::GetSymbol () => error: process is running", frame); 244 } 245 } 246 if (log) 247 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", 248 frame, sb_symbol.get()); 249 return sb_symbol; 250 } 251 252 SBBlock 253 SBFrame::GetBlock () const 254 { 255 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 256 SBBlock sb_block; 257 ExecutionContext exe_ctx(m_opaque_sp.get()); 258 StackFrame *frame = exe_ctx.GetFramePtr(); 259 Target *target = exe_ctx.GetTargetPtr(); 260 if (frame && target) 261 { 262 Process::StopLocker stop_locker; 263 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 264 { 265 Mutex::Locker api_locker (target->GetAPIMutex()); 266 sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block); 267 } 268 else 269 { 270 if (log) 271 log->Printf ("SBFrame(%p)::GetBlock () => error: process is running", frame); 272 } 273 } 274 if (log) 275 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", 276 frame, sb_block.GetPtr()); 277 return sb_block; 278 } 279 280 SBBlock 281 SBFrame::GetFrameBlock () const 282 { 283 SBBlock sb_block; 284 ExecutionContext exe_ctx(m_opaque_sp.get()); 285 StackFrame *frame = exe_ctx.GetFramePtr(); 286 Target *target = exe_ctx.GetTargetPtr(); 287 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 288 if (frame && target) 289 { 290 Process::StopLocker stop_locker; 291 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 292 { 293 Mutex::Locker api_locker (target->GetAPIMutex()); 294 sb_block.SetPtr(frame->GetFrameBlock ()); 295 } 296 else 297 { 298 if (log) 299 log->Printf ("SBFrame(%p)::GetFrameBlock () => error: process is running", frame); 300 } 301 } 302 if (log) 303 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", 304 frame, sb_block.GetPtr()); 305 return sb_block; 306 } 307 308 SBLineEntry 309 SBFrame::GetLineEntry () const 310 { 311 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 312 SBLineEntry sb_line_entry; 313 ExecutionContext exe_ctx(m_opaque_sp.get()); 314 StackFrame *frame = exe_ctx.GetFramePtr(); 315 Target *target = exe_ctx.GetTargetPtr(); 316 if (frame && target) 317 { 318 Process::StopLocker stop_locker; 319 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 320 { 321 Mutex::Locker api_locker (target->GetAPIMutex()); 322 sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry); 323 } 324 else 325 { 326 if (log) 327 log->Printf ("SBFrame(%p)::GetLineEntry () => error: process is running", frame); 328 } 329 } 330 if (log) 331 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", 332 frame, sb_line_entry.get()); 333 return sb_line_entry; 334 } 335 336 uint32_t 337 SBFrame::GetFrameID () const 338 { 339 uint32_t frame_idx = UINT32_MAX; 340 341 ExecutionContext exe_ctx(m_opaque_sp.get()); 342 StackFrame *frame = exe_ctx.GetFramePtr(); 343 if (frame) 344 frame_idx = frame->GetFrameIndex (); 345 346 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 347 if (log) 348 log->Printf ("SBFrame(%p)::GetFrameID () => %u", 349 frame, frame_idx); 350 return frame_idx; 351 } 352 353 addr_t 354 SBFrame::GetPC () const 355 { 356 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 357 addr_t addr = LLDB_INVALID_ADDRESS; 358 ExecutionContext exe_ctx(m_opaque_sp.get()); 359 StackFrame *frame = exe_ctx.GetFramePtr(); 360 Target *target = exe_ctx.GetTargetPtr(); 361 if (frame && target) 362 { 363 Process::StopLocker stop_locker; 364 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 365 { 366 Mutex::Locker api_locker (target->GetAPIMutex()); 367 addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target); 368 } 369 else 370 { 371 if (log) 372 log->Printf ("SBFrame(%p)::GetPC () => error: process is running", frame); 373 } 374 } 375 376 if (log) 377 log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame, addr); 378 379 return addr; 380 } 381 382 bool 383 SBFrame::SetPC (addr_t new_pc) 384 { 385 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 386 bool ret_val = false; 387 ExecutionContext exe_ctx(m_opaque_sp.get()); 388 StackFrame *frame = exe_ctx.GetFramePtr(); 389 Target *target = exe_ctx.GetTargetPtr(); 390 if (frame && target) 391 { 392 Process::StopLocker stop_locker; 393 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 394 { 395 Mutex::Locker api_locker (target->GetAPIMutex()); 396 ret_val = frame->GetRegisterContext()->SetPC (new_pc); 397 } 398 else 399 { 400 if (log) 401 log->Printf ("SBFrame(%p)::SetPC () => error: process is running", frame); 402 } 403 } 404 405 if (log) 406 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i", 407 frame, new_pc, ret_val); 408 409 return ret_val; 410 } 411 412 addr_t 413 SBFrame::GetSP () const 414 { 415 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 416 addr_t addr = LLDB_INVALID_ADDRESS; 417 ExecutionContext exe_ctx(m_opaque_sp.get()); 418 StackFrame *frame = exe_ctx.GetFramePtr(); 419 Target *target = exe_ctx.GetTargetPtr(); 420 if (frame && target) 421 { 422 Process::StopLocker stop_locker; 423 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 424 { 425 Mutex::Locker api_locker (target->GetAPIMutex()); 426 addr = frame->GetRegisterContext()->GetSP(); 427 } 428 else 429 { 430 if (log) 431 log->Printf ("SBFrame(%p)::GetSP () => error: process is running", frame); 432 } 433 } 434 if (log) 435 log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame, addr); 436 437 return addr; 438 } 439 440 441 addr_t 442 SBFrame::GetFP () const 443 { 444 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 445 addr_t addr = LLDB_INVALID_ADDRESS; 446 ExecutionContext exe_ctx(m_opaque_sp.get()); 447 StackFrame *frame = exe_ctx.GetFramePtr(); 448 Target *target = exe_ctx.GetTargetPtr(); 449 if (frame && target) 450 { 451 Process::StopLocker stop_locker; 452 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 453 { 454 Mutex::Locker api_locker (target->GetAPIMutex()); 455 addr = frame->GetRegisterContext()->GetFP(); 456 } 457 else 458 { 459 if (log) 460 log->Printf ("SBFrame(%p)::GetFP () => error: process is running", frame); 461 } 462 } 463 464 if (log) 465 log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame, addr); 466 return addr; 467 } 468 469 470 SBAddress 471 SBFrame::GetPCAddress () const 472 { 473 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 474 SBAddress sb_addr; 475 ExecutionContext exe_ctx(m_opaque_sp.get()); 476 StackFrame *frame = exe_ctx.GetFramePtr(); 477 Target *target = exe_ctx.GetTargetPtr(); 478 if (frame && target) 479 { 480 Process::StopLocker stop_locker; 481 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 482 { 483 Mutex::Locker api_locker (target->GetAPIMutex()); 484 sb_addr.SetAddress (&frame->GetFrameCodeAddress()); 485 } 486 else 487 { 488 if (log) 489 log->Printf ("SBFrame(%p)::GetPCAddress () => error: process is running", frame); 490 } 491 } 492 if (log) 493 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get()); 494 return sb_addr; 495 } 496 497 void 498 SBFrame::Clear() 499 { 500 m_opaque_sp.reset(); 501 } 502 503 lldb::SBValue 504 SBFrame::GetValueForVariablePath (const char *var_path) 505 { 506 SBValue sb_value; 507 ExecutionContext exe_ctx(m_opaque_sp.get()); 508 StackFrame *frame = exe_ctx.GetFramePtr(); 509 Target *target = exe_ctx.GetTargetPtr(); 510 if (frame && target) 511 { 512 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 513 sb_value = GetValueForVariablePath (var_path, use_dynamic); 514 } 515 return sb_value; 516 } 517 518 lldb::SBValue 519 SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic) 520 { 521 SBValue sb_value; 522 ExecutionContext exe_ctx(m_opaque_sp.get()); 523 StackFrame *frame = exe_ctx.GetFramePtr(); 524 Target *target = exe_ctx.GetTargetPtr(); 525 if (frame && target && var_path && var_path[0]) 526 { 527 Process::StopLocker stop_locker; 528 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 529 { 530 Mutex::Locker api_locker (target->GetAPIMutex()); 531 VariableSP var_sp; 532 Error error; 533 ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path, 534 use_dynamic, 535 StackFrame::eExpressionPathOptionCheckPtrVsMember, 536 var_sp, 537 error)); 538 sb_value.SetSP(value_sp); 539 } 540 else 541 { 542 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 543 if (log) 544 log->Printf ("SBFrame(%p)::GetValueForVariablePath () => error: process is running", frame); 545 } 546 } 547 return sb_value; 548 } 549 550 SBValue 551 SBFrame::FindVariable (const char *name) 552 { 553 SBValue value; 554 ExecutionContext exe_ctx(m_opaque_sp.get()); 555 StackFrame *frame = exe_ctx.GetFramePtr(); 556 Target *target = exe_ctx.GetTargetPtr(); 557 if (frame && target) 558 { 559 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 560 value = FindVariable (name, use_dynamic); 561 } 562 return value; 563 } 564 565 566 SBValue 567 SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) 568 { 569 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 570 VariableSP var_sp; 571 SBValue sb_value; 572 ValueObjectSP value_sp; 573 ExecutionContext exe_ctx(m_opaque_sp.get()); 574 StackFrame *frame = exe_ctx.GetFramePtr(); 575 Target *target = exe_ctx.GetTargetPtr(); 576 if (frame && target && name && name[0]) 577 { 578 Process::StopLocker stop_locker; 579 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 580 { 581 VariableList variable_list; 582 Mutex::Locker api_locker (target->GetAPIMutex()); 583 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); 584 585 if (sc.block) 586 { 587 const bool can_create = true; 588 const bool get_parent_variables = true; 589 const bool stop_if_block_is_inlined_function = true; 590 591 if (sc.block->AppendVariables (can_create, 592 get_parent_variables, 593 stop_if_block_is_inlined_function, 594 &variable_list)) 595 { 596 var_sp = variable_list.FindVariable (ConstString(name)); 597 } 598 } 599 600 if (var_sp) 601 { 602 value_sp = frame->GetValueObjectForFrameVariable(var_sp, use_dynamic); 603 sb_value.SetSP(value_sp); 604 } 605 } 606 else 607 { 608 if (log) 609 log->Printf ("SBFrame(%p)::FindVariable () => error: process is running", frame); 610 } 611 } 612 613 if (log) 614 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", 615 frame, name, value_sp.get()); 616 617 return sb_value; 618 } 619 620 SBValue 621 SBFrame::FindValue (const char *name, ValueType value_type) 622 { 623 SBValue value; 624 ExecutionContext exe_ctx(m_opaque_sp.get()); 625 StackFrame *frame = exe_ctx.GetFramePtr(); 626 Target *target = exe_ctx.GetTargetPtr(); 627 if (frame && target) 628 { 629 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 630 value = FindValue (name, value_type, use_dynamic); 631 } 632 return value; 633 } 634 635 SBValue 636 SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic) 637 { 638 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 639 SBValue sb_value; 640 ValueObjectSP value_sp; 641 ExecutionContext exe_ctx(m_opaque_sp.get()); 642 StackFrame *frame = exe_ctx.GetFramePtr(); 643 Target *target = exe_ctx.GetTargetPtr(); 644 if (frame && target && name && name[0]) 645 { 646 Process::StopLocker stop_locker; 647 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 648 { 649 Mutex::Locker api_locker (target->GetAPIMutex()); 650 651 switch (value_type) 652 { 653 case eValueTypeVariableGlobal: // global variable 654 case eValueTypeVariableStatic: // static variable 655 case eValueTypeVariableArgument: // function argument variables 656 case eValueTypeVariableLocal: // function local variables 657 { 658 VariableList *variable_list = frame->GetVariableList(true); 659 660 SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); 661 662 const bool can_create = true; 663 const bool get_parent_variables = true; 664 const bool stop_if_block_is_inlined_function = true; 665 666 if (sc.block && sc.block->AppendVariables (can_create, 667 get_parent_variables, 668 stop_if_block_is_inlined_function, 669 variable_list)) 670 { 671 ConstString const_name(name); 672 const uint32_t num_variables = variable_list->GetSize(); 673 for (uint32_t i = 0; i < num_variables; ++i) 674 { 675 VariableSP variable_sp (variable_list->GetVariableAtIndex(i)); 676 if (variable_sp && 677 variable_sp->GetScope() == value_type && 678 variable_sp->GetName() == const_name) 679 { 680 value_sp = frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic); 681 sb_value.SetSP (value_sp); 682 break; 683 } 684 } 685 } 686 } 687 break; 688 689 case eValueTypeRegister: // stack frame register value 690 { 691 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 692 if (reg_ctx) 693 { 694 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 695 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 696 { 697 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 698 if (reg_info && 699 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 700 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 701 { 702 value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 703 sb_value.SetSP (value_sp); 704 break; 705 } 706 } 707 } 708 } 709 break; 710 711 case eValueTypeRegisterSet: // A collection of stack frame register values 712 { 713 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 714 if (reg_ctx) 715 { 716 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 717 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 718 { 719 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx); 720 if (reg_set && 721 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || 722 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) 723 { 724 value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx); 725 sb_value.SetSP (value_sp); 726 break; 727 } 728 } 729 } 730 } 731 break; 732 733 case eValueTypeConstResult: // constant result variables 734 { 735 ConstString const_name(name); 736 ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name)); 737 if (expr_var_sp) 738 { 739 value_sp = expr_var_sp->GetValueObject(); 740 sb_value.SetSP (value_sp); 741 } 742 } 743 break; 744 745 default: 746 break; 747 } 748 } 749 else 750 { 751 if (log) 752 log->Printf ("SBFrame(%p)::FindValue () => error: process is running", frame); 753 } 754 } 755 756 if (log) 757 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", 758 frame, name, value_type, value_sp.get()); 759 760 761 return sb_value; 762 } 763 764 bool 765 SBFrame::IsEqual (const SBFrame &that) const 766 { 767 lldb::StackFrameSP this_sp = GetFrameSP(); 768 lldb::StackFrameSP that_sp = that.GetFrameSP(); 769 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID()); 770 } 771 772 bool 773 SBFrame::operator == (const SBFrame &rhs) const 774 { 775 return IsEqual(rhs); 776 } 777 778 bool 779 SBFrame::operator != (const SBFrame &rhs) const 780 { 781 return !IsEqual(rhs); 782 } 783 784 SBThread 785 SBFrame::GetThread () const 786 { 787 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 788 789 ExecutionContext exe_ctx(m_opaque_sp.get()); 790 ThreadSP thread_sp (exe_ctx.GetThreadSP()); 791 SBThread sb_thread (thread_sp); 792 793 if (log) 794 { 795 SBStream sstr; 796 sb_thread.GetDescription (sstr); 797 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", 798 exe_ctx.GetFramePtr(), 799 thread_sp.get(), 800 sstr.GetData()); 801 } 802 803 return sb_thread; 804 } 805 806 const char * 807 SBFrame::Disassemble () const 808 { 809 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 810 const char *disassembly = NULL; 811 ExecutionContext exe_ctx(m_opaque_sp.get()); 812 StackFrame *frame = exe_ctx.GetFramePtr(); 813 Target *target = exe_ctx.GetTargetPtr(); 814 if (frame && target) 815 { 816 Process::StopLocker stop_locker; 817 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 818 { 819 Mutex::Locker api_locker (target->GetAPIMutex()); 820 disassembly = frame->Disassemble(); 821 } 822 else 823 { 824 if (log) 825 log->Printf ("SBFrame(%p)::Disassemble () => error: process is running", frame); 826 } 827 } 828 829 if (log) 830 log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly); 831 832 return disassembly; 833 } 834 835 836 SBValueList 837 SBFrame::GetVariables (bool arguments, 838 bool locals, 839 bool statics, 840 bool in_scope_only) 841 { 842 SBValueList value_list; 843 ExecutionContext exe_ctx(m_opaque_sp.get()); 844 StackFrame *frame = exe_ctx.GetFramePtr(); 845 Target *target = exe_ctx.GetTargetPtr(); 846 if (frame && target) 847 { 848 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 849 value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic); 850 } 851 return value_list; 852 } 853 854 SBValueList 855 SBFrame::GetVariables (bool arguments, 856 bool locals, 857 bool statics, 858 bool in_scope_only, 859 lldb::DynamicValueType use_dynamic) 860 { 861 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 862 863 SBValueList value_list; 864 ExecutionContext exe_ctx(m_opaque_sp.get()); 865 StackFrame *frame = exe_ctx.GetFramePtr(); 866 Target *target = exe_ctx.GetTargetPtr(); 867 868 if (log) 869 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)", 870 frame, 871 arguments, 872 locals, 873 statics, 874 in_scope_only); 875 876 if (frame && target) 877 { 878 Process::StopLocker stop_locker; 879 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 880 { 881 882 size_t i; 883 VariableList *variable_list = NULL; 884 // Scope for locker 885 { 886 Mutex::Locker api_locker (target->GetAPIMutex()); 887 variable_list = frame->GetVariableList(true); 888 } 889 if (variable_list) 890 { 891 const size_t num_variables = variable_list->GetSize(); 892 if (num_variables) 893 { 894 for (i = 0; i < num_variables; ++i) 895 { 896 VariableSP variable_sp (variable_list->GetVariableAtIndex(i)); 897 if (variable_sp) 898 { 899 bool add_variable = false; 900 switch (variable_sp->GetScope()) 901 { 902 case eValueTypeVariableGlobal: 903 case eValueTypeVariableStatic: 904 add_variable = statics; 905 break; 906 907 case eValueTypeVariableArgument: 908 add_variable = arguments; 909 break; 910 911 case eValueTypeVariableLocal: 912 add_variable = locals; 913 break; 914 915 default: 916 break; 917 } 918 if (add_variable) 919 { 920 if (in_scope_only && !variable_sp->IsInScope(frame)) 921 continue; 922 923 value_list.Append(frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic)); 924 } 925 } 926 } 927 } 928 } 929 } 930 else 931 { 932 if (log) 933 log->Printf ("SBFrame(%p)::GetVariables () => error: process is running", frame); 934 } 935 } 936 937 if (log) 938 { 939 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame, 940 value_list.get()); 941 } 942 943 return value_list; 944 } 945 946 SBValueList 947 SBFrame::GetRegisters () 948 { 949 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 950 951 SBValueList value_list; 952 ExecutionContext exe_ctx(m_opaque_sp.get()); 953 StackFrame *frame = exe_ctx.GetFramePtr(); 954 Target *target = exe_ctx.GetTargetPtr(); 955 if (frame && target) 956 { 957 Process::StopLocker stop_locker; 958 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 959 { 960 Mutex::Locker api_locker (target->GetAPIMutex()); 961 RegisterContextSP reg_ctx (frame->GetRegisterContext()); 962 if (reg_ctx) 963 { 964 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 965 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 966 { 967 value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx)); 968 } 969 } 970 } 971 else 972 { 973 if (log) 974 log->Printf ("SBFrame(%p)::GetRegisters () => error: process is running", frame); 975 } 976 } 977 978 if (log) 979 log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", frame, value_list.get()); 980 981 return value_list; 982 } 983 984 bool 985 SBFrame::GetDescription (SBStream &description) 986 { 987 Stream &strm = description.ref(); 988 989 ExecutionContext exe_ctx(m_opaque_sp.get()); 990 StackFrame *frame = exe_ctx.GetFramePtr(); 991 Target *target = exe_ctx.GetTargetPtr(); 992 if (frame && target) 993 { 994 Process::StopLocker stop_locker; 995 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 996 { 997 Mutex::Locker api_locker (target->GetAPIMutex()); 998 frame->DumpUsingSettingsFormat (&strm); 999 } 1000 else 1001 { 1002 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1003 if (log) 1004 log->Printf ("SBFrame(%p)::GetDescription () => error: process is running", frame); 1005 } 1006 1007 } 1008 else 1009 strm.PutCString ("No value"); 1010 1011 return true; 1012 } 1013 1014 SBValue 1015 SBFrame::EvaluateExpression (const char *expr) 1016 { 1017 SBValue result; 1018 ExecutionContext exe_ctx(m_opaque_sp.get()); 1019 StackFrame *frame = exe_ctx.GetFramePtr(); 1020 Target *target = exe_ctx.GetTargetPtr(); 1021 if (frame && target) 1022 { 1023 lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 1024 result = EvaluateExpression (expr, use_dynamic); 1025 } 1026 return result; 1027 } 1028 1029 SBValue 1030 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value) 1031 { 1032 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1033 1034 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 1035 1036 ExecutionResults exe_results; 1037 SBValue expr_result; 1038 ValueObjectSP expr_value_sp; 1039 1040 ExecutionContext exe_ctx(m_opaque_sp.get()); 1041 StackFrame *frame = exe_ctx.GetFramePtr(); 1042 Target *target = exe_ctx.GetTargetPtr(); 1043 if (log) 1044 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame, expr); 1045 1046 if (frame && target) 1047 { 1048 Process::StopLocker stop_locker; 1049 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 1050 { 1051 1052 Mutex::Locker api_locker (target->GetAPIMutex()); 1053 1054 1055 StreamString frame_description; 1056 frame->DumpUsingSettingsFormat (&frame_description); 1057 1058 Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", 1059 expr, fetch_dynamic_value, frame_description.GetString().c_str()); 1060 1061 const bool coerce_to_id = false; 1062 const bool unwind_on_error = true; 1063 const bool keep_in_memory = false; 1064 1065 exe_results = target->EvaluateExpression (expr, 1066 frame, 1067 eExecutionPolicyOnlyWhenNeeded, 1068 coerce_to_id, 1069 unwind_on_error, 1070 keep_in_memory, 1071 fetch_dynamic_value, 1072 expr_value_sp); 1073 expr_result.SetSP(expr_value_sp); 1074 Host::SetCrashDescription (NULL); 1075 } 1076 else 1077 { 1078 if (log) 1079 log->Printf ("SBFrame(%p)::EvaluateExpression () => error: process is running", frame); 1080 } 1081 } 1082 1083 #ifndef LLDB_DISABLE_PYTHON 1084 if (expr_log) 1085 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **", 1086 expr_result.GetValue(), 1087 expr_result.GetSummary()); 1088 1089 if (log) 1090 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", 1091 frame, 1092 expr, 1093 expr_value_sp.get(), 1094 exe_results); 1095 #endif 1096 1097 return expr_result; 1098 } 1099 1100 bool 1101 SBFrame::IsInlined() 1102 { 1103 ExecutionContext exe_ctx(m_opaque_sp.get()); 1104 StackFrame *frame = exe_ctx.GetFramePtr(); 1105 Target *target = exe_ctx.GetTargetPtr(); 1106 if (frame && target) 1107 { 1108 Process::StopLocker stop_locker; 1109 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 1110 { 1111 1112 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block; 1113 if (block) 1114 return block->GetContainingInlinedBlock () != NULL; 1115 } 1116 else 1117 { 1118 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1119 if (log) 1120 log->Printf ("SBFrame(%p)::IsInlined () => error: process is running", frame); 1121 } 1122 1123 } 1124 return false; 1125 } 1126 1127 const char * 1128 SBFrame::GetFunctionName() 1129 { 1130 const char *name = NULL; 1131 ExecutionContext exe_ctx(m_opaque_sp.get()); 1132 StackFrame *frame = exe_ctx.GetFramePtr(); 1133 Target *target = exe_ctx.GetTargetPtr(); 1134 if (frame && target) 1135 { 1136 Process::StopLocker stop_locker; 1137 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) 1138 { 1139 SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); 1140 if (sc.block) 1141 { 1142 Block *inlined_block = sc.block->GetContainingInlinedBlock (); 1143 if (inlined_block) 1144 { 1145 const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo(); 1146 name = inlined_info->GetName().AsCString(); 1147 } 1148 } 1149 1150 if (name == NULL) 1151 { 1152 if (sc.function) 1153 name = sc.function->GetName().GetCString(); 1154 } 1155 1156 if (name == NULL) 1157 { 1158 if (sc.symbol) 1159 name = sc.symbol->GetName().GetCString(); 1160 } 1161 } 1162 else 1163 { 1164 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1165 if (log) 1166 log->Printf ("SBFrame(%p)::GetFunctionName() => error: process is running", frame); 1167 1168 } 1169 } 1170 return name; 1171 } 1172 1173