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