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