1 //===-- ObjectFile.h --------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SYMBOL_OBJECTFILE_H
10 #define LLDB_SYMBOL_OBJECTFILE_H
11 
12 #include "lldb/Core/FileSpecList.h"
13 #include "lldb/Core/ModuleChild.h"
14 #include "lldb/Core/PluginInterface.h"
15 #include "lldb/Symbol/Symtab.h"
16 #include "lldb/Symbol/UnwindTable.h"
17 #include "lldb/Utility/DataExtractor.h"
18 #include "lldb/Utility/Endian.h"
19 #include "lldb/Utility/FileSpec.h"
20 #include "lldb/Utility/UUID.h"
21 #include "lldb/lldb-private.h"
22 #include "llvm/Support/VersionTuple.h"
23 
24 namespace lldb_private {
25 
26 class ObjectFileJITDelegate {
27 public:
28   ObjectFileJITDelegate() = default;
29 
30   virtual ~ObjectFileJITDelegate() = default;
31 
32   virtual lldb::ByteOrder GetByteOrder() const = 0;
33 
34   virtual uint32_t GetAddressByteSize() const = 0;
35 
36   virtual void PopulateSymtab(lldb_private::ObjectFile *obj_file,
37                               lldb_private::Symtab &symtab) = 0;
38 
39   virtual void PopulateSectionList(lldb_private::ObjectFile *obj_file,
40                                    lldb_private::SectionList &section_list) = 0;
41 
42   virtual ArchSpec GetArchitecture() = 0;
43 };
44 
45 /// \class ObjectFile ObjectFile.h "lldb/Symbol/ObjectFile.h"
46 /// A plug-in interface definition class for object file parsers.
47 ///
48 /// Object files belong to Module objects and know how to extract information
49 /// from executable, shared library, and object (.o) files used by operating
50 /// system runtime. The symbol table and section list for an object file.
51 ///
52 /// Object files can be represented by the entire file, or by part of a file.
53 /// An example of a partial file ObjectFile is one that contains information
54 /// for one of multiple architectures in the same file.
55 ///
56 /// Once an architecture is selected the object file information can be
57 /// extracted from this abstract class.
58 class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
59                    public PluginInterface,
60                    public ModuleChild {
61   friend class lldb_private::Module;
62 
63 public:
64   enum Type {
65     eTypeInvalid = 0,
66     /// A core file that has a checkpoint of a program's execution state.
67     eTypeCoreFile,
68     /// A normal executable.
69     eTypeExecutable,
70     /// An object file that contains only debug information.
71     eTypeDebugInfo,
72     /// The platform's dynamic linker executable.
73     eTypeDynamicLinker,
74     /// An intermediate object file.
75     eTypeObjectFile,
76     /// A shared library that can be used during execution.
77     eTypeSharedLibrary,
78     /// A library that can be linked against but not used for execution.
79     eTypeStubLibrary,
80     /// JIT code that has symbols, sections and possibly debug info.
81     eTypeJIT,
82     eTypeUnknown
83   };
84 
85   enum Strata {
86     eStrataInvalid = 0,
87     eStrataUnknown,
88     eStrataUser,
89     eStrataKernel,
90     eStrataRawImage,
91     eStrataJIT
92   };
93 
94   /// If we have a corefile binary hint, this enum
95   /// specifies the binary type which we can use to
96   /// select the correct DynamicLoader plugin.
97   enum BinaryType {
98     eBinaryTypeInvalid = 0,
99     eBinaryTypeUnknown,
100     eBinaryTypeKernel,    /// kernel binary
101     eBinaryTypeUser,      /// user process binary
102     eBinaryTypeStandalone /// standalone binary / firmware
103   };
104 
105   struct LoadableData {
106     lldb::addr_t Dest;
107     llvm::ArrayRef<uint8_t> Contents;
108   };
109 
110   /// Construct with a parent module, offset, and header data.
111   ///
112   /// Object files belong to modules and a valid module must be supplied upon
113   /// construction. The at an offset within a file for objects that contain
114   /// more than one architecture or object.
115   ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr,
116              lldb::offset_t file_offset, lldb::offset_t length,
117              const lldb::DataBufferSP &data_sp, lldb::offset_t data_offset);
118 
119   ObjectFile(const lldb::ModuleSP &module_sp, const lldb::ProcessSP &process_sp,
120              lldb::addr_t header_addr, lldb::DataBufferSP &data_sp);
121 
122   /// Destructor.
123   ///
124   /// The destructor is virtual since this class is designed to be inherited
125   /// from by the plug-in instance.
126   ~ObjectFile() override;
127 
128   /// Dump a description of this object to a Stream.
129   ///
130   /// Dump a description of the current contents of this object to the
131   /// supplied stream \a s. The dumping should include the section list if it
132   /// has been parsed, and the symbol table if it has been parsed.
133   ///
134   /// \param[in] s
135   ///     The stream to which to dump the object description.
136   virtual void Dump(Stream *s) = 0;
137 
138   /// Find a ObjectFile plug-in that can parse \a file_spec.
139   ///
140   /// Scans all loaded plug-in interfaces that implement versions of the
141   /// ObjectFile plug-in interface and returns the first instance that can
142   /// parse the file.
143   ///
144   /// \param[in] module_sp
145   ///     The parent module that owns this object file.
146   ///
147   /// \param[in] file_spec
148   ///     A file specification that indicates which file to use as the
149   ///     object file.
150   ///
151   /// \param[in] file_offset
152   ///     The offset into the file at which to start parsing the
153   ///     object. This is for files that contain multiple
154   ///     architectures or objects.
155   ///
156   /// \param[in] file_size
157   ///     The size of the current object file if it can be determined
158   ///     or if it is known. This can be zero.
159   ///
160   /// \see ObjectFile::ParseHeader()
161   static lldb::ObjectFileSP
162   FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec,
163              lldb::offset_t file_offset, lldb::offset_t file_size,
164              lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset);
165 
166   /// Find a ObjectFile plug-in that can parse a file in memory.
167   ///
168   /// Scans all loaded plug-in interfaces that implement versions of the
169   /// ObjectFile plug-in interface and returns the first instance that can
170   /// parse the file.
171   ///
172   /// \param[in] module_sp
173   ///     The parent module that owns this object file.
174   ///
175   /// \param[in] process_sp
176   ///     A shared pointer to the process whose memory space contains
177   ///     an object file. This will be stored as a std::weak_ptr.
178   ///
179   /// \param[in] header_addr
180   ///     The address of the header for the object file in memory.
181   static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp,
182                                        const lldb::ProcessSP &process_sp,
183                                        lldb::addr_t header_addr,
184                                        lldb::DataBufferSP &file_data_sp);
185 
186   static size_t
187   GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset,
188                           lldb::offset_t file_size, ModuleSpecList &specs,
189                           lldb::DataBufferSP data_sp = lldb::DataBufferSP());
190 
191   static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
192                                         lldb::DataBufferSP &data_sp,
193                                         lldb::offset_t data_offset,
194                                         lldb::offset_t file_offset,
195                                         lldb::offset_t file_size,
196                                         lldb_private::ModuleSpecList &specs);
197   /// Split a path into a file path with object name.
198   ///
199   /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path up into
200   /// the actual path name and into the object name so we can make a valid
201   /// object file from it.
202   ///
203   /// \param[in] path_with_object
204   ///     A path that might contain an archive path with a .o file
205   ///     specified in parens in the basename of the path.
206   ///
207   /// \param[out] archive_file
208   ///     If \b true is returned, \a file_spec will be filled in with
209   ///     the path to the archive.
210   ///
211   /// \param[out] archive_object
212   ///     If \b true is returned, \a object will be filled in with
213   ///     the name of the object inside the archive.
214   ///
215   /// \return
216   ///     \b true if the path matches the pattern of archive + object
217   ///     and \a archive_file and \a archive_object are modified,
218   ///     \b false otherwise and \a archive_file and \a archive_object
219   ///     are guaranteed to be remain unchanged.
220   static bool SplitArchivePathWithObject(
221       llvm::StringRef path_with_object, lldb_private::FileSpec &archive_file,
222       lldb_private::ConstString &archive_object, bool must_exist);
223 
224   // LLVM RTTI support
225   static char ID;
isA(const void * ClassID)226   virtual bool isA(const void *ClassID) const { return ClassID == &ID; }
227 
228   /// Gets the address size in bytes for the current object file.
229   ///
230   /// \return
231   ///     The size of an address in bytes for the currently selected
232   ///     architecture (and object for archives). Returns zero if no
233   ///     architecture or object has been selected.
234   virtual uint32_t GetAddressByteSize() const = 0;
235 
236   /// Get the address type given a file address in an object file.
237   ///
238   /// Many binary file formats know what kinds This is primarily for ARM
239   /// binaries, though it can be applied to any executable file format that
240   /// supports different opcode types within the same binary. ARM binaries
241   /// support having both ARM and Thumb within the same executable container.
242   /// We need to be able to get \return
243   ///     The size of an address in bytes for the currently selected
244   ///     architecture (and object for archives). Returns zero if no
245   ///     architecture or object has been selected.
246   virtual AddressClass GetAddressClass(lldb::addr_t file_addr);
247 
248   /// Extract the dependent modules from an object file.
249   ///
250   /// If an object file has information about which other images it depends on
251   /// (such as shared libraries), this function will provide the list. Since
252   /// many executables or shared libraries may depend on the same files,
253   /// FileSpecList::AppendIfUnique(const FileSpec &) should be used to make
254   /// sure any files that are added are not already in the list.
255   ///
256   /// \param[out] file_list
257   ///     A list of file specification objects that gets dependent
258   ///     files appended to.
259   ///
260   /// \return
261   ///     The number of new files that were appended to \a file_list.
262   ///
263   /// \see FileSpecList::AppendIfUnique(const FileSpec &)
264   virtual uint32_t GetDependentModules(FileSpecList &file_list) = 0;
265 
266   /// Tells whether this object file is capable of being the main executable
267   /// for a process.
268   ///
269   /// \return
270   ///     \b true if it is, \b false otherwise.
271   virtual bool IsExecutable() const = 0;
272 
273   /// Returns the offset into a file at which this object resides.
274   ///
275   /// Some files contain many object files, and this function allows access to
276   /// an object's offset within the file.
277   ///
278   /// \return
279   ///     The offset in bytes into the file. Defaults to zero for
280   ///     simple object files that a represented by an entire file.
GetFileOffset()281   virtual lldb::addr_t GetFileOffset() const { return m_file_offset; }
282 
GetByteSize()283   virtual lldb::addr_t GetByteSize() const { return m_length; }
284 
285   /// Get accessor to the object file specification.
286   ///
287   /// \return
288   ///     The file specification object pointer if there is one, or
289   ///     NULL if this object is only from memory.
GetFileSpec()290   virtual FileSpec &GetFileSpec() { return m_file; }
291 
292   /// Get const accessor to the object file specification.
293   ///
294   /// \return
295   ///     The const file specification object pointer if there is one,
296   ///     or NULL if this object is only from memory.
GetFileSpec()297   virtual const FileSpec &GetFileSpec() const { return m_file; }
298 
299   /// Get the ArchSpec for this object file.
300   ///
301   /// \return
302   ///     The ArchSpec of this object file. In case of error, an invalid
303   ///     ArchSpec object is returned.
304   virtual ArchSpec GetArchitecture() = 0;
305 
306   /// Gets the section list for the currently selected architecture (and
307   /// object for archives).
308   ///
309   /// Section list parsing can be deferred by ObjectFile instances until this
310   /// accessor is called the first time.
311   ///
312   /// \return
313   ///     The list of sections contained in this object file.
314   virtual SectionList *GetSectionList(bool update_module_section_list = true);
315 
316   virtual void CreateSections(SectionList &unified_section_list) = 0;
317 
318   /// Notify the ObjectFile that the file addresses in the Sections for this
319   /// module have been changed.
SectionFileAddressesChanged()320   virtual void SectionFileAddressesChanged() {}
321 
322   /// Gets the symbol table for the currently selected architecture (and
323   /// object for archives).
324   ///
325   /// Symbol table parsing can be deferred by ObjectFile instances until this
326   /// accessor is called the first time.
327   ///
328   /// \return
329   ///     The symbol table for this object file.
330   virtual Symtab *GetSymtab() = 0;
331 
332   /// Perform relocations on the section if necessary.
333   ///
334   virtual void RelocateSection(lldb_private::Section *section);
335 
336   /// Appends a Symbol for the specified so_addr to the symbol table.
337   ///
338   /// If verify_unique is false, the symbol table is not searched to determine
339   /// if a Symbol found at this address has already been added to the symbol
340   /// table.  When verify_unique is true, this method resolves the Symbol as
341   /// the first match in the SymbolTable and appends a Symbol only if
342   /// required/found.
343   ///
344   /// \return
345   ///     The resolved symbol or nullptr.  Returns nullptr if a
346   ///     a Symbol could not be found for the specified so_addr.
ResolveSymbolForAddress(const Address & so_addr,bool verify_unique)347   virtual Symbol *ResolveSymbolForAddress(const Address &so_addr,
348                                           bool verify_unique) {
349     // Typically overridden to lazily add stripped symbols recoverable from the
350     // exception handling unwind information (i.e. without parsing the entire
351     // eh_frame section.
352     //
353     // The availability of LC_FUNCTION_STARTS allows ObjectFileMachO to
354     // efficiently add stripped symbols when the symbol table is first
355     // constructed.  Poorer cousins are PECoff and ELF.
356     return nullptr;
357   }
358 
359   /// Detect if this object file has been stripped of local symbols.
360   /// Detect if this object file has been stripped of local symbols.
361   ///
362   /// \return
363   ///     Return \b true if the object file has been stripped of local
364   ///     symbols.
365   virtual bool IsStripped() = 0;
366 
367   /// Frees the symbol table.
368   ///
369   /// This function should only be used when an object file is
370   virtual void ClearSymtab();
371 
372   /// Gets the UUID for this object file.
373   ///
374   /// If the object file format contains a UUID, the value should be returned.
375   /// Else ObjectFile instances should return the MD5 checksum of all of the
376   /// bytes for the object file (or memory for memory based object files).
377   ///
378   /// \return
379   ///     The object file's UUID. In case of an error, an empty UUID is
380   ///     returned.
381   virtual UUID GetUUID() = 0;
382 
383   /// Gets the file spec list of libraries re-exported by this object file.
384   ///
385   /// If the object file format has the notion of one library re-exporting the
386   /// symbols from another, the re-exported libraries will be returned in the
387   /// FileSpecList.
388   ///
389   /// \return
390   ///     Returns filespeclist.
GetReExportedLibraries()391   virtual lldb_private::FileSpecList GetReExportedLibraries() {
392     return FileSpecList();
393   }
394 
395   /// Sets the load address for an entire module, assuming a rigid slide of
396   /// sections, if possible in the implementation.
397   ///
398   /// \return
399   ///     Returns true iff any section's load address changed.
SetLoadAddress(Target & target,lldb::addr_t value,bool value_is_offset)400   virtual bool SetLoadAddress(Target &target, lldb::addr_t value,
401                               bool value_is_offset) {
402     return false;
403   }
404 
405   /// Gets whether endian swapping should occur when extracting data from this
406   /// object file.
407   ///
408   /// \return
409   ///     Returns \b true if endian swapping is needed, \b false
410   ///     otherwise.
411   virtual lldb::ByteOrder GetByteOrder() const = 0;
412 
413   /// Attempts to parse the object header.
414   ///
415   /// This function is used as a test to see if a given plug-in instance can
416   /// parse the header data already contained in ObjectFile::m_data. If an
417   /// object file parser does not recognize that magic bytes in a header,
418   /// false should be returned and the next plug-in can attempt to parse an
419   /// object file.
420   ///
421   /// \return
422   ///     Returns \b true if the header was parsed successfully, \b
423   ///     false otherwise.
424   virtual bool ParseHeader() = 0;
425 
426   /// Returns if the function bounds for symbols in this symbol file are
427   /// likely accurate.
428   ///
429   /// The unwinder can emulate the instructions of functions to understand
430   /// prologue/epilogue code sequences, where registers are spilled on the
431   /// stack, etc.  This feature relies on having the correct start addresses
432   /// of all functions.  If the ObjectFile has a way to tell that symbols have
433   /// been stripped and there's no way to reconstruct start addresses (e.g.
434   /// LC_FUNCTION_STARTS on Mach-O, or eh_frame unwind info), the ObjectFile
435   /// should indicate that assembly emulation should not be used for this
436   /// module.
437   ///
438   /// It is uncommon for this to return false.  An ObjectFile needs to be sure
439   /// that symbol start addresses are unavailable before false is returned.
440   /// If it is unclear, this should return true.
441   ///
442   /// \return
443   ///     Returns true if assembly emulation should be used for this
444   ///     module.
445   ///     Only returns false if the ObjectFile is sure that symbol
446   ///     addresses are insufficient for accurate assembly emulation.
AllowAssemblyEmulationUnwindPlans()447   virtual bool AllowAssemblyEmulationUnwindPlans() { return true; }
448 
449   /// Similar to Process::GetImageInfoAddress().
450   ///
451   /// Some platforms embed auxiliary structures useful to debuggers in the
452   /// address space of the inferior process.  This method returns the address
453   /// of such a structure if the information can be resolved via entries in
454   /// the object file.  ELF, for example, provides a means to hook into the
455   /// runtime linker so that a debugger may monitor the loading and unloading
456   /// of shared libraries.
457   ///
458   /// \return
459   ///     The address of any auxiliary tables, or an invalid address if this
460   ///     object file format does not support or contain such information.
GetImageInfoAddress(Target * target)461   virtual lldb_private::Address GetImageInfoAddress(Target *target) {
462     return Address();
463   }
464 
465   /// Returns the address of the Entry Point in this object file - if the
466   /// object file doesn't have an entry point (because it is not an executable
467   /// file) then an invalid address is returned.
468   ///
469   /// \return
470   ///     Returns the entry address for this module.
GetEntryPointAddress()471   virtual lldb_private::Address GetEntryPointAddress() { return Address(); }
472 
473   /// Returns base address of this object file.
474   ///
475   /// This also sometimes referred to as the "preferred load address" or the
476   /// "image base address". Addresses within object files are often expressed
477   /// relative to this base. If this address corresponds to a specific section
478   /// (usually the first byte of the first section) then the returned address
479   /// will have this section set. Otherwise, the address will just have the
480   /// offset member filled in, indicating that this represents a file address.
GetBaseAddress()481   virtual lldb_private::Address GetBaseAddress() {
482     return Address(m_memory_addr);
483   }
484 
GetNumThreadContexts()485   virtual uint32_t GetNumThreadContexts() { return 0; }
486 
487   /// Some object files may have an identifier string embedded in them, e.g.
488   /// in a Mach-O core file using the LC_IDENT load command (which  is
489   /// obsolete, but can still be found in some old files)
490   ///
491   /// \return
492   ///     Returns the identifier string if one exists, else an empty
493   ///     string.
GetIdentifierString()494   virtual std::string GetIdentifierString () {
495       return std::string();
496   }
497 
498   /// Some object files may have the number of bits used for addressing
499   /// embedded in them, e.g. a Mach-O core file using an LC_NOTE.  These
500   /// object files can return the address mask that should be used in
501   /// the Process.
502   /// \return
503   ///     The mask will have bits set which aren't used for addressing --
504   ///     typically, the high bits.
505   ///     Zero is returned when no address bits mask is available.
GetAddressMask()506   virtual lldb::addr_t GetAddressMask() { return 0; }
507 
508   /// When the ObjectFile is a core file, lldb needs to locate the "binary" in
509   /// the core file.  lldb can iterate over the pages looking for a valid
510   /// binary, but some core files may have metadata  describing where the main
511   /// binary is exactly which removes ambiguity when there are multiple
512   /// binaries present in the captured memory pages.
513   ///
514   /// \param[out] address
515   ///   If the address of the binary is specified, this will be set.
516   ///   This is an address is the virtual address space of the core file
517   ///   memory segments; it is not an offset into the object file.
518   ///   If no address is available, will be set to LLDB_INVALID_ADDRESS.
519   ///
520   /// \param[out] uuid
521   ///   If the uuid of the binary is specified, this will be set.
522   ///   If no UUID is available, will be cleared.
523   ///
524   /// \param[out] type
525   ///   Return the type of the binary, which will dictate which
526   ///   DynamicLoader plugin should be used.
527   ///
528   /// \return
529   ///   Returns true if either address or uuid has been set.
GetCorefileMainBinaryInfo(lldb::addr_t & address,UUID & uuid,ObjectFile::BinaryType & type)530   virtual bool GetCorefileMainBinaryInfo(lldb::addr_t &address, UUID &uuid,
531                                          ObjectFile::BinaryType &type) {
532     address = LLDB_INVALID_ADDRESS;
533     uuid.Clear();
534     return false;
535   }
536 
537   virtual lldb::RegisterContextSP
GetThreadContextAtIndex(uint32_t idx,lldb_private::Thread & thread)538   GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) {
539     return lldb::RegisterContextSP();
540   }
541 
542   /// The object file should be able to calculate its type by looking at its
543   /// file header and possibly the sections or other data in the object file.
544   /// The file type is used in the debugger to help select the correct plug-
545   /// ins for the job at hand, so this is important to get right. If any
546   /// eTypeXXX definitions do not match up with the type of file you are
547   /// loading, please feel free to add a new enumeration value.
548   ///
549   /// \return
550   ///     The calculated file type for the current object file.
551   virtual Type CalculateType() = 0;
552 
553   /// In cases where the type can't be calculated (elf files), this routine
554   /// allows someone to explicitly set it. As an example, SymbolVendorELF uses
555   /// this routine to set eTypeDebugInfo when loading debug link files.
SetType(Type type)556   virtual void SetType(Type type) { m_type = type; }
557 
558   /// The object file should be able to calculate the strata of the object
559   /// file.
560   ///
561   /// Many object files for platforms might be for either user space debugging
562   /// or for kernel debugging. If your object file subclass can figure this
563   /// out, it will help with debugger plug-in selection when it comes time to
564   /// debug.
565   ///
566   /// \return
567   ///     The calculated object file strata for the current object
568   ///     file.
569   virtual Strata CalculateStrata() = 0;
570 
571   /// Get the object file version numbers.
572   ///
573   /// Many object files have a set of version numbers that describe the
574   /// version of the executable or shared library. Typically there are major,
575   /// minor and build, but there may be more. This function will extract the
576   /// versions from object files if they are available.
577   ///
578   /// \return
579   ///     This function returns extracted version numbers as a
580   ///     llvm::VersionTuple. In case of error an empty VersionTuple is
581   ///     returned.
GetVersion()582   virtual llvm::VersionTuple GetVersion() { return llvm::VersionTuple(); }
583 
584   /// Get the minimum OS version this object file can run on.
585   ///
586   /// Some object files have information that specifies the minimum OS version
587   /// that they can be used on.
588   ///
589   /// \return
590   ///     This function returns extracted version numbers as a
591   ///     llvm::VersionTuple. In case of error an empty VersionTuple is
592   ///     returned.
GetMinimumOSVersion()593   virtual llvm::VersionTuple GetMinimumOSVersion() {
594     return llvm::VersionTuple();
595   }
596 
597   /// Get the SDK OS version this object file was built with.
598   ///
599   /// \return
600   ///     This function returns extracted version numbers as a
601   ///     llvm::VersionTuple. In case of error an empty VersionTuple is
602   ///     returned.
GetSDKVersion()603   virtual llvm::VersionTuple GetSDKVersion() { return llvm::VersionTuple(); }
604 
605   /// Return true if this file is a dynamic link editor (dyld)
606   ///
607   /// Often times dyld has symbols that mirror symbols in libc and other
608   /// shared libraries (like "malloc" and "free") and the user does _not_ want
609   /// to stop in these shared libraries by default. We can ask the ObjectFile
610   /// if it is such a file and should be avoided for things like settings
611   /// breakpoints and doing function lookups for expressions.
GetIsDynamicLinkEditor()612   virtual bool GetIsDynamicLinkEditor() { return false; }
613 
614   // Member Functions
GetType()615   Type GetType() {
616     if (m_type == eTypeInvalid)
617       m_type = CalculateType();
618     return m_type;
619   }
620 
GetStrata()621   Strata GetStrata() {
622     if (m_strata == eStrataInvalid)
623       m_strata = CalculateStrata();
624     return m_strata;
625   }
626 
627   // When an object file is in memory, subclasses should try and lock the
628   // process weak pointer. If the process weak pointer produces a valid
629   // ProcessSP, then subclasses can call this function to read memory.
630   static lldb::DataBufferSP ReadMemory(const lldb::ProcessSP &process_sp,
631                                        lldb::addr_t addr, size_t byte_size);
632 
633   // This function returns raw file contents. Do not use it if you want
634   // transparent decompression of section contents.
635   size_t GetData(lldb::offset_t offset, size_t length,
636                  DataExtractor &data) const;
637 
638   // This function returns raw file contents. Do not use it if you want
639   // transparent decompression of section contents.
640   size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const;
641 
642   // This function will transparently decompress section data if the section if
643   // compressed.
644   virtual size_t ReadSectionData(Section *section,
645                                  lldb::offset_t section_offset, void *dst,
646                                  size_t dst_len);
647 
648   // This function will transparently decompress section data if the section if
649   // compressed. Note that for compressed section the resulting data size may
650   // be larger than what Section::GetFileSize reports.
651   virtual size_t ReadSectionData(Section *section,
652                                  DataExtractor &section_data);
653 
IsInMemory()654   bool IsInMemory() const { return m_memory_addr != LLDB_INVALID_ADDRESS; }
655 
656   // Strip linker annotations (such as @@VERSION) from symbol names.
657   virtual llvm::StringRef
StripLinkerSymbolAnnotations(llvm::StringRef symbol_name)658   StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
659     return symbol_name;
660   }
661 
662   static lldb::SymbolType GetSymbolTypeFromName(
663       llvm::StringRef name,
664       lldb::SymbolType symbol_type_hint = lldb::eSymbolTypeUndefined);
665 
666   /// Loads this objfile to memory.
667   ///
668   /// Loads the bits needed to create an executable image to the memory. It is
669   /// useful with bare-metal targets where target does not have the ability to
670   /// start a process itself.
671   ///
672   /// \param[in] target
673   ///     Target where to load.
674   virtual std::vector<LoadableData> GetLoadableData(Target &target);
675 
676   /// Creates a plugin-specific call frame info
677   virtual std::unique_ptr<CallFrameInfo> CreateCallFrameInfo();
678 
679   /// Load binaries listed in a corefile
680   ///
681   /// A corefile may have metadata listing binaries that can be loaded,
682   /// and the offsets at which they were loaded.  This method will try
683   /// to add them to the Target.  If any binaries were loaded,
684   ///
685   /// \param[in] process
686   ///     Process where to load binaries.
687   ///
688   /// \return
689   ///     Returns true if any binaries were loaded.
690 
LoadCoreFileImages(lldb_private::Process & process)691   virtual bool LoadCoreFileImages(lldb_private::Process &process) {
692     return false;
693   }
694 
695 protected:
696   // Member variables.
697   FileSpec m_file;
698   Type m_type;
699   Strata m_strata;
700   lldb::addr_t m_file_offset; ///< The offset in bytes into the file, or the
701                               ///address in memory
702   lldb::addr_t m_length; ///< The length of this object file if it is known (can
703                          ///be zero if length is unknown or can't be
704                          ///determined).
705   DataExtractor
706       m_data; ///< The data for this object file so things can be parsed lazily.
707   lldb::ProcessWP m_process_wp;
708   const lldb::addr_t m_memory_addr;
709   std::unique_ptr<lldb_private::SectionList> m_sections_up;
710   std::unique_ptr<lldb_private::Symtab> m_symtab_up;
711   uint32_t m_synthetic_symbol_idx;
712 
713   /// Sets the architecture for a module.  At present the architecture can
714   /// only be set if it is invalid.  It is not allowed to switch from one
715   /// concrete architecture to another.
716   ///
717   /// \param[in] new_arch
718   ///     The architecture this module will be set to.
719   ///
720   /// \return
721   ///     Returns \b true if the architecture was changed, \b
722   ///     false otherwise.
723   bool SetModulesArchitecture(const ArchSpec &new_arch);
724 
725   static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
726                                         uint64_t Offset);
727 
728 private:
729   ObjectFile(const ObjectFile &) = delete;
730   const ObjectFile &operator=(const ObjectFile &) = delete;
731 };
732 
733 } // namespace lldb_private
734 
735 namespace llvm {
736 template <> struct format_provider<lldb_private::ObjectFile::Type> {
737   static void format(const lldb_private::ObjectFile::Type &type,
738                      raw_ostream &OS, StringRef Style);
739 };
740 
741 template <> struct format_provider<lldb_private::ObjectFile::Strata> {
742   static void format(const lldb_private::ObjectFile::Strata &strata,
743                      raw_ostream &OS, StringRef Style);
744 };
745 } // namespace llvm
746 
747 #endif // LLDB_SYMBOL_OBJECTFILE_H
748