|
|
|||
File indexing completed on 2026-05-10 08:42:51
0001 //===-- ObjectFile.h --------------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLDB_SYMBOL_OBJECTFILE_H 0010 #define LLDB_SYMBOL_OBJECTFILE_H 0011 0012 #include "lldb/Core/ModuleChild.h" 0013 #include "lldb/Core/PluginInterface.h" 0014 #include "lldb/Symbol/Symtab.h" 0015 #include "lldb/Symbol/UnwindTable.h" 0016 #include "lldb/Utility/AddressableBits.h" 0017 #include "lldb/Utility/DataExtractor.h" 0018 #include "lldb/Utility/Endian.h" 0019 #include "lldb/Utility/FileSpec.h" 0020 #include "lldb/Utility/FileSpecList.h" 0021 #include "lldb/Utility/UUID.h" 0022 #include "lldb/lldb-private.h" 0023 #include "llvm/Support/Threading.h" 0024 #include "llvm/Support/VersionTuple.h" 0025 #include <optional> 0026 0027 namespace lldb_private { 0028 0029 /// \class ObjectFile ObjectFile.h "lldb/Symbol/ObjectFile.h" 0030 /// A plug-in interface definition class for object file parsers. 0031 /// 0032 /// Object files belong to Module objects and know how to extract information 0033 /// from executable, shared library, and object (.o) files used by operating 0034 /// system runtime. The symbol table and section list for an object file. 0035 /// 0036 /// Object files can be represented by the entire file, or by part of a file. 0037 /// An example of a partial file ObjectFile is one that contains information 0038 /// for one of multiple architectures in the same file. 0039 /// 0040 /// Once an architecture is selected the object file information can be 0041 /// extracted from this abstract class. 0042 class ObjectFile : public std::enable_shared_from_this<ObjectFile>, 0043 public PluginInterface, 0044 public ModuleChild { 0045 friend class lldb_private::Module; 0046 0047 public: 0048 enum Type { 0049 eTypeInvalid = 0, 0050 /// A core file that has a checkpoint of a program's execution state. 0051 eTypeCoreFile, 0052 /// A normal executable. 0053 eTypeExecutable, 0054 /// An object file that contains only debug information. 0055 eTypeDebugInfo, 0056 /// The platform's dynamic linker executable. 0057 eTypeDynamicLinker, 0058 /// An intermediate object file. 0059 eTypeObjectFile, 0060 /// A shared library that can be used during execution. 0061 eTypeSharedLibrary, 0062 /// A library that can be linked against but not used for execution. 0063 eTypeStubLibrary, 0064 /// JIT code that has symbols, sections and possibly debug info. 0065 eTypeJIT, 0066 eTypeUnknown 0067 }; 0068 0069 enum Strata { 0070 eStrataInvalid = 0, 0071 eStrataUnknown, 0072 eStrataUser, 0073 eStrataKernel, 0074 eStrataRawImage, 0075 eStrataJIT 0076 }; 0077 0078 /// If we have a corefile binary hint, this enum 0079 /// specifies the binary type which we can use to 0080 /// select the correct DynamicLoader plugin. 0081 enum BinaryType { 0082 eBinaryTypeInvalid = 0, 0083 eBinaryTypeUnknown, 0084 eBinaryTypeKernel, /// kernel binary 0085 eBinaryTypeUser, /// user process binary 0086 eBinaryTypeStandalone /// standalone binary / firmware 0087 }; 0088 0089 struct LoadableData { 0090 lldb::addr_t Dest; 0091 llvm::ArrayRef<uint8_t> Contents; 0092 }; 0093 0094 /// Construct with a parent module, offset, and header data. 0095 /// 0096 /// Object files belong to modules and a valid module must be supplied upon 0097 /// construction. The at an offset within a file for objects that contain 0098 /// more than one architecture or object. 0099 ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, 0100 lldb::offset_t file_offset, lldb::offset_t length, 0101 lldb::DataBufferSP data_sp, lldb::offset_t data_offset); 0102 0103 ObjectFile(const lldb::ModuleSP &module_sp, const lldb::ProcessSP &process_sp, 0104 lldb::addr_t header_addr, lldb::DataBufferSP data_sp); 0105 0106 /// Destructor. 0107 /// 0108 /// The destructor is virtual since this class is designed to be inherited 0109 /// from by the plug-in instance. 0110 ~ObjectFile() override; 0111 0112 /// Dump a description of this object to a Stream. 0113 /// 0114 /// Dump a description of the current contents of this object to the 0115 /// supplied stream \a s. The dumping should include the section list if it 0116 /// has been parsed, and the symbol table if it has been parsed. 0117 /// 0118 /// \param[in] s 0119 /// The stream to which to dump the object description. 0120 virtual void Dump(Stream *s) = 0; 0121 0122 /// Find a ObjectFile plug-in that can parse \a file_spec. 0123 /// 0124 /// Scans all loaded plug-in interfaces that implement versions of the 0125 /// ObjectFile plug-in interface and returns the first instance that can 0126 /// parse the file. 0127 /// 0128 /// \param[in] module_sp 0129 /// The parent module that owns this object file. 0130 /// 0131 /// \param[in] file_spec 0132 /// A file specification that indicates which file to use as the 0133 /// object file. 0134 /// 0135 /// \param[in] file_offset 0136 /// The offset into the file at which to start parsing the 0137 /// object. This is for files that contain multiple 0138 /// architectures or objects. 0139 /// 0140 /// \param[in] file_size 0141 /// The size of the current object file if it can be determined 0142 /// or if it is known. This can be zero. 0143 /// 0144 /// \see ObjectFile::ParseHeader() 0145 static lldb::ObjectFileSP 0146 FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, 0147 lldb::offset_t file_offset, lldb::offset_t file_size, 0148 lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset); 0149 0150 /// Find a ObjectFile plug-in that can parse a file in memory. 0151 /// 0152 /// Scans all loaded plug-in interfaces that implement versions of the 0153 /// ObjectFile plug-in interface and returns the first instance that can 0154 /// parse the file. 0155 /// 0156 /// \param[in] module_sp 0157 /// The parent module that owns this object file. 0158 /// 0159 /// \param[in] process_sp 0160 /// A shared pointer to the process whose memory space contains 0161 /// an object file. This will be stored as a std::weak_ptr. 0162 /// 0163 /// \param[in] header_addr 0164 /// The address of the header for the object file in memory. 0165 static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, 0166 const lldb::ProcessSP &process_sp, 0167 lldb::addr_t header_addr, 0168 lldb::WritableDataBufferSP file_data_sp); 0169 0170 static size_t 0171 GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, 0172 lldb::offset_t file_size, ModuleSpecList &specs, 0173 lldb::DataBufferSP data_sp = lldb::DataBufferSP()); 0174 0175 static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, 0176 lldb::DataBufferSP &data_sp, 0177 lldb::offset_t data_offset, 0178 lldb::offset_t file_offset, 0179 lldb::offset_t file_size, 0180 lldb_private::ModuleSpecList &specs); 0181 static bool IsObjectFile(lldb_private::FileSpec file_spec); 0182 /// Split a path into a file path with object name. 0183 /// 0184 /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path up into 0185 /// the actual path name and into the object name so we can make a valid 0186 /// object file from it. 0187 /// 0188 /// \param[in] path_with_object 0189 /// A path that might contain an archive path with a .o file 0190 /// specified in parens in the basename of the path. 0191 /// 0192 /// \param[out] archive_file 0193 /// If \b true is returned, \a file_spec will be filled in with 0194 /// the path to the archive. 0195 /// 0196 /// \param[out] archive_object 0197 /// If \b true is returned, \a object will be filled in with 0198 /// the name of the object inside the archive. 0199 /// 0200 /// \return 0201 /// \b true if the path matches the pattern of archive + object 0202 /// and \a archive_file and \a archive_object are modified, 0203 /// \b false otherwise and \a archive_file and \a archive_object 0204 /// are guaranteed to be remain unchanged. 0205 static bool SplitArchivePathWithObject( 0206 llvm::StringRef path_with_object, lldb_private::FileSpec &archive_file, 0207 lldb_private::ConstString &archive_object, bool must_exist); 0208 0209 // LLVM RTTI support 0210 static char ID; 0211 virtual bool isA(const void *ClassID) const { return ClassID == &ID; } 0212 0213 /// Gets the address size in bytes for the current object file. 0214 /// 0215 /// \return 0216 /// The size of an address in bytes for the currently selected 0217 /// architecture (and object for archives). Returns zero if no 0218 /// architecture or object has been selected. 0219 virtual uint32_t GetAddressByteSize() const = 0; 0220 0221 /// Get the address type given a file address in an object file. 0222 /// 0223 /// Many binary file formats know what kinds This is primarily for ARM 0224 /// binaries, though it can be applied to any executable file format that 0225 /// supports different opcode types within the same binary. ARM binaries 0226 /// support having both ARM and Thumb within the same executable container. 0227 /// We need to be able to get \return 0228 /// The size of an address in bytes for the currently selected 0229 /// architecture (and object for archives). Returns zero if no 0230 /// architecture or object has been selected. 0231 virtual AddressClass GetAddressClass(lldb::addr_t file_addr); 0232 0233 /// Extract the dependent modules from an object file. 0234 /// 0235 /// If an object file has information about which other images it depends on 0236 /// (such as shared libraries), this function will provide the list. Since 0237 /// many executables or shared libraries may depend on the same files, 0238 /// FileSpecList::AppendIfUnique(const FileSpec &) should be used to make 0239 /// sure any files that are added are not already in the list. 0240 /// 0241 /// \param[out] file_list 0242 /// A list of file specification objects that gets dependent 0243 /// files appended to. 0244 /// 0245 /// \return 0246 /// The number of new files that were appended to \a file_list. 0247 /// 0248 /// \see FileSpecList::AppendIfUnique(const FileSpec &) 0249 virtual uint32_t GetDependentModules(FileSpecList &file_list) = 0; 0250 0251 /// Tells whether this object file is capable of being the main executable 0252 /// for a process. 0253 /// 0254 /// \return 0255 /// \b true if it is, \b false otherwise. 0256 virtual bool IsExecutable() const = 0; 0257 0258 /// Returns the offset into a file at which this object resides. 0259 /// 0260 /// Some files contain many object files, and this function allows access to 0261 /// an object's offset within the file. 0262 /// 0263 /// \return 0264 /// The offset in bytes into the file. Defaults to zero for 0265 /// simple object files that a represented by an entire file. 0266 virtual lldb::addr_t GetFileOffset() const { return m_file_offset; } 0267 0268 virtual lldb::addr_t GetByteSize() const { return m_length; } 0269 0270 /// Get accessor to the object file specification. 0271 /// 0272 /// \return 0273 /// The file specification object pointer if there is one, or 0274 /// NULL if this object is only from memory. 0275 virtual FileSpec &GetFileSpec() { return m_file; } 0276 0277 /// Get const accessor to the object file specification. 0278 /// 0279 /// \return 0280 /// The const file specification object pointer if there is one, 0281 /// or NULL if this object is only from memory. 0282 virtual const FileSpec &GetFileSpec() const { return m_file; } 0283 0284 /// Get the ArchSpec for this object file. 0285 /// 0286 /// \return 0287 /// The ArchSpec of this object file. In case of error, an invalid 0288 /// ArchSpec object is returned. 0289 virtual ArchSpec GetArchitecture() = 0; 0290 0291 /// Gets the section list for the currently selected architecture (and 0292 /// object for archives). 0293 /// 0294 /// Section list parsing can be deferred by ObjectFile instances until this 0295 /// accessor is called the first time. 0296 /// 0297 /// \return 0298 /// The list of sections contained in this object file. 0299 virtual SectionList *GetSectionList(bool update_module_section_list = true); 0300 0301 virtual void CreateSections(SectionList &unified_section_list) = 0; 0302 0303 /// Notify the ObjectFile that the file addresses in the Sections for this 0304 /// module have been changed. 0305 virtual void SectionFileAddressesChanged() {} 0306 0307 /// Gets the symbol table for the currently selected architecture (and 0308 /// object for archives). 0309 /// 0310 /// This function will manage when ParseSymtab(...) is called to actually do 0311 /// the symbol table parsing in each plug-in. This function will take care of 0312 /// taking all the necessary locks and finalizing the symbol table when the 0313 /// symbol table does get parsed. 0314 /// 0315 /// \return 0316 /// The symbol table for this object file. 0317 Symtab *GetSymtab(); 0318 0319 /// Parse the symbol table into the provides symbol table object. 0320 /// 0321 /// Symbol table parsing will be done once when this function is called by 0322 /// each object file plugin. All of the necessary locks will already be 0323 /// acquired before this function is called and the symbol table object to 0324 /// populate is supplied as an argument and doesn't need to be created by 0325 /// each plug-in. 0326 /// 0327 /// \param 0328 /// The symbol table to populate. 0329 virtual void ParseSymtab(Symtab &symtab) = 0; 0330 0331 /// Perform relocations on the section if necessary. 0332 /// 0333 virtual void RelocateSection(lldb_private::Section *section); 0334 0335 /// Appends a Symbol for the specified so_addr to the symbol table. 0336 /// 0337 /// If verify_unique is false, the symbol table is not searched to determine 0338 /// if a Symbol found at this address has already been added to the symbol 0339 /// table. When verify_unique is true, this method resolves the Symbol as 0340 /// the first match in the SymbolTable and appends a Symbol only if 0341 /// required/found. 0342 /// 0343 /// \return 0344 /// The resolved symbol or nullptr. Returns nullptr if a 0345 /// a Symbol could not be found for the specified so_addr. 0346 virtual Symbol *ResolveSymbolForAddress(const Address &so_addr, 0347 bool verify_unique) { 0348 // Typically overridden to lazily add stripped symbols recoverable from the 0349 // exception handling unwind information (i.e. without parsing the entire 0350 // eh_frame section. 0351 // 0352 // The availability of LC_FUNCTION_STARTS allows ObjectFileMachO to 0353 // efficiently add stripped symbols when the symbol table is first 0354 // constructed. Poorer cousins are PECoff and ELF. 0355 return nullptr; 0356 } 0357 0358 /// Detect if this object file has been stripped of local symbols. 0359 /// Detect if this object file has been stripped of local symbols. 0360 /// 0361 /// \return 0362 /// Return \b true if the object file has been stripped of local 0363 /// symbols. 0364 virtual bool IsStripped() = 0; 0365 0366 /// Frees the symbol table. 0367 /// 0368 /// This function should only be used when an object file is 0369 virtual void ClearSymtab(); 0370 0371 /// Gets the UUID for this object file. 0372 /// 0373 /// If the object file format contains a UUID, the value should be returned. 0374 /// Else ObjectFile instances should return the MD5 checksum of all of the 0375 /// bytes for the object file (or memory for memory based object files). 0376 /// 0377 /// \return 0378 /// The object file's UUID. In case of an error, an empty UUID is 0379 /// returned. 0380 virtual UUID GetUUID() = 0; 0381 0382 /// Gets the file spec list of libraries re-exported by this object file. 0383 /// 0384 /// If the object file format has the notion of one library re-exporting the 0385 /// symbols from another, the re-exported libraries will be returned in the 0386 /// FileSpecList. 0387 /// 0388 /// \return 0389 /// Returns filespeclist. 0390 virtual lldb_private::FileSpecList GetReExportedLibraries() { 0391 return FileSpecList(); 0392 } 0393 0394 /// Sets the load address for an entire module, assuming a rigid slide of 0395 /// sections, if possible in the implementation. 0396 /// 0397 /// \return 0398 /// Returns true iff any section's load address changed. 0399 virtual bool SetLoadAddress(Target &target, lldb::addr_t value, 0400 bool value_is_offset) { 0401 return false; 0402 } 0403 0404 /// Gets whether endian swapping should occur when extracting data from this 0405 /// object file. 0406 /// 0407 /// \return 0408 /// Returns \b true if endian swapping is needed, \b false 0409 /// otherwise. 0410 virtual lldb::ByteOrder GetByteOrder() const = 0; 0411 0412 /// Attempts to parse the object header. 0413 /// 0414 /// This function is used as a test to see if a given plug-in instance can 0415 /// parse the header data already contained in ObjectFile::m_data. If an 0416 /// object file parser does not recognize that magic bytes in a header, 0417 /// false should be returned and the next plug-in can attempt to parse an 0418 /// object file. 0419 /// 0420 /// \return 0421 /// Returns \b true if the header was parsed successfully, \b 0422 /// false otherwise. 0423 virtual bool ParseHeader() = 0; 0424 0425 /// Returns if the function bounds for symbols in this symbol file are 0426 /// likely accurate. 0427 /// 0428 /// The unwinder can emulate the instructions of functions to understand 0429 /// prologue/epilogue code sequences, where registers are spilled on the 0430 /// stack, etc. This feature relies on having the correct start addresses 0431 /// of all functions. If the ObjectFile has a way to tell that symbols have 0432 /// been stripped and there's no way to reconstruct start addresses (e.g. 0433 /// LC_FUNCTION_STARTS on Mach-O, or eh_frame unwind info), the ObjectFile 0434 /// should indicate that assembly emulation should not be used for this 0435 /// module. 0436 /// 0437 /// It is uncommon for this to return false. An ObjectFile needs to be sure 0438 /// that symbol start addresses are unavailable before false is returned. 0439 /// If it is unclear, this should return true. 0440 /// 0441 /// \return 0442 /// Returns true if assembly emulation should be used for this 0443 /// module. 0444 /// Only returns false if the ObjectFile is sure that symbol 0445 /// addresses are insufficient for accurate assembly emulation. 0446 virtual bool AllowAssemblyEmulationUnwindPlans() { return true; } 0447 0448 /// Similar to Process::GetImageInfoAddress(). 0449 /// 0450 /// Some platforms embed auxiliary structures useful to debuggers in the 0451 /// address space of the inferior process. This method returns the address 0452 /// of such a structure if the information can be resolved via entries in 0453 /// the object file. ELF, for example, provides a means to hook into the 0454 /// runtime linker so that a debugger may monitor the loading and unloading 0455 /// of shared libraries. 0456 /// 0457 /// \return 0458 /// The address of any auxiliary tables, or an invalid address if this 0459 /// object file format does not support or contain such information. 0460 virtual lldb_private::Address GetImageInfoAddress(Target *target) { 0461 return Address(); 0462 } 0463 0464 /// Returns the address of the Entry Point in this object file - if the 0465 /// object file doesn't have an entry point (because it is not an executable 0466 /// file) then an invalid address is returned. 0467 /// 0468 /// \return 0469 /// Returns the entry address for this module. 0470 virtual lldb_private::Address GetEntryPointAddress() { return Address(); } 0471 0472 /// Returns base address of this object file. 0473 /// 0474 /// This also sometimes referred to as the "preferred load address" or the 0475 /// "image base address". Addresses within object files are often expressed 0476 /// relative to this base. If this address corresponds to a specific section 0477 /// (usually the first byte of the first section) then the returned address 0478 /// will have this section set. Otherwise, the address will just have the 0479 /// offset member filled in, indicating that this represents a file address. 0480 virtual lldb_private::Address GetBaseAddress() { 0481 return Address(m_memory_addr); 0482 } 0483 0484 virtual uint32_t GetNumThreadContexts() { return 0; } 0485 0486 /// Some object files may have an identifier string embedded in them, e.g. 0487 /// in a Mach-O core file using the LC_IDENT load command (which is 0488 /// obsolete, but can still be found in some old files) 0489 /// 0490 /// \return 0491 /// Returns the identifier string if one exists, else an empty 0492 /// string. 0493 virtual std::string GetIdentifierString () { 0494 return std::string(); 0495 } 0496 0497 /// Some object files may have the number of bits used for addressing 0498 /// embedded in them, e.g. a Mach-O core file using an LC_NOTE. These 0499 /// object files can return an AddressableBits object that can can be 0500 /// used to set the address masks in the Process. 0501 /// 0502 /// \return 0503 /// Returns an AddressableBits object which can be used to set 0504 /// the address masks in the Process. 0505 virtual lldb_private::AddressableBits GetAddressableBits() { return {}; } 0506 0507 /// When the ObjectFile is a core file, lldb needs to locate the "binary" in 0508 /// the core file. lldb can iterate over the pages looking for a valid 0509 /// binary, but some core files may have metadata describing where the main 0510 /// binary is exactly which removes ambiguity when there are multiple 0511 /// binaries present in the captured memory pages. 0512 /// 0513 /// \param[out] value 0514 /// The address or offset (slide) where the binary is loaded in memory. 0515 /// LLDB_INVALID_ADDRESS for unspecified. If an offset is given, 0516 /// this offset should be added to the binary's file address to get 0517 /// the load address. 0518 /// 0519 /// \param[out] value_is_offset 0520 /// Specifies if \b value is a load address, or an offset to calculate 0521 /// the load address. 0522 /// 0523 /// \param[out] uuid 0524 /// If the uuid of the binary is specified, this will be set. 0525 /// If no UUID is available, will be cleared. 0526 /// 0527 /// \param[out] type 0528 /// Return the type of the binary, which will dictate which 0529 /// DynamicLoader plugin should be used. 0530 /// 0531 /// \return 0532 /// Returns true if either address or uuid has been set. 0533 virtual bool GetCorefileMainBinaryInfo(lldb::addr_t &value, 0534 bool &value_is_offset, UUID &uuid, 0535 ObjectFile::BinaryType &type) { 0536 value = LLDB_INVALID_ADDRESS; 0537 value_is_offset = false; 0538 uuid.Clear(); 0539 return false; 0540 } 0541 0542 /// Get metadata about threads from the corefile. 0543 /// 0544 /// The corefile may have metadata (e.g. a Mach-O "thread extrainfo" 0545 /// LC_NOTE) which for the threads in the process; this method tries 0546 /// to retrieve them. 0547 /// 0548 /// \param[out] tids 0549 /// Filled in with a vector of tid_t's that matches the number 0550 /// of threads in the corefile (ObjectFile::GetNumThreadContexts). 0551 /// If a tid is not specified for one of the corefile threads, 0552 /// that entry in the vector will have LLDB_INVALID_THREAD_ID and 0553 /// the caller should assign a tid to the thread that does not 0554 /// conflict with the ones provided in this array. 0555 /// As additional metadata are added, this method may return a 0556 /// \a tids vector with no thread id's specified at all; the 0557 /// corefile may only specify one of the other metadata. 0558 /// 0559 /// \return 0560 /// Returns true if thread metadata was found in this corefile. 0561 /// 0562 virtual bool GetCorefileThreadExtraInfos(std::vector<lldb::tid_t> &tids) { 0563 return false; 0564 } 0565 0566 virtual lldb::RegisterContextSP 0567 GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) { 0568 return lldb::RegisterContextSP(); 0569 } 0570 0571 /// The object file should be able to calculate its type by looking at its 0572 /// file header and possibly the sections or other data in the object file. 0573 /// The file type is used in the debugger to help select the correct plug- 0574 /// ins for the job at hand, so this is important to get right. If any 0575 /// eTypeXXX definitions do not match up with the type of file you are 0576 /// loading, please feel free to add a new enumeration value. 0577 /// 0578 /// \return 0579 /// The calculated file type for the current object file. 0580 virtual Type CalculateType() = 0; 0581 0582 /// In cases where the type can't be calculated (elf files), this routine 0583 /// allows someone to explicitly set it. As an example, SymbolVendorELF uses 0584 /// this routine to set eTypeDebugInfo when loading debug link files. 0585 virtual void SetType(Type type) { m_type = type; } 0586 0587 /// The object file should be able to calculate the strata of the object 0588 /// file. 0589 /// 0590 /// Many object files for platforms might be for either user space debugging 0591 /// or for kernel debugging. If your object file subclass can figure this 0592 /// out, it will help with debugger plug-in selection when it comes time to 0593 /// debug. 0594 /// 0595 /// \return 0596 /// The calculated object file strata for the current object 0597 /// file. 0598 virtual Strata CalculateStrata() = 0; 0599 0600 /// Get the object file version numbers. 0601 /// 0602 /// Many object files have a set of version numbers that describe the 0603 /// version of the executable or shared library. Typically there are major, 0604 /// minor and build, but there may be more. This function will extract the 0605 /// versions from object files if they are available. 0606 /// 0607 /// \return 0608 /// This function returns extracted version numbers as a 0609 /// llvm::VersionTuple. In case of error an empty VersionTuple is 0610 /// returned. 0611 virtual llvm::VersionTuple GetVersion() { return llvm::VersionTuple(); } 0612 0613 /// Get the minimum OS version this object file can run on. 0614 /// 0615 /// Some object files have information that specifies the minimum OS version 0616 /// that they can be used on. 0617 /// 0618 /// \return 0619 /// This function returns extracted version numbers as a 0620 /// llvm::VersionTuple. In case of error an empty VersionTuple is 0621 /// returned. 0622 virtual llvm::VersionTuple GetMinimumOSVersion() { 0623 return llvm::VersionTuple(); 0624 } 0625 0626 /// Get the SDK OS version this object file was built with. 0627 /// 0628 /// \return 0629 /// This function returns extracted version numbers as a 0630 /// llvm::VersionTuple. In case of error an empty VersionTuple is 0631 /// returned. 0632 virtual llvm::VersionTuple GetSDKVersion() { return llvm::VersionTuple(); } 0633 0634 /// Return true if this file is a dynamic link editor (dyld) 0635 /// 0636 /// Often times dyld has symbols that mirror symbols in libc and other 0637 /// shared libraries (like "malloc" and "free") and the user does _not_ want 0638 /// to stop in these shared libraries by default. We can ask the ObjectFile 0639 /// if it is such a file and should be avoided for things like settings 0640 /// breakpoints and doing function lookups for expressions. 0641 virtual bool GetIsDynamicLinkEditor() { return false; } 0642 0643 // Member Functions 0644 Type GetType() { 0645 if (m_type == eTypeInvalid) 0646 m_type = CalculateType(); 0647 return m_type; 0648 } 0649 0650 Strata GetStrata() { 0651 if (m_strata == eStrataInvalid) 0652 m_strata = CalculateStrata(); 0653 return m_strata; 0654 } 0655 0656 // When an object file is in memory, subclasses should try and lock the 0657 // process weak pointer. If the process weak pointer produces a valid 0658 // ProcessSP, then subclasses can call this function to read memory. 0659 static lldb::WritableDataBufferSP 0660 ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, 0661 size_t byte_size); 0662 0663 // This function returns raw file contents. Do not use it if you want 0664 // transparent decompression of section contents. 0665 size_t GetData(lldb::offset_t offset, size_t length, 0666 DataExtractor &data) const; 0667 0668 // This function returns raw file contents. Do not use it if you want 0669 // transparent decompression of section contents. 0670 size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const; 0671 0672 // This function will transparently decompress section data if the section if 0673 // compressed. 0674 virtual size_t ReadSectionData(Section *section, 0675 lldb::offset_t section_offset, void *dst, 0676 size_t dst_len); 0677 0678 // This function will transparently decompress section data if the section if 0679 // compressed. Note that for compressed section the resulting data size may 0680 // be larger than what Section::GetFileSize reports. 0681 virtual size_t ReadSectionData(Section *section, 0682 DataExtractor §ion_data); 0683 0684 // Returns the section data size. This is special-cased for PECOFF 0685 // due to file alignment. 0686 virtual size_t GetSectionDataSize(Section *section) { 0687 return section->GetFileSize(); 0688 } 0689 0690 /// Returns true if the object file exists only in memory. 0691 bool IsInMemory() const { return m_memory_addr != LLDB_INVALID_ADDRESS; } 0692 0693 // Strip linker annotations (such as @@VERSION) from symbol names. 0694 virtual llvm::StringRef 0695 StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const { 0696 return symbol_name; 0697 } 0698 0699 /// Can we trust the address ranges accelerator associated with this object 0700 /// file to be complete. 0701 virtual bool CanTrustAddressRanges() { return false; } 0702 0703 static lldb::SymbolType GetSymbolTypeFromName( 0704 llvm::StringRef name, 0705 lldb::SymbolType symbol_type_hint = lldb::eSymbolTypeUndefined); 0706 0707 /// Loads this objfile to memory. 0708 /// 0709 /// Loads the bits needed to create an executable image to the memory. It is 0710 /// useful with bare-metal targets where target does not have the ability to 0711 /// start a process itself. 0712 /// 0713 /// \param[in] target 0714 /// Target where to load. 0715 virtual std::vector<LoadableData> GetLoadableData(Target &target); 0716 0717 /// Creates a plugin-specific call frame info 0718 virtual std::unique_ptr<CallFrameInfo> CreateCallFrameInfo(); 0719 0720 /// Load binaries listed in a corefile 0721 /// 0722 /// A corefile may have metadata listing binaries that can be loaded, 0723 /// and the offsets at which they were loaded. This method will try 0724 /// to add them to the Target. If any binaries were loaded, 0725 /// 0726 /// \param[in] process 0727 /// Process where to load binaries. 0728 /// 0729 /// \return 0730 /// Returns true if any binaries were loaded. 0731 0732 virtual bool LoadCoreFileImages(lldb_private::Process &process) { 0733 return false; 0734 } 0735 0736 /// Get a hash that can be used for caching object file releated information. 0737 /// 0738 /// Data for object files can be cached between runs of debug sessions and 0739 /// a module can end up using a main file and a symbol file, both of which 0740 /// can be object files. So we need a unique hash that identifies an object 0741 /// file when storing cached data. 0742 uint32_t GetCacheHash(); 0743 0744 static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, 0745 uint64_t Offset); 0746 0747 protected: 0748 // Member variables. 0749 FileSpec m_file; 0750 Type m_type; 0751 Strata m_strata; 0752 lldb::addr_t m_file_offset; ///< The offset in bytes into the file, or the 0753 ///address in memory 0754 lldb::addr_t m_length; ///< The length of this object file if it is known (can 0755 ///be zero if length is unknown or can't be 0756 ///determined). 0757 DataExtractor 0758 m_data; ///< The data for this object file so things can be parsed lazily. 0759 lldb::ProcessWP m_process_wp; 0760 /// Set if the object file only exists in memory. 0761 const lldb::addr_t m_memory_addr; 0762 std::unique_ptr<lldb_private::SectionList> m_sections_up; 0763 std::unique_ptr<lldb_private::Symtab> m_symtab_up; 0764 /// We need a llvm::once_flag that we can use to avoid locking the module 0765 /// lock and deadlocking LLDB. See comments in ObjectFile::GetSymtab() for 0766 /// the full details. We also need to be able to clear the symbol table, so we 0767 /// need to use a std::unique_ptr to a llvm::once_flag so if we clear the 0768 /// symbol table, we can have a new once flag to use when it is created again. 0769 std::unique_ptr<llvm::once_flag> m_symtab_once_up; 0770 std::optional<uint32_t> m_cache_hash; 0771 0772 /// Sets the architecture for a module. At present the architecture can 0773 /// only be set if it is invalid. It is not allowed to switch from one 0774 /// concrete architecture to another. 0775 /// 0776 /// \param[in] new_arch 0777 /// The architecture this module will be set to. 0778 /// 0779 /// \return 0780 /// Returns \b true if the architecture was changed, \b 0781 /// false otherwise. 0782 bool SetModulesArchitecture(const ArchSpec &new_arch); 0783 0784 /// The number of bytes to read when going through the plugins. 0785 static size_t g_initial_bytes_to_read; 0786 0787 private: 0788 ObjectFile(const ObjectFile &) = delete; 0789 const ObjectFile &operator=(const ObjectFile &) = delete; 0790 }; 0791 0792 } // namespace lldb_private 0793 0794 namespace llvm { 0795 template <> struct format_provider<lldb_private::ObjectFile::Type> { 0796 static void format(const lldb_private::ObjectFile::Type &type, 0797 raw_ostream &OS, StringRef Style); 0798 }; 0799 0800 template <> struct format_provider<lldb_private::ObjectFile::Strata> { 0801 static void format(const lldb_private::ObjectFile::Strata &strata, 0802 raw_ostream &OS, StringRef Style); 0803 }; 0804 0805 namespace json { 0806 bool fromJSON(const llvm::json::Value &value, lldb_private::ObjectFile::Type &, 0807 llvm::json::Path path); 0808 } // namespace json 0809 } // namespace llvm 0810 0811 #endif // LLDB_SYMBOL_OBJECTFILE_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|