]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Symbol/ObjectContainer.h
Update to Zstandard 1.3.8
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Symbol / ObjectContainer.h
1 //===-- ObjectContainer.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_ObjectContainer_h_
11 #define liblldb_ObjectContainer_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Core/ModuleChild.h"
18 #include "lldb/Core/PluginInterface.h"
19 #include "lldb/Utility/DataExtractor.h"
20 #include "lldb/Utility/Endian.h"
21 #include "lldb/Utility/FileSpec.h"
22 #include "lldb/lldb-private.h"
23
24 namespace lldb_private {
25
26 //----------------------------------------------------------------------
27 /// @class ObjectContainer ObjectContainer.h "lldb/Symbol/ObjectContainer.h"
28 /// A plug-in interface definition class for object containers.
29 ///
30 /// Object containers contain object files from one or more architectures, and
31 /// also can contain one or more named objects.
32 ///
33 /// Typical object containers are static libraries (.a files) that contain
34 /// multiple named object files, and universal files that contain multiple
35 /// architectures.
36 //----------------------------------------------------------------------
37 class ObjectContainer : public PluginInterface, public ModuleChild {
38 public:
39   //------------------------------------------------------------------
40   /// Construct with a parent module, offset, and header data.
41   ///
42   /// Object files belong to modules and a valid module must be supplied upon
43   /// construction. The at an offset within a file for objects that contain
44   /// more than one architecture or object.
45   //------------------------------------------------------------------
46   ObjectContainer(const lldb::ModuleSP &module_sp, const FileSpec *file,
47                   lldb::offset_t file_offset, lldb::offset_t length,
48                   lldb::DataBufferSP &data_sp, lldb::offset_t data_offset)
49       : ModuleChild(module_sp),
50         m_file(), // This file can be different than the module's file spec
51         m_offset(file_offset), m_length(length), m_data() {
52     if (file)
53       m_file = *file;
54     if (data_sp)
55       m_data.SetData(data_sp, data_offset, length);
56   }
57
58   //------------------------------------------------------------------
59   /// Destructor.
60   ///
61   /// The destructor is virtual since this class is designed to be inherited
62   /// from by the plug-in instance.
63   //------------------------------------------------------------------
64   ~ObjectContainer() override = default;
65
66   //------------------------------------------------------------------
67   /// Dump a description of this object to a Stream.
68   ///
69   /// Dump a description of the current contents of this object to the
70   /// supplied stream \a s. The dumping should include the section list if it
71   /// has been parsed, and the symbol table if it has been parsed.
72   ///
73   /// @param[in] s
74   ///     The stream to which to dump the object description.
75   //------------------------------------------------------------------
76   virtual void Dump(Stream *s) const = 0;
77
78   //------------------------------------------------------------------
79   /// Gets the architecture given an index.
80   ///
81   /// Copies the architecture specification for index \a idx.
82   ///
83   /// @param[in] idx
84   ///     The architecture index to extract.
85   ///
86   /// @param[out] arch
87   ///     A architecture object that will be filled in if \a idx is a
88   ///     architecture valid index.
89   ///
90   /// @return
91   ///     Returns \b true if \a idx is valid and \a arch has been
92   ///     filled in, \b false otherwise.
93   ///
94   /// @see ObjectContainer::GetNumArchitectures() const
95   //------------------------------------------------------------------
96   virtual bool GetArchitectureAtIndex(uint32_t idx, ArchSpec &arch) const {
97     return false;
98   }
99
100   //------------------------------------------------------------------
101   /// Returns the offset into a file at which this object resides.
102   ///
103   /// Some files contain many object files, and this function allows access to
104   /// an object's offset within the file.
105   ///
106   /// @return
107   ///     The offset in bytes into the file. Defaults to zero for
108   ///     simple object files that a represented by an entire file.
109   //------------------------------------------------------------------
110   virtual lldb::addr_t GetOffset() const { return m_offset; }
111
112   virtual lldb::addr_t GetByteSize() const { return m_length; }
113
114   //------------------------------------------------------------------
115   /// Get the number of objects within this object file (archives).
116   ///
117   /// @return
118   ///     Zero for object files that are not archives, or the number
119   ///     of objects contained in the archive.
120   //------------------------------------------------------------------
121   virtual size_t GetNumObjects() const { return 0; }
122
123   //------------------------------------------------------------------
124   /// Get the number of architectures in this object file.
125   ///
126   /// The default implementation returns 1 as for object files that contain a
127   /// single architecture. ObjectContainer instances that contain more than
128   /// one architecture should override this function and return an appropriate
129   /// value.
130   ///
131   /// @return
132   ///     The number of architectures contained in this object file.
133   //------------------------------------------------------------------
134   virtual size_t GetNumArchitectures() const { return 0; }
135
136   //------------------------------------------------------------------
137   /// Attempts to parse the object header.
138   ///
139   /// This function is used as a test to see if a given plug-in instance can
140   /// parse the header data already contained in ObjectContainer::m_data. If
141   /// an object file parser does not recognize that magic bytes in a header,
142   /// false should be returned and the next plug-in can attempt to parse an
143   /// object file.
144   ///
145   /// @return
146   ///     Returns \b true if the header was parsed successfully, \b
147   ///     false otherwise.
148   //------------------------------------------------------------------
149   virtual bool ParseHeader() = 0;
150
151   //------------------------------------------------------------------
152   /// Selects an architecture in an object file.
153   ///
154   /// Object files that contain a single architecture should verify that the
155   /// specified \a arch matches the architecture in in object file and return
156   /// \b true or \b false accordingly.
157   ///
158   /// Object files that contain more than one architecture should attempt to
159   /// select that architecture, and if successful, clear out any previous
160   /// state from any previously selected architecture and prepare to return
161   /// information for the new architecture.
162   ///
163   /// @return
164   ///     Returns a pointer to the object file of the requested \a
165   ///     arch and optional \a name. Returns nullptr of no such object
166   ///     file exists in the container.
167   //------------------------------------------------------------------
168   virtual lldb::ObjectFileSP GetObjectFile(const FileSpec *file) = 0;
169
170   virtual bool ObjectAtIndexIsContainer(uint32_t object_idx) { return false; }
171
172   virtual ObjectFile *GetObjectFileAtIndex(uint32_t object_idx) {
173     return nullptr;
174   }
175
176   virtual ObjectContainer *GetObjectContainerAtIndex(uint32_t object_idx) {
177     return nullptr;
178   }
179
180   virtual const char *GetObjectNameAtIndex(uint32_t object_idx) const {
181     return nullptr;
182   }
183
184 protected:
185   //------------------------------------------------------------------
186   // Member variables.
187   //------------------------------------------------------------------
188   FileSpec m_file; ///< The file that represents this container objects (which
189                    ///can be different from the module's file).
190   lldb::addr_t
191       m_offset; ///< The offset in bytes into the file, or the address in memory
192   lldb::addr_t m_length; ///< The size in bytes if known (can be zero).
193   DataExtractor
194       m_data; ///< The data for this object file so things can be parsed lazily.
195
196 private:
197   DISALLOW_COPY_AND_ASSIGN(ObjectContainer);
198 };
199
200 } // namespace lldb_private
201
202 #endif // liblldb_ObjectContainer_h_