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/StreamFile.h" 25 #include "lldb/Core/ValueObjectRegister.h" 26 #include "lldb/Core/ValueObjectVariable.h" 27 #include "lldb/Expression/UserExpression.h" 28 #include "lldb/Host/Host.h" 29 #include "lldb/Symbol/Block.h" 30 #include "lldb/Symbol/Function.h" 31 #include "lldb/Symbol/Symbol.h" 32 #include "lldb/Symbol/SymbolContext.h" 33 #include "lldb/Symbol/Variable.h" 34 #include "lldb/Symbol/VariableList.h" 35 #include "lldb/Target/ExecutionContext.h" 36 #include "lldb/Target/Process.h" 37 #include "lldb/Target/RegisterContext.h" 38 #include "lldb/Target/StackFrame.h" 39 #include "lldb/Target/StackID.h" 40 #include "lldb/Target/Target.h" 41 #include "lldb/Target/Thread.h" 42 #include "lldb/Utility/ConstString.h" 43 #include "lldb/Utility/Log.h" 44 #include "lldb/Utility/Stream.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, AddressClass::eCode); 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 Status 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 value_sp = frame->FindVariable(ConstString(name)); 670 671 if (value_sp) 672 sb_value.SetSP(value_sp, use_dynamic); 673 } else { 674 if (log) 675 log->Printf("SBFrame::FindVariable () => error: could not " 676 "reconstruct frame object for this SBFrame."); 677 } 678 } else { 679 if (log) 680 log->Printf("SBFrame::FindVariable () => error: process is running"); 681 } 682 } 683 684 if (log) 685 log->Printf("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", 686 static_cast<void *>(frame), name, 687 static_cast<void *>(value_sp.get())); 688 689 return sb_value; 690 } 691 692 SBValue SBFrame::FindValue(const char *name, ValueType value_type) { 693 SBValue value; 694 std::unique_lock<std::recursive_mutex> lock; 695 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 696 697 StackFrame *frame = exe_ctx.GetFramePtr(); 698 Target *target = exe_ctx.GetTargetPtr(); 699 if (frame && target) { 700 lldb::DynamicValueType use_dynamic = 701 frame->CalculateTarget()->GetPreferDynamicValue(); 702 value = FindValue(name, value_type, use_dynamic); 703 } 704 return value; 705 } 706 707 SBValue SBFrame::FindValue(const char *name, ValueType value_type, 708 lldb::DynamicValueType use_dynamic) { 709 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 710 SBValue sb_value; 711 712 if (name == nullptr || name[0] == '\0') { 713 if (log) 714 log->Printf("SBFrame::FindValue called with empty name."); 715 return sb_value; 716 } 717 718 ValueObjectSP value_sp; 719 std::unique_lock<std::recursive_mutex> lock; 720 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 721 722 StackFrame *frame = nullptr; 723 Target *target = exe_ctx.GetTargetPtr(); 724 Process *process = exe_ctx.GetProcessPtr(); 725 if (target && process) { 726 Process::StopLocker stop_locker; 727 if (stop_locker.TryLock(&process->GetRunLock())) { 728 frame = exe_ctx.GetFramePtr(); 729 if (frame) { 730 VariableList variable_list; 731 732 switch (value_type) { 733 case eValueTypeVariableGlobal: // global variable 734 case eValueTypeVariableStatic: // static variable 735 case eValueTypeVariableArgument: // function argument variables 736 case eValueTypeVariableLocal: // function local variables 737 case eValueTypeVariableThreadLocal: // thread local variables 738 { 739 SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock)); 740 741 const bool can_create = true; 742 const bool get_parent_variables = true; 743 const bool stop_if_block_is_inlined_function = true; 744 745 if (sc.block) 746 sc.block->AppendVariables( 747 can_create, get_parent_variables, 748 stop_if_block_is_inlined_function, 749 [frame](Variable *v) { return v->IsInScope(frame); }, 750 &variable_list); 751 if (value_type == eValueTypeVariableGlobal) { 752 const bool get_file_globals = true; 753 VariableList *frame_vars = frame->GetVariableList(get_file_globals); 754 if (frame_vars) 755 frame_vars->AppendVariablesIfUnique(variable_list); 756 } 757 ConstString const_name(name); 758 VariableSP variable_sp( 759 variable_list.FindVariable(const_name, value_type)); 760 if (variable_sp) { 761 value_sp = frame->GetValueObjectForFrameVariable(variable_sp, 762 eNoDynamicValues); 763 sb_value.SetSP(value_sp, use_dynamic); 764 } 765 } break; 766 767 case eValueTypeRegister: // stack frame register value 768 { 769 RegisterContextSP reg_ctx(frame->GetRegisterContext()); 770 if (reg_ctx) { 771 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 772 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) { 773 const RegisterInfo *reg_info = 774 reg_ctx->GetRegisterInfoAtIndex(reg_idx); 775 if (reg_info && 776 ((reg_info->name && strcasecmp(reg_info->name, name) == 0) || 777 (reg_info->alt_name && 778 strcasecmp(reg_info->alt_name, name) == 0))) { 779 value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx); 780 sb_value.SetSP(value_sp); 781 break; 782 } 783 } 784 } 785 } break; 786 787 case eValueTypeRegisterSet: // A collection of stack frame register 788 // values 789 { 790 RegisterContextSP reg_ctx(frame->GetRegisterContext()); 791 if (reg_ctx) { 792 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 793 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) { 794 const RegisterSet *reg_set = reg_ctx->GetRegisterSet(set_idx); 795 if (reg_set && 796 ((reg_set->name && strcasecmp(reg_set->name, name) == 0) || 797 (reg_set->short_name && 798 strcasecmp(reg_set->short_name, name) == 0))) { 799 value_sp = 800 ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx); 801 sb_value.SetSP(value_sp); 802 break; 803 } 804 } 805 } 806 } break; 807 808 case eValueTypeConstResult: // constant result variables 809 { 810 ConstString const_name(name); 811 ExpressionVariableSP expr_var_sp( 812 target->GetPersistentVariable(const_name)); 813 if (expr_var_sp) { 814 value_sp = expr_var_sp->GetValueObject(); 815 sb_value.SetSP(value_sp, use_dynamic); 816 } 817 } break; 818 819 default: 820 break; 821 } 822 } else { 823 if (log) 824 log->Printf("SBFrame::FindValue () => error: could not reconstruct " 825 "frame object for this SBFrame."); 826 } 827 } else { 828 if (log) 829 log->Printf("SBFrame::FindValue () => error: process is running"); 830 } 831 } 832 833 if (log) 834 log->Printf("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) " 835 "=> SBValue(%p)", 836 static_cast<void *>(frame), name, value_type, 837 static_cast<void *>(value_sp.get())); 838 839 return sb_value; 840 } 841 842 bool SBFrame::IsEqual(const SBFrame &that) const { 843 lldb::StackFrameSP this_sp = GetFrameSP(); 844 lldb::StackFrameSP that_sp = that.GetFrameSP(); 845 return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID()); 846 } 847 848 bool SBFrame::operator==(const SBFrame &rhs) const { return IsEqual(rhs); } 849 850 bool SBFrame::operator!=(const SBFrame &rhs) const { return !IsEqual(rhs); } 851 852 SBThread SBFrame::GetThread() const { 853 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 854 855 std::unique_lock<std::recursive_mutex> lock; 856 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 857 858 ThreadSP thread_sp(exe_ctx.GetThreadSP()); 859 SBThread sb_thread(thread_sp); 860 861 if (log) { 862 SBStream sstr; 863 sb_thread.GetDescription(sstr); 864 log->Printf("SBFrame(%p)::GetThread () => SBThread(%p): %s", 865 static_cast<void *>(exe_ctx.GetFramePtr()), 866 static_cast<void *>(thread_sp.get()), sstr.GetData()); 867 } 868 869 return sb_thread; 870 } 871 872 const char *SBFrame::Disassemble() const { 873 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 874 const char *disassembly = nullptr; 875 std::unique_lock<std::recursive_mutex> lock; 876 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 877 878 StackFrame *frame = nullptr; 879 Target *target = exe_ctx.GetTargetPtr(); 880 Process *process = exe_ctx.GetProcessPtr(); 881 if (target && process) { 882 Process::StopLocker stop_locker; 883 if (stop_locker.TryLock(&process->GetRunLock())) { 884 frame = exe_ctx.GetFramePtr(); 885 if (frame) { 886 disassembly = frame->Disassemble(); 887 } else { 888 if (log) 889 log->Printf("SBFrame::Disassemble () => error: could not reconstruct " 890 "frame object for this SBFrame."); 891 } 892 } else { 893 if (log) 894 log->Printf("SBFrame::Disassemble () => error: process is running"); 895 } 896 } 897 898 if (log) 899 log->Printf("SBFrame(%p)::Disassemble () => %s", static_cast<void *>(frame), 900 disassembly); 901 902 return disassembly; 903 } 904 905 SBValueList SBFrame::GetVariables(bool arguments, bool locals, bool statics, 906 bool in_scope_only) { 907 SBValueList value_list; 908 std::unique_lock<std::recursive_mutex> lock; 909 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 910 911 StackFrame *frame = exe_ctx.GetFramePtr(); 912 Target *target = exe_ctx.GetTargetPtr(); 913 if (frame && target) { 914 lldb::DynamicValueType use_dynamic = 915 frame->CalculateTarget()->GetPreferDynamicValue(); 916 const bool include_runtime_support_values = 917 target ? target->GetDisplayRuntimeSupportValues() : false; 918 919 SBVariablesOptions options; 920 options.SetIncludeArguments(arguments); 921 options.SetIncludeLocals(locals); 922 options.SetIncludeStatics(statics); 923 options.SetInScopeOnly(in_scope_only); 924 options.SetIncludeRuntimeSupportValues(include_runtime_support_values); 925 options.SetUseDynamic(use_dynamic); 926 927 value_list = GetVariables(options); 928 } 929 return value_list; 930 } 931 932 lldb::SBValueList SBFrame::GetVariables(bool arguments, bool locals, 933 bool statics, bool in_scope_only, 934 lldb::DynamicValueType use_dynamic) { 935 std::unique_lock<std::recursive_mutex> lock; 936 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 937 938 Target *target = exe_ctx.GetTargetPtr(); 939 const bool include_runtime_support_values = 940 target ? target->GetDisplayRuntimeSupportValues() : false; 941 SBVariablesOptions options; 942 options.SetIncludeArguments(arguments); 943 options.SetIncludeLocals(locals); 944 options.SetIncludeStatics(statics); 945 options.SetInScopeOnly(in_scope_only); 946 options.SetIncludeRuntimeSupportValues(include_runtime_support_values); 947 options.SetUseDynamic(use_dynamic); 948 return GetVariables(options); 949 } 950 951 SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) { 952 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 953 954 SBValueList value_list; 955 std::unique_lock<std::recursive_mutex> lock; 956 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 957 958 StackFrame *frame = nullptr; 959 Target *target = exe_ctx.GetTargetPtr(); 960 961 const bool statics = options.GetIncludeStatics(); 962 const bool arguments = options.GetIncludeArguments(); 963 const bool locals = options.GetIncludeLocals(); 964 const bool in_scope_only = options.GetInScopeOnly(); 965 const bool include_runtime_support_values = 966 options.GetIncludeRuntimeSupportValues(); 967 const lldb::DynamicValueType use_dynamic = options.GetUseDynamic(); 968 969 if (log) 970 log->Printf("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, " 971 "in_scope_only=%i runtime=%i dynamic=%i)", 972 arguments, locals, statics, in_scope_only, 973 include_runtime_support_values, use_dynamic); 974 975 std::set<VariableSP> variable_set; 976 Process *process = exe_ctx.GetProcessPtr(); 977 if (target && process) { 978 Process::StopLocker stop_locker; 979 if (stop_locker.TryLock(&process->GetRunLock())) { 980 frame = exe_ctx.GetFramePtr(); 981 if (frame) { 982 size_t i; 983 VariableList *variable_list = nullptr; 984 variable_list = frame->GetVariableList(true); 985 if (variable_list) { 986 const size_t num_variables = variable_list->GetSize(); 987 if (num_variables) { 988 for (i = 0; i < num_variables; ++i) { 989 VariableSP variable_sp(variable_list->GetVariableAtIndex(i)); 990 if (variable_sp) { 991 bool add_variable = false; 992 switch (variable_sp->GetScope()) { 993 case eValueTypeVariableGlobal: 994 case eValueTypeVariableStatic: 995 case eValueTypeVariableThreadLocal: 996 add_variable = statics; 997 break; 998 999 case eValueTypeVariableArgument: 1000 add_variable = arguments; 1001 break; 1002 1003 case eValueTypeVariableLocal: 1004 add_variable = locals; 1005 break; 1006 1007 default: 1008 break; 1009 } 1010 if (add_variable) { 1011 // Only add variables once so we don't end up with duplicates 1012 if (variable_set.find(variable_sp) == variable_set.end()) 1013 variable_set.insert(variable_sp); 1014 else 1015 continue; 1016 1017 if (in_scope_only && !variable_sp->IsInScope(frame)) 1018 continue; 1019 1020 ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable( 1021 variable_sp, eNoDynamicValues)); 1022 1023 if (!include_runtime_support_values && valobj_sp != nullptr && 1024 valobj_sp->IsRuntimeSupportValue()) 1025 continue; 1026 1027 SBValue value_sb; 1028 value_sb.SetSP(valobj_sp, use_dynamic); 1029 value_list.Append(value_sb); 1030 } 1031 } 1032 } 1033 } 1034 } 1035 } else { 1036 if (log) 1037 log->Printf("SBFrame::GetVariables () => error: could not " 1038 "reconstruct frame object for this SBFrame."); 1039 } 1040 } else { 1041 if (log) 1042 log->Printf("SBFrame::GetVariables () => error: process is running"); 1043 } 1044 } 1045 1046 if (log) 1047 log->Printf("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", 1048 static_cast<void *>(frame), 1049 static_cast<void *>(value_list.opaque_ptr())); 1050 1051 return value_list; 1052 } 1053 1054 SBValueList SBFrame::GetRegisters() { 1055 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1056 1057 SBValueList value_list; 1058 std::unique_lock<std::recursive_mutex> lock; 1059 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1060 1061 StackFrame *frame = nullptr; 1062 Target *target = exe_ctx.GetTargetPtr(); 1063 Process *process = exe_ctx.GetProcessPtr(); 1064 if (target && process) { 1065 Process::StopLocker stop_locker; 1066 if (stop_locker.TryLock(&process->GetRunLock())) { 1067 frame = exe_ctx.GetFramePtr(); 1068 if (frame) { 1069 RegisterContextSP reg_ctx(frame->GetRegisterContext()); 1070 if (reg_ctx) { 1071 const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 1072 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) { 1073 value_list.Append( 1074 ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx)); 1075 } 1076 } 1077 } else { 1078 if (log) 1079 log->Printf("SBFrame::GetRegisters () => error: could not " 1080 "reconstruct frame object for this SBFrame."); 1081 } 1082 } else { 1083 if (log) 1084 log->Printf("SBFrame::GetRegisters () => error: process is running"); 1085 } 1086 } 1087 1088 if (log) 1089 log->Printf("SBFrame(%p)::GetRegisters () => SBValueList(%p)", 1090 static_cast<void *>(frame), 1091 static_cast<void *>(value_list.opaque_ptr())); 1092 1093 return value_list; 1094 } 1095 1096 SBValue SBFrame::FindRegister(const char *name) { 1097 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1098 1099 SBValue result; 1100 ValueObjectSP value_sp; 1101 std::unique_lock<std::recursive_mutex> lock; 1102 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1103 1104 StackFrame *frame = nullptr; 1105 Target *target = exe_ctx.GetTargetPtr(); 1106 Process *process = exe_ctx.GetProcessPtr(); 1107 if (target && process) { 1108 Process::StopLocker stop_locker; 1109 if (stop_locker.TryLock(&process->GetRunLock())) { 1110 frame = exe_ctx.GetFramePtr(); 1111 if (frame) { 1112 RegisterContextSP reg_ctx(frame->GetRegisterContext()); 1113 if (reg_ctx) { 1114 const uint32_t num_regs = reg_ctx->GetRegisterCount(); 1115 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) { 1116 const RegisterInfo *reg_info = 1117 reg_ctx->GetRegisterInfoAtIndex(reg_idx); 1118 if (reg_info && 1119 ((reg_info->name && strcasecmp(reg_info->name, name) == 0) || 1120 (reg_info->alt_name && 1121 strcasecmp(reg_info->alt_name, name) == 0))) { 1122 value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx); 1123 result.SetSP(value_sp); 1124 break; 1125 } 1126 } 1127 } 1128 } else { 1129 if (log) 1130 log->Printf("SBFrame::FindRegister () => error: could not " 1131 "reconstruct frame object for this SBFrame."); 1132 } 1133 } else { 1134 if (log) 1135 log->Printf("SBFrame::FindRegister () => error: process is running"); 1136 } 1137 } 1138 1139 if (log) 1140 log->Printf("SBFrame(%p)::FindRegister () => SBValue(%p)", 1141 static_cast<void *>(frame), 1142 static_cast<void *>(value_sp.get())); 1143 1144 return result; 1145 } 1146 1147 bool SBFrame::GetDescription(SBStream &description) { 1148 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1149 Stream &strm = description.ref(); 1150 1151 std::unique_lock<std::recursive_mutex> lock; 1152 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1153 1154 StackFrame *frame; 1155 Target *target = exe_ctx.GetTargetPtr(); 1156 Process *process = exe_ctx.GetProcessPtr(); 1157 if (target && process) { 1158 Process::StopLocker stop_locker; 1159 if (stop_locker.TryLock(&process->GetRunLock())) { 1160 frame = exe_ctx.GetFramePtr(); 1161 if (frame) { 1162 frame->DumpUsingSettingsFormat(&strm); 1163 } else { 1164 if (log) 1165 log->Printf("SBFrame::GetDescription () => error: could not " 1166 "reconstruct frame object for this SBFrame."); 1167 } 1168 } else { 1169 if (log) 1170 log->Printf("SBFrame::GetDescription () => error: process is running"); 1171 } 1172 1173 } else 1174 strm.PutCString("No value"); 1175 1176 return true; 1177 } 1178 1179 SBValue SBFrame::EvaluateExpression(const char *expr) { 1180 SBValue result; 1181 std::unique_lock<std::recursive_mutex> lock; 1182 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1183 1184 StackFrame *frame = exe_ctx.GetFramePtr(); 1185 Target *target = exe_ctx.GetTargetPtr(); 1186 if (frame && target) { 1187 SBExpressionOptions options; 1188 lldb::DynamicValueType fetch_dynamic_value = 1189 frame->CalculateTarget()->GetPreferDynamicValue(); 1190 options.SetFetchDynamicValue(fetch_dynamic_value); 1191 options.SetUnwindOnError(true); 1192 options.SetIgnoreBreakpoints(true); 1193 if (target->GetLanguage() != eLanguageTypeUnknown) 1194 options.SetLanguage(target->GetLanguage()); 1195 else 1196 options.SetLanguage(frame->GetLanguage()); 1197 return EvaluateExpression(expr, options); 1198 } 1199 return result; 1200 } 1201 1202 SBValue 1203 SBFrame::EvaluateExpression(const char *expr, 1204 lldb::DynamicValueType fetch_dynamic_value) { 1205 SBExpressionOptions options; 1206 options.SetFetchDynamicValue(fetch_dynamic_value); 1207 options.SetUnwindOnError(true); 1208 options.SetIgnoreBreakpoints(true); 1209 std::unique_lock<std::recursive_mutex> lock; 1210 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1211 1212 StackFrame *frame = exe_ctx.GetFramePtr(); 1213 Target *target = exe_ctx.GetTargetPtr(); 1214 if (target && target->GetLanguage() != eLanguageTypeUnknown) 1215 options.SetLanguage(target->GetLanguage()); 1216 else if (frame) 1217 options.SetLanguage(frame->GetLanguage()); 1218 return EvaluateExpression(expr, options); 1219 } 1220 1221 SBValue SBFrame::EvaluateExpression(const char *expr, 1222 lldb::DynamicValueType fetch_dynamic_value, 1223 bool unwind_on_error) { 1224 SBExpressionOptions options; 1225 std::unique_lock<std::recursive_mutex> lock; 1226 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1227 1228 options.SetFetchDynamicValue(fetch_dynamic_value); 1229 options.SetUnwindOnError(unwind_on_error); 1230 options.SetIgnoreBreakpoints(true); 1231 StackFrame *frame = exe_ctx.GetFramePtr(); 1232 Target *target = exe_ctx.GetTargetPtr(); 1233 if (target && target->GetLanguage() != eLanguageTypeUnknown) 1234 options.SetLanguage(target->GetLanguage()); 1235 else if (frame) 1236 options.SetLanguage(frame->GetLanguage()); 1237 return EvaluateExpression(expr, options); 1238 } 1239 1240 lldb::SBValue SBFrame::EvaluateExpression(const char *expr, 1241 const SBExpressionOptions &options) { 1242 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1243 1244 #ifndef LLDB_DISABLE_PYTHON 1245 Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); 1246 #endif 1247 1248 ExpressionResults exe_results = eExpressionSetupError; 1249 SBValue expr_result; 1250 1251 if (expr == nullptr || expr[0] == '\0') { 1252 if (log) 1253 log->Printf( 1254 "SBFrame::EvaluateExpression called with an empty expression"); 1255 return expr_result; 1256 } 1257 1258 ValueObjectSP expr_value_sp; 1259 1260 std::unique_lock<std::recursive_mutex> lock; 1261 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1262 1263 if (log) 1264 log->Printf("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr); 1265 1266 StackFrame *frame = nullptr; 1267 Target *target = exe_ctx.GetTargetPtr(); 1268 Process *process = exe_ctx.GetProcessPtr(); 1269 1270 if (target && process) { 1271 Process::StopLocker stop_locker; 1272 if (stop_locker.TryLock(&process->GetRunLock())) { 1273 frame = exe_ctx.GetFramePtr(); 1274 if (frame) { 1275 std::unique_ptr<llvm::PrettyStackTraceFormat> stack_trace; 1276 if (target->GetDisplayExpressionsInCrashlogs()) { 1277 StreamString frame_description; 1278 frame->DumpUsingSettingsFormat(&frame_description); 1279 stack_trace = llvm::make_unique<llvm::PrettyStackTraceFormat>( 1280 "SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value " 1281 "= %u) %s", 1282 expr, options.GetFetchDynamicValue(), 1283 frame_description.GetData()); 1284 } 1285 1286 exe_results = target->EvaluateExpression(expr, frame, expr_value_sp, 1287 options.ref()); 1288 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); 1289 } else { 1290 if (log) 1291 log->Printf("SBFrame::EvaluateExpression () => error: could not " 1292 "reconstruct frame object for this SBFrame."); 1293 } 1294 } else { 1295 if (log) 1296 log->Printf( 1297 "SBFrame::EvaluateExpression () => error: process is running"); 1298 } 1299 } 1300 1301 #ifndef LLDB_DISABLE_PYTHON 1302 if (expr_log) 1303 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is " 1304 "%s, summary %s **", 1305 expr_result.GetValue(), expr_result.GetSummary()); 1306 1307 if (log) 1308 log->Printf("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) " 1309 "(execution result=%d)", 1310 static_cast<void *>(frame), expr, 1311 static_cast<void *>(expr_value_sp.get()), exe_results); 1312 #endif 1313 1314 return expr_result; 1315 } 1316 1317 bool SBFrame::IsInlined() { 1318 return static_cast<const SBFrame *>(this)->IsInlined(); 1319 } 1320 1321 bool SBFrame::IsInlined() const { 1322 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1323 std::unique_lock<std::recursive_mutex> lock; 1324 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1325 1326 StackFrame *frame = nullptr; 1327 Target *target = exe_ctx.GetTargetPtr(); 1328 Process *process = exe_ctx.GetProcessPtr(); 1329 if (target && process) { 1330 Process::StopLocker stop_locker; 1331 if (stop_locker.TryLock(&process->GetRunLock())) { 1332 frame = exe_ctx.GetFramePtr(); 1333 if (frame) { 1334 1335 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block; 1336 if (block) 1337 return block->GetContainingInlinedBlock() != nullptr; 1338 } else { 1339 if (log) 1340 log->Printf("SBFrame::IsInlined () => error: could not reconstruct " 1341 "frame object for this SBFrame."); 1342 } 1343 } else { 1344 if (log) 1345 log->Printf("SBFrame::IsInlined () => error: process is running"); 1346 } 1347 } 1348 return false; 1349 } 1350 1351 const char *SBFrame::GetFunctionName() { 1352 return static_cast<const SBFrame *>(this)->GetFunctionName(); 1353 } 1354 1355 lldb::LanguageType SBFrame::GuessLanguage() const { 1356 std::unique_lock<std::recursive_mutex> lock; 1357 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1358 1359 StackFrame *frame = nullptr; 1360 Target *target = exe_ctx.GetTargetPtr(); 1361 Process *process = exe_ctx.GetProcessPtr(); 1362 if (target && process) { 1363 Process::StopLocker stop_locker; 1364 if (stop_locker.TryLock(&process->GetRunLock())) { 1365 frame = exe_ctx.GetFramePtr(); 1366 if (frame) { 1367 return frame->GuessLanguage(); 1368 } 1369 } 1370 } 1371 return eLanguageTypeUnknown; 1372 } 1373 1374 const char *SBFrame::GetFunctionName() const { 1375 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1376 const char *name = nullptr; 1377 std::unique_lock<std::recursive_mutex> lock; 1378 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1379 1380 StackFrame *frame = nullptr; 1381 Target *target = exe_ctx.GetTargetPtr(); 1382 Process *process = exe_ctx.GetProcessPtr(); 1383 if (target && process) { 1384 Process::StopLocker stop_locker; 1385 if (stop_locker.TryLock(&process->GetRunLock())) { 1386 frame = exe_ctx.GetFramePtr(); 1387 if (frame) { 1388 SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction | 1389 eSymbolContextBlock | 1390 eSymbolContextSymbol)); 1391 if (sc.block) { 1392 Block *inlined_block = sc.block->GetContainingInlinedBlock(); 1393 if (inlined_block) { 1394 const InlineFunctionInfo *inlined_info = 1395 inlined_block->GetInlinedFunctionInfo(); 1396 name = 1397 inlined_info->GetName(sc.function->GetLanguage()).AsCString(); 1398 } 1399 } 1400 1401 if (name == nullptr) { 1402 if (sc.function) 1403 name = sc.function->GetName().GetCString(); 1404 } 1405 1406 if (name == nullptr) { 1407 if (sc.symbol) 1408 name = sc.symbol->GetName().GetCString(); 1409 } 1410 } else { 1411 if (log) 1412 log->Printf("SBFrame::GetFunctionName () => error: could not " 1413 "reconstruct frame object for this SBFrame."); 1414 } 1415 } else { 1416 if (log) 1417 log->Printf("SBFrame::GetFunctionName() => error: process is running"); 1418 } 1419 } 1420 return name; 1421 } 1422 1423 const char *SBFrame::GetDisplayFunctionName() { 1424 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1425 const char *name = nullptr; 1426 1427 std::unique_lock<std::recursive_mutex> lock; 1428 ExecutionContext exe_ctx(m_opaque_sp.get(), lock); 1429 1430 StackFrame *frame = nullptr; 1431 Target *target = exe_ctx.GetTargetPtr(); 1432 Process *process = exe_ctx.GetProcessPtr(); 1433 if (target && process) { 1434 Process::StopLocker stop_locker; 1435 if (stop_locker.TryLock(&process->GetRunLock())) { 1436 frame = exe_ctx.GetFramePtr(); 1437 if (frame) { 1438 SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction | 1439 eSymbolContextBlock | 1440 eSymbolContextSymbol)); 1441 if (sc.block) { 1442 Block *inlined_block = sc.block->GetContainingInlinedBlock(); 1443 if (inlined_block) { 1444 const InlineFunctionInfo *inlined_info = 1445 inlined_block->GetInlinedFunctionInfo(); 1446 name = inlined_info->GetDisplayName(sc.function->GetLanguage()) 1447 .AsCString(); 1448 } 1449 } 1450 1451 if (name == nullptr) { 1452 if (sc.function) 1453 name = sc.function->GetDisplayName().GetCString(); 1454 } 1455 1456 if (name == nullptr) { 1457 if (sc.symbol) 1458 name = sc.symbol->GetDisplayName().GetCString(); 1459 } 1460 } else { 1461 if (log) 1462 log->Printf("SBFrame::GetDisplayFunctionName () => error: could not " 1463 "reconstruct frame object for this SBFrame."); 1464 } 1465 } else { 1466 if (log) 1467 log->Printf( 1468 "SBFrame::GetDisplayFunctionName() => error: process is running"); 1469 } 1470 } 1471 return name; 1472 } 1473