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