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