1 //===-- SymbolContext.cpp ---------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Symbol/SymbolContext.h" 11 12 #include "lldb/Core/Log.h" 13 #include "lldb/Core/Module.h" 14 #include "lldb/Host/Host.h" 15 #include "lldb/Interpreter/Args.h" 16 #include "lldb/Symbol/CompileUnit.h" 17 #include "lldb/Symbol/ObjectFile.h" 18 #include "lldb/Symbol/Symbol.h" 19 #include "lldb/Symbol/SymbolFile.h" 20 #include "lldb/Symbol/SymbolVendor.h" 21 #include "lldb/Target/Target.h" 22 23 using namespace lldb; 24 using namespace lldb_private; 25 26 SymbolContext::SymbolContext() : 27 target_sp (), 28 module_sp (), 29 comp_unit (NULL), 30 function (NULL), 31 block (NULL), 32 line_entry (), 33 symbol (NULL) 34 { 35 } 36 37 SymbolContext::SymbolContext(const ModuleSP& m, CompileUnit *cu, Function *f, Block *b, LineEntry *le, Symbol *s) : 38 target_sp (), 39 module_sp (m), 40 comp_unit (cu), 41 function (f), 42 block (b), 43 line_entry (), 44 symbol (s) 45 { 46 if (le) 47 line_entry = *le; 48 } 49 50 SymbolContext::SymbolContext(const TargetSP &t, const ModuleSP& m, CompileUnit *cu, Function *f, Block *b, LineEntry *le, Symbol *s) : 51 target_sp (t), 52 module_sp (m), 53 comp_unit (cu), 54 function (f), 55 block (b), 56 line_entry (), 57 symbol (s) 58 { 59 if (le) 60 line_entry = *le; 61 } 62 63 SymbolContext::SymbolContext(const SymbolContext& rhs) : 64 target_sp (rhs.target_sp), 65 module_sp (rhs.module_sp), 66 comp_unit (rhs.comp_unit), 67 function (rhs.function), 68 block (rhs.block), 69 line_entry (rhs.line_entry), 70 symbol (rhs.symbol) 71 { 72 } 73 74 75 SymbolContext::SymbolContext (SymbolContextScope *sc_scope) : 76 target_sp (), 77 module_sp (), 78 comp_unit (NULL), 79 function (NULL), 80 block (NULL), 81 line_entry (), 82 symbol (NULL) 83 { 84 sc_scope->CalculateSymbolContext (this); 85 } 86 87 SymbolContext::~SymbolContext () 88 { 89 } 90 91 const SymbolContext& 92 SymbolContext::operator= (const SymbolContext& rhs) 93 { 94 if (this != &rhs) 95 { 96 target_sp = rhs.target_sp; 97 module_sp = rhs.module_sp; 98 comp_unit = rhs.comp_unit; 99 function = rhs.function; 100 block = rhs.block; 101 line_entry = rhs.line_entry; 102 symbol = rhs.symbol; 103 } 104 return *this; 105 } 106 107 void 108 SymbolContext::Clear() 109 { 110 target_sp.reset(); 111 module_sp.reset(); 112 comp_unit = NULL; 113 function = NULL; 114 block = NULL; 115 line_entry.Clear(); 116 symbol = NULL; 117 } 118 119 bool 120 SymbolContext::DumpStopContext 121 ( 122 Stream *s, 123 ExecutionContextScope *exe_scope, 124 const Address &addr, 125 bool show_fullpaths, 126 bool show_module, 127 bool show_inlined_frames 128 ) const 129 { 130 bool dumped_something = false; 131 if (show_module && module_sp) 132 { 133 if (show_fullpaths) 134 *s << module_sp->GetFileSpec(); 135 else 136 *s << module_sp->GetFileSpec().GetFilename(); 137 s->PutChar('`'); 138 dumped_something = true; 139 } 140 141 if (function != NULL) 142 { 143 SymbolContext inline_parent_sc; 144 Address inline_parent_addr; 145 if (function->GetMangled().GetName()) 146 { 147 dumped_something = true; 148 function->GetMangled().GetName().Dump(s); 149 } 150 151 if (addr.IsValid()) 152 { 153 const addr_t function_offset = addr.GetOffset() - function->GetAddressRange().GetBaseAddress().GetOffset(); 154 if (function_offset) 155 { 156 dumped_something = true; 157 s->Printf(" + %llu", function_offset); 158 } 159 } 160 161 if (GetParentOfInlinedScope (addr, inline_parent_sc, inline_parent_addr)) 162 { 163 dumped_something = true; 164 Block *inlined_block = block->GetContainingInlinedBlock(); 165 const InlineFunctionInfo* inlined_block_info = inlined_block->GetInlinedFunctionInfo(); 166 s->Printf (" [inlined] %s", inlined_block_info->GetName().GetCString()); 167 168 lldb_private::AddressRange block_range; 169 if (inlined_block->GetRangeContainingAddress(addr, block_range)) 170 { 171 const addr_t inlined_function_offset = addr.GetOffset() - block_range.GetBaseAddress().GetOffset(); 172 if (inlined_function_offset) 173 { 174 s->Printf(" + %llu", inlined_function_offset); 175 } 176 } 177 const Declaration &call_site = inlined_block_info->GetCallSite(); 178 if (call_site.IsValid()) 179 { 180 s->PutCString(" at "); 181 call_site.DumpStopContext (s, show_fullpaths); 182 } 183 if (show_inlined_frames) 184 { 185 s->EOL(); 186 s->Indent(); 187 return inline_parent_sc.DumpStopContext (s, exe_scope, inline_parent_addr, show_fullpaths, show_module, show_inlined_frames); 188 } 189 } 190 else 191 { 192 if (line_entry.IsValid()) 193 { 194 dumped_something = true; 195 s->PutCString(" at "); 196 if (line_entry.DumpStopContext(s, show_fullpaths)) 197 dumped_something = true; 198 } 199 } 200 } 201 else if (symbol != NULL) 202 { 203 if (symbol->GetMangled().GetName()) 204 { 205 dumped_something = true; 206 symbol->GetMangled().GetName().Dump(s); 207 } 208 209 if (addr.IsValid() && symbol->ValueIsAddress()) 210 { 211 const addr_t symbol_offset = addr.GetOffset() - symbol->GetAddress().GetOffset(); 212 if (symbol_offset) 213 { 214 dumped_something = true; 215 s->Printf(" + %llu", symbol_offset); 216 } 217 } 218 } 219 else if (addr.IsValid()) 220 { 221 addr.Dump(s, exe_scope, Address::DumpStyleModuleWithFileAddress); 222 dumped_something = true; 223 } 224 return dumped_something; 225 } 226 227 void 228 SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target) const 229 { 230 if (module_sp) 231 { 232 s->Indent(" Module: file = \""); 233 module_sp->GetFileSpec().Dump(s); 234 *s << '"'; 235 if (module_sp->GetArchitecture().IsValid()) 236 s->Printf (", arch = \"%s\"", module_sp->GetArchitecture().GetArchitectureName()); 237 s->EOL(); 238 } 239 240 if (comp_unit != NULL) 241 { 242 s->Indent("CompileUnit: "); 243 comp_unit->GetDescription (s, level); 244 s->EOL(); 245 } 246 247 if (function != NULL) 248 { 249 s->Indent(" Function: "); 250 function->GetDescription (s, level, target); 251 s->EOL(); 252 253 Type *func_type = function->GetType(); 254 if (func_type) 255 { 256 s->Indent(" FuncType: "); 257 func_type->GetDescription (s, level, false); 258 s->EOL(); 259 } 260 } 261 262 if (block != NULL) 263 { 264 std::vector<Block *> blocks; 265 blocks.push_back (block); 266 Block *parent_block = block->GetParent(); 267 268 while (parent_block) 269 { 270 blocks.push_back (parent_block); 271 parent_block = parent_block->GetParent(); 272 } 273 std::vector<Block *>::reverse_iterator pos; 274 std::vector<Block *>::reverse_iterator begin = blocks.rbegin(); 275 std::vector<Block *>::reverse_iterator end = blocks.rend(); 276 for (pos = begin; pos != end; ++pos) 277 { 278 if (pos == begin) 279 s->Indent(" Blocks: "); 280 else 281 s->Indent(" "); 282 (*pos)->GetDescription(s, function, level, target); 283 s->EOL(); 284 } 285 } 286 287 if (line_entry.IsValid()) 288 { 289 s->Indent(" LineEntry: "); 290 line_entry.GetDescription (s, level, comp_unit, target, false); 291 s->EOL(); 292 } 293 294 if (symbol != NULL) 295 { 296 s->Indent(" Symbol: "); 297 symbol->GetDescription(s, level, target); 298 s->EOL(); 299 } 300 } 301 302 uint32_t 303 SymbolContext::GetResolvedMask () const 304 { 305 uint32_t resolved_mask = 0; 306 if (target_sp) resolved_mask |= eSymbolContextTarget; 307 if (module_sp) resolved_mask |= eSymbolContextModule; 308 if (comp_unit) resolved_mask |= eSymbolContextCompUnit; 309 if (function) resolved_mask |= eSymbolContextFunction; 310 if (block) resolved_mask |= eSymbolContextBlock; 311 if (line_entry.IsValid()) resolved_mask |= eSymbolContextLineEntry; 312 if (symbol) resolved_mask |= eSymbolContextSymbol; 313 return resolved_mask; 314 } 315 316 317 void 318 SymbolContext::Dump(Stream *s, Target *target) const 319 { 320 *s << (void *)this << ": "; 321 s->Indent(); 322 s->PutCString("SymbolContext"); 323 s->IndentMore(); 324 s->EOL(); 325 s->IndentMore(); 326 s->Indent(); 327 *s << "Module = " << (void *)module_sp.get() << ' '; 328 if (module_sp) 329 module_sp->GetFileSpec().Dump(s); 330 s->EOL(); 331 s->Indent(); 332 *s << "CompileUnit = " << (void *)comp_unit; 333 if (comp_unit != NULL) 334 *s << " {0x" << comp_unit->GetID() << "} " << *(static_cast<FileSpec*> (comp_unit)); 335 s->EOL(); 336 s->Indent(); 337 *s << "Function = " << (void *)function; 338 if (function != NULL) 339 { 340 *s << " {0x" << function->GetID() << "} " << function->GetType()->GetName() << ", address-range = "; 341 function->GetAddressRange().Dump(s, target, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); 342 s->EOL(); 343 s->Indent(); 344 Type* func_type = function->GetType(); 345 if (func_type) 346 { 347 *s << " Type = "; 348 func_type->Dump (s, false); 349 } 350 } 351 s->EOL(); 352 s->Indent(); 353 *s << "Block = " << (void *)block; 354 if (block != NULL) 355 *s << " {0x" << block->GetID() << '}'; 356 // Dump the block and pass it a negative depth to we print all the parent blocks 357 //if (block != NULL) 358 // block->Dump(s, function->GetFileAddress(), INT_MIN); 359 s->EOL(); 360 s->Indent(); 361 *s << "LineEntry = "; 362 line_entry.Dump (s, target, true, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, true); 363 s->EOL(); 364 s->Indent(); 365 *s << "Symbol = " << (void *)symbol; 366 if (symbol != NULL && symbol->GetMangled()) 367 *s << ' ' << symbol->GetMangled().GetName().AsCString(); 368 s->EOL(); 369 s->IndentLess(); 370 s->IndentLess(); 371 } 372 373 bool 374 lldb_private::operator== (const SymbolContext& lhs, const SymbolContext& rhs) 375 { 376 return lhs.function == rhs.function 377 && lhs.symbol == rhs.symbol 378 && lhs.module_sp.get() == rhs.module_sp.get() 379 && lhs.comp_unit == rhs.comp_unit 380 && lhs.target_sp.get() == rhs.target_sp.get() 381 && LineEntry::Compare(lhs.line_entry, rhs.line_entry) == 0; 382 } 383 384 bool 385 lldb_private::operator!= (const SymbolContext& lhs, const SymbolContext& rhs) 386 { 387 return lhs.function != rhs.function 388 || lhs.symbol != rhs.symbol 389 || lhs.module_sp.get() != rhs.module_sp.get() 390 || lhs.comp_unit != rhs.comp_unit 391 || lhs.target_sp.get() != rhs.target_sp.get() 392 || LineEntry::Compare(lhs.line_entry, rhs.line_entry) != 0; 393 } 394 395 bool 396 SymbolContext::GetAddressRange (uint32_t scope, 397 uint32_t range_idx, 398 bool use_inline_block_range, 399 AddressRange &range) const 400 { 401 if ((scope & eSymbolContextLineEntry) && line_entry.IsValid()) 402 { 403 range = line_entry.range; 404 return true; 405 } 406 407 if ((scope & eSymbolContextBlock) && (block != NULL)) 408 { 409 if (use_inline_block_range) 410 { 411 Block *inline_block = block->GetContainingInlinedBlock(); 412 if (inline_block) 413 return inline_block->GetRangeAtIndex (range_idx, range); 414 } 415 else 416 { 417 return block->GetRangeAtIndex (range_idx, range); 418 } 419 } 420 421 if ((scope & eSymbolContextFunction) && (function != NULL)) 422 { 423 if (range_idx == 0) 424 { 425 range = function->GetAddressRange(); 426 return true; 427 } 428 } 429 430 if ((scope & eSymbolContextSymbol) && (symbol != NULL)) 431 { 432 if (range_idx == 0) 433 { 434 if (symbol->ValueIsAddress()) 435 { 436 range.GetBaseAddress() = symbol->GetAddress(); 437 range.SetByteSize (symbol->GetByteSize()); 438 return true; 439 } 440 } 441 } 442 range.Clear(); 443 return false; 444 } 445 446 bool 447 SymbolContext::GetParentOfInlinedScope (const Address &curr_frame_pc, 448 SymbolContext &next_frame_sc, 449 Address &next_frame_pc) const 450 { 451 next_frame_sc.Clear(); 452 next_frame_pc.Clear(); 453 454 if (block) 455 { 456 //const addr_t curr_frame_file_addr = curr_frame_pc.GetFileAddress(); 457 458 // In order to get the parent of an inlined function we first need to 459 // see if we are in an inlined block as "this->block" could be an 460 // inlined block, or a parent of "block" could be. So lets check if 461 // this block or one of this blocks parents is an inlined function. 462 Block *curr_inlined_block = block->GetContainingInlinedBlock(); 463 if (curr_inlined_block) 464 { 465 // "this->block" is contained in an inline function block, so to 466 // get the scope above the inlined block, we get the parent of the 467 // inlined block itself 468 Block *next_frame_block = curr_inlined_block->GetParent(); 469 // Now calculate the symbol context of the containing block 470 next_frame_block->CalculateSymbolContext (&next_frame_sc); 471 472 // If we get here we weren't able to find the return line entry using the nesting of the blocks and 473 // the line table. So just use the call site info from our inlined block. 474 475 AddressRange range; 476 if (curr_inlined_block->GetRangeContainingAddress (curr_frame_pc, range)) 477 { 478 // To see there this new frame block it, we need to look at the 479 // call site information from 480 const InlineFunctionInfo* curr_inlined_block_inlined_info = curr_inlined_block->GetInlinedFunctionInfo(); 481 next_frame_pc = range.GetBaseAddress(); 482 next_frame_sc.line_entry.range.GetBaseAddress() = next_frame_pc; 483 next_frame_sc.line_entry.file = curr_inlined_block_inlined_info->GetCallSite().GetFile(); 484 next_frame_sc.line_entry.line = curr_inlined_block_inlined_info->GetCallSite().GetLine(); 485 next_frame_sc.line_entry.column = curr_inlined_block_inlined_info->GetCallSite().GetColumn(); 486 return true; 487 } 488 else 489 { 490 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYMBOLS)); 491 492 if (log) 493 { 494 log->Printf ("warning: inlined block 0x%8.8llx doesn't have a range that contains file address 0x%llx", 495 curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress()); 496 } 497 #ifdef LLDB_CONFIGURATION_DEBUG 498 else 499 { 500 ObjectFile *objfile = NULL; 501 if (module_sp) 502 { 503 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); 504 if (symbol_vendor) 505 { 506 SymbolFile *symbol_file = symbol_vendor->GetSymbolFile(); 507 if (symbol_file) 508 objfile = symbol_file->GetObjectFile(); 509 } 510 } 511 if (objfile) 512 { 513 Host::SystemLog (Host::eSystemLogWarning, 514 "warning: inlined block 0x%8.8llx doesn't have a range that contains file address 0x%llx in %s/%s\n", 515 curr_inlined_block->GetID(), 516 curr_frame_pc.GetFileAddress(), 517 objfile->GetFileSpec().GetDirectory().GetCString(), 518 objfile->GetFileSpec().GetFilename().GetCString()); 519 } 520 else 521 { 522 Host::SystemLog (Host::eSystemLogWarning, 523 "warning: inlined block 0x%8.8llx doesn't have a range that contains file address 0x%llx\n", 524 curr_inlined_block->GetID(), 525 curr_frame_pc.GetFileAddress()); 526 } 527 } 528 #endif 529 } 530 } 531 } 532 533 return false; 534 } 535 536 ConstString 537 SymbolContext::GetFunctionName (Mangled::NamePreference preference) 538 { 539 if (function) 540 { 541 if (block) 542 { 543 Block *inlined_block = block->GetContainingInlinedBlock(); 544 545 if (inlined_block) 546 { 547 const InlineFunctionInfo *inline_info = inlined_block->GetInlinedFunctionInfo(); 548 if (inline_info) 549 return inline_info->GetName(); 550 } 551 } 552 return function->GetMangled().GetName(preference); 553 } 554 else if (symbol && symbol->ValueIsAddress()) 555 { 556 return symbol->GetMangled().GetName(preference); 557 } 558 else 559 { 560 // No function, return an empty string. 561 return ConstString(); 562 } 563 } 564 565 //---------------------------------------------------------------------- 566 // 567 // SymbolContextSpecifier 568 // 569 //---------------------------------------------------------------------- 570 571 SymbolContextSpecifier::SymbolContextSpecifier (const TargetSP &target_sp) : 572 m_target_sp (target_sp), 573 m_module_spec (), 574 m_module_sp (), 575 m_file_spec_ap (), 576 m_start_line (0), 577 m_end_line (0), 578 m_function_spec (), 579 m_class_name (), 580 m_address_range_ap (), 581 m_type (eNothingSpecified) 582 { 583 } 584 585 SymbolContextSpecifier::~SymbolContextSpecifier() 586 { 587 } 588 589 bool 590 SymbolContextSpecifier::AddLineSpecification (uint32_t line_no, SpecificationType type) 591 { 592 bool return_value = true; 593 switch (type) 594 { 595 case eNothingSpecified: 596 Clear(); 597 break; 598 case eLineStartSpecified: 599 m_start_line = line_no; 600 m_type |= eLineStartSpecified; 601 break; 602 case eLineEndSpecified: 603 m_end_line = line_no; 604 m_type |= eLineEndSpecified; 605 break; 606 default: 607 return_value = false; 608 break; 609 } 610 return return_value; 611 } 612 613 bool 614 SymbolContextSpecifier::AddSpecification (const char *spec_string, SpecificationType type) 615 { 616 bool return_value = true; 617 switch (type) 618 { 619 case eNothingSpecified: 620 Clear(); 621 break; 622 case eModuleSpecified: 623 { 624 // See if we can find the Module, if so stick it in the SymbolContext. 625 FileSpec module_file_spec(spec_string, false); 626 ModuleSpec module_spec (module_file_spec); 627 lldb::ModuleSP module_sp (m_target_sp->GetImages().FindFirstModule (module_spec)); 628 m_type |= eModuleSpecified; 629 if (module_sp) 630 m_module_sp = module_sp; 631 else 632 m_module_spec.assign (spec_string); 633 } 634 break; 635 case eFileSpecified: 636 // CompUnits can't necessarily be resolved here, since an inlined function might show up in 637 // a number of CompUnits. Instead we just convert to a FileSpec and store it away. 638 m_file_spec_ap.reset (new FileSpec (spec_string, false)); 639 m_type |= eFileSpecified; 640 break; 641 case eLineStartSpecified: 642 m_start_line = Args::StringToSInt32(spec_string, 0, 0, &return_value); 643 if (return_value) 644 m_type |= eLineStartSpecified; 645 break; 646 case eLineEndSpecified: 647 m_end_line = Args::StringToSInt32(spec_string, 0, 0, &return_value); 648 if (return_value) 649 m_type |= eLineEndSpecified; 650 break; 651 case eFunctionSpecified: 652 m_function_spec.assign(spec_string); 653 m_type |= eFunctionSpecified; 654 break; 655 case eClassOrNamespaceSpecified: 656 Clear(); 657 m_class_name.assign (spec_string); 658 m_type = eClassOrNamespaceSpecified; 659 break; 660 case eAddressRangeSpecified: 661 // Not specified yet... 662 break; 663 } 664 665 return return_value; 666 } 667 668 void 669 SymbolContextSpecifier::Clear() 670 { 671 m_module_spec.clear(); 672 m_file_spec_ap.reset(); 673 m_function_spec.clear(); 674 m_class_name.clear(); 675 m_start_line = 0; 676 m_end_line = 0; 677 m_address_range_ap.reset(); 678 679 m_type = eNothingSpecified; 680 } 681 682 bool 683 SymbolContextSpecifier::SymbolContextMatches(SymbolContext &sc) 684 { 685 if (m_type == eNothingSpecified) 686 return true; 687 688 if (m_target_sp.get() != sc.target_sp.get()) 689 return false; 690 691 if (m_type & eModuleSpecified) 692 { 693 if (sc.module_sp) 694 { 695 if (m_module_sp.get() != NULL) 696 { 697 if (m_module_sp.get() != sc.module_sp.get()) 698 return false; 699 } 700 else 701 { 702 FileSpec module_file_spec (m_module_spec.c_str(), false); 703 if (!FileSpec::Equal (module_file_spec, sc.module_sp->GetFileSpec(), false)) 704 return false; 705 } 706 } 707 } 708 if (m_type & eFileSpecified) 709 { 710 if (m_file_spec_ap.get()) 711 { 712 // If we don't have a block or a comp_unit, then we aren't going to match a source file. 713 if (sc.block == NULL && sc.comp_unit == NULL) 714 return false; 715 716 // Check if the block is present, and if so is it inlined: 717 bool was_inlined = false; 718 if (sc.block != NULL) 719 { 720 const InlineFunctionInfo *inline_info = sc.block->GetInlinedFunctionInfo(); 721 if (inline_info != NULL) 722 { 723 was_inlined = true; 724 if (!FileSpec::Equal (inline_info->GetDeclaration().GetFile(), *(m_file_spec_ap.get()), false)) 725 return false; 726 } 727 } 728 729 // Next check the comp unit, but only if the SymbolContext was not inlined. 730 if (!was_inlined && sc.comp_unit != NULL) 731 { 732 if (!FileSpec::Equal (*(sc.comp_unit), *(m_file_spec_ap.get()), false)) 733 return false; 734 } 735 } 736 } 737 if (m_type & eLineStartSpecified 738 || m_type & eLineEndSpecified) 739 { 740 if (sc.line_entry.line < m_start_line || sc.line_entry.line > m_end_line) 741 return false; 742 } 743 744 if (m_type & eFunctionSpecified) 745 { 746 // First check the current block, and if it is inlined, get the inlined function name: 747 bool was_inlined = false; 748 ConstString func_name(m_function_spec.c_str()); 749 750 if (sc.block != NULL) 751 { 752 const InlineFunctionInfo *inline_info = sc.block->GetInlinedFunctionInfo(); 753 if (inline_info != NULL) 754 { 755 was_inlined = true; 756 const Mangled &name = inline_info->GetMangled(); 757 if (!name.NameMatches (func_name)) 758 return false; 759 } 760 } 761 // If it wasn't inlined, check the name in the function or symbol: 762 if (!was_inlined) 763 { 764 if (sc.function != NULL) 765 { 766 if (!sc.function->GetMangled().NameMatches(func_name)) 767 return false; 768 } 769 else if (sc.symbol != NULL) 770 { 771 if (!sc.symbol->GetMangled().NameMatches(func_name)) 772 return false; 773 } 774 } 775 776 777 } 778 779 return true; 780 } 781 782 bool 783 SymbolContextSpecifier::AddressMatches(lldb::addr_t addr) 784 { 785 if (m_type & eAddressRangeSpecified) 786 { 787 788 } 789 else 790 { 791 Address match_address (addr, NULL); 792 SymbolContext sc; 793 m_target_sp->GetImages().ResolveSymbolContextForAddress(match_address, eSymbolContextEverything, sc); 794 return SymbolContextMatches(sc); 795 } 796 return true; 797 } 798 799 void 800 SymbolContextSpecifier::GetDescription (Stream *s, lldb::DescriptionLevel level) const 801 { 802 char path_str[PATH_MAX + 1]; 803 804 if (m_type == eNothingSpecified) 805 { 806 s->Printf ("Nothing specified.\n"); 807 } 808 809 if (m_type == eModuleSpecified) 810 { 811 s->Indent(); 812 if (m_module_sp) 813 { 814 m_module_sp->GetFileSpec().GetPath (path_str, PATH_MAX); 815 s->Printf ("Module: %s\n", path_str); 816 } 817 else 818 s->Printf ("Module: %s\n", m_module_spec.c_str()); 819 } 820 821 if (m_type == eFileSpecified && m_file_spec_ap.get() != NULL) 822 { 823 m_file_spec_ap->GetPath (path_str, PATH_MAX); 824 s->Indent(); 825 s->Printf ("File: %s", path_str); 826 if (m_type == eLineStartSpecified) 827 { 828 s->Printf (" from line %lu", m_start_line); 829 if (m_type == eLineEndSpecified) 830 s->Printf ("to line %lu", m_end_line); 831 else 832 s->Printf ("to end"); 833 } 834 else if (m_type == eLineEndSpecified) 835 { 836 s->Printf (" from start to line %ld", m_end_line); 837 } 838 s->Printf (".\n"); 839 } 840 841 if (m_type == eLineStartSpecified) 842 { 843 s->Indent(); 844 s->Printf ("From line %lu", m_start_line); 845 if (m_type == eLineEndSpecified) 846 s->Printf ("to line %lu", m_end_line); 847 else 848 s->Printf ("to end"); 849 s->Printf (".\n"); 850 } 851 else if (m_type == eLineEndSpecified) 852 { 853 s->Printf ("From start to line %ld.\n", m_end_line); 854 } 855 856 if (m_type == eFunctionSpecified) 857 { 858 s->Indent(); 859 s->Printf ("Function: %s.\n", m_function_spec.c_str()); 860 } 861 862 if (m_type == eClassOrNamespaceSpecified) 863 { 864 s->Indent(); 865 s->Printf ("Class name: %s.\n", m_class_name.c_str()); 866 } 867 868 if (m_type == eAddressRangeSpecified && m_address_range_ap.get() != NULL) 869 { 870 s->Indent(); 871 s->PutCString ("Address range: "); 872 m_address_range_ap->Dump (s, m_target_sp.get(), Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress); 873 s->PutCString ("\n"); 874 } 875 } 876 877 //---------------------------------------------------------------------- 878 // 879 // SymbolContextList 880 // 881 //---------------------------------------------------------------------- 882 883 884 SymbolContextList::SymbolContextList() : 885 m_symbol_contexts() 886 { 887 } 888 889 SymbolContextList::~SymbolContextList() 890 { 891 } 892 893 void 894 SymbolContextList::Append(const SymbolContext& sc) 895 { 896 m_symbol_contexts.push_back(sc); 897 } 898 899 void 900 SymbolContextList::Append (const SymbolContextList& sc_list) 901 { 902 collection::const_iterator pos, end = sc_list.m_symbol_contexts.end(); 903 for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos) 904 m_symbol_contexts.push_back (*pos); 905 } 906 907 908 uint32_t 909 SymbolContextList::AppendIfUnique (const SymbolContextList& sc_list, bool merge_symbol_into_function) 910 { 911 uint32_t unique_sc_add_count = 0; 912 collection::const_iterator pos, end = sc_list.m_symbol_contexts.end(); 913 for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos) 914 { 915 if (AppendIfUnique (*pos, merge_symbol_into_function)) 916 ++unique_sc_add_count; 917 } 918 return unique_sc_add_count; 919 } 920 921 bool 922 SymbolContextList::AppendIfUnique (const SymbolContext& sc, bool merge_symbol_into_function) 923 { 924 collection::iterator pos, end = m_symbol_contexts.end(); 925 for (pos = m_symbol_contexts.begin(); pos != end; ++pos) 926 { 927 if (*pos == sc) 928 return false; 929 } 930 if (merge_symbol_into_function 931 && sc.symbol != NULL 932 && sc.comp_unit == NULL 933 && sc.function == NULL 934 && sc.block == NULL 935 && sc.line_entry.IsValid() == false) 936 { 937 if (sc.symbol->ValueIsAddress()) 938 { 939 for (pos = m_symbol_contexts.begin(); pos != end; ++pos) 940 { 941 if (pos->function) 942 { 943 if (pos->function->GetAddressRange().GetBaseAddress() == sc.symbol->GetAddress()) 944 { 945 // Do we already have a function with this symbol? 946 if (pos->symbol == sc.symbol) 947 return false; 948 if (pos->symbol == NULL) 949 { 950 pos->symbol = sc.symbol; 951 return false; 952 } 953 } 954 } 955 } 956 } 957 } 958 m_symbol_contexts.push_back(sc); 959 return true; 960 } 961 962 void 963 SymbolContextList::Clear() 964 { 965 m_symbol_contexts.clear(); 966 } 967 968 void 969 SymbolContextList::Dump(Stream *s, Target *target) const 970 { 971 972 *s << (void *)this << ": "; 973 s->Indent(); 974 s->PutCString("SymbolContextList"); 975 s->EOL(); 976 s->IndentMore(); 977 978 collection::const_iterator pos, end = m_symbol_contexts.end(); 979 for (pos = m_symbol_contexts.begin(); pos != end; ++pos) 980 { 981 //pos->Dump(s, target); 982 pos->GetDescription(s, eDescriptionLevelVerbose, target); 983 } 984 s->IndentLess(); 985 } 986 987 bool 988 SymbolContextList::GetContextAtIndex(uint32_t idx, SymbolContext& sc) const 989 { 990 if (idx < m_symbol_contexts.size()) 991 { 992 sc = m_symbol_contexts[idx]; 993 return true; 994 } 995 return false; 996 } 997 998 bool 999 SymbolContextList::RemoveContextAtIndex (uint32_t idx) 1000 { 1001 if (idx < m_symbol_contexts.size()) 1002 { 1003 m_symbol_contexts.erase(m_symbol_contexts.begin() + idx); 1004 return true; 1005 } 1006 return false; 1007 } 1008 1009 uint32_t 1010 SymbolContextList::GetSize() const 1011 { 1012 return m_symbol_contexts.size(); 1013 } 1014 1015 uint32_t 1016 SymbolContextList::NumLineEntriesWithLine (uint32_t line) const 1017 { 1018 uint32_t match_count = 0; 1019 const uint32_t size = m_symbol_contexts.size(); 1020 for (uint32_t idx = 0; idx<size; ++idx) 1021 { 1022 if (m_symbol_contexts[idx].line_entry.line == line) 1023 ++match_count; 1024 } 1025 return match_count; 1026 } 1027 1028 void 1029 SymbolContextList::GetDescription(Stream *s, 1030 lldb::DescriptionLevel level, 1031 Target *target) const 1032 { 1033 const uint32_t size = m_symbol_contexts.size(); 1034 for (uint32_t idx = 0; idx<size; ++idx) 1035 m_symbol_contexts[idx].GetDescription (s, level, target); 1036 } 1037 1038 bool 1039 lldb_private::operator== (const SymbolContextList& lhs, const SymbolContextList& rhs) 1040 { 1041 const uint32_t size = lhs.GetSize(); 1042 if (size != rhs.GetSize()) 1043 return false; 1044 1045 SymbolContext lhs_sc; 1046 SymbolContext rhs_sc; 1047 for (uint32_t i=0; i<size; ++i) 1048 { 1049 lhs.GetContextAtIndex(i, lhs_sc); 1050 rhs.GetContextAtIndex(i, rhs_sc); 1051 if (lhs_sc != rhs_sc) 1052 return false; 1053 } 1054 return true; 1055 } 1056 1057 bool 1058 lldb_private::operator!= (const SymbolContextList& lhs, const SymbolContextList& rhs) 1059 { 1060 return !(lhs == rhs); 1061 } 1062 1063