1 //===-- StackFrame.cpp ------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // C Includes 11 // C++ Includes 12 // Other libraries and framework includes 13 // Project includes 14 #include "lldb/Target/StackFrame.h" 15 #include "lldb/Core/Debugger.h" 16 #include "lldb/Core/Disassembler.h" 17 #include "lldb/Core/FormatEntity.h" 18 #include "lldb/Core/Mangled.h" 19 #include "lldb/Core/Module.h" 20 #include "lldb/Core/RegisterValue.h" 21 #include "lldb/Core/Value.h" 22 #include "lldb/Core/ValueObjectConstResult.h" 23 #include "lldb/Core/ValueObjectMemory.h" 24 #include "lldb/Core/ValueObjectVariable.h" 25 #include "lldb/Symbol/CompileUnit.h" 26 #include "lldb/Symbol/Function.h" 27 #include "lldb/Symbol/Symbol.h" 28 #include "lldb/Symbol/SymbolContextScope.h" 29 #include "lldb/Symbol/Type.h" 30 #include "lldb/Symbol/VariableList.h" 31 #include "lldb/Target/ABI.h" 32 #include "lldb/Target/ExecutionContext.h" 33 #include "lldb/Target/Process.h" 34 #include "lldb/Target/RegisterContext.h" 35 #include "lldb/Target/Target.h" 36 #include "lldb/Target/Thread.h" 37 38 using namespace lldb; 39 using namespace lldb_private; 40 41 // The first bits in the flags are reserved for the SymbolContext::Scope bits 42 // so we know if we have tried to look up information in our internal symbol 43 // context (m_sc) already. 44 #define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1)) 45 #define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1) 46 #define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1) 47 #define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1) 48 #define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1) 49 50 StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx, 51 user_id_t unwind_frame_index, addr_t cfa, 52 bool cfa_is_valid, addr_t pc, uint32_t stop_id, 53 bool stop_id_is_valid, bool is_history_frame, 54 const SymbolContext *sc_ptr) 55 : m_thread_wp(thread_sp), m_frame_index(frame_idx), 56 m_concrete_frame_index(unwind_frame_index), m_reg_context_sp(), 57 m_id(pc, cfa, nullptr), m_frame_code_addr(pc), m_sc(), m_flags(), 58 m_frame_base(), m_frame_base_error(), m_cfa_is_valid(cfa_is_valid), 59 m_stop_id(stop_id), m_stop_id_is_valid(stop_id_is_valid), 60 m_is_history_frame(is_history_frame), m_variable_list_sp(), 61 m_variable_list_value_objects(), m_disassembly(), m_mutex() { 62 // If we don't have a CFA value, use the frame index for our StackID so that 63 // recursive 64 // functions properly aren't confused with one another on a history stack. 65 if (m_is_history_frame && !m_cfa_is_valid) { 66 m_id.SetCFA(m_frame_index); 67 } 68 69 if (sc_ptr != nullptr) { 70 m_sc = *sc_ptr; 71 m_flags.Set(m_sc.GetResolvedMask()); 72 } 73 } 74 75 StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx, 76 user_id_t unwind_frame_index, 77 const RegisterContextSP ®_context_sp, addr_t cfa, 78 addr_t pc, const SymbolContext *sc_ptr) 79 : m_thread_wp(thread_sp), m_frame_index(frame_idx), 80 m_concrete_frame_index(unwind_frame_index), 81 m_reg_context_sp(reg_context_sp), m_id(pc, cfa, nullptr), 82 m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(), 83 m_frame_base_error(), m_cfa_is_valid(true), m_stop_id(0), 84 m_stop_id_is_valid(false), m_is_history_frame(false), 85 m_variable_list_sp(), m_variable_list_value_objects(), m_disassembly(), 86 m_mutex() { 87 if (sc_ptr != nullptr) { 88 m_sc = *sc_ptr; 89 m_flags.Set(m_sc.GetResolvedMask()); 90 } 91 92 if (reg_context_sp && !m_sc.target_sp) { 93 m_sc.target_sp = reg_context_sp->CalculateTarget(); 94 if (m_sc.target_sp) 95 m_flags.Set(eSymbolContextTarget); 96 } 97 } 98 99 StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx, 100 user_id_t unwind_frame_index, 101 const RegisterContextSP ®_context_sp, addr_t cfa, 102 const Address &pc_addr, const SymbolContext *sc_ptr) 103 : m_thread_wp(thread_sp), m_frame_index(frame_idx), 104 m_concrete_frame_index(unwind_frame_index), 105 m_reg_context_sp(reg_context_sp), 106 m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa, 107 nullptr), 108 m_frame_code_addr(pc_addr), m_sc(), m_flags(), m_frame_base(), 109 m_frame_base_error(), m_cfa_is_valid(true), m_stop_id(0), 110 m_stop_id_is_valid(false), m_is_history_frame(false), 111 m_variable_list_sp(), m_variable_list_value_objects(), m_disassembly(), 112 m_mutex() { 113 if (sc_ptr != nullptr) { 114 m_sc = *sc_ptr; 115 m_flags.Set(m_sc.GetResolvedMask()); 116 } 117 118 if (!m_sc.target_sp && reg_context_sp) { 119 m_sc.target_sp = reg_context_sp->CalculateTarget(); 120 if (m_sc.target_sp) 121 m_flags.Set(eSymbolContextTarget); 122 } 123 124 ModuleSP pc_module_sp(pc_addr.GetModule()); 125 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp) { 126 if (pc_module_sp) { 127 m_sc.module_sp = pc_module_sp; 128 m_flags.Set(eSymbolContextModule); 129 } else { 130 m_sc.module_sp.reset(); 131 } 132 } 133 } 134 135 StackFrame::~StackFrame() = default; 136 137 StackID &StackFrame::GetStackID() { 138 std::lock_guard<std::recursive_mutex> guard(m_mutex); 139 // Make sure we have resolved the StackID object's symbol context scope if 140 // we already haven't looked it up. 141 142 if (m_flags.IsClear(RESOLVED_FRAME_ID_SYMBOL_SCOPE)) { 143 if (m_id.GetSymbolContextScope()) { 144 // We already have a symbol context scope, we just don't have our 145 // flag bit set. 146 m_flags.Set(RESOLVED_FRAME_ID_SYMBOL_SCOPE); 147 } else { 148 // Calculate the frame block and use this for the stack ID symbol 149 // context scope if we have one. 150 SymbolContextScope *scope = GetFrameBlock(); 151 if (scope == nullptr) { 152 // We don't have a block, so use the symbol 153 if (m_flags.IsClear(eSymbolContextSymbol)) 154 GetSymbolContext(eSymbolContextSymbol); 155 156 // It is ok if m_sc.symbol is nullptr here 157 scope = m_sc.symbol; 158 } 159 // Set the symbol context scope (the accessor will set the 160 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags). 161 SetSymbolContextScope(scope); 162 } 163 } 164 return m_id; 165 } 166 167 uint32_t StackFrame::GetFrameIndex() const { 168 ThreadSP thread_sp = GetThread(); 169 if (thread_sp) 170 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex( 171 m_frame_index); 172 else 173 return m_frame_index; 174 } 175 176 void StackFrame::SetSymbolContextScope(SymbolContextScope *symbol_scope) { 177 std::lock_guard<std::recursive_mutex> guard(m_mutex); 178 m_flags.Set(RESOLVED_FRAME_ID_SYMBOL_SCOPE); 179 m_id.SetSymbolContextScope(symbol_scope); 180 } 181 182 const Address &StackFrame::GetFrameCodeAddress() { 183 std::lock_guard<std::recursive_mutex> guard(m_mutex); 184 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && 185 !m_frame_code_addr.IsSectionOffset()) { 186 m_flags.Set(RESOLVED_FRAME_CODE_ADDR); 187 188 // Resolve the PC into a temporary address because if ResolveLoadAddress 189 // fails to resolve the address, it will clear the address object... 190 ThreadSP thread_sp(GetThread()); 191 if (thread_sp) { 192 TargetSP target_sp(thread_sp->CalculateTarget()); 193 if (target_sp) { 194 if (m_frame_code_addr.SetOpcodeLoadAddress( 195 m_frame_code_addr.GetOffset(), target_sp.get(), 196 eAddressClassCode)) { 197 ModuleSP module_sp(m_frame_code_addr.GetModule()); 198 if (module_sp) { 199 m_sc.module_sp = module_sp; 200 m_flags.Set(eSymbolContextModule); 201 } 202 } 203 } 204 } 205 } 206 return m_frame_code_addr; 207 } 208 209 bool StackFrame::ChangePC(addr_t pc) { 210 std::lock_guard<std::recursive_mutex> guard(m_mutex); 211 // We can't change the pc value of a history stack frame - it is immutable. 212 if (m_is_history_frame) 213 return false; 214 m_frame_code_addr.SetRawAddress(pc); 215 m_sc.Clear(false); 216 m_flags.Reset(0); 217 ThreadSP thread_sp(GetThread()); 218 if (thread_sp) 219 thread_sp->ClearStackFrames(); 220 return true; 221 } 222 223 const char *StackFrame::Disassemble() { 224 std::lock_guard<std::recursive_mutex> guard(m_mutex); 225 if (m_disassembly.Empty()) { 226 ExecutionContext exe_ctx(shared_from_this()); 227 Target *target = exe_ctx.GetTargetPtr(); 228 if (target) { 229 const char *plugin_name = nullptr; 230 const char *flavor = nullptr; 231 Disassembler::Disassemble(target->GetDebugger(), 232 target->GetArchitecture(), plugin_name, flavor, 233 exe_ctx, 0, false, 0, 0, m_disassembly); 234 } 235 if (m_disassembly.Empty()) 236 return nullptr; 237 } 238 239 return m_disassembly.GetData(); 240 } 241 242 Block *StackFrame::GetFrameBlock() { 243 if (m_sc.block == nullptr && m_flags.IsClear(eSymbolContextBlock)) 244 GetSymbolContext(eSymbolContextBlock); 245 246 if (m_sc.block) { 247 Block *inline_block = m_sc.block->GetContainingInlinedBlock(); 248 if (inline_block) { 249 // Use the block with the inlined function info 250 // as the frame block we want this frame to have only the variables 251 // for the inlined function and its non-inlined block child blocks. 252 return inline_block; 253 } else { 254 // This block is not contained within any inlined function blocks 255 // with so we want to use the top most function block. 256 return &m_sc.function->GetBlock(false); 257 } 258 } 259 return nullptr; 260 } 261 262 //---------------------------------------------------------------------- 263 // Get the symbol context if we already haven't done so by resolving the 264 // PC address as much as possible. This way when we pass around a 265 // StackFrame object, everyone will have as much information as 266 // possible and no one will ever have to look things up manually. 267 //---------------------------------------------------------------------- 268 const SymbolContext &StackFrame::GetSymbolContext(uint32_t resolve_scope) { 269 std::lock_guard<std::recursive_mutex> guard(m_mutex); 270 // Copy our internal symbol context into "sc". 271 if ((m_flags.Get() & resolve_scope) != resolve_scope) { 272 uint32_t resolved = 0; 273 274 // If the target was requested add that: 275 if (!m_sc.target_sp) { 276 m_sc.target_sp = CalculateTarget(); 277 if (m_sc.target_sp) 278 resolved |= eSymbolContextTarget; 279 } 280 281 // Resolve our PC to section offset if we haven't already done so 282 // and if we don't have a module. The resolved address section will 283 // contain the module to which it belongs 284 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR)) 285 GetFrameCodeAddress(); 286 287 // If this is not frame zero, then we need to subtract 1 from the PC 288 // value when doing address lookups since the PC will be on the 289 // instruction following the function call instruction... 290 291 Address lookup_addr(GetFrameCodeAddress()); 292 if (m_frame_index > 0 && lookup_addr.IsValid()) { 293 addr_t offset = lookup_addr.GetOffset(); 294 if (offset > 0) { 295 lookup_addr.SetOffset(offset - 1); 296 297 } else { 298 // lookup_addr is the start of a section. We need 299 // do the math on the actual load address and re-compute 300 // the section. We're working with a 'noreturn' function 301 // at the end of a section. 302 ThreadSP thread_sp(GetThread()); 303 if (thread_sp) { 304 TargetSP target_sp(thread_sp->CalculateTarget()); 305 if (target_sp) { 306 addr_t addr_minus_one = 307 lookup_addr.GetLoadAddress(target_sp.get()) - 1; 308 lookup_addr.SetLoadAddress(addr_minus_one, target_sp.get()); 309 } else { 310 lookup_addr.SetOffset(offset - 1); 311 } 312 } 313 } 314 } 315 316 if (m_sc.module_sp) { 317 // We have something in our stack frame symbol context, lets check 318 // if we haven't already tried to lookup one of those things. If we 319 // haven't then we will do the query. 320 321 uint32_t actual_resolve_scope = 0; 322 323 if (resolve_scope & eSymbolContextCompUnit) { 324 if (m_flags.IsClear(eSymbolContextCompUnit)) { 325 if (m_sc.comp_unit) 326 resolved |= eSymbolContextCompUnit; 327 else 328 actual_resolve_scope |= eSymbolContextCompUnit; 329 } 330 } 331 332 if (resolve_scope & eSymbolContextFunction) { 333 if (m_flags.IsClear(eSymbolContextFunction)) { 334 if (m_sc.function) 335 resolved |= eSymbolContextFunction; 336 else 337 actual_resolve_scope |= eSymbolContextFunction; 338 } 339 } 340 341 if (resolve_scope & eSymbolContextBlock) { 342 if (m_flags.IsClear(eSymbolContextBlock)) { 343 if (m_sc.block) 344 resolved |= eSymbolContextBlock; 345 else 346 actual_resolve_scope |= eSymbolContextBlock; 347 } 348 } 349 350 if (resolve_scope & eSymbolContextSymbol) { 351 if (m_flags.IsClear(eSymbolContextSymbol)) { 352 if (m_sc.symbol) 353 resolved |= eSymbolContextSymbol; 354 else 355 actual_resolve_scope |= eSymbolContextSymbol; 356 } 357 } 358 359 if (resolve_scope & eSymbolContextLineEntry) { 360 if (m_flags.IsClear(eSymbolContextLineEntry)) { 361 if (m_sc.line_entry.IsValid()) 362 resolved |= eSymbolContextLineEntry; 363 else 364 actual_resolve_scope |= eSymbolContextLineEntry; 365 } 366 } 367 368 if (actual_resolve_scope) { 369 // We might be resolving less information than what is already 370 // in our current symbol context so resolve into a temporary 371 // symbol context "sc" so we don't clear out data we have 372 // already found in "m_sc" 373 SymbolContext sc; 374 // Set flags that indicate what we have tried to resolve 375 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress( 376 lookup_addr, actual_resolve_scope, sc); 377 // Only replace what we didn't already have as we may have 378 // information for an inlined function scope that won't match 379 // what a standard lookup by address would match 380 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == nullptr) 381 m_sc.comp_unit = sc.comp_unit; 382 if ((resolved & eSymbolContextFunction) && m_sc.function == nullptr) 383 m_sc.function = sc.function; 384 if ((resolved & eSymbolContextBlock) && m_sc.block == nullptr) 385 m_sc.block = sc.block; 386 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == nullptr) 387 m_sc.symbol = sc.symbol; 388 if ((resolved & eSymbolContextLineEntry) && 389 !m_sc.line_entry.IsValid()) { 390 m_sc.line_entry = sc.line_entry; 391 m_sc.line_entry.ApplyFileMappings(m_sc.target_sp); 392 } 393 } 394 } else { 395 // If we don't have a module, then we can't have the compile unit, 396 // function, block, line entry or symbol, so we can safely call 397 // ResolveSymbolContextForAddress with our symbol context member m_sc. 398 if (m_sc.target_sp) { 399 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress( 400 lookup_addr, resolve_scope, m_sc); 401 } 402 } 403 404 // Update our internal flags so we remember what we have tried to locate so 405 // we don't have to keep trying when more calls to this function are made. 406 // We might have dug up more information that was requested (for example 407 // if we were asked to only get the block, we will have gotten the 408 // compile unit, and function) so set any additional bits that we resolved 409 m_flags.Set(resolve_scope | resolved); 410 } 411 412 // Return the symbol context with everything that was possible to resolve 413 // resolved. 414 return m_sc; 415 } 416 417 VariableList *StackFrame::GetVariableList(bool get_file_globals) { 418 std::lock_guard<std::recursive_mutex> guard(m_mutex); 419 if (m_flags.IsClear(RESOLVED_VARIABLES)) { 420 m_flags.Set(RESOLVED_VARIABLES); 421 422 Block *frame_block = GetFrameBlock(); 423 424 if (frame_block) { 425 const bool get_child_variables = true; 426 const bool can_create = true; 427 const bool stop_if_child_block_is_inlined_function = true; 428 m_variable_list_sp.reset(new VariableList()); 429 frame_block->AppendBlockVariables(can_create, get_child_variables, 430 stop_if_child_block_is_inlined_function, 431 [](Variable *v) { return true; }, 432 m_variable_list_sp.get()); 433 } 434 } 435 436 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && get_file_globals) { 437 m_flags.Set(RESOLVED_GLOBAL_VARIABLES); 438 439 if (m_flags.IsClear(eSymbolContextCompUnit)) 440 GetSymbolContext(eSymbolContextCompUnit); 441 442 if (m_sc.comp_unit) { 443 VariableListSP global_variable_list_sp( 444 m_sc.comp_unit->GetVariableList(true)); 445 if (m_variable_list_sp) 446 m_variable_list_sp->AddVariables(global_variable_list_sp.get()); 447 else 448 m_variable_list_sp = global_variable_list_sp; 449 } 450 } 451 452 return m_variable_list_sp.get(); 453 } 454 455 VariableListSP 456 StackFrame::GetInScopeVariableList(bool get_file_globals, 457 bool must_have_valid_location) { 458 std::lock_guard<std::recursive_mutex> guard(m_mutex); 459 // We can't fetch variable information for a history stack frame. 460 if (m_is_history_frame) 461 return VariableListSP(); 462 463 VariableListSP var_list_sp(new VariableList); 464 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextBlock); 465 466 if (m_sc.block) { 467 const bool can_create = true; 468 const bool get_parent_variables = true; 469 const bool stop_if_block_is_inlined_function = true; 470 m_sc.block->AppendVariables( 471 can_create, get_parent_variables, stop_if_block_is_inlined_function, 472 [this, must_have_valid_location](Variable *v) { 473 return v->IsInScope(this) && (!must_have_valid_location || 474 v->LocationIsValidForFrame(this)); 475 }, 476 var_list_sp.get()); 477 } 478 479 if (m_sc.comp_unit && get_file_globals) { 480 VariableListSP global_variable_list_sp( 481 m_sc.comp_unit->GetVariableList(true)); 482 if (global_variable_list_sp) 483 var_list_sp->AddVariables(global_variable_list_sp.get()); 484 } 485 486 return var_list_sp; 487 } 488 489 ValueObjectSP StackFrame::GetValueForVariableExpressionPath( 490 llvm::StringRef var_expr, DynamicValueType use_dynamic, uint32_t options, 491 VariableSP &var_sp, Error &error) { 492 llvm::StringRef original_var_expr = var_expr; 493 // We can't fetch variable information for a history stack frame. 494 if (m_is_history_frame) 495 return ValueObjectSP(); 496 497 if (var_expr.empty()) { 498 error.SetErrorStringWithFormat("invalid variable path '%s'", 499 var_expr.str().c_str()); 500 return ValueObjectSP(); 501 } 502 503 const bool check_ptr_vs_member = 504 (options & eExpressionPathOptionCheckPtrVsMember) != 0; 505 const bool no_fragile_ivar = 506 (options & eExpressionPathOptionsNoFragileObjcIvar) != 0; 507 const bool no_synth_child = 508 (options & eExpressionPathOptionsNoSyntheticChildren) != 0; 509 // const bool no_synth_array = (options & 510 // eExpressionPathOptionsNoSyntheticArrayRange) != 0; 511 error.Clear(); 512 bool deref = false; 513 bool address_of = false; 514 ValueObjectSP valobj_sp; 515 const bool get_file_globals = true; 516 // When looking up a variable for an expression, we need only consider the 517 // variables that are in scope. 518 VariableListSP var_list_sp(GetInScopeVariableList(get_file_globals)); 519 VariableList *variable_list = var_list_sp.get(); 520 521 if (!variable_list) 522 return ValueObjectSP(); 523 524 // If first character is a '*', then show pointer contents 525 std::string var_expr_storage; 526 if (var_expr[0] == '*') { 527 deref = true; 528 var_expr = var_expr.drop_front(); // Skip the '*' 529 } else if (var_expr[0] == '&') { 530 address_of = true; 531 var_expr = var_expr.drop_front(); // Skip the '&' 532 } 533 534 size_t separator_idx = var_expr.find_first_of(".-[=+~|&^%#@!/?,<>{}"); 535 StreamString var_expr_path_strm; 536 537 ConstString name_const_string(var_expr.substr(0, separator_idx)); 538 539 var_sp = variable_list->FindVariable(name_const_string, false); 540 541 bool synthetically_added_instance_object = false; 542 543 if (var_sp) { 544 var_expr = var_expr.drop_front(name_const_string.GetLength()); 545 } 546 547 if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess)) { 548 // Check for direct ivars access which helps us with implicit 549 // access to ivars with the "this->" or "self->" 550 GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock); 551 lldb::LanguageType method_language = eLanguageTypeUnknown; 552 bool is_instance_method = false; 553 ConstString method_object_name; 554 if (m_sc.GetFunctionMethodInfo(method_language, is_instance_method, 555 method_object_name)) { 556 if (is_instance_method && method_object_name) { 557 var_sp = variable_list->FindVariable(method_object_name); 558 if (var_sp) { 559 separator_idx = 0; 560 var_expr_storage = "->"; 561 var_expr_storage += var_expr; 562 var_expr = var_expr_storage; 563 synthetically_added_instance_object = true; 564 } 565 } 566 } 567 } 568 569 if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) { 570 // Check if any anonymous unions are there which contain a variable with 571 // the name we need 572 for (size_t i = 0; i < variable_list->GetSize(); i++) { 573 VariableSP variable_sp = variable_list->GetVariableAtIndex(i); 574 if (!variable_sp) 575 continue; 576 if (!variable_sp->GetName().IsEmpty()) 577 continue; 578 579 Type *var_type = variable_sp->GetType(); 580 if (!var_type) 581 continue; 582 583 if (!var_type->GetForwardCompilerType().IsAnonymousType()) 584 continue; 585 valobj_sp = GetValueObjectForFrameVariable(variable_sp, use_dynamic); 586 if (!valobj_sp) 587 return valobj_sp; 588 valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string, true); 589 if (valobj_sp) 590 break; 591 } 592 } 593 594 if (var_sp && !valobj_sp) { 595 valobj_sp = GetValueObjectForFrameVariable(var_sp, use_dynamic); 596 if (!valobj_sp) 597 return valobj_sp; 598 } 599 if (!valobj_sp) { 600 error.SetErrorStringWithFormat("no variable named '%s' found in this frame", 601 name_const_string.GetCString()); 602 return ValueObjectSP(); 603 } 604 605 // We are dumping at least one child 606 while (separator_idx != std::string::npos) { 607 // Calculate the next separator index ahead of time 608 ValueObjectSP child_valobj_sp; 609 const char separator_type = var_expr[0]; 610 bool expr_is_ptr = false; 611 switch (separator_type) { 612 case '-': 613 expr_is_ptr = true; 614 if (var_expr.size() >= 2 && var_expr[1] != '>') 615 return ValueObjectSP(); 616 617 if (no_fragile_ivar) { 618 // Make sure we aren't trying to deref an objective 619 // C ivar if this is not allowed 620 const uint32_t pointer_type_flags = 621 valobj_sp->GetCompilerType().GetTypeInfo(nullptr); 622 if ((pointer_type_flags & eTypeIsObjC) && 623 (pointer_type_flags & eTypeIsPointer)) { 624 // This was an objective C object pointer and 625 // it was requested we skip any fragile ivars 626 // so return nothing here 627 return ValueObjectSP(); 628 } 629 } 630 631 // If we have a non pointer type with a sythetic value then lets check if 632 // we have an sythetic dereference specified. 633 if (!valobj_sp->IsPointerType() && valobj_sp->HasSyntheticValue()) { 634 Error deref_error; 635 if (valobj_sp->GetCompilerType().IsReferenceType()) { 636 valobj_sp = valobj_sp->GetSyntheticValue()->Dereference(deref_error); 637 if (error.Fail()) { 638 error.SetErrorStringWithFormatv( 639 "Failed to dereference reference type: %s", deref_error); 640 return ValueObjectSP(); 641 } 642 } 643 644 valobj_sp = valobj_sp->Dereference(deref_error); 645 if (error.Fail()) { 646 error.SetErrorStringWithFormatv( 647 "Failed to dereference sythetic value: %s", deref_error); 648 return ValueObjectSP(); 649 } 650 expr_is_ptr = false; 651 } 652 653 var_expr = var_expr.drop_front(); // Remove the '-' 654 LLVM_FALLTHROUGH; 655 case '.': { 656 var_expr = var_expr.drop_front(); // Remove the '.' or '>' 657 separator_idx = var_expr.find_first_of(".-["); 658 ConstString child_name(var_expr.substr(0, var_expr.find_first_of(".-["))); 659 660 if (check_ptr_vs_member) { 661 // We either have a pointer type and need to verify 662 // valobj_sp is a pointer, or we have a member of a 663 // class/union/struct being accessed with the . syntax 664 // and need to verify we don't have a pointer. 665 const bool actual_is_ptr = valobj_sp->IsPointerType(); 666 667 if (actual_is_ptr != expr_is_ptr) { 668 // Incorrect use of "." with a pointer, or "->" with 669 // a class/union/struct instance or reference. 670 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 671 if (actual_is_ptr) 672 error.SetErrorStringWithFormat( 673 "\"%s\" is a pointer and . was used to attempt to access " 674 "\"%s\". Did you mean \"%s->%s\"?", 675 var_expr_path_strm.GetData(), child_name.GetCString(), 676 var_expr_path_strm.GetData(), var_expr.str().c_str()); 677 else 678 error.SetErrorStringWithFormat( 679 "\"%s\" is not a pointer and -> was used to attempt to " 680 "access \"%s\". Did you mean \"%s.%s\"?", 681 var_expr_path_strm.GetData(), child_name.GetCString(), 682 var_expr_path_strm.GetData(), var_expr.str().c_str()); 683 return ValueObjectSP(); 684 } 685 } 686 child_valobj_sp = valobj_sp->GetChildMemberWithName(child_name, true); 687 if (!child_valobj_sp) { 688 if (!no_synth_child) { 689 child_valobj_sp = valobj_sp->GetSyntheticValue(); 690 if (child_valobj_sp) 691 child_valobj_sp = 692 child_valobj_sp->GetChildMemberWithName(child_name, true); 693 } 694 695 if (no_synth_child || !child_valobj_sp) { 696 // No child member with name "child_name" 697 if (synthetically_added_instance_object) { 698 // We added a "this->" or "self->" to the beginning of the 699 // expression 700 // and this is the first pointer ivar access, so just return 701 // the normal 702 // error 703 error.SetErrorStringWithFormat( 704 "no variable or instance variable named '%s' found in " 705 "this frame", 706 name_const_string.GetCString()); 707 } else { 708 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 709 if (child_name) { 710 error.SetErrorStringWithFormat( 711 "\"%s\" is not a member of \"(%s) %s\"", 712 child_name.GetCString(), 713 valobj_sp->GetTypeName().AsCString("<invalid type>"), 714 var_expr_path_strm.GetData()); 715 } else { 716 error.SetErrorStringWithFormat( 717 "incomplete expression path after \"%s\" in \"%s\"", 718 var_expr_path_strm.GetData(), 719 original_var_expr.str().c_str()); 720 } 721 } 722 return ValueObjectSP(); 723 } 724 } 725 synthetically_added_instance_object = false; 726 // Remove the child name from the path 727 var_expr = var_expr.drop_front(child_name.GetLength()); 728 if (use_dynamic != eNoDynamicValues) { 729 ValueObjectSP dynamic_value_sp( 730 child_valobj_sp->GetDynamicValue(use_dynamic)); 731 if (dynamic_value_sp) 732 child_valobj_sp = dynamic_value_sp; 733 } 734 } break; 735 736 case '[': { 737 // Array member access, or treating pointer as an array 738 // Need at least two brackets and a number 739 if (var_expr.size() <= 2) { 740 error.SetErrorStringWithFormat( 741 "invalid square bracket encountered after \"%s\" in \"%s\"", 742 var_expr_path_strm.GetData(), var_expr.str().c_str()); 743 return ValueObjectSP(); 744 } 745 746 // Drop the open brace. 747 var_expr = var_expr.drop_front(); 748 long child_index = 0; 749 750 // If there's no closing brace, this is an invalid expression. 751 size_t end_pos = var_expr.find_first_of(']'); 752 if (end_pos == llvm::StringRef::npos) { 753 error.SetErrorStringWithFormat( 754 "missing closing square bracket in expression \"%s\"", 755 var_expr_path_strm.GetData()); 756 return ValueObjectSP(); 757 } 758 llvm::StringRef index_expr = var_expr.take_front(end_pos); 759 llvm::StringRef original_index_expr = index_expr; 760 // Drop all of "[index_expr]" 761 var_expr = var_expr.drop_front(end_pos + 1); 762 763 if (index_expr.consumeInteger(0, child_index)) { 764 // If there was no integer anywhere in the index expression, this is 765 // erroneous expression. 766 error.SetErrorStringWithFormat("invalid index expression \"%s\"", 767 index_expr.str().c_str()); 768 return ValueObjectSP(); 769 } 770 771 if (index_expr.empty()) { 772 // The entire index expression was a single integer. 773 774 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) { 775 // what we have is *ptr[low]. the most similar C++ syntax is to deref 776 // ptr and extract bit low out of it. reading array item low would be 777 // done by saying ptr[low], without a deref * sign 778 Error error; 779 ValueObjectSP temp(valobj_sp->Dereference(error)); 780 if (error.Fail()) { 781 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 782 error.SetErrorStringWithFormat( 783 "could not dereference \"(%s) %s\"", 784 valobj_sp->GetTypeName().AsCString("<invalid type>"), 785 var_expr_path_strm.GetData()); 786 return ValueObjectSP(); 787 } 788 valobj_sp = temp; 789 deref = false; 790 } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && 791 deref) { 792 // what we have is *arr[low]. the most similar C++ syntax is 793 // to get arr[0] 794 // (an operation that is equivalent to deref-ing arr) 795 // and extract bit low out of it. reading array item low 796 // would be done by saying arr[low], without a deref * sign 797 Error error; 798 ValueObjectSP temp(valobj_sp->GetChildAtIndex(0, true)); 799 if (error.Fail()) { 800 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 801 error.SetErrorStringWithFormat( 802 "could not get item 0 for \"(%s) %s\"", 803 valobj_sp->GetTypeName().AsCString("<invalid type>"), 804 var_expr_path_strm.GetData()); 805 return ValueObjectSP(); 806 } 807 valobj_sp = temp; 808 deref = false; 809 } 810 811 bool is_incomplete_array = false; 812 if (valobj_sp->IsPointerType()) { 813 bool is_objc_pointer = true; 814 815 if (valobj_sp->GetCompilerType().GetMinimumLanguage() != 816 eLanguageTypeObjC) 817 is_objc_pointer = false; 818 else if (!valobj_sp->GetCompilerType().IsPointerType()) 819 is_objc_pointer = false; 820 821 if (no_synth_child && is_objc_pointer) { 822 error.SetErrorStringWithFormat( 823 "\"(%s) %s\" is an Objective-C pointer, and cannot be " 824 "subscripted", 825 valobj_sp->GetTypeName().AsCString("<invalid type>"), 826 var_expr_path_strm.GetData()); 827 828 return ValueObjectSP(); 829 } else if (is_objc_pointer) { 830 // dereferencing ObjC variables is not valid.. so let's try 831 // and recur to synthetic children 832 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); 833 if (!synthetic /* no synthetic */ 834 || synthetic == valobj_sp) /* synthetic is the same as 835 the original object */ 836 { 837 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 838 error.SetErrorStringWithFormat( 839 "\"(%s) %s\" is not an array type", 840 valobj_sp->GetTypeName().AsCString("<invalid type>"), 841 var_expr_path_strm.GetData()); 842 } else if ( 843 static_cast<uint32_t>(child_index) >= 844 synthetic 845 ->GetNumChildren() /* synthetic does not have that many values */) { 846 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 847 error.SetErrorStringWithFormat( 848 "array index %ld is not valid for \"(%s) %s\"", child_index, 849 valobj_sp->GetTypeName().AsCString("<invalid type>"), 850 var_expr_path_strm.GetData()); 851 } else { 852 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); 853 if (!child_valobj_sp) { 854 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 855 error.SetErrorStringWithFormat( 856 "array index %ld is not valid for \"(%s) %s\"", child_index, 857 valobj_sp->GetTypeName().AsCString("<invalid type>"), 858 var_expr_path_strm.GetData()); 859 } 860 } 861 } else { 862 child_valobj_sp = 863 valobj_sp->GetSyntheticArrayMember(child_index, true); 864 if (!child_valobj_sp) { 865 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 866 error.SetErrorStringWithFormat( 867 "failed to use pointer as array for index %ld for " 868 "\"(%s) %s\"", 869 child_index, 870 valobj_sp->GetTypeName().AsCString("<invalid type>"), 871 var_expr_path_strm.GetData()); 872 } 873 } 874 } else if (valobj_sp->GetCompilerType().IsArrayType( 875 nullptr, nullptr, &is_incomplete_array)) { 876 // Pass false to dynamic_value here so we can tell the 877 // difference between 878 // no dynamic value and no member of this type... 879 child_valobj_sp = valobj_sp->GetChildAtIndex(child_index, true); 880 if (!child_valobj_sp && (is_incomplete_array || !no_synth_child)) 881 child_valobj_sp = 882 valobj_sp->GetSyntheticArrayMember(child_index, true); 883 884 if (!child_valobj_sp) { 885 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 886 error.SetErrorStringWithFormat( 887 "array index %ld is not valid for \"(%s) %s\"", child_index, 888 valobj_sp->GetTypeName().AsCString("<invalid type>"), 889 var_expr_path_strm.GetData()); 890 } 891 } else if (valobj_sp->GetCompilerType().IsScalarType()) { 892 // this is a bitfield asking to display just one bit 893 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild( 894 child_index, child_index, true); 895 if (!child_valobj_sp) { 896 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 897 error.SetErrorStringWithFormat( 898 "bitfield range %ld-%ld is not valid for \"(%s) %s\"", 899 child_index, child_index, 900 valobj_sp->GetTypeName().AsCString("<invalid type>"), 901 var_expr_path_strm.GetData()); 902 } 903 } else { 904 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); 905 if (no_synth_child /* synthetic is forbidden */ || 906 !synthetic /* no synthetic */ 907 || synthetic == valobj_sp) /* synthetic is the same as the 908 original object */ 909 { 910 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 911 error.SetErrorStringWithFormat( 912 "\"(%s) %s\" is not an array type", 913 valobj_sp->GetTypeName().AsCString("<invalid type>"), 914 var_expr_path_strm.GetData()); 915 } else if ( 916 static_cast<uint32_t>(child_index) >= 917 synthetic 918 ->GetNumChildren() /* synthetic does not have that many values */) { 919 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 920 error.SetErrorStringWithFormat( 921 "array index %ld is not valid for \"(%s) %s\"", child_index, 922 valobj_sp->GetTypeName().AsCString("<invalid type>"), 923 var_expr_path_strm.GetData()); 924 } else { 925 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); 926 if (!child_valobj_sp) { 927 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 928 error.SetErrorStringWithFormat( 929 "array index %ld is not valid for \"(%s) %s\"", child_index, 930 valobj_sp->GetTypeName().AsCString("<invalid type>"), 931 var_expr_path_strm.GetData()); 932 } 933 } 934 } 935 936 if (!child_valobj_sp) { 937 // Invalid array index... 938 return ValueObjectSP(); 939 } 940 941 separator_idx = var_expr.find_first_of(".-["); 942 if (use_dynamic != eNoDynamicValues) { 943 ValueObjectSP dynamic_value_sp( 944 child_valobj_sp->GetDynamicValue(use_dynamic)); 945 if (dynamic_value_sp) 946 child_valobj_sp = dynamic_value_sp; 947 } 948 // Break out early from the switch since we were able to find the child 949 // member 950 break; 951 } 952 953 // this is most probably a BitField, let's take a look 954 if (index_expr.front() != '-') { 955 error.SetErrorStringWithFormat("invalid range expression \"'%s'\"", 956 original_index_expr.str().c_str()); 957 return ValueObjectSP(); 958 } 959 960 index_expr = index_expr.drop_front(); 961 long final_index = 0; 962 if (index_expr.getAsInteger(0, final_index)) { 963 error.SetErrorStringWithFormat("invalid range expression \"'%s'\"", 964 original_index_expr.str().c_str()); 965 return ValueObjectSP(); 966 } 967 968 // if the format given is [high-low], swap range 969 if (child_index > final_index) { 970 long temp = child_index; 971 child_index = final_index; 972 final_index = temp; 973 } 974 975 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) { 976 // what we have is *ptr[low-high]. the most similar C++ syntax is to 977 // deref ptr and extract bits low thru high out of it. reading array 978 // items low thru high would be done by saying ptr[low-high], without 979 // a deref * sign 980 Error error; 981 ValueObjectSP temp(valobj_sp->Dereference(error)); 982 if (error.Fail()) { 983 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 984 error.SetErrorStringWithFormat( 985 "could not dereference \"(%s) %s\"", 986 valobj_sp->GetTypeName().AsCString("<invalid type>"), 987 var_expr_path_strm.GetData()); 988 return ValueObjectSP(); 989 } 990 valobj_sp = temp; 991 deref = false; 992 } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) { 993 // what we have is *arr[low-high]. the most similar C++ syntax is to get 994 // arr[0] (an operation that is equivalent to deref-ing arr) and extract 995 // bits low thru high out of it. reading array items low thru high would 996 // be done by saying arr[low-high], without a deref * sign 997 Error error; 998 ValueObjectSP temp(valobj_sp->GetChildAtIndex(0, true)); 999 if (error.Fail()) { 1000 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 1001 error.SetErrorStringWithFormat( 1002 "could not get item 0 for \"(%s) %s\"", 1003 valobj_sp->GetTypeName().AsCString("<invalid type>"), 1004 var_expr_path_strm.GetData()); 1005 return ValueObjectSP(); 1006 } 1007 valobj_sp = temp; 1008 deref = false; 1009 } 1010 1011 child_valobj_sp = 1012 valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true); 1013 if (!child_valobj_sp) { 1014 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 1015 error.SetErrorStringWithFormat( 1016 "bitfield range %ld-%ld is not valid for \"(%s) %s\"", child_index, 1017 final_index, valobj_sp->GetTypeName().AsCString("<invalid type>"), 1018 var_expr_path_strm.GetData()); 1019 } 1020 1021 if (!child_valobj_sp) { 1022 // Invalid bitfield range... 1023 return ValueObjectSP(); 1024 } 1025 1026 separator_idx = var_expr.find_first_of(".-["); 1027 if (use_dynamic != eNoDynamicValues) { 1028 ValueObjectSP dynamic_value_sp( 1029 child_valobj_sp->GetDynamicValue(use_dynamic)); 1030 if (dynamic_value_sp) 1031 child_valobj_sp = dynamic_value_sp; 1032 } 1033 // Break out early from the switch since we were able to find the child 1034 // member 1035 break; 1036 } 1037 default: 1038 // Failure... 1039 { 1040 valobj_sp->GetExpressionPath(var_expr_path_strm, false); 1041 error.SetErrorStringWithFormat( 1042 "unexpected char '%c' encountered after \"%s\" in \"%s\"", 1043 separator_type, var_expr_path_strm.GetData(), 1044 var_expr.str().c_str()); 1045 1046 return ValueObjectSP(); 1047 } 1048 } 1049 1050 if (child_valobj_sp) 1051 valobj_sp = child_valobj_sp; 1052 1053 if (var_expr.empty()) 1054 break; 1055 } 1056 if (valobj_sp) { 1057 if (deref) { 1058 ValueObjectSP deref_valobj_sp(valobj_sp->Dereference(error)); 1059 valobj_sp = deref_valobj_sp; 1060 } else if (address_of) { 1061 ValueObjectSP address_of_valobj_sp(valobj_sp->AddressOf(error)); 1062 valobj_sp = address_of_valobj_sp; 1063 } 1064 } 1065 return valobj_sp; 1066 } 1067 1068 bool StackFrame::GetFrameBaseValue(Scalar &frame_base, Error *error_ptr) { 1069 std::lock_guard<std::recursive_mutex> guard(m_mutex); 1070 if (!m_cfa_is_valid) { 1071 m_frame_base_error.SetErrorString( 1072 "No frame base available for this historical stack frame."); 1073 return false; 1074 } 1075 1076 if (m_flags.IsClear(GOT_FRAME_BASE)) { 1077 if (m_sc.function) { 1078 m_frame_base.Clear(); 1079 m_frame_base_error.Clear(); 1080 1081 m_flags.Set(GOT_FRAME_BASE); 1082 ExecutionContext exe_ctx(shared_from_this()); 1083 Value expr_value; 1084 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; 1085 if (m_sc.function->GetFrameBaseExpression().IsLocationList()) 1086 loclist_base_addr = 1087 m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress( 1088 exe_ctx.GetTargetPtr()); 1089 1090 if (m_sc.function->GetFrameBaseExpression().Evaluate( 1091 &exe_ctx, nullptr, nullptr, nullptr, loclist_base_addr, nullptr, 1092 nullptr, expr_value, &m_frame_base_error) == false) { 1093 // We should really have an error if evaluate returns, but in case 1094 // we don't, lets set the error to something at least. 1095 if (m_frame_base_error.Success()) 1096 m_frame_base_error.SetErrorString( 1097 "Evaluation of the frame base expression failed."); 1098 } else { 1099 m_frame_base = expr_value.ResolveValue(&exe_ctx); 1100 } 1101 } else { 1102 m_frame_base_error.SetErrorString("No function in symbol context."); 1103 } 1104 } 1105 1106 if (m_frame_base_error.Success()) 1107 frame_base = m_frame_base; 1108 1109 if (error_ptr) 1110 *error_ptr = m_frame_base_error; 1111 return m_frame_base_error.Success(); 1112 } 1113 1114 DWARFExpression *StackFrame::GetFrameBaseExpression(Error *error_ptr) { 1115 if (!m_sc.function) { 1116 if (error_ptr) { 1117 error_ptr->SetErrorString("No function in symbol context."); 1118 } 1119 return nullptr; 1120 } 1121 1122 return &m_sc.function->GetFrameBaseExpression(); 1123 } 1124 1125 RegisterContextSP StackFrame::GetRegisterContext() { 1126 std::lock_guard<std::recursive_mutex> guard(m_mutex); 1127 if (!m_reg_context_sp) { 1128 ThreadSP thread_sp(GetThread()); 1129 if (thread_sp) 1130 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame(this); 1131 } 1132 return m_reg_context_sp; 1133 } 1134 1135 bool StackFrame::HasDebugInformation() { 1136 GetSymbolContext(eSymbolContextLineEntry); 1137 return m_sc.line_entry.IsValid(); 1138 } 1139 1140 ValueObjectSP 1141 StackFrame::GetValueObjectForFrameVariable(const VariableSP &variable_sp, 1142 DynamicValueType use_dynamic) { 1143 std::lock_guard<std::recursive_mutex> guard(m_mutex); 1144 ValueObjectSP valobj_sp; 1145 if (m_is_history_frame) { 1146 return valobj_sp; 1147 } 1148 VariableList *var_list = GetVariableList(true); 1149 if (var_list) { 1150 // Make sure the variable is a frame variable 1151 const uint32_t var_idx = var_list->FindIndexForVariable(variable_sp.get()); 1152 const uint32_t num_variables = var_list->GetSize(); 1153 if (var_idx < num_variables) { 1154 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex(var_idx); 1155 if (!valobj_sp) { 1156 if (m_variable_list_value_objects.GetSize() < num_variables) 1157 m_variable_list_value_objects.Resize(num_variables); 1158 valobj_sp = ValueObjectVariable::Create(this, variable_sp); 1159 m_variable_list_value_objects.SetValueObjectAtIndex(var_idx, valobj_sp); 1160 } 1161 } 1162 } 1163 if (use_dynamic != eNoDynamicValues && valobj_sp) { 1164 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue(use_dynamic); 1165 if (dynamic_sp) 1166 return dynamic_sp; 1167 } 1168 return valobj_sp; 1169 } 1170 1171 ValueObjectSP StackFrame::TrackGlobalVariable(const VariableSP &variable_sp, 1172 DynamicValueType use_dynamic) { 1173 std::lock_guard<std::recursive_mutex> guard(m_mutex); 1174 if (m_is_history_frame) 1175 return ValueObjectSP(); 1176 1177 // Check to make sure we aren't already tracking this variable? 1178 ValueObjectSP valobj_sp( 1179 GetValueObjectForFrameVariable(variable_sp, use_dynamic)); 1180 if (!valobj_sp) { 1181 // We aren't already tracking this global 1182 VariableList *var_list = GetVariableList(true); 1183 // If this frame has no variables, create a new list 1184 if (var_list == nullptr) 1185 m_variable_list_sp.reset(new VariableList()); 1186 1187 // Add the global/static variable to this frame 1188 m_variable_list_sp->AddVariable(variable_sp); 1189 1190 // Now make a value object for it so we can track its changes 1191 valobj_sp = GetValueObjectForFrameVariable(variable_sp, use_dynamic); 1192 } 1193 return valobj_sp; 1194 } 1195 1196 bool StackFrame::IsInlined() { 1197 if (m_sc.block == nullptr) 1198 GetSymbolContext(eSymbolContextBlock); 1199 if (m_sc.block) 1200 return m_sc.block->GetContainingInlinedBlock() != nullptr; 1201 return false; 1202 } 1203 1204 lldb::LanguageType StackFrame::GetLanguage() { 1205 CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit; 1206 if (cu) 1207 return cu->GetLanguage(); 1208 return lldb::eLanguageTypeUnknown; 1209 } 1210 1211 lldb::LanguageType StackFrame::GuessLanguage() { 1212 LanguageType lang_type = GetLanguage(); 1213 1214 if (lang_type == eLanguageTypeUnknown) { 1215 Function *f = GetSymbolContext(eSymbolContextFunction).function; 1216 if (f) { 1217 lang_type = f->GetMangled().GuessLanguage(); 1218 } 1219 } 1220 1221 return lang_type; 1222 } 1223 1224 namespace { 1225 std::pair<const Instruction::Operand *, int64_t> 1226 GetBaseExplainingValue(const Instruction::Operand &operand, 1227 RegisterContext ®ister_context, lldb::addr_t value) { 1228 switch (operand.m_type) { 1229 case Instruction::Operand::Type::Dereference: 1230 case Instruction::Operand::Type::Immediate: 1231 case Instruction::Operand::Type::Invalid: 1232 case Instruction::Operand::Type::Product: 1233 // These are not currently interesting 1234 return std::make_pair(nullptr, 0); 1235 case Instruction::Operand::Type::Sum: { 1236 const Instruction::Operand *immediate_child = nullptr; 1237 const Instruction::Operand *variable_child = nullptr; 1238 if (operand.m_children[0].m_type == Instruction::Operand::Type::Immediate) { 1239 immediate_child = &operand.m_children[0]; 1240 variable_child = &operand.m_children[1]; 1241 } else if (operand.m_children[1].m_type == 1242 Instruction::Operand::Type::Immediate) { 1243 immediate_child = &operand.m_children[1]; 1244 variable_child = &operand.m_children[0]; 1245 } 1246 if (!immediate_child) { 1247 return std::make_pair(nullptr, 0); 1248 } 1249 lldb::addr_t adjusted_value = value; 1250 if (immediate_child->m_negative) { 1251 adjusted_value += immediate_child->m_immediate; 1252 } else { 1253 adjusted_value -= immediate_child->m_immediate; 1254 } 1255 std::pair<const Instruction::Operand *, int64_t> base_and_offset = 1256 GetBaseExplainingValue(*variable_child, register_context, 1257 adjusted_value); 1258 if (!base_and_offset.first) { 1259 return std::make_pair(nullptr, 0); 1260 } 1261 if (immediate_child->m_negative) { 1262 base_and_offset.second -= immediate_child->m_immediate; 1263 } else { 1264 base_and_offset.second += immediate_child->m_immediate; 1265 } 1266 return base_and_offset; 1267 } 1268 case Instruction::Operand::Type::Register: { 1269 const RegisterInfo *info = 1270 register_context.GetRegisterInfoByName(operand.m_register.AsCString()); 1271 if (!info) { 1272 return std::make_pair(nullptr, 0); 1273 } 1274 RegisterValue reg_value; 1275 if (!register_context.ReadRegister(info, reg_value)) { 1276 return std::make_pair(nullptr, 0); 1277 } 1278 if (reg_value.GetAsUInt64() == value) { 1279 return std::make_pair(&operand, 0); 1280 } else { 1281 return std::make_pair(nullptr, 0); 1282 } 1283 } 1284 } 1285 return std::make_pair(nullptr, 0); 1286 } 1287 1288 std::pair<const Instruction::Operand *, int64_t> 1289 GetBaseExplainingDereference(const Instruction::Operand &operand, 1290 RegisterContext ®ister_context, 1291 lldb::addr_t addr) { 1292 if (operand.m_type == Instruction::Operand::Type::Dereference) { 1293 return GetBaseExplainingValue(operand.m_children[0], register_context, 1294 addr); 1295 } 1296 return std::make_pair(nullptr, 0); 1297 } 1298 } 1299 1300 lldb::ValueObjectSP StackFrame::GuessValueForAddress(lldb::addr_t addr) { 1301 TargetSP target_sp = CalculateTarget(); 1302 1303 const ArchSpec &target_arch = target_sp->GetArchitecture(); 1304 1305 AddressRange pc_range; 1306 pc_range.GetBaseAddress() = GetFrameCodeAddress(); 1307 pc_range.SetByteSize(target_arch.GetMaximumOpcodeByteSize()); 1308 1309 ExecutionContext exe_ctx(shared_from_this()); 1310 1311 const char *plugin_name = nullptr; 1312 const char *flavor = nullptr; 1313 const bool prefer_file_cache = false; 1314 1315 DisassemblerSP disassembler_sp = Disassembler::DisassembleRange( 1316 target_arch, plugin_name, flavor, exe_ctx, pc_range, prefer_file_cache); 1317 1318 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) { 1319 return ValueObjectSP(); 1320 } 1321 1322 InstructionSP instruction_sp = 1323 disassembler_sp->GetInstructionList().GetInstructionAtIndex(0); 1324 1325 llvm::SmallVector<Instruction::Operand, 3> operands; 1326 1327 if (!instruction_sp->ParseOperands(operands)) { 1328 return ValueObjectSP(); 1329 } 1330 1331 RegisterContextSP register_context_sp = GetRegisterContext(); 1332 1333 if (!register_context_sp) { 1334 return ValueObjectSP(); 1335 } 1336 1337 for (const Instruction::Operand &operand : operands) { 1338 std::pair<const Instruction::Operand *, int64_t> base_and_offset = 1339 GetBaseExplainingDereference(operand, *register_context_sp, addr); 1340 1341 if (!base_and_offset.first) { 1342 continue; 1343 } 1344 1345 switch (base_and_offset.first->m_type) { 1346 case Instruction::Operand::Type::Immediate: { 1347 lldb_private::Address addr; 1348 if (target_sp->ResolveLoadAddress(base_and_offset.first->m_immediate + 1349 base_and_offset.second, 1350 addr)) { 1351 TypeSystem *c_type_system = 1352 target_sp->GetScratchTypeSystemForLanguage(nullptr, eLanguageTypeC); 1353 if (!c_type_system) { 1354 return ValueObjectSP(); 1355 } else { 1356 CompilerType void_ptr_type = 1357 c_type_system 1358 ->GetBasicTypeFromAST(lldb::BasicType::eBasicTypeChar) 1359 .GetPointerType(); 1360 return ValueObjectMemory::Create(this, "", addr, void_ptr_type); 1361 } 1362 } else { 1363 return ValueObjectSP(); 1364 } 1365 break; 1366 } 1367 case Instruction::Operand::Type::Register: { 1368 return GuessValueForRegisterAndOffset(base_and_offset.first->m_register, 1369 base_and_offset.second); 1370 } 1371 default: 1372 return ValueObjectSP(); 1373 } 1374 } 1375 1376 return ValueObjectSP(); 1377 } 1378 1379 namespace { 1380 ValueObjectSP GetValueForOffset(StackFrame &frame, ValueObjectSP &parent, 1381 int64_t offset) { 1382 if (offset < 0 || uint64_t(offset) >= parent->GetByteSize()) { 1383 return ValueObjectSP(); 1384 } 1385 1386 if (parent->IsPointerOrReferenceType()) { 1387 return parent; 1388 } 1389 1390 for (int ci = 0, ce = parent->GetNumChildren(); ci != ce; ++ci) { 1391 const bool can_create = true; 1392 ValueObjectSP child_sp = parent->GetChildAtIndex(ci, can_create); 1393 1394 if (!child_sp) { 1395 return ValueObjectSP(); 1396 } 1397 1398 int64_t child_offset = child_sp->GetByteOffset(); 1399 int64_t child_size = child_sp->GetByteSize(); 1400 1401 if (offset >= child_offset && offset < (child_offset + child_size)) { 1402 return GetValueForOffset(frame, child_sp, offset - child_offset); 1403 } 1404 } 1405 1406 if (offset == 0) { 1407 return parent; 1408 } else { 1409 return ValueObjectSP(); 1410 } 1411 } 1412 1413 ValueObjectSP GetValueForDereferincingOffset(StackFrame &frame, 1414 ValueObjectSP &base, 1415 int64_t offset) { 1416 // base is a pointer to something 1417 // offset is the thing to add to the pointer 1418 // We return the most sensible ValueObject for the result of *(base+offset) 1419 1420 if (!base->IsPointerOrReferenceType()) { 1421 return ValueObjectSP(); 1422 } 1423 1424 Error error; 1425 ValueObjectSP pointee = base->Dereference(error); 1426 1427 if (!pointee) { 1428 return ValueObjectSP(); 1429 } 1430 1431 if (offset >= 0 && uint64_t(offset) >= pointee->GetByteSize()) { 1432 int64_t index = offset / pointee->GetByteSize(); 1433 offset = offset % pointee->GetByteSize(); 1434 const bool can_create = true; 1435 pointee = base->GetSyntheticArrayMember(index, can_create); 1436 } 1437 1438 if (!pointee || error.Fail()) { 1439 return ValueObjectSP(); 1440 } 1441 1442 return GetValueForOffset(frame, pointee, offset); 1443 } 1444 1445 //------------------------------------------------------------------ 1446 /// Attempt to reconstruct the ValueObject for the address contained in a 1447 /// given register plus an offset. 1448 /// 1449 /// @params [in] frame 1450 /// The current stack frame. 1451 /// 1452 /// @params [in] reg 1453 /// The register. 1454 /// 1455 /// @params [in] offset 1456 /// The offset from the register. 1457 /// 1458 /// @param [in] disassembler 1459 /// A disassembler containing instructions valid up to the current PC. 1460 /// 1461 /// @param [in] variables 1462 /// The variable list from the current frame, 1463 /// 1464 /// @param [in] pc 1465 /// The program counter for the instruction considered the 'user'. 1466 /// 1467 /// @return 1468 /// A string describing the base for the ExpressionPath. This could be a 1469 /// variable, a register value, an argument, or a function return value. 1470 /// The ValueObject if found. If valid, it has a valid ExpressionPath. 1471 //------------------------------------------------------------------ 1472 lldb::ValueObjectSP DoGuessValueAt(StackFrame &frame, ConstString reg, 1473 int64_t offset, Disassembler &disassembler, 1474 VariableList &variables, const Address &pc) { 1475 // Example of operation for Intel: 1476 // 1477 // +14: movq -0x8(%rbp), %rdi 1478 // +18: movq 0x8(%rdi), %rdi 1479 // +22: addl 0x4(%rdi), %eax 1480 // 1481 // f, a pointer to a struct, is known to be at -0x8(%rbp). 1482 // 1483 // DoGuessValueAt(frame, rdi, 4, dis, vars, 0x22) finds the instruction at +18 1484 // that assigns to rdi, and calls itself recursively for that dereference 1485 // DoGuessValueAt(frame, rdi, 8, dis, vars, 0x18) finds the instruction at 1486 // +14 that assigns to rdi, and calls itself recursively for that 1487 // derefernece 1488 // DoGuessValueAt(frame, rbp, -8, dis, vars, 0x14) finds "f" in the 1489 // variable list. 1490 // Returns a ValueObject for f. (That's what was stored at rbp-8 at +14) 1491 // Returns a ValueObject for *(f+8) or f->b (That's what was stored at rdi+8 1492 // at +18) 1493 // Returns a ValueObject for *(f->b+4) or f->b->a (That's what was stored at 1494 // rdi+4 at +22) 1495 1496 // First, check the variable list to see if anything is at the specified 1497 // location. 1498 1499 using namespace OperandMatchers; 1500 1501 const RegisterInfo *reg_info = 1502 frame.GetRegisterContext()->GetRegisterInfoByName(reg.AsCString()); 1503 if (!reg_info) { 1504 return ValueObjectSP(); 1505 } 1506 1507 Instruction::Operand op = 1508 offset ? Instruction::Operand::BuildDereference( 1509 Instruction::Operand::BuildSum( 1510 Instruction::Operand::BuildRegister(reg), 1511 Instruction::Operand::BuildImmediate(offset))) 1512 : Instruction::Operand::BuildDereference( 1513 Instruction::Operand::BuildRegister(reg)); 1514 1515 for (size_t vi = 0, ve = variables.GetSize(); vi != ve; ++vi) { 1516 VariableSP var_sp = variables.GetVariableAtIndex(vi); 1517 if (var_sp->LocationExpression().MatchesOperand(frame, op)) { 1518 return frame.GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); 1519 } 1520 } 1521 1522 const uint32_t current_inst = 1523 disassembler.GetInstructionList().GetIndexOfInstructionAtAddress(pc); 1524 if (current_inst == UINT32_MAX) { 1525 return ValueObjectSP(); 1526 } 1527 1528 for (uint32_t ii = current_inst - 1; ii != (uint32_t)-1; --ii) { 1529 // This is not an exact algorithm, and it sacrifices accuracy for 1530 // generality. Recognizing "mov" and "ld" instructions –– and which are 1531 // their source and destination operands -- is something the disassembler 1532 // should do for us. 1533 InstructionSP instruction_sp = 1534 disassembler.GetInstructionList().GetInstructionAtIndex(ii); 1535 1536 if (instruction_sp->IsCall()) { 1537 ABISP abi_sp = frame.CalculateProcess()->GetABI(); 1538 if (!abi_sp) { 1539 continue; 1540 } 1541 1542 const char *return_register_name; 1543 if (!abi_sp->GetPointerReturnRegister(return_register_name)) { 1544 continue; 1545 } 1546 1547 const RegisterInfo *return_register_info = 1548 frame.GetRegisterContext()->GetRegisterInfoByName( 1549 return_register_name); 1550 if (!return_register_info) { 1551 continue; 1552 } 1553 1554 int64_t offset = 0; 1555 1556 if (!MatchUnaryOp(MatchOpType(Instruction::Operand::Type::Dereference), 1557 MatchRegOp(*return_register_info))(op) && 1558 !MatchUnaryOp( 1559 MatchOpType(Instruction::Operand::Type::Dereference), 1560 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum), 1561 MatchRegOp(*return_register_info), 1562 FetchImmOp(offset)))(op)) { 1563 continue; 1564 } 1565 1566 llvm::SmallVector<Instruction::Operand, 1> operands; 1567 if (!instruction_sp->ParseOperands(operands) || operands.size() != 1) { 1568 continue; 1569 } 1570 1571 switch (operands[0].m_type) { 1572 default: 1573 break; 1574 case Instruction::Operand::Type::Immediate: { 1575 SymbolContext sc; 1576 Address load_address; 1577 if (!frame.CalculateTarget()->ResolveLoadAddress( 1578 operands[0].m_immediate, load_address)) { 1579 break; 1580 } 1581 frame.CalculateTarget()->GetImages().ResolveSymbolContextForAddress( 1582 load_address, eSymbolContextFunction, sc); 1583 if (!sc.function) { 1584 break; 1585 } 1586 CompilerType function_type = sc.function->GetCompilerType(); 1587 if (!function_type.IsFunctionType()) { 1588 break; 1589 } 1590 CompilerType return_type = function_type.GetFunctionReturnType(); 1591 RegisterValue return_value; 1592 if (!frame.GetRegisterContext()->ReadRegister(return_register_info, 1593 return_value)) { 1594 break; 1595 } 1596 std::string name_str( 1597 sc.function->GetName().AsCString("<unknown function>")); 1598 name_str.append("()"); 1599 Address return_value_address(return_value.GetAsUInt64()); 1600 ValueObjectSP return_value_sp = ValueObjectMemory::Create( 1601 &frame, name_str, return_value_address, return_type); 1602 return GetValueForDereferincingOffset(frame, return_value_sp, offset); 1603 } 1604 } 1605 1606 continue; 1607 } 1608 1609 llvm::SmallVector<Instruction::Operand, 2> operands; 1610 if (!instruction_sp->ParseOperands(operands) || operands.size() != 2) { 1611 continue; 1612 } 1613 1614 Instruction::Operand *origin_operand = nullptr; 1615 auto clobbered_reg_matcher = [reg_info](const Instruction::Operand &op) { 1616 return MatchRegOp(*reg_info)(op) && op.m_clobbered; 1617 }; 1618 1619 if (clobbered_reg_matcher(operands[0])) { 1620 origin_operand = &operands[1]; 1621 } 1622 else if (clobbered_reg_matcher(operands[1])) { 1623 origin_operand = &operands[0]; 1624 } 1625 else { 1626 continue; 1627 } 1628 1629 // We have an origin operand. Can we track its value down? 1630 ValueObjectSP source_path; 1631 ConstString origin_register; 1632 int64_t origin_offset = 0; 1633 1634 if (FetchRegOp(origin_register)(*origin_operand)) { 1635 source_path = DoGuessValueAt(frame, origin_register, 0, disassembler, 1636 variables, instruction_sp->GetAddress()); 1637 } else if (MatchUnaryOp( 1638 MatchOpType(Instruction::Operand::Type::Dereference), 1639 FetchRegOp(origin_register))(*origin_operand) || 1640 MatchUnaryOp( 1641 MatchOpType(Instruction::Operand::Type::Dereference), 1642 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum), 1643 FetchRegOp(origin_register), 1644 FetchImmOp(origin_offset)))(*origin_operand)) { 1645 source_path = 1646 DoGuessValueAt(frame, origin_register, origin_offset, disassembler, 1647 variables, instruction_sp->GetAddress()); 1648 if (!source_path) { 1649 continue; 1650 } 1651 source_path = 1652 GetValueForDereferincingOffset(frame, source_path, offset); 1653 } 1654 1655 if (source_path) { 1656 return source_path; 1657 } 1658 } 1659 1660 return ValueObjectSP(); 1661 } 1662 } 1663 1664 lldb::ValueObjectSP StackFrame::GuessValueForRegisterAndOffset(ConstString reg, 1665 int64_t offset) { 1666 TargetSP target_sp = CalculateTarget(); 1667 1668 const ArchSpec &target_arch = target_sp->GetArchitecture(); 1669 1670 Block *frame_block = GetFrameBlock(); 1671 1672 if (!frame_block) { 1673 return ValueObjectSP(); 1674 } 1675 1676 Function *function = frame_block->CalculateSymbolContextFunction(); 1677 if (!function) { 1678 return ValueObjectSP(); 1679 } 1680 1681 AddressRange pc_range = function->GetAddressRange(); 1682 1683 if (GetFrameCodeAddress().GetFileAddress() < 1684 pc_range.GetBaseAddress().GetFileAddress() || 1685 GetFrameCodeAddress().GetFileAddress() - 1686 pc_range.GetBaseAddress().GetFileAddress() >= 1687 pc_range.GetByteSize()) { 1688 return ValueObjectSP(); 1689 } 1690 1691 ExecutionContext exe_ctx(shared_from_this()); 1692 1693 const char *plugin_name = nullptr; 1694 const char *flavor = nullptr; 1695 const bool prefer_file_cache = false; 1696 DisassemblerSP disassembler_sp = Disassembler::DisassembleRange( 1697 target_arch, plugin_name, flavor, exe_ctx, pc_range, prefer_file_cache); 1698 1699 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) { 1700 return ValueObjectSP(); 1701 } 1702 1703 const bool get_file_globals = false; 1704 VariableList *variables = GetVariableList(get_file_globals); 1705 1706 if (!variables) { 1707 return ValueObjectSP(); 1708 } 1709 1710 return DoGuessValueAt(*this, reg, offset, *disassembler_sp, *variables, 1711 GetFrameCodeAddress()); 1712 } 1713 1714 TargetSP StackFrame::CalculateTarget() { 1715 TargetSP target_sp; 1716 ThreadSP thread_sp(GetThread()); 1717 if (thread_sp) { 1718 ProcessSP process_sp(thread_sp->CalculateProcess()); 1719 if (process_sp) 1720 target_sp = process_sp->CalculateTarget(); 1721 } 1722 return target_sp; 1723 } 1724 1725 ProcessSP StackFrame::CalculateProcess() { 1726 ProcessSP process_sp; 1727 ThreadSP thread_sp(GetThread()); 1728 if (thread_sp) 1729 process_sp = thread_sp->CalculateProcess(); 1730 return process_sp; 1731 } 1732 1733 ThreadSP StackFrame::CalculateThread() { return GetThread(); } 1734 1735 StackFrameSP StackFrame::CalculateStackFrame() { return shared_from_this(); } 1736 1737 void StackFrame::CalculateExecutionContext(ExecutionContext &exe_ctx) { 1738 exe_ctx.SetContext(shared_from_this()); 1739 } 1740 1741 void StackFrame::DumpUsingSettingsFormat(Stream *strm, 1742 const char *frame_marker) { 1743 if (strm == nullptr) 1744 return; 1745 1746 GetSymbolContext(eSymbolContextEverything); 1747 ExecutionContext exe_ctx(shared_from_this()); 1748 StreamString s; 1749 1750 if (frame_marker) 1751 s.PutCString(frame_marker); 1752 1753 const FormatEntity::Entry *frame_format = nullptr; 1754 Target *target = exe_ctx.GetTargetPtr(); 1755 if (target) 1756 frame_format = target->GetDebugger().GetFrameFormat(); 1757 if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, 1758 nullptr, nullptr, false, false)) { 1759 strm->PutCString(s.GetString()); 1760 } else { 1761 Dump(strm, true, false); 1762 strm->EOL(); 1763 } 1764 } 1765 1766 void StackFrame::Dump(Stream *strm, bool show_frame_index, 1767 bool show_fullpaths) { 1768 if (strm == nullptr) 1769 return; 1770 1771 if (show_frame_index) 1772 strm->Printf("frame #%u: ", m_frame_index); 1773 ExecutionContext exe_ctx(shared_from_this()); 1774 Target *target = exe_ctx.GetTargetPtr(); 1775 strm->Printf("0x%0*" PRIx64 " ", 1776 target ? (target->GetArchitecture().GetAddressByteSize() * 2) 1777 : 16, 1778 GetFrameCodeAddress().GetLoadAddress(target)); 1779 GetSymbolContext(eSymbolContextEverything); 1780 const bool show_module = true; 1781 const bool show_inline = true; 1782 const bool show_function_arguments = true; 1783 const bool show_function_name = true; 1784 m_sc.DumpStopContext(strm, exe_ctx.GetBestExecutionContextScope(), 1785 GetFrameCodeAddress(), show_fullpaths, show_module, 1786 show_inline, show_function_arguments, 1787 show_function_name); 1788 } 1789 1790 void StackFrame::UpdateCurrentFrameFromPreviousFrame(StackFrame &prev_frame) { 1791 std::lock_guard<std::recursive_mutex> guard(m_mutex); 1792 assert(GetStackID() == 1793 prev_frame.GetStackID()); // TODO: remove this after some testing 1794 m_variable_list_sp = prev_frame.m_variable_list_sp; 1795 m_variable_list_value_objects.Swap(prev_frame.m_variable_list_value_objects); 1796 if (!m_disassembly.GetString().empty()) { 1797 m_disassembly.Clear(); 1798 m_disassembly.PutCString(prev_frame.m_disassembly.GetString()); 1799 } 1800 } 1801 1802 void StackFrame::UpdatePreviousFrameFromCurrentFrame(StackFrame &curr_frame) { 1803 std::lock_guard<std::recursive_mutex> guard(m_mutex); 1804 assert(GetStackID() == 1805 curr_frame.GetStackID()); // TODO: remove this after some testing 1806 m_id.SetPC(curr_frame.m_id.GetPC()); // Update the Stack ID PC value 1807 assert(GetThread() == curr_frame.GetThread()); 1808 m_frame_index = curr_frame.m_frame_index; 1809 m_concrete_frame_index = curr_frame.m_concrete_frame_index; 1810 m_reg_context_sp = curr_frame.m_reg_context_sp; 1811 m_frame_code_addr = curr_frame.m_frame_code_addr; 1812 assert(!m_sc.target_sp || !curr_frame.m_sc.target_sp || 1813 m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get()); 1814 assert(!m_sc.module_sp || !curr_frame.m_sc.module_sp || 1815 m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get()); 1816 assert(m_sc.comp_unit == nullptr || curr_frame.m_sc.comp_unit == nullptr || 1817 m_sc.comp_unit == curr_frame.m_sc.comp_unit); 1818 assert(m_sc.function == nullptr || curr_frame.m_sc.function == nullptr || 1819 m_sc.function == curr_frame.m_sc.function); 1820 m_sc = curr_frame.m_sc; 1821 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything); 1822 m_flags.Set(m_sc.GetResolvedMask()); 1823 m_frame_base.Clear(); 1824 m_frame_base_error.Clear(); 1825 } 1826 1827 bool StackFrame::HasCachedData() const { 1828 if (m_variable_list_sp) 1829 return true; 1830 if (m_variable_list_value_objects.GetSize() > 0) 1831 return true; 1832 if (!m_disassembly.GetString().empty()) 1833 return true; 1834 return false; 1835 } 1836 1837 bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source, 1838 const char *frame_marker) { 1839 1840 if (show_frame_info) { 1841 strm.Indent(); 1842 DumpUsingSettingsFormat(&strm, frame_marker); 1843 } 1844 1845 if (show_source) { 1846 ExecutionContext exe_ctx(shared_from_this()); 1847 bool have_source = false, have_debuginfo = false; 1848 Debugger::StopDisassemblyType disasm_display = 1849 Debugger::eStopDisassemblyTypeNever; 1850 Target *target = exe_ctx.GetTargetPtr(); 1851 if (target) { 1852 Debugger &debugger = target->GetDebugger(); 1853 const uint32_t source_lines_before = 1854 debugger.GetStopSourceLineCount(true); 1855 const uint32_t source_lines_after = 1856 debugger.GetStopSourceLineCount(false); 1857 disasm_display = debugger.GetStopDisassemblyDisplay(); 1858 1859 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry); 1860 if (m_sc.comp_unit && m_sc.line_entry.IsValid()) { 1861 have_debuginfo = true; 1862 if (source_lines_before > 0 || source_lines_after > 0) { 1863 size_t num_lines = 1864 target->GetSourceManager().DisplaySourceLinesWithLineNumbers( 1865 m_sc.line_entry.file, m_sc.line_entry.line, 1866 m_sc.line_entry.column, source_lines_before, 1867 source_lines_after, "->", &strm); 1868 if (num_lines != 0) 1869 have_source = true; 1870 // TODO: Give here a one time warning if source file is missing. 1871 } 1872 } 1873 switch (disasm_display) { 1874 case Debugger::eStopDisassemblyTypeNever: 1875 break; 1876 1877 case Debugger::eStopDisassemblyTypeNoDebugInfo: 1878 if (have_debuginfo) 1879 break; 1880 LLVM_FALLTHROUGH; 1881 1882 case Debugger::eStopDisassemblyTypeNoSource: 1883 if (have_source) 1884 break; 1885 LLVM_FALLTHROUGH; 1886 1887 case Debugger::eStopDisassemblyTypeAlways: 1888 if (target) { 1889 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount(); 1890 if (disasm_lines > 0) { 1891 const ArchSpec &target_arch = target->GetArchitecture(); 1892 AddressRange pc_range; 1893 pc_range.GetBaseAddress() = GetFrameCodeAddress(); 1894 pc_range.SetByteSize(disasm_lines * 1895 target_arch.GetMaximumOpcodeByteSize()); 1896 const char *plugin_name = nullptr; 1897 const char *flavor = nullptr; 1898 const bool mixed_source_and_assembly = false; 1899 Disassembler::Disassemble( 1900 target->GetDebugger(), target_arch, plugin_name, flavor, 1901 exe_ctx, pc_range, disasm_lines, mixed_source_and_assembly, 0, 1902 Disassembler::eOptionMarkPCAddress, strm); 1903 } 1904 } 1905 break; 1906 } 1907 } 1908 } 1909 return true; 1910 } 1911