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