LLDB  mainline
ObjectContainer.h
Go to the documentation of this file.
1 //===-- ObjectContainer.h ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SYMBOL_OBJECTCONTAINER_H
10 #define LLDB_SYMBOL_OBJECTCONTAINER_H
11 
12 #include "lldb/Core/ModuleChild.h"
15 #include "lldb/Utility/Endian.h"
16 #include "lldb/Utility/FileSpec.h"
17 #include "lldb/lldb-private.h"
18 
19 namespace lldb_private {
20 
21 /// \class ObjectContainer ObjectContainer.h "lldb/Symbol/ObjectContainer.h"
22 /// A plug-in interface definition class for object containers.
23 ///
24 /// Object containers contain object files from one or more architectures, and
25 /// also can contain one or more named objects.
26 ///
27 /// Typical object containers are static libraries (.a files) that contain
28 /// multiple named object files, and universal files that contain multiple
29 /// architectures.
31 public:
32  /// Construct with a parent module, offset, and header data.
33  ///
34  /// Object files belong to modules and a valid module must be supplied upon
35  /// construction. The at an offset within a file for objects that contain
36  /// more than one architecture or object.
37  ObjectContainer(const lldb::ModuleSP &module_sp, const FileSpec *file,
38  lldb::offset_t file_offset, lldb::offset_t length,
39  lldb::DataBufferSP data_sp, lldb::offset_t data_offset);
40 
41  /// Destructor.
42  ///
43  /// The destructor is virtual since this class is designed to be inherited
44  /// from by the plug-in instance.
45  ~ObjectContainer() override = default;
46 
47  /// Gets the architecture given an index.
48  ///
49  /// Copies the architecture specification for index \a idx.
50  ///
51  /// \param[in] idx
52  /// The architecture index to extract.
53  ///
54  /// \param[out] arch
55  /// A architecture object that will be filled in if \a idx is a
56  /// architecture valid index.
57  ///
58  /// \return
59  /// Returns \b true if \a idx is valid and \a arch has been
60  /// filled in, \b false otherwise.
61  ///
62  /// \see ObjectContainer::GetNumArchitectures() const
63  virtual bool GetArchitectureAtIndex(uint32_t idx, ArchSpec &arch) const {
64  return false;
65  }
66 
67  /// Returns the offset into a file at which this object resides.
68  ///
69  /// Some files contain many object files, and this function allows access to
70  /// an object's offset within the file.
71  ///
72  /// \return
73  /// The offset in bytes into the file. Defaults to zero for
74  /// simple object files that a represented by an entire file.
75  virtual lldb::addr_t GetOffset() const { return m_offset; }
76 
77  virtual lldb::addr_t GetByteSize() const { return m_length; }
78 
79  /// Get the number of objects within this object file (archives).
80  ///
81  /// \return
82  /// Zero for object files that are not archives, or the number
83  /// of objects contained in the archive.
84  virtual size_t GetNumObjects() const { return 0; }
85 
86  /// Get the number of architectures in this object file.
87  ///
88  /// The default implementation returns 1 as for object files that contain a
89  /// single architecture. ObjectContainer instances that contain more than
90  /// one architecture should override this function and return an appropriate
91  /// value.
92  ///
93  /// \return
94  /// The number of architectures contained in this object file.
95  virtual size_t GetNumArchitectures() const { return 0; }
96 
97  /// Attempts to parse the object header.
98  ///
99  /// This function is used as a test to see if a given plug-in instance can
100  /// parse the header data already contained in ObjectContainer::m_data. If
101  /// an object file parser does not recognize that magic bytes in a header,
102  /// false should be returned and the next plug-in can attempt to parse an
103  /// object file.
104  ///
105  /// \return
106  /// Returns \b true if the header was parsed successfully, \b
107  /// false otherwise.
108  virtual bool ParseHeader() = 0;
109 
110  /// Selects an architecture in an object file.
111  ///
112  /// Object files that contain a single architecture should verify that the
113  /// specified \a arch matches the architecture in in object file and return
114  /// \b true or \b false accordingly.
115  ///
116  /// Object files that contain more than one architecture should attempt to
117  /// select that architecture, and if successful, clear out any previous
118  /// state from any previously selected architecture and prepare to return
119  /// information for the new architecture.
120  ///
121  /// \return
122  /// Returns a pointer to the object file of the requested \a
123  /// arch and optional \a name. Returns nullptr of no such object
124  /// file exists in the container.
125  virtual lldb::ObjectFileSP GetObjectFile(const FileSpec *file) = 0;
126 
127  static lldb::ObjectContainerSP
128  FindPlugin(const lldb::ModuleSP &module_sp, const lldb::ProcessSP &process_sp,
129  lldb::addr_t header_addr, lldb::WritableDataBufferSP file_data_sp);
130 
131 protected:
132  /// The file that represents this container objects (which can be different
133  /// from the module's file).
135 
136  /// The offset in bytes into the file, or the address in memory
138 
139  /// The size in bytes if known (can be zero).
141 
142  /// The data for this object file so things can be parsed lazily.
144 
145 private:
146  ObjectContainer(const ObjectContainer &) = delete;
147  const ObjectContainer &operator=(const ObjectContainer &) = delete;
148 };
149 
150 } // namespace lldb_private
151 
152 #endif // LLDB_SYMBOL_OBJECTCONTAINER_H
lldb_private::ObjectContainer::GetByteSize
virtual lldb::addr_t GetByteSize() const
Definition: ObjectContainer.h:77
lldb_private::ArchSpec
Definition: ArchSpec.h:32
lldb_private::ModuleChild
Definition: ModuleChild.h:19
lldb_private::PluginInterface
Definition: PluginInterface.h:16
lldb_private::ObjectContainer
Definition: ObjectContainer.h:30
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::ObjectContainer::m_data
DataExtractor m_data
The data for this object file so things can be parsed lazily.
Definition: ObjectContainer.h:143
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::ObjectContainer::GetNumArchitectures
virtual size_t GetNumArchitectures() const
Get the number of architectures in this object file.
Definition: ObjectContainer.h:95
lldb_private::ObjectContainer::GetObjectFile
virtual lldb::ObjectFileSP GetObjectFile(const FileSpec *file)=0
Selects an architecture in an object file.
lldb_private::FileSpec
Definition: FileSpec.h:55
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::ObjectContainer::m_offset
lldb::addr_t m_offset
The offset in bytes into the file, or the address in memory.
Definition: ObjectContainer.h:137
PluginInterface.h
lldb_private::ObjectContainer::operator=
const ObjectContainer & operator=(const ObjectContainer &)=delete
lldb_private::ObjectContainer::m_file
FileSpec m_file
The file that represents this container objects (which can be different from the module's file).
Definition: ObjectContainer.h:134
lldb_private::ObjectContainer::FindPlugin
static lldb::ObjectContainerSP FindPlugin(const lldb::ModuleSP &module_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, lldb::WritableDataBufferSP file_data_sp)
Definition: ObjectContainer.cpp:33
lldb_private::ObjectContainer::GetArchitectureAtIndex
virtual bool GetArchitectureAtIndex(uint32_t idx, ArchSpec &arch) const
Gets the architecture given an index.
Definition: ObjectContainer.h:63
lldb-private.h
lldb_private::ObjectContainer::ParseHeader
virtual bool ParseHeader()=0
Attempts to parse the object header.
uint32_t
ModuleChild.h
lldb_private::ObjectContainer::~ObjectContainer
~ObjectContainer() override=default
Destructor.
DataExtractor.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ObjectContainer::GetOffset
virtual lldb::addr_t GetOffset() const
Returns the offset into a file at which this object resides.
Definition: ObjectContainer.h:75
FileSpec.h
lldb_private::ObjectContainer::m_length
lldb::addr_t m_length
The size in bytes if known (can be zero).
Definition: ObjectContainer.h:140
lldb_private::ObjectContainer::ObjectContainer
ObjectContainer(const lldb::ModuleSP &module_sp, const FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataBufferSP data_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
Definition: ObjectContainer.cpp:18
lldb_private::ObjectContainer::GetNumObjects
virtual size_t GetNumObjects() const
Get the number of objects within this object file (archives).
Definition: ObjectContainer.h:84
Endian.h