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