1 //===-- ObjectFile.h --------------------------------------------*- 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 #ifndef liblldb_ObjectFile_h_ 11 #define liblldb_ObjectFile_h_ 12 13 #include "lldb/lldb-private.h" 14 #include "lldb/Core/DataExtractor.h" 15 #include "lldb/Host/FileSpec.h" 16 #include "lldb/Core/FileSpecList.h" 17 #include "lldb/Core/ModuleChild.h" 18 #include "lldb/Core/PluginInterface.h" 19 #include "lldb/Host/Endian.h" 20 #include "lldb/Symbol/Symtab.h" 21 #include "lldb/Symbol/UnwindTable.h" 22 23 namespace lldb_private { 24 25 class ObjectFileJITDelegate 26 { 27 public: ObjectFileJITDelegate()28 ObjectFileJITDelegate () 29 { 30 } 31 32 virtual ~ObjectFileJITDelegate()33 ~ObjectFileJITDelegate() 34 { 35 } 36 37 virtual lldb::ByteOrder 38 GetByteOrder () const = 0; 39 40 virtual uint32_t 41 GetAddressByteSize () const = 0; 42 43 virtual void 44 PopulateSymtab (lldb_private::ObjectFile *obj_file, 45 lldb_private::Symtab &symtab) = 0; 46 47 virtual void 48 PopulateSectionList (lldb_private::ObjectFile *obj_file, 49 lldb_private::SectionList §ion_list) = 0; 50 51 virtual bool 52 GetArchitecture (lldb_private::ArchSpec &arch) = 0; 53 }; 54 55 //---------------------------------------------------------------------- 56 /// @class ObjectFile ObjectFile.h "lldb/Symbol/ObjectFile.h" 57 /// @brief A plug-in interface definition class for object file parsers. 58 /// 59 /// Object files belong to Module objects and know how to extract 60 /// information from executable, shared library, and object (.o) files 61 /// used by operating system runtime. The symbol table and section list 62 /// for an object file. 63 /// 64 /// Object files can be represented by the entire file, or by part of a 65 /// file. An example of a partial file ObjectFile is one that contains 66 /// information for one of multiple architectures in the same file. 67 /// 68 /// Once an architecture is selected the object file information can be 69 /// extracted from this abstract class. 70 //---------------------------------------------------------------------- 71 class ObjectFile: 72 public std::enable_shared_from_this<ObjectFile>, 73 public PluginInterface, 74 public ModuleChild 75 { 76 friend class lldb_private::Module; 77 78 public: 79 typedef enum 80 { 81 eTypeInvalid = 0, 82 eTypeCoreFile, /// A core file that has a checkpoint of a program's execution state 83 eTypeExecutable, /// A normal executable 84 eTypeDebugInfo, /// An object file that contains only debug information 85 eTypeDynamicLinker, /// The platform's dynamic linker executable 86 eTypeObjectFile, /// An intermediate object file 87 eTypeSharedLibrary, /// A shared library that can be used during execution 88 eTypeStubLibrary, /// A library that can be linked against but not used for execution 89 eTypeJIT, /// JIT code that has symbols, sections and possibly debug info 90 eTypeUnknown 91 } Type; 92 93 typedef enum 94 { 95 eStrataInvalid = 0, 96 eStrataUnknown, 97 eStrataUser, 98 eStrataKernel, 99 eStrataRawImage, 100 eStrataJIT 101 } Strata; 102 103 //------------------------------------------------------------------ 104 /// Construct with a parent module, offset, and header data. 105 /// 106 /// Object files belong to modules and a valid module must be 107 /// supplied upon construction. The at an offset within a file for 108 /// objects that contain more than one architecture or object. 109 //------------------------------------------------------------------ 110 ObjectFile (const lldb::ModuleSP &module_sp, 111 const FileSpec *file_spec_ptr, 112 lldb::offset_t file_offset, 113 lldb::offset_t length, 114 const lldb::DataBufferSP& data_sp, 115 lldb::offset_t data_offset); 116 117 ObjectFile (const lldb::ModuleSP &module_sp, 118 const lldb::ProcessSP &process_sp, 119 lldb::addr_t header_addr, 120 lldb::DataBufferSP& data_sp); 121 122 //------------------------------------------------------------------ 123 /// Destructor. 124 /// 125 /// The destructor is virtual since this class is designed to be 126 /// inherited from by the plug-in instance. 127 //------------------------------------------------------------------ 128 virtual 129 ~ObjectFile(); 130 131 //------------------------------------------------------------------ 132 /// Dump a description of this object to a Stream. 133 /// 134 /// Dump a description of the current contents of this object 135 /// to the supplied stream \a s. The dumping should include the 136 /// section list if it has been parsed, and the symbol table 137 /// if it has been parsed. 138 /// 139 /// @param[in] s 140 /// The stream to which to dump the object description. 141 //------------------------------------------------------------------ 142 virtual void 143 Dump (Stream *s) = 0; 144 145 //------------------------------------------------------------------ 146 /// Find a ObjectFile plug-in that can parse \a file_spec. 147 /// 148 /// Scans all loaded plug-in interfaces that implement versions of 149 /// the ObjectFile plug-in interface and returns the first 150 /// instance that can parse the file. 151 /// 152 /// @param[in] module 153 /// The parent module that owns this object file. 154 /// 155 /// @param[in] file_spec 156 /// A file specification that indicates which file to use as the 157 /// object file. 158 /// 159 /// @param[in] file_offset 160 /// The offset into the file at which to start parsing the 161 /// object. This is for files that contain multiple 162 /// architectures or objects. 163 /// 164 /// @param[in] file_size 165 /// The size of the current object file if it can be determined 166 /// or if it is known. This can be zero. 167 /// 168 /// @see ObjectFile::ParseHeader() 169 //------------------------------------------------------------------ 170 static lldb::ObjectFileSP 171 FindPlugin (const lldb::ModuleSP &module_sp, 172 const FileSpec* file_spec, 173 lldb::offset_t file_offset, 174 lldb::offset_t file_size, 175 lldb::DataBufferSP &data_sp, 176 lldb::offset_t &data_offset); 177 178 //------------------------------------------------------------------ 179 /// Find a ObjectFile plug-in that can parse a file in memory. 180 /// 181 /// Scans all loaded plug-in interfaces that implement versions of 182 /// the ObjectFile plug-in interface and returns the first 183 /// instance that can parse the file. 184 /// 185 /// @param[in] module 186 /// The parent module that owns this object file. 187 /// 188 /// @param[in] process_sp 189 /// A shared pointer to the process whose memory space contains 190 /// an object file. This will be stored as a std::weak_ptr. 191 /// 192 /// @param[in] header_addr 193 /// The address of the header for the object file in memory. 194 //------------------------------------------------------------------ 195 static lldb::ObjectFileSP 196 FindPlugin (const lldb::ModuleSP &module_sp, 197 const lldb::ProcessSP &process_sp, 198 lldb::addr_t header_addr, 199 lldb::DataBufferSP &file_data_sp); 200 201 202 static size_t 203 GetModuleSpecifications (const FileSpec &file, 204 lldb::offset_t file_offset, 205 lldb::offset_t file_size, 206 ModuleSpecList &specs); 207 208 static size_t 209 GetModuleSpecifications (const lldb_private::FileSpec& file, 210 lldb::DataBufferSP& data_sp, 211 lldb::offset_t data_offset, 212 lldb::offset_t file_offset, 213 lldb::offset_t file_size, 214 lldb_private::ModuleSpecList &specs); 215 //------------------------------------------------------------------ 216 /// Split a path into a file path with object name. 217 /// 218 /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path 219 /// up into the actual path name and into the object name so we can 220 /// make a valid object file from it. 221 /// 222 /// @param[in] path_with_object 223 /// A path that might contain an archive path with a .o file 224 /// specified in parens in the basename of the path. 225 /// 226 /// @param[out] archive_file 227 /// If \b true is returned, \a file_spec will be filled in with 228 /// the path to the archive. 229 /// 230 /// @param[out] archive_object 231 /// If \b true is returned, \a object will be filled in with 232 /// the name of the object inside the archive. 233 /// 234 /// @return 235 /// \b true if the path matches the pattern of archive + object 236 /// and \a archive_file and \a archive_object are modified, 237 /// \b false otherwise and \a archive_file and \a archive_object 238 /// are guaranteed to be remain unchanged. 239 //------------------------------------------------------------------ 240 static bool 241 SplitArchivePathWithObject (const char *path_with_object, 242 lldb_private::FileSpec &archive_file, 243 lldb_private::ConstString &archive_object, 244 bool must_exist); 245 246 //------------------------------------------------------------------ 247 /// Gets the address size in bytes for the current object file. 248 /// 249 /// @return 250 /// The size of an address in bytes for the currently selected 251 /// architecture (and object for archives). Returns zero if no 252 /// architecture or object has been selected. 253 //------------------------------------------------------------------ 254 virtual uint32_t 255 GetAddressByteSize () const = 0; 256 257 //------------------------------------------------------------------ 258 /// Get the address type given a file address in an object file. 259 /// 260 /// Many binary file formats know what kinds 261 /// This is primarily for ARM binaries, though it can be applied to 262 /// any executable file format that supports different opcode types 263 /// within the same binary. ARM binaries support having both ARM and 264 /// Thumb within the same executable container. We need to be able 265 /// to get 266 /// @return 267 /// The size of an address in bytes for the currently selected 268 /// architecture (and object for archives). Returns zero if no 269 /// architecture or object has been selected. 270 //------------------------------------------------------------------ 271 virtual lldb::AddressClass 272 GetAddressClass (lldb::addr_t file_addr); 273 274 //------------------------------------------------------------------ 275 /// Extract the dependent modules from an object file. 276 /// 277 /// If an object file has information about which other images it 278 /// depends on (such as shared libraries), this function will 279 /// provide the list. Since many executables or shared libraries 280 /// may depend on the same files, 281 /// FileSpecList::AppendIfUnique(const FileSpec &) should be 282 /// used to make sure any files that are added are not already in 283 /// the list. 284 /// 285 /// @param[out] file_list 286 /// A list of file specification objects that gets dependent 287 /// files appended to. 288 /// 289 /// @return 290 /// The number of new files that were appended to \a file_list. 291 /// 292 /// @see FileSpecList::AppendIfUnique(const FileSpec &) 293 //------------------------------------------------------------------ 294 virtual uint32_t 295 GetDependentModules (FileSpecList& file_list) = 0; 296 297 //------------------------------------------------------------------ 298 /// Tells whether this object file is capable of being the main executable 299 /// for a process. 300 /// 301 /// @return 302 /// \b true if it is, \b false otherwise. 303 //------------------------------------------------------------------ 304 virtual bool 305 IsExecutable () const = 0; 306 307 //------------------------------------------------------------------ 308 /// Returns the offset into a file at which this object resides. 309 /// 310 /// Some files contain many object files, and this function allows 311 /// access to an object's offset within the file. 312 /// 313 /// @return 314 /// The offset in bytes into the file. Defaults to zero for 315 /// simple object files that a represented by an entire file. 316 //------------------------------------------------------------------ 317 virtual lldb::addr_t GetFileOffset()318 GetFileOffset () const 319 { return m_file_offset; } 320 321 virtual lldb::addr_t GetByteSize()322 GetByteSize () const 323 { return m_length; } 324 325 //------------------------------------------------------------------ 326 /// Get accessor to the object file specification. 327 /// 328 /// @return 329 /// The file specification object pointer if there is one, or 330 /// NULL if this object is only from memory. 331 //------------------------------------------------------------------ 332 virtual FileSpec& GetFileSpec()333 GetFileSpec() { return m_file; } 334 335 //------------------------------------------------------------------ 336 /// Get const accessor to the object file specification. 337 /// 338 /// @return 339 /// The const file specification object pointer if there is one, 340 /// or NULL if this object is only from memory. 341 //------------------------------------------------------------------ 342 virtual const FileSpec& GetFileSpec()343 GetFileSpec() const { return m_file; } 344 345 //------------------------------------------------------------------ 346 /// Get the name of the cpu, vendor and OS for this object file. 347 /// 348 /// This value is a string that represents the target triple where 349 /// the cpu type, the vendor and the OS are encoded into a string. 350 /// 351 /// @param[out] target_triple 352 /// The string value of the target triple. 353 /// 354 /// @return 355 /// \b True if the target triple was able to be computed, \b 356 /// false otherwise. 357 //------------------------------------------------------------------ 358 virtual bool 359 GetArchitecture (ArchSpec &arch) = 0; 360 361 //------------------------------------------------------------------ 362 /// Gets the section list for the currently selected architecture 363 /// (and object for archives). 364 /// 365 /// Section list parsing can be deferred by ObjectFile instances 366 /// until this accessor is called the first time. 367 /// 368 /// @return 369 /// The list of sections contained in this object file. 370 //------------------------------------------------------------------ 371 virtual SectionList * 372 GetSectionList (); 373 374 virtual void 375 CreateSections (SectionList &unified_section_list) = 0; 376 377 378 //------------------------------------------------------------------ 379 /// Notify the ObjectFile that the file addresses in the Sections 380 /// for this module have been changed. 381 //------------------------------------------------------------------ 382 virtual void SectionFileAddressesChanged()383 SectionFileAddressesChanged () 384 { 385 } 386 387 //------------------------------------------------------------------ 388 /// Gets the symbol table for the currently selected architecture 389 /// (and object for archives). 390 /// 391 /// Symbol table parsing can be deferred by ObjectFile instances 392 /// until this accessor is called the first time. 393 /// 394 /// @return 395 /// The symbol table for this object file. 396 //------------------------------------------------------------------ 397 virtual Symtab * 398 GetSymtab () = 0; 399 400 //------------------------------------------------------------------ 401 /// Appends a Symbol for the specified so_addr to the symbol table. 402 /// 403 /// If verify_unique is false, the symbol table is not searched 404 /// to determine if a Symbol found at this address has already been 405 /// added to the symbol table. When verify_unique is true, this 406 /// method resolves the Symbol as the first match in the SymbolTable 407 /// and appends a Symbol only if required/found. 408 /// 409 /// @return 410 /// The resolved symbol or nullptr. Returns nullptr if a 411 /// a Symbol could not be found for the specified so_addr. 412 //------------------------------------------------------------------ 413 virtual Symbol * ResolveSymbolForAddress(const Address & so_addr,bool verify_unique)414 ResolveSymbolForAddress(const Address &so_addr, bool verify_unique) 415 { 416 // Typically overridden to lazily add stripped symbols recoverable from 417 // the exception handling unwind information (i.e. without parsing 418 // the entire eh_frame section. 419 // 420 // The availability of LC_FUNCTION_STARTS allows ObjectFileMachO 421 // to efficiently add stripped symbols when the symbol table is 422 // first constructed. Poorer cousins are PECoff and ELF. 423 return nullptr; 424 } 425 426 //------------------------------------------------------------------ 427 /// Detect if this object file has been stripped of local symbols. 428 //------------------------------------------------------------------ 429 /// Detect if this object file has been stripped of local symbols. 430 /// 431 /// @return 432 /// Return \b true if the object file has been stripped of local 433 /// symbols. 434 //------------------------------------------------------------------ 435 virtual bool 436 IsStripped () = 0; 437 438 //------------------------------------------------------------------ 439 /// Frees the symbol table. 440 /// 441 /// This function should only be used when an object file is 442 /// 443 /// @param[in] flags 444 /// eSymtabFromUnifiedSectionList: Whether to clear symbol table 445 /// for unified module section list, or object file. 446 /// 447 /// @return 448 /// The symbol table for this object file. 449 //------------------------------------------------------------------ 450 virtual void 451 ClearSymtab (); 452 453 //------------------------------------------------------------------ 454 /// Gets the UUID for this object file. 455 /// 456 /// If the object file format contains a UUID, the value should be 457 /// returned. Else ObjectFile instances should return the MD5 458 /// checksum of all of the bytes for the object file (or memory for 459 /// memory based object files). 460 /// 461 /// @return 462 /// Returns \b true if a UUID was successfully extracted into 463 /// \a uuid, \b false otherwise. 464 //------------------------------------------------------------------ 465 virtual bool 466 GetUUID (lldb_private::UUID* uuid) = 0; 467 468 //------------------------------------------------------------------ 469 /// Gets the symbol file spec list for this object file. 470 /// 471 /// If the object file format contains a debug symbol file link, 472 /// the values will be returned in the FileSpecList. 473 /// 474 /// @return 475 /// Returns filespeclist. 476 //------------------------------------------------------------------ 477 virtual lldb_private::FileSpecList GetDebugSymbolFilePaths()478 GetDebugSymbolFilePaths() 479 { 480 return FileSpecList(); 481 } 482 483 //------------------------------------------------------------------ 484 /// Gets the file spec list of libraries re-exported by this object file. 485 /// 486 /// If the object file format has the notion of one library re-exporting the symbols from another, 487 /// the re-exported libraries will be returned in the FileSpecList. 488 /// 489 /// @return 490 /// Returns filespeclist. 491 //------------------------------------------------------------------ 492 virtual lldb_private::FileSpecList GetReExportedLibraries()493 GetReExportedLibraries () 494 { 495 return FileSpecList(); 496 } 497 498 //------------------------------------------------------------------ 499 /// Sets the load address for an entire module, assuming a rigid 500 /// slide of sections, if possible in the implementation. 501 /// 502 /// @return 503 /// Returns true iff any section's load address changed. 504 //------------------------------------------------------------------ 505 virtual bool SetLoadAddress(Target & target,lldb::addr_t value,bool value_is_offset)506 SetLoadAddress(Target &target, 507 lldb::addr_t value, 508 bool value_is_offset) 509 { 510 return false; 511 } 512 513 //------------------------------------------------------------------ 514 /// Gets whether endian swapping should occur when extracting data 515 /// from this object file. 516 /// 517 /// @return 518 /// Returns \b true if endian swapping is needed, \b false 519 /// otherwise. 520 //------------------------------------------------------------------ 521 virtual lldb::ByteOrder 522 GetByteOrder () const = 0; 523 524 //------------------------------------------------------------------ 525 /// Attempts to parse the object header. 526 /// 527 /// This function is used as a test to see if a given plug-in 528 /// instance can parse the header data already contained in 529 /// ObjectFile::m_data. If an object file parser does not 530 /// recognize that magic bytes in a header, false should be returned 531 /// and the next plug-in can attempt to parse an object file. 532 /// 533 /// @return 534 /// Returns \b true if the header was parsed successfully, \b 535 /// false otherwise. 536 //------------------------------------------------------------------ 537 virtual bool 538 ParseHeader () = 0; 539 540 //------------------------------------------------------------------ 541 /// Returns a reference to the UnwindTable for this ObjectFile 542 /// 543 /// The UnwindTable contains FuncUnwinders objects for any function in 544 /// this ObjectFile. If a FuncUnwinders object hasn't been created yet 545 /// (i.e. the function has yet to be unwound in a stack walk), it 546 /// will be created when requested. Specifically, we do not create 547 /// FuncUnwinders objects for functions until they are needed. 548 /// 549 /// @return 550 /// Returns the unwind table for this object file. 551 //------------------------------------------------------------------ 552 virtual lldb_private::UnwindTable& GetUnwindTable()553 GetUnwindTable () { return m_unwind_table; } 554 555 //------------------------------------------------------------------ 556 /// Similar to Process::GetImageInfoAddress(). 557 /// 558 /// Some platforms embed auxiliary structures useful to debuggers in the 559 /// address space of the inferior process. This method returns the address 560 /// of such a structure if the information can be resolved via entries in 561 /// the object file. ELF, for example, provides a means to hook into the 562 /// runtime linker so that a debugger may monitor the loading and unloading 563 /// of shared libraries. 564 /// 565 /// @return 566 /// The address of any auxiliary tables, or an invalid address if this 567 /// object file format does not support or contain such information. 568 virtual lldb_private::Address GetImageInfoAddress(Target * target)569 GetImageInfoAddress (Target *target) { return Address(); } 570 571 //------------------------------------------------------------------ 572 /// Returns the address of the Entry Point in this object file - if 573 /// the object file doesn't have an entry point (because it is not an 574 /// executable file) then an invalid address is returned. 575 /// 576 /// @return 577 /// Returns the entry address for this module. 578 //------------------------------------------------------------------ 579 virtual lldb_private::Address GetEntryPointAddress()580 GetEntryPointAddress () { return Address();} 581 582 //------------------------------------------------------------------ 583 /// Returns the address that represents the header of this object 584 /// file. 585 /// 586 /// The header address is defined as where the header for the object 587 /// file is that describes the content of the file. If the header 588 /// doesn't appear in a section that is defined in the object file, 589 /// an address with no section is returned that has the file offset 590 /// set in the m_file_offset member of the lldb_private::Address object. 591 /// 592 /// @return 593 /// Returns the entry address for this module. 594 //------------------------------------------------------------------ 595 virtual lldb_private::Address GetHeaderAddress()596 GetHeaderAddress () { return Address(m_memory_addr);} 597 598 599 virtual uint32_t GetNumThreadContexts()600 GetNumThreadContexts () 601 { 602 return 0; 603 } 604 605 virtual lldb::RegisterContextSP GetThreadContextAtIndex(uint32_t idx,lldb_private::Thread & thread)606 GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &thread) 607 { 608 return lldb::RegisterContextSP(); 609 } 610 611 //------------------------------------------------------------------ 612 /// The object file should be able to calculate its type by looking 613 /// at its file header and possibly the sections or other data in 614 /// the object file. The file type is used in the debugger to help 615 /// select the correct plug-ins for the job at hand, so this is 616 /// important to get right. If any eTypeXXX definitions do not match 617 /// up with the type of file you are loading, please feel free to 618 /// add a new enumeration value. 619 /// 620 /// @return 621 /// The calculated file type for the current object file. 622 //------------------------------------------------------------------ 623 virtual Type 624 CalculateType() = 0; 625 626 //------------------------------------------------------------------ 627 /// In cases where the type can't be calculated (elf files), this 628 /// routine allows someone to explicitly set it. As an example, 629 /// SymbolVendorELF uses this routine to set eTypeDebugInfo when 630 /// loading debug link files. 631 virtual void SetType(Type type)632 SetType (Type type) 633 { 634 m_type = type; 635 } 636 637 //------------------------------------------------------------------ 638 /// The object file should be able to calculate the strata of the 639 /// object file. 640 /// 641 /// Many object files for platforms might be for either user space 642 /// debugging or for kernel debugging. If your object file subclass 643 /// can figure this out, it will help with debugger plug-in selection 644 /// when it comes time to debug. 645 /// 646 /// @return 647 /// The calculated object file strata for the current object 648 /// file. 649 //------------------------------------------------------------------ 650 virtual Strata 651 CalculateStrata() = 0; 652 653 //------------------------------------------------------------------ 654 /// Get the object file version numbers. 655 /// 656 /// Many object files have a set of version numbers that describe 657 /// the version of the executable or shared library. Typically there 658 /// are major, minor and build, but there may be more. This function 659 /// will extract the versions from object files if they are available. 660 /// 661 /// If \a versions is NULL, or if \a num_versions is 0, the return 662 /// value will indicate how many version numbers are available in 663 /// this object file. Then a subsequent call can be made to this 664 /// function with a value of \a versions and \a num_versions that 665 /// has enough storage to store some or all version numbers. 666 /// 667 /// @param[out] versions 668 /// A pointer to an array of uint32_t types that is \a num_versions 669 /// long. If this value is NULL, the return value will indicate 670 /// how many version numbers are required for a subsequent call 671 /// to this function so that all versions can be retrieved. If 672 /// the value is non-NULL, then at most \a num_versions of the 673 /// existing versions numbers will be filled into \a versions. 674 /// If there is no version information available, \a versions 675 /// will be filled with \a num_versions UINT32_MAX values 676 /// and zero will be returned. 677 /// 678 /// @param[in] num_versions 679 /// The maximum number of entries to fill into \a versions. If 680 /// this value is zero, then the return value will indicate 681 /// how many version numbers there are in total so another call 682 /// to this function can be make with adequate storage in 683 /// \a versions to get all of the version numbers. If \a 684 /// num_versions is less than the actual number of version 685 /// numbers in this object file, only \a num_versions will be 686 /// filled into \a versions (if \a versions is non-NULL). 687 /// 688 /// @return 689 /// This function always returns the number of version numbers 690 /// that this object file has regardless of the number of 691 /// version numbers that were copied into \a versions. 692 //------------------------------------------------------------------ 693 virtual uint32_t GetVersion(uint32_t * versions,uint32_t num_versions)694 GetVersion (uint32_t *versions, uint32_t num_versions) 695 { 696 if (versions && num_versions) 697 { 698 for (uint32_t i=0; i<num_versions; ++i) 699 versions[i] = UINT32_MAX; 700 } 701 return 0; 702 } 703 704 //------------------------------------------------------------------ 705 /// Get the minimum OS version this object file can run on. 706 /// 707 /// Some object files have information that specifies the minimum OS 708 /// version that they can be used on. 709 /// 710 /// If \a versions is NULL, or if \a num_versions is 0, the return 711 /// value will indicate how many version numbers are available in 712 /// this object file. Then a subsequent call can be made to this 713 /// function with a value of \a versions and \a num_versions that 714 /// has enough storage to store some or all version numbers. 715 /// 716 /// @param[out] versions 717 /// A pointer to an array of uint32_t types that is \a num_versions 718 /// long. If this value is NULL, the return value will indicate 719 /// how many version numbers are required for a subsequent call 720 /// to this function so that all versions can be retrieved. If 721 /// the value is non-NULL, then at most \a num_versions of the 722 /// existing versions numbers will be filled into \a versions. 723 /// If there is no version information available, \a versions 724 /// will be filled with \a num_versions UINT32_MAX values 725 /// and zero will be returned. 726 /// 727 /// @param[in] num_versions 728 /// The maximum number of entries to fill into \a versions. If 729 /// this value is zero, then the return value will indicate 730 /// how many version numbers there are in total so another call 731 /// to this function can be make with adequate storage in 732 /// \a versions to get all of the version numbers. If \a 733 /// num_versions is less than the actual number of version 734 /// numbers in this object file, only \a num_versions will be 735 /// filled into \a versions (if \a versions is non-NULL). 736 /// 737 /// @return 738 /// This function always returns the number of version numbers 739 /// that this object file has regardless of the number of 740 /// version numbers that were copied into \a versions. 741 //------------------------------------------------------------------ 742 virtual uint32_t GetMinimumOSVersion(uint32_t * versions,uint32_t num_versions)743 GetMinimumOSVersion (uint32_t *versions, uint32_t num_versions) 744 { 745 if (versions && num_versions) 746 { 747 for (uint32_t i=0; i<num_versions; ++i) 748 versions[i] = UINT32_MAX; 749 } 750 return 0; 751 } 752 753 //------------------------------------------------------------------ 754 /// Get the SDK OS version this object file was built with. 755 /// 756 /// The versions arguments and returns values are the same as the 757 /// GetMinimumOSVersion() 758 //------------------------------------------------------------------ 759 virtual uint32_t GetSDKVersion(uint32_t * versions,uint32_t num_versions)760 GetSDKVersion (uint32_t *versions, uint32_t num_versions) 761 { 762 if (versions && num_versions) 763 { 764 for (uint32_t i=0; i<num_versions; ++i) 765 versions[i] = UINT32_MAX; 766 } 767 return 0; 768 } 769 770 771 //------------------------------------------------------------------ 772 /// Return true if this file is a dynamic link editor (dyld) 773 /// 774 /// Often times dyld has symbols that mirror symbols in libc and 775 /// other shared libraries (like "malloc" and "free") and the user 776 /// does _not_ want to stop in these shared libraries by default. 777 /// We can ask the ObjectFile if it is such a file and should be 778 /// avoided for things like settings breakpoints and doing function 779 /// lookups for expressions. 780 //------------------------------------------------------------------ 781 virtual bool GetIsDynamicLinkEditor()782 GetIsDynamicLinkEditor() 783 { 784 return false; 785 } 786 787 //------------------------------------------------------------------ 788 // Member Functions 789 //------------------------------------------------------------------ 790 Type GetType()791 GetType () 792 { 793 if (m_type == eTypeInvalid) 794 m_type = CalculateType(); 795 return m_type; 796 } 797 798 Strata GetStrata()799 GetStrata () 800 { 801 if (m_strata == eStrataInvalid) 802 m_strata = CalculateStrata(); 803 return m_strata; 804 } 805 806 // When an object file is in memory, subclasses should try and lock 807 // the process weak pointer. If the process weak pointer produces a 808 // valid ProcessSP, then subclasses can call this function to read 809 // memory. 810 static lldb::DataBufferSP 811 ReadMemory (const lldb::ProcessSP &process_sp, 812 lldb::addr_t addr, 813 size_t byte_size); 814 815 size_t 816 GetData (lldb::offset_t offset, size_t length, DataExtractor &data) const; 817 818 size_t 819 CopyData (lldb::offset_t offset, size_t length, void *dst) const; 820 821 virtual size_t 822 ReadSectionData (const Section *section, 823 lldb::offset_t section_offset, 824 void *dst, 825 size_t dst_len) const; 826 virtual size_t 827 ReadSectionData (const Section *section, 828 DataExtractor& section_data) const; 829 830 size_t 831 MemoryMapSectionData (const Section *section, 832 DataExtractor& section_data) const; 833 834 bool IsInMemory()835 IsInMemory () const 836 { 837 return m_memory_addr != LLDB_INVALID_ADDRESS; 838 } 839 840 // Strip linker annotations (such as @@VERSION) from symbol names. 841 virtual std::string StripLinkerSymbolAnnotations(llvm::StringRef symbol_name)842 StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const 843 { 844 return symbol_name.str(); 845 } 846 847 protected: 848 //------------------------------------------------------------------ 849 // Member variables. 850 //------------------------------------------------------------------ 851 FileSpec m_file; 852 Type m_type; 853 Strata m_strata; 854 lldb::addr_t m_file_offset; ///< The offset in bytes into the file, or the address in memory 855 lldb::addr_t m_length; ///< The length of this object file if it is known (can be zero if length is unknown or can't be determined). 856 DataExtractor m_data; ///< The data for this object file so things can be parsed lazily. 857 lldb_private::UnwindTable m_unwind_table; /// < Table of FuncUnwinders objects created for this ObjectFile's functions 858 lldb::ProcessWP m_process_wp; 859 const lldb::addr_t m_memory_addr; 860 std::unique_ptr<lldb_private::SectionList> m_sections_ap; 861 std::unique_ptr<lldb_private::Symtab> m_symtab_ap; 862 863 //------------------------------------------------------------------ 864 /// Sets the architecture for a module. At present the architecture 865 /// can only be set if it is invalid. It is not allowed to switch from 866 /// one concrete architecture to another. 867 /// 868 /// @param[in] new_arch 869 /// The architecture this module will be set to. 870 /// 871 /// @return 872 /// Returns \b true if the architecture was changed, \b 873 /// false otherwise. 874 //------------------------------------------------------------------ 875 bool SetModulesArchitecture (const ArchSpec &new_arch); 876 877 private: 878 DISALLOW_COPY_AND_ASSIGN (ObjectFile); 879 }; 880 881 } // namespace lldb_private 882 883 #endif // liblldb_ObjectFile_h_ 884 885