1 //===-- ObjectFile.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ObjectFile_h_
11 #define liblldb_ObjectFile_h_
13 #include "lldb/Core/FileSpecList.h"
14 #include "lldb/Core/ModuleChild.h"
15 #include "lldb/Core/PluginInterface.h"
16 #include "lldb/Symbol/Symtab.h"
17 #include "lldb/Symbol/UnwindTable.h"
18 #include "lldb/Utility/DataExtractor.h"
19 #include "lldb/Utility/Endian.h"
20 #include "lldb/Utility/FileSpec.h"
21 #include "lldb/Utility/UUID.h"
22 #include "lldb/lldb-private.h"
24 namespace lldb_private {
26 class ObjectFileJITDelegate {
28 ObjectFileJITDelegate() {}
30 virtual ~ObjectFileJITDelegate() {}
32 virtual lldb::ByteOrder GetByteOrder() const = 0;
34 virtual uint32_t GetAddressByteSize() const = 0;
36 virtual void PopulateSymtab(lldb_private::ObjectFile *obj_file,
37 lldb_private::Symtab &symtab) = 0;
39 virtual void PopulateSectionList(lldb_private::ObjectFile *obj_file,
40 lldb_private::SectionList §ion_list) = 0;
42 virtual bool GetArchitecture(lldb_private::ArchSpec &arch) = 0;
45 //----------------------------------------------------------------------
46 /// @class ObjectFile ObjectFile.h "lldb/Symbol/ObjectFile.h"
47 /// @brief A plug-in interface definition class for object file parsers.
49 /// Object files belong to Module objects and know how to extract
50 /// information from executable, shared library, and object (.o) files
51 /// used by operating system runtime. The symbol table and section list
52 /// for an object file.
54 /// Object files can be represented by the entire file, or by part of a
55 /// file. An example of a partial file ObjectFile is one that contains
56 /// information for one of multiple architectures in the same file.
58 /// Once an architecture is selected the object file information can be
59 /// extracted from this abstract class.
60 //----------------------------------------------------------------------
61 class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
62 public PluginInterface,
64 friend class lldb_private::Module;
69 eTypeCoreFile, /// A core file that has a checkpoint of a program's
71 eTypeExecutable, /// A normal executable
72 eTypeDebugInfo, /// An object file that contains only debug information
73 eTypeDynamicLinker, /// The platform's dynamic linker executable
74 eTypeObjectFile, /// An intermediate object file
75 eTypeSharedLibrary, /// A shared library that can be used during execution
76 eTypeStubLibrary, /// A library that can be linked against but not used for
78 eTypeJIT, /// JIT code that has symbols, sections and possibly debug info
91 //------------------------------------------------------------------
92 /// Construct with a parent module, offset, and header data.
94 /// Object files belong to modules and a valid module must be
95 /// supplied upon construction. The at an offset within a file for
96 /// objects that contain more than one architecture or object.
97 //------------------------------------------------------------------
98 ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr,
99 lldb::offset_t file_offset, lldb::offset_t length,
100 const lldb::DataBufferSP &data_sp, lldb::offset_t data_offset);
102 ObjectFile(const lldb::ModuleSP &module_sp, const lldb::ProcessSP &process_sp,
103 lldb::addr_t header_addr, lldb::DataBufferSP &data_sp);
105 //------------------------------------------------------------------
108 /// The destructor is virtual since this class is designed to be
109 /// inherited from by the plug-in instance.
110 //------------------------------------------------------------------
111 ~ObjectFile() override;
113 //------------------------------------------------------------------
114 /// Dump a description of this object to a Stream.
116 /// Dump a description of the current contents of this object
117 /// to the supplied stream \a s. The dumping should include the
118 /// section list if it has been parsed, and the symbol table
119 /// if it has been parsed.
122 /// The stream to which to dump the object description.
123 //------------------------------------------------------------------
124 virtual void Dump(Stream *s) = 0;
126 //------------------------------------------------------------------
127 /// Find a ObjectFile plug-in that can parse \a file_spec.
129 /// Scans all loaded plug-in interfaces that implement versions of
130 /// the ObjectFile plug-in interface and returns the first
131 /// instance that can parse the file.
133 /// @param[in] module
134 /// The parent module that owns this object file.
136 /// @param[in] file_spec
137 /// A file specification that indicates which file to use as the
140 /// @param[in] file_offset
141 /// The offset into the file at which to start parsing the
142 /// object. This is for files that contain multiple
143 /// architectures or objects.
145 /// @param[in] file_size
146 /// The size of the current object file if it can be determined
147 /// or if it is known. This can be zero.
149 /// @see ObjectFile::ParseHeader()
150 //------------------------------------------------------------------
151 static lldb::ObjectFileSP
152 FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec,
153 lldb::offset_t file_offset, lldb::offset_t file_size,
154 lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset);
156 //------------------------------------------------------------------
157 /// Find a ObjectFile plug-in that can parse a file in memory.
159 /// Scans all loaded plug-in interfaces that implement versions of
160 /// the ObjectFile plug-in interface and returns the first
161 /// instance that can parse the file.
163 /// @param[in] module
164 /// The parent module that owns this object file.
166 /// @param[in] process_sp
167 /// A shared pointer to the process whose memory space contains
168 /// an object file. This will be stored as a std::weak_ptr.
170 /// @param[in] header_addr
171 /// The address of the header for the object file in memory.
172 //------------------------------------------------------------------
173 static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp,
174 const lldb::ProcessSP &process_sp,
175 lldb::addr_t header_addr,
176 lldb::DataBufferSP &file_data_sp);
178 static size_t GetModuleSpecifications(const FileSpec &file,
179 lldb::offset_t file_offset,
180 lldb::offset_t file_size,
181 ModuleSpecList &specs);
183 static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
184 lldb::DataBufferSP &data_sp,
185 lldb::offset_t data_offset,
186 lldb::offset_t file_offset,
187 lldb::offset_t file_size,
188 lldb_private::ModuleSpecList &specs);
189 //------------------------------------------------------------------
190 /// Split a path into a file path with object name.
192 /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path
193 /// up into the actual path name and into the object name so we can
194 /// make a valid object file from it.
196 /// @param[in] path_with_object
197 /// A path that might contain an archive path with a .o file
198 /// specified in parens in the basename of the path.
200 /// @param[out] archive_file
201 /// If \b true is returned, \a file_spec will be filled in with
202 /// the path to the archive.
204 /// @param[out] archive_object
205 /// If \b true is returned, \a object will be filled in with
206 /// the name of the object inside the archive.
209 /// \b true if the path matches the pattern of archive + object
210 /// and \a archive_file and \a archive_object are modified,
211 /// \b false otherwise and \a archive_file and \a archive_object
212 /// are guaranteed to be remain unchanged.
213 //------------------------------------------------------------------
214 static bool SplitArchivePathWithObject(
215 const char *path_with_object, lldb_private::FileSpec &archive_file,
216 lldb_private::ConstString &archive_object, bool must_exist);
218 //------------------------------------------------------------------
219 /// Gets the address size in bytes for the current object file.
222 /// The size of an address in bytes for the currently selected
223 /// architecture (and object for archives). Returns zero if no
224 /// architecture or object has been selected.
225 //------------------------------------------------------------------
226 virtual uint32_t GetAddressByteSize() const = 0;
228 //------------------------------------------------------------------
229 /// Get the address type given a file address in an object file.
231 /// Many binary file formats know what kinds
232 /// This is primarily for ARM binaries, though it can be applied to
233 /// any executable file format that supports different opcode types
234 /// within the same binary. ARM binaries support having both ARM and
235 /// Thumb within the same executable container. We need to be able
238 /// The size of an address in bytes for the currently selected
239 /// architecture (and object for archives). Returns zero if no
240 /// architecture or object has been selected.
241 //------------------------------------------------------------------
242 virtual lldb::AddressClass GetAddressClass(lldb::addr_t file_addr);
244 //------------------------------------------------------------------
245 /// Extract the dependent modules from an object file.
247 /// If an object file has information about which other images it
248 /// depends on (such as shared libraries), this function will
249 /// provide the list. Since many executables or shared libraries
250 /// may depend on the same files,
251 /// FileSpecList::AppendIfUnique(const FileSpec &) should be
252 /// used to make sure any files that are added are not already in
255 /// @param[out] file_list
256 /// A list of file specification objects that gets dependent
257 /// files appended to.
260 /// The number of new files that were appended to \a file_list.
262 /// @see FileSpecList::AppendIfUnique(const FileSpec &)
263 //------------------------------------------------------------------
264 virtual uint32_t GetDependentModules(FileSpecList &file_list) = 0;
266 //------------------------------------------------------------------
267 /// Tells whether this object file is capable of being the main executable
271 /// \b true if it is, \b false otherwise.
272 //------------------------------------------------------------------
273 virtual bool IsExecutable() const = 0;
275 //------------------------------------------------------------------
276 /// Returns the offset into a file at which this object resides.
278 /// Some files contain many object files, and this function allows
279 /// access to an object's offset within the file.
282 /// The offset in bytes into the file. Defaults to zero for
283 /// simple object files that a represented by an entire file.
284 //------------------------------------------------------------------
285 virtual lldb::addr_t GetFileOffset() const { return m_file_offset; }
287 virtual lldb::addr_t GetByteSize() const { return m_length; }
289 //------------------------------------------------------------------
290 /// Get accessor to the object file specification.
293 /// The file specification object pointer if there is one, or
294 /// NULL if this object is only from memory.
295 //------------------------------------------------------------------
296 virtual FileSpec &GetFileSpec() { return m_file; }
298 //------------------------------------------------------------------
299 /// Get const accessor to the object file specification.
302 /// The const file specification object pointer if there is one,
303 /// or NULL if this object is only from memory.
304 //------------------------------------------------------------------
305 virtual const FileSpec &GetFileSpec() const { return m_file; }
307 //------------------------------------------------------------------
308 /// Get the name of the cpu, vendor and OS for this object file.
310 /// This value is a string that represents the target triple where
311 /// the cpu type, the vendor and the OS are encoded into a string.
313 /// @param[out] target_triple
314 /// The string value of the target triple.
317 /// \b True if the target triple was able to be computed, \b
319 //------------------------------------------------------------------
320 virtual bool GetArchitecture(ArchSpec &arch) = 0;
322 //------------------------------------------------------------------
323 /// Gets the section list for the currently selected architecture
324 /// (and object for archives).
326 /// Section list parsing can be deferred by ObjectFile instances
327 /// until this accessor is called the first time.
330 /// The list of sections contained in this object file.
331 //------------------------------------------------------------------
332 virtual SectionList *GetSectionList(bool update_module_section_list = true);
334 virtual void CreateSections(SectionList &unified_section_list) = 0;
336 //------------------------------------------------------------------
337 /// Notify the ObjectFile that the file addresses in the Sections
338 /// for this module have been changed.
339 //------------------------------------------------------------------
340 virtual void SectionFileAddressesChanged() {}
342 //------------------------------------------------------------------
343 /// Gets the symbol table for the currently selected architecture
344 /// (and object for archives).
346 /// Symbol table parsing can be deferred by ObjectFile instances
347 /// until this accessor is called the first time.
350 /// The symbol table for this object file.
351 //------------------------------------------------------------------
352 virtual Symtab *GetSymtab() = 0;
354 //------------------------------------------------------------------
355 /// Perform relocations on the section if necessary.
357 //------------------------------------------------------------------
358 virtual void RelocateSection(lldb_private::Section *section);
360 //------------------------------------------------------------------
361 /// Appends a Symbol for the specified so_addr to the symbol table.
363 /// If verify_unique is false, the symbol table is not searched
364 /// to determine if a Symbol found at this address has already been
365 /// added to the symbol table. When verify_unique is true, this
366 /// method resolves the Symbol as the first match in the SymbolTable
367 /// and appends a Symbol only if required/found.
370 /// The resolved symbol or nullptr. Returns nullptr if a
371 /// a Symbol could not be found for the specified so_addr.
372 //------------------------------------------------------------------
373 virtual Symbol *ResolveSymbolForAddress(const Address &so_addr,
374 bool verify_unique) {
375 // Typically overridden to lazily add stripped symbols recoverable from
376 // the exception handling unwind information (i.e. without parsing
377 // the entire eh_frame section.
379 // The availability of LC_FUNCTION_STARTS allows ObjectFileMachO
380 // to efficiently add stripped symbols when the symbol table is
381 // first constructed. Poorer cousins are PECoff and ELF.
385 //------------------------------------------------------------------
386 /// Detect if this object file has been stripped of local symbols.
387 //------------------------------------------------------------------
388 /// Detect if this object file has been stripped of local symbols.
391 /// Return \b true if the object file has been stripped of local
393 //------------------------------------------------------------------
394 virtual bool IsStripped() = 0;
396 //------------------------------------------------------------------
397 /// Frees the symbol table.
399 /// This function should only be used when an object file is
402 /// eSymtabFromUnifiedSectionList: Whether to clear symbol table
403 /// for unified module section list, or object file.
406 /// The symbol table for this object file.
407 //------------------------------------------------------------------
408 virtual void ClearSymtab();
410 //------------------------------------------------------------------
411 /// Gets the UUID for this object file.
413 /// If the object file format contains a UUID, the value should be
414 /// returned. Else ObjectFile instances should return the MD5
415 /// checksum of all of the bytes for the object file (or memory for
416 /// memory based object files).
419 /// Returns \b true if a UUID was successfully extracted into
420 /// \a uuid, \b false otherwise.
421 //------------------------------------------------------------------
422 virtual bool GetUUID(lldb_private::UUID *uuid) = 0;
424 //------------------------------------------------------------------
425 /// Gets the symbol file spec list for this object file.
427 /// If the object file format contains a debug symbol file link,
428 /// the values will be returned in the FileSpecList.
431 /// Returns filespeclist.
432 //------------------------------------------------------------------
433 virtual lldb_private::FileSpecList GetDebugSymbolFilePaths() {
434 return FileSpecList();
437 //------------------------------------------------------------------
438 /// Gets the file spec list of libraries re-exported by this object file.
440 /// If the object file format has the notion of one library re-exporting the
441 /// symbols from another,
442 /// the re-exported libraries will be returned in the FileSpecList.
445 /// Returns filespeclist.
446 //------------------------------------------------------------------
447 virtual lldb_private::FileSpecList GetReExportedLibraries() {
448 return FileSpecList();
451 //------------------------------------------------------------------
452 /// Sets the load address for an entire module, assuming a rigid
453 /// slide of sections, if possible in the implementation.
456 /// Returns true iff any section's load address changed.
457 //------------------------------------------------------------------
458 virtual bool SetLoadAddress(Target &target, lldb::addr_t value,
459 bool value_is_offset) {
463 //------------------------------------------------------------------
464 /// Gets whether endian swapping should occur when extracting data
465 /// from this object file.
468 /// Returns \b true if endian swapping is needed, \b false
470 //------------------------------------------------------------------
471 virtual lldb::ByteOrder GetByteOrder() const = 0;
473 //------------------------------------------------------------------
474 /// Attempts to parse the object header.
476 /// This function is used as a test to see if a given plug-in
477 /// instance can parse the header data already contained in
478 /// ObjectFile::m_data. If an object file parser does not
479 /// recognize that magic bytes in a header, false should be returned
480 /// and the next plug-in can attempt to parse an object file.
483 /// Returns \b true if the header was parsed successfully, \b
485 //------------------------------------------------------------------
486 virtual bool ParseHeader() = 0;
488 //------------------------------------------------------------------
489 /// Returns a reference to the UnwindTable for this ObjectFile
491 /// The UnwindTable contains FuncUnwinders objects for any function in
492 /// this ObjectFile. If a FuncUnwinders object hasn't been created yet
493 /// (i.e. the function has yet to be unwound in a stack walk), it
494 /// will be created when requested. Specifically, we do not create
495 /// FuncUnwinders objects for functions until they are needed.
498 /// Returns the unwind table for this object file.
499 //------------------------------------------------------------------
500 virtual lldb_private::UnwindTable &GetUnwindTable() { return m_unwind_table; }
502 //------------------------------------------------------------------
503 /// Returns if the function bounds for symbols in this symbol file
504 /// are likely accurate.
506 /// The unwinder can emulate the instructions of functions to understand
507 /// prologue/epilogue code sequences, where registers are spilled on
508 /// the stack, etc. This feature relies on having the correct start
509 /// addresses of all functions. If the ObjectFile has a way to tell
510 /// that symbols have been stripped and there's no way to reconstruct
511 /// start addresses (e.g. LC_FUNCTION_STARTS on Mach-O, or eh_frame
512 /// unwind info), the ObjectFile should indicate that assembly emulation
513 /// should not be used for this module.
515 /// It is uncommon for this to return false. An ObjectFile needs to
516 /// be sure that symbol start addresses are unavailable before false
517 /// is returned. If it is unclear, this should return true.
520 /// Returns true if assembly emulation should be used for this
522 /// Only returns false if the ObjectFile is sure that symbol
523 /// addresses are insufficient for accurate assembly emulation.
524 //------------------------------------------------------------------
525 virtual bool AllowAssemblyEmulationUnwindPlans() { return true; }
527 //------------------------------------------------------------------
528 /// Similar to Process::GetImageInfoAddress().
530 /// Some platforms embed auxiliary structures useful to debuggers in the
531 /// address space of the inferior process. This method returns the address
532 /// of such a structure if the information can be resolved via entries in
533 /// the object file. ELF, for example, provides a means to hook into the
534 /// runtime linker so that a debugger may monitor the loading and unloading
535 /// of shared libraries.
538 /// The address of any auxiliary tables, or an invalid address if this
539 /// object file format does not support or contain such information.
540 virtual lldb_private::Address GetImageInfoAddress(Target *target) {
544 //------------------------------------------------------------------
545 /// Returns the address of the Entry Point in this object file - if
546 /// the object file doesn't have an entry point (because it is not an
547 /// executable file) then an invalid address is returned.
550 /// Returns the entry address for this module.
551 //------------------------------------------------------------------
552 virtual lldb_private::Address GetEntryPointAddress() { return Address(); }
554 //------------------------------------------------------------------
555 /// Returns the address that represents the header of this object
558 /// The header address is defined as where the header for the object
559 /// file is that describes the content of the file. If the header
560 /// doesn't appear in a section that is defined in the object file,
561 /// an address with no section is returned that has the file offset
562 /// set in the m_file_offset member of the lldb_private::Address object.
565 /// Returns the entry address for this module.
566 //------------------------------------------------------------------
567 virtual lldb_private::Address GetHeaderAddress() {
568 return Address(m_memory_addr);
571 virtual uint32_t GetNumThreadContexts() { return 0; }
573 //------------------------------------------------------------------
574 /// Some object files may have an identifier string embedded in them,
575 /// e.g. in a Mach-O core file using the LC_IDENT load command (which
576 /// is obsolete, but can still be found in some old files)
579 /// Returns the identifier string if one exists, else an empty
581 //------------------------------------------------------------------
582 virtual std::string GetIdentifierString () {
583 return std::string();
586 //------------------------------------------------------------------
587 /// When the ObjectFile is a core file, lldb needs to locate the
588 /// "binary" in the core file. lldb can iterate over the pages looking
589 /// for a valid binary, but some core files may have metadata
590 /// describing where the main binary is exactly which removes ambiguity
591 /// when there are multiple binaries present in the captured memory pages.
593 /// @param[out] address
594 /// If the address of the binary is specified, this will be set.
595 /// This is an address is the virtual address space of the core file
596 /// memory segments; it is not an offset into the object file.
597 /// If no address is available, will be set to LLDB_INVALID_ADDRESS.
600 /// If the uuid of the binary is specified, this will be set.
601 /// If no UUID is available, will be cleared.
604 /// Returns true if either address or uuid has been set.
605 //------------------------------------------------------------------
606 virtual bool GetCorefileMainBinaryInfo (lldb::addr_t &address, UUID &uuid) {
607 address = LLDB_INVALID_ADDRESS;
612 virtual lldb::RegisterContextSP
613 GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) {
614 return lldb::RegisterContextSP();
617 //------------------------------------------------------------------
618 /// The object file should be able to calculate its type by looking
619 /// at its file header and possibly the sections or other data in
620 /// the object file. The file type is used in the debugger to help
621 /// select the correct plug-ins for the job at hand, so this is
622 /// important to get right. If any eTypeXXX definitions do not match
623 /// up with the type of file you are loading, please feel free to
624 /// add a new enumeration value.
627 /// The calculated file type for the current object file.
628 //------------------------------------------------------------------
629 virtual Type CalculateType() = 0;
631 //------------------------------------------------------------------
632 /// In cases where the type can't be calculated (elf files), this
633 /// routine allows someone to explicitly set it. As an example,
634 /// SymbolVendorELF uses this routine to set eTypeDebugInfo when
635 /// loading debug link files.
636 virtual void SetType(Type type) { m_type = type; }
638 //------------------------------------------------------------------
639 /// The object file should be able to calculate the strata of the
642 /// Many object files for platforms might be for either user space
643 /// debugging or for kernel debugging. If your object file subclass
644 /// can figure this out, it will help with debugger plug-in selection
645 /// when it comes time to debug.
648 /// The calculated object file strata for the current object
650 //------------------------------------------------------------------
651 virtual Strata CalculateStrata() = 0;
653 //------------------------------------------------------------------
654 /// Get the object file version numbers.
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.
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.
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.
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).
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 if (versions && num_versions) {
695 for (uint32_t i = 0; i < num_versions; ++i)
696 versions[i] = UINT32_MAX;
701 //------------------------------------------------------------------
702 /// Get the minimum OS version this object file can run on.
704 /// Some object files have information that specifies the minimum OS
705 /// version that they can be used on.
707 /// If \a versions is NULL, or if \a num_versions is 0, the return
708 /// value will indicate how many version numbers are available in
709 /// this object file. Then a subsequent call can be made to this
710 /// function with a value of \a versions and \a num_versions that
711 /// has enough storage to store some or all version numbers.
713 /// @param[out] versions
714 /// A pointer to an array of uint32_t types that is \a num_versions
715 /// long. If this value is NULL, the return value will indicate
716 /// how many version numbers are required for a subsequent call
717 /// to this function so that all versions can be retrieved. If
718 /// the value is non-NULL, then at most \a num_versions of the
719 /// existing versions numbers will be filled into \a versions.
720 /// If there is no version information available, \a versions
721 /// will be filled with \a num_versions UINT32_MAX values
722 /// and zero will be returned.
724 /// @param[in] num_versions
725 /// The maximum number of entries to fill into \a versions. If
726 /// this value is zero, then the return value will indicate
727 /// how many version numbers there are in total so another call
728 /// to this function can be make with adequate storage in
729 /// \a versions to get all of the version numbers. If \a
730 /// num_versions is less than the actual number of version
731 /// numbers in this object file, only \a num_versions will be
732 /// filled into \a versions (if \a versions is non-NULL).
735 /// This function always returns the number of version numbers
736 /// that this object file has regardless of the number of
737 /// version numbers that were copied into \a versions.
738 //------------------------------------------------------------------
739 virtual uint32_t GetMinimumOSVersion(uint32_t *versions,
740 uint32_t num_versions) {
741 if (versions && num_versions) {
742 for (uint32_t i = 0; i < num_versions; ++i)
743 versions[i] = UINT32_MAX;
748 //------------------------------------------------------------------
749 /// Get the SDK OS version this object file was built with.
751 /// The versions arguments and returns values are the same as the
752 /// GetMinimumOSVersion()
753 //------------------------------------------------------------------
754 virtual uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) {
755 if (versions && num_versions) {
756 for (uint32_t i = 0; i < num_versions; ++i)
757 versions[i] = UINT32_MAX;
762 //------------------------------------------------------------------
763 /// Return true if this file is a dynamic link editor (dyld)
765 /// Often times dyld has symbols that mirror symbols in libc and
766 /// other shared libraries (like "malloc" and "free") and the user
767 /// does _not_ want to stop in these shared libraries by default.
768 /// We can ask the ObjectFile if it is such a file and should be
769 /// avoided for things like settings breakpoints and doing function
770 /// lookups for expressions.
771 //------------------------------------------------------------------
772 virtual bool GetIsDynamicLinkEditor() { return false; }
774 //------------------------------------------------------------------
776 //------------------------------------------------------------------
778 if (m_type == eTypeInvalid)
779 m_type = CalculateType();
784 if (m_strata == eStrataInvalid)
785 m_strata = CalculateStrata();
789 // When an object file is in memory, subclasses should try and lock
790 // the process weak pointer. If the process weak pointer produces a
791 // valid ProcessSP, then subclasses can call this function to read
793 static lldb::DataBufferSP ReadMemory(const lldb::ProcessSP &process_sp,
794 lldb::addr_t addr, size_t byte_size);
796 // This function returns raw file contents. Do not use it if you want
797 // transparent decompression of section contents.
798 size_t GetData(lldb::offset_t offset, size_t length,
799 DataExtractor &data) const;
801 // This function returns raw file contents. Do not use it if you want
802 // transparent decompression of section contents.
803 size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const;
805 // This function will transparently decompress section data if the section if
807 virtual size_t ReadSectionData(Section *section,
808 lldb::offset_t section_offset, void *dst,
811 // This function will transparently decompress section data if the section if
812 // compressed. Note that for compressed section the resulting data size may be
813 // larger than what Section::GetFileSize reports.
814 virtual size_t ReadSectionData(Section *section,
815 DataExtractor §ion_data);
817 bool IsInMemory() const { return m_memory_addr != LLDB_INVALID_ADDRESS; }
819 // Strip linker annotations (such as @@VERSION) from symbol names.
820 virtual llvm::StringRef
821 StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
825 static lldb::SymbolType GetSymbolTypeFromName(
826 llvm::StringRef name,
827 lldb::SymbolType symbol_type_hint = lldb::eSymbolTypeUndefined);
829 //------------------------------------------------------------------
830 /// Loads this objfile to memory.
832 /// Loads the bits needed to create an executable image to the memory.
833 /// It is useful with bare-metal targets where target does not have the
834 /// ability to start a process itself.
836 /// @param[in] target
837 /// Target where to load.
840 //------------------------------------------------------------------
841 virtual Status LoadInMemory(Target &target, bool set_pc);
844 //------------------------------------------------------------------
846 //------------------------------------------------------------------
850 lldb::addr_t m_file_offset; ///< The offset in bytes into the file, or the
852 lldb::addr_t m_length; ///< The length of this object file if it is known (can
853 ///be zero if length is unknown or can't be
856 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
858 /// created for this ObjectFile's
860 lldb::ProcessWP m_process_wp;
861 const lldb::addr_t m_memory_addr;
862 std::unique_ptr<lldb_private::SectionList> m_sections_ap;
863 std::unique_ptr<lldb_private::Symtab> m_symtab_ap;
864 uint32_t m_synthetic_symbol_idx;
866 //------------------------------------------------------------------
867 /// Sets the architecture for a module. At present the architecture
868 /// can only be set if it is invalid. It is not allowed to switch from
869 /// one concrete architecture to another.
871 /// @param[in] new_arch
872 /// The architecture this module will be set to.
875 /// Returns \b true if the architecture was changed, \b
877 //------------------------------------------------------------------
878 bool SetModulesArchitecture(const ArchSpec &new_arch);
880 ConstString GetNextSyntheticSymbolName();
882 static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
886 DISALLOW_COPY_AND_ASSIGN(ObjectFile);
889 } // namespace lldb_private
891 #endif // liblldb_ObjectFile_h_