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