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 /// Appends a Symbol for the specified so_addr to the symbol table.
357 /// If verify_unique is false, the symbol table is not searched
358 /// to determine if a Symbol found at this address has already been
359 /// added to the symbol table. When verify_unique is true, this
360 /// method resolves the Symbol as the first match in the SymbolTable
361 /// and appends a Symbol only if required/found.
364 /// The resolved symbol or nullptr. Returns nullptr if a
365 /// a Symbol could not be found for the specified so_addr.
366 //------------------------------------------------------------------
367 virtual Symbol *ResolveSymbolForAddress(const Address &so_addr,
368 bool verify_unique) {
369 // Typically overridden to lazily add stripped symbols recoverable from
370 // the exception handling unwind information (i.e. without parsing
371 // the entire eh_frame section.
373 // The availability of LC_FUNCTION_STARTS allows ObjectFileMachO
374 // to efficiently add stripped symbols when the symbol table is
375 // first constructed. Poorer cousins are PECoff and ELF.
379 //------------------------------------------------------------------
380 /// Detect if this object file has been stripped of local symbols.
381 //------------------------------------------------------------------
382 /// Detect if this object file has been stripped of local symbols.
385 /// Return \b true if the object file has been stripped of local
387 //------------------------------------------------------------------
388 virtual bool IsStripped() = 0;
390 //------------------------------------------------------------------
391 /// Frees the symbol table.
393 /// This function should only be used when an object file is
396 /// eSymtabFromUnifiedSectionList: Whether to clear symbol table
397 /// for unified module section list, or object file.
400 /// The symbol table for this object file.
401 //------------------------------------------------------------------
402 virtual void ClearSymtab();
404 //------------------------------------------------------------------
405 /// Gets the UUID for this object file.
407 /// If the object file format contains a UUID, the value should be
408 /// returned. Else ObjectFile instances should return the MD5
409 /// checksum of all of the bytes for the object file (or memory for
410 /// memory based object files).
413 /// Returns \b true if a UUID was successfully extracted into
414 /// \a uuid, \b false otherwise.
415 //------------------------------------------------------------------
416 virtual bool GetUUID(lldb_private::UUID *uuid) = 0;
418 //------------------------------------------------------------------
419 /// Gets the symbol file spec list for this object file.
421 /// If the object file format contains a debug symbol file link,
422 /// the values will be returned in the FileSpecList.
425 /// Returns filespeclist.
426 //------------------------------------------------------------------
427 virtual lldb_private::FileSpecList GetDebugSymbolFilePaths() {
428 return FileSpecList();
431 //------------------------------------------------------------------
432 /// Gets the file spec list of libraries re-exported by this object file.
434 /// If the object file format has the notion of one library re-exporting the
435 /// symbols from another,
436 /// the re-exported libraries will be returned in the FileSpecList.
439 /// Returns filespeclist.
440 //------------------------------------------------------------------
441 virtual lldb_private::FileSpecList GetReExportedLibraries() {
442 return FileSpecList();
445 //------------------------------------------------------------------
446 /// Sets the load address for an entire module, assuming a rigid
447 /// slide of sections, if possible in the implementation.
450 /// Returns true iff any section's load address changed.
451 //------------------------------------------------------------------
452 virtual bool SetLoadAddress(Target &target, lldb::addr_t value,
453 bool value_is_offset) {
457 //------------------------------------------------------------------
458 /// Gets whether endian swapping should occur when extracting data
459 /// from this object file.
462 /// Returns \b true if endian swapping is needed, \b false
464 //------------------------------------------------------------------
465 virtual lldb::ByteOrder GetByteOrder() const = 0;
467 //------------------------------------------------------------------
468 /// Attempts to parse the object header.
470 /// This function is used as a test to see if a given plug-in
471 /// instance can parse the header data already contained in
472 /// ObjectFile::m_data. If an object file parser does not
473 /// recognize that magic bytes in a header, false should be returned
474 /// and the next plug-in can attempt to parse an object file.
477 /// Returns \b true if the header was parsed successfully, \b
479 //------------------------------------------------------------------
480 virtual bool ParseHeader() = 0;
482 //------------------------------------------------------------------
483 /// Returns a reference to the UnwindTable for this ObjectFile
485 /// The UnwindTable contains FuncUnwinders objects for any function in
486 /// this ObjectFile. If a FuncUnwinders object hasn't been created yet
487 /// (i.e. the function has yet to be unwound in a stack walk), it
488 /// will be created when requested. Specifically, we do not create
489 /// FuncUnwinders objects for functions until they are needed.
492 /// Returns the unwind table for this object file.
493 //------------------------------------------------------------------
494 virtual lldb_private::UnwindTable &GetUnwindTable() { return m_unwind_table; }
496 //------------------------------------------------------------------
497 /// Returns if the function bounds for symbols in this symbol file
498 /// are likely accurate.
500 /// The unwinder can emulate the instructions of functions to understand
501 /// prologue/epilogue code sequences, where registers are spilled on
502 /// the stack, etc. This feature relies on having the correct start
503 /// addresses of all functions. If the ObjectFile has a way to tell
504 /// that symbols have been stripped and there's no way to reconstruct
505 /// start addresses (e.g. LC_FUNCTION_STARTS on Mach-O, or eh_frame
506 /// unwind info), the ObjectFile should indicate that assembly emulation
507 /// should not be used for this module.
509 /// It is uncommon for this to return false. An ObjectFile needs to
510 /// be sure that symbol start addresses are unavailable before false
511 /// is returned. If it is unclear, this should return true.
514 /// Returns true if assembly emulation should be used for this
516 /// Only returns false if the ObjectFile is sure that symbol
517 /// addresses are insufficient for accurate assembly emulation.
518 //------------------------------------------------------------------
519 virtual bool AllowAssemblyEmulationUnwindPlans() { return true; }
521 //------------------------------------------------------------------
522 /// Similar to Process::GetImageInfoAddress().
524 /// Some platforms embed auxiliary structures useful to debuggers in the
525 /// address space of the inferior process. This method returns the address
526 /// of such a structure if the information can be resolved via entries in
527 /// the object file. ELF, for example, provides a means to hook into the
528 /// runtime linker so that a debugger may monitor the loading and unloading
529 /// of shared libraries.
532 /// The address of any auxiliary tables, or an invalid address if this
533 /// object file format does not support or contain such information.
534 virtual lldb_private::Address GetImageInfoAddress(Target *target) {
538 //------------------------------------------------------------------
539 /// Returns the address of the Entry Point in this object file - if
540 /// the object file doesn't have an entry point (because it is not an
541 /// executable file) then an invalid address is returned.
544 /// Returns the entry address for this module.
545 //------------------------------------------------------------------
546 virtual lldb_private::Address GetEntryPointAddress() { return Address(); }
548 //------------------------------------------------------------------
549 /// Returns the address that represents the header of this object
552 /// The header address is defined as where the header for the object
553 /// file is that describes the content of the file. If the header
554 /// doesn't appear in a section that is defined in the object file,
555 /// an address with no section is returned that has the file offset
556 /// set in the m_file_offset member of the lldb_private::Address object.
559 /// Returns the entry address for this module.
560 //------------------------------------------------------------------
561 virtual lldb_private::Address GetHeaderAddress() {
562 return Address(m_memory_addr);
565 virtual uint32_t GetNumThreadContexts() { return 0; }
567 //------------------------------------------------------------------
568 /// Some object files may have an identifier string embedded in them,
569 /// e.g. in a Mach-O core file using the LC_IDENT load command (which
570 /// is obsolete, but can still be found in some old files)
573 /// Returns the identifier string if one exists, else an empty
575 //------------------------------------------------------------------
576 virtual std::string GetIdentifierString () {
577 return std::string();
580 //------------------------------------------------------------------
581 /// When the ObjectFile is a core file, lldb needs to locate the
582 /// "binary" in the core file. lldb can iterate over the pages looking
583 /// for a valid binary, but some core files may have metadata
584 /// describing where the main binary is exactly which removes ambiguity
585 /// when there are multiple binaries present in the captured memory pages.
587 /// @param[out] address
588 /// If the address of the binary is specified, this will be set.
589 /// This is an address is the virtual address space of the core file
590 /// memory segments; it is not an offset into the object file.
591 /// If no address is available, will be set to LLDB_INVALID_ADDRESS.
594 /// If the uuid of the binary is specified, this will be set.
595 /// If no UUID is available, will be cleared.
598 /// Returns true if either address or uuid has been set.
599 //------------------------------------------------------------------
600 virtual bool GetCorefileMainBinaryInfo (lldb::addr_t &address, UUID &uuid) {
601 address = LLDB_INVALID_ADDRESS;
606 virtual lldb::RegisterContextSP
607 GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) {
608 return lldb::RegisterContextSP();
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.
621 /// The calculated file type for the current object file.
622 //------------------------------------------------------------------
623 virtual Type CalculateType() = 0;
625 //------------------------------------------------------------------
626 /// In cases where the type can't be calculated (elf files), this
627 /// routine allows someone to explicitly set it. As an example,
628 /// SymbolVendorELF uses this routine to set eTypeDebugInfo when
629 /// loading debug link files.
630 virtual void SetType(Type type) { m_type = type; }
632 //------------------------------------------------------------------
633 /// The object file should be able to calculate the strata of the
636 /// Many object files for platforms might be for either user space
637 /// debugging or for kernel debugging. If your object file subclass
638 /// can figure this out, it will help with debugger plug-in selection
639 /// when it comes time to debug.
642 /// The calculated object file strata for the current object
644 //------------------------------------------------------------------
645 virtual Strata CalculateStrata() = 0;
647 //------------------------------------------------------------------
648 /// Get the object file version numbers.
650 /// Many object files have a set of version numbers that describe
651 /// the version of the executable or shared library. Typically there
652 /// are major, minor and build, but there may be more. This function
653 /// will extract the versions from object files if they are available.
655 /// If \a versions is NULL, or if \a num_versions is 0, the return
656 /// value will indicate how many version numbers are available in
657 /// this object file. Then a subsequent call can be made to this
658 /// function with a value of \a versions and \a num_versions that
659 /// has enough storage to store some or all version numbers.
661 /// @param[out] versions
662 /// A pointer to an array of uint32_t types that is \a num_versions
663 /// long. If this value is NULL, the return value will indicate
664 /// how many version numbers are required for a subsequent call
665 /// to this function so that all versions can be retrieved. If
666 /// the value is non-NULL, then at most \a num_versions of the
667 /// existing versions numbers will be filled into \a versions.
668 /// If there is no version information available, \a versions
669 /// will be filled with \a num_versions UINT32_MAX values
670 /// and zero will be returned.
672 /// @param[in] num_versions
673 /// The maximum number of entries to fill into \a versions. If
674 /// this value is zero, then the return value will indicate
675 /// how many version numbers there are in total so another call
676 /// to this function can be make with adequate storage in
677 /// \a versions to get all of the version numbers. If \a
678 /// num_versions is less than the actual number of version
679 /// numbers in this object file, only \a num_versions will be
680 /// filled into \a versions (if \a versions is non-NULL).
683 /// This function always returns the number of version numbers
684 /// that this object file has regardless of the number of
685 /// version numbers that were copied into \a versions.
686 //------------------------------------------------------------------
687 virtual uint32_t GetVersion(uint32_t *versions, uint32_t num_versions) {
688 if (versions && num_versions) {
689 for (uint32_t i = 0; i < num_versions; ++i)
690 versions[i] = UINT32_MAX;
695 //------------------------------------------------------------------
696 /// Get the minimum OS version this object file can run on.
698 /// Some object files have information that specifies the minimum OS
699 /// version that they can be used on.
701 /// If \a versions is NULL, or if \a num_versions is 0, the return
702 /// value will indicate how many version numbers are available in
703 /// this object file. Then a subsequent call can be made to this
704 /// function with a value of \a versions and \a num_versions that
705 /// has enough storage to store some or all version numbers.
707 /// @param[out] versions
708 /// A pointer to an array of uint32_t types that is \a num_versions
709 /// long. If this value is NULL, the return value will indicate
710 /// how many version numbers are required for a subsequent call
711 /// to this function so that all versions can be retrieved. If
712 /// the value is non-NULL, then at most \a num_versions of the
713 /// existing versions numbers will be filled into \a versions.
714 /// If there is no version information available, \a versions
715 /// will be filled with \a num_versions UINT32_MAX values
716 /// and zero will be returned.
718 /// @param[in] num_versions
719 /// The maximum number of entries to fill into \a versions. If
720 /// this value is zero, then the return value will indicate
721 /// how many version numbers there are in total so another call
722 /// to this function can be make with adequate storage in
723 /// \a versions to get all of the version numbers. If \a
724 /// num_versions is less than the actual number of version
725 /// numbers in this object file, only \a num_versions will be
726 /// filled into \a versions (if \a versions is non-NULL).
729 /// This function always returns the number of version numbers
730 /// that this object file has regardless of the number of
731 /// version numbers that were copied into \a versions.
732 //------------------------------------------------------------------
733 virtual uint32_t GetMinimumOSVersion(uint32_t *versions,
734 uint32_t num_versions) {
735 if (versions && num_versions) {
736 for (uint32_t i = 0; i < num_versions; ++i)
737 versions[i] = UINT32_MAX;
742 //------------------------------------------------------------------
743 /// Get the SDK OS version this object file was built with.
745 /// The versions arguments and returns values are the same as the
746 /// GetMinimumOSVersion()
747 //------------------------------------------------------------------
748 virtual uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) {
749 if (versions && num_versions) {
750 for (uint32_t i = 0; i < num_versions; ++i)
751 versions[i] = UINT32_MAX;
756 //------------------------------------------------------------------
757 /// Return true if this file is a dynamic link editor (dyld)
759 /// Often times dyld has symbols that mirror symbols in libc and
760 /// other shared libraries (like "malloc" and "free") and the user
761 /// does _not_ want to stop in these shared libraries by default.
762 /// We can ask the ObjectFile if it is such a file and should be
763 /// avoided for things like settings breakpoints and doing function
764 /// lookups for expressions.
765 //------------------------------------------------------------------
766 virtual bool GetIsDynamicLinkEditor() { return false; }
768 //------------------------------------------------------------------
770 //------------------------------------------------------------------
772 if (m_type == eTypeInvalid)
773 m_type = CalculateType();
778 if (m_strata == eStrataInvalid)
779 m_strata = CalculateStrata();
783 // When an object file is in memory, subclasses should try and lock
784 // the process weak pointer. If the process weak pointer produces a
785 // valid ProcessSP, then subclasses can call this function to read
787 static lldb::DataBufferSP ReadMemory(const lldb::ProcessSP &process_sp,
788 lldb::addr_t addr, size_t byte_size);
790 size_t GetData(lldb::offset_t offset, size_t length,
791 DataExtractor &data) const;
793 size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const;
795 virtual size_t ReadSectionData(const Section *section,
796 lldb::offset_t section_offset, void *dst,
797 size_t dst_len) const;
799 virtual size_t ReadSectionData(const Section *section,
800 DataExtractor §ion_data) const;
802 size_t MemoryMapSectionData(const Section *section,
803 DataExtractor §ion_data) const;
805 bool IsInMemory() const { return m_memory_addr != LLDB_INVALID_ADDRESS; }
807 // Strip linker annotations (such as @@VERSION) from symbol names.
808 virtual llvm::StringRef
809 StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
813 static lldb::SymbolType GetSymbolTypeFromName(
814 llvm::StringRef name,
815 lldb::SymbolType symbol_type_hint = lldb::eSymbolTypeUndefined);
817 //------------------------------------------------------------------
818 /// Loads this objfile to memory.
820 /// Loads the bits needed to create an executable image to the memory.
821 /// It is useful with bare-metal targets where target does not have the
822 /// ability to start a process itself.
824 /// @param[in] target
825 /// Target where to load.
828 //------------------------------------------------------------------
829 virtual Status LoadInMemory(Target &target, bool set_pc);
832 //------------------------------------------------------------------
834 //------------------------------------------------------------------
838 lldb::addr_t m_file_offset; ///< The offset in bytes into the file, or the
840 lldb::addr_t m_length; ///< The length of this object file if it is known (can
841 ///be zero if length is unknown or can't be
844 m_data; ///< The data for this object file so things can be parsed lazily.
845 lldb_private::UnwindTable m_unwind_table; /// < Table of FuncUnwinders objects
846 /// created for this ObjectFile's
848 lldb::ProcessWP m_process_wp;
849 const lldb::addr_t m_memory_addr;
850 std::unique_ptr<lldb_private::SectionList> m_sections_ap;
851 std::unique_ptr<lldb_private::Symtab> m_symtab_ap;
852 uint32_t m_synthetic_symbol_idx;
854 //------------------------------------------------------------------
855 /// Sets the architecture for a module. At present the architecture
856 /// can only be set if it is invalid. It is not allowed to switch from
857 /// one concrete architecture to another.
859 /// @param[in] new_arch
860 /// The architecture this module will be set to.
863 /// Returns \b true if the architecture was changed, \b
865 //------------------------------------------------------------------
866 bool SetModulesArchitecture(const ArchSpec &new_arch);
868 ConstString GetNextSyntheticSymbolName();
871 DISALLOW_COPY_AND_ASSIGN(ObjectFile);
874 } // namespace lldb_private
876 #endif // liblldb_ObjectFile_h_