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