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