ObjectContainer.h revision 321369
1139825Simp//===-- ObjectContainer.h ---------------------------------------*- C++ -*-===// 2103620Sgrehan// 3103620Sgrehan// The LLVM Compiler Infrastructure 4103620Sgrehan// 5103620Sgrehan// This file is distributed under the University of Illinois Open Source 6103620Sgrehan// License. See LICENSE.TXT for details. 7103620Sgrehan// 8103620Sgrehan//===----------------------------------------------------------------------===// 9103620Sgrehan 10103620Sgrehan#ifndef liblldb_ObjectContainer_h_ 11103620Sgrehan#define liblldb_ObjectContainer_h_ 12103620Sgrehan 13103620Sgrehan// C Includes 14103620Sgrehan// C++ Includes 15103620Sgrehan// Other libraries and framework includes 16103620Sgrehan// Project includes 17103620Sgrehan#include "lldb/Core/ModuleChild.h" 18103620Sgrehan#include "lldb/Core/PluginInterface.h" 19103620Sgrehan#include "lldb/Utility/DataExtractor.h" 20103620Sgrehan#include "lldb/Utility/Endian.h" 21103620Sgrehan#include "lldb/Utility/FileSpec.h" 22103620Sgrehan#include "lldb/lldb-private.h" 23103620Sgrehan 24103620Sgrehannamespace lldb_private { 25103620Sgrehan 26103620Sgrehan//---------------------------------------------------------------------- 27103620Sgrehan/// @class ObjectContainer ObjectContainer.h "lldb/Symbol/ObjectContainer.h" 28103620Sgrehan/// @brief A plug-in interface definition class for object containers. 29103620Sgrehan/// 30103620Sgrehan/// Object containers contain object files from one or more 31103620Sgrehan/// architectures, and also can contain one or more named objects. 32103620Sgrehan/// 33103620Sgrehan/// Typical object containers are static libraries (.a files) that 34103620Sgrehan/// contain multiple named object files, and universal files that contain 35103620Sgrehan/// multiple architectures. 36103620Sgrehan//---------------------------------------------------------------------- 37103620Sgrehanclass ObjectContainer : public PluginInterface, public ModuleChild { 38103620Sgrehanpublic: 39103620Sgrehan //------------------------------------------------------------------ 40103620Sgrehan /// Construct with a parent module, offset, and header data. 41103620Sgrehan /// 42131102Sgrehan /// Object files belong to modules and a valid module must be 43103620Sgrehan /// supplied upon construction. The at an offset within a file for 44103620Sgrehan /// objects that contain more than one architecture or object. 45103620Sgrehan //------------------------------------------------------------------ 46103620Sgrehan ObjectContainer(const lldb::ModuleSP &module_sp, const FileSpec *file, 47183882Snwhitehorn lldb::offset_t file_offset, lldb::offset_t length, 48103620Sgrehan lldb::DataBufferSP &data_sp, lldb::offset_t data_offset) 49103620Sgrehan : ModuleChild(module_sp), 50103620Sgrehan m_file(), // This file can be different than the module's file spec 51103620Sgrehan m_offset(file_offset), m_length(length), m_data() { 52103620Sgrehan if (file) 53103620Sgrehan m_file = *file; 54103620Sgrehan if (data_sp) 55103620Sgrehan m_data.SetData(data_sp, data_offset, length); 56103620Sgrehan } 57103620Sgrehan 58131400Sgrehan //------------------------------------------------------------------ 59131400Sgrehan /// Destructor. 60131400Sgrehan /// 61131400Sgrehan /// The destructor is virtual since this class is designed to be 62131400Sgrehan /// inherited from by the plug-in instance. 63131400Sgrehan //------------------------------------------------------------------ 64131400Sgrehan ~ObjectContainer() override = default; 65103620Sgrehan 66103620Sgrehan //------------------------------------------------------------------ 67103620Sgrehan /// Dump a description of this object to a Stream. 68103620Sgrehan /// 69103620Sgrehan /// Dump a description of the current contents of this object 70103620Sgrehan /// to the supplied stream \a s. The dumping should include the 71103620Sgrehan /// section list if it has been parsed, and the symbol table 72103620Sgrehan /// if it has been parsed. 73103620Sgrehan /// 74294883Sjhibbits /// @param[in] s 75294883Sjhibbits /// The stream to which to dump the object description. 76103620Sgrehan //------------------------------------------------------------------ 77103620Sgrehan virtual void Dump(Stream *s) const = 0; 78103620Sgrehan 79103620Sgrehan //------------------------------------------------------------------ 80103620Sgrehan /// Gets the architecture given an index. 81103620Sgrehan /// 82103620Sgrehan /// Copies the architecture specification for index \a idx. 83103620Sgrehan /// 84103620Sgrehan /// @param[in] idx 85103620Sgrehan /// The architecture index to extract. 86103620Sgrehan /// 87103620Sgrehan /// @param[out] arch 88103620Sgrehan /// A architecture object that will be filled in if \a idx is a 89103620Sgrehan /// architecture valid index. 90103620Sgrehan /// 91103620Sgrehan /// @return 92103620Sgrehan /// Returns \b true if \a idx is valid and \a arch has been 93103620Sgrehan /// filled in, \b false otherwise. 94103620Sgrehan /// 95103620Sgrehan /// @see ObjectContainer::GetNumArchitectures() const 96103620Sgrehan //------------------------------------------------------------------ 97103620Sgrehan virtual bool GetArchitectureAtIndex(uint32_t idx, ArchSpec &arch) const { 98103620Sgrehan return false; 99103620Sgrehan } 100103620Sgrehan 101103620Sgrehan //------------------------------------------------------------------ 102103620Sgrehan /// Returns the offset into a file at which this object resides. 103103620Sgrehan /// 104103620Sgrehan /// Some files contain many object files, and this function allows 105103620Sgrehan /// access to an object's offset within the file. 106103620Sgrehan /// 107103620Sgrehan /// @return 108103620Sgrehan /// The offset in bytes into the file. Defaults to zero for 109103620Sgrehan /// simple object files that a represented by an entire file. 110103620Sgrehan //------------------------------------------------------------------ 111103620Sgrehan virtual lldb::addr_t GetOffset() const { return m_offset; } 112103620Sgrehan 113103620Sgrehan virtual lldb::addr_t GetByteSize() const { return m_length; } 114103620Sgrehan 115103620Sgrehan //------------------------------------------------------------------ 116103620Sgrehan /// Get the number of objects within this object file (archives). 117103620Sgrehan /// 118103620Sgrehan /// @return 119261513Snwhitehorn /// Zero for object files that are not archives, or the number 120103620Sgrehan /// of objects contained in the archive. 121103620Sgrehan //------------------------------------------------------------------ 122103620Sgrehan virtual size_t GetNumObjects() const { return 0; } 123103620Sgrehan 124183882Snwhitehorn //------------------------------------------------------------------ 125103620Sgrehan /// Get the number of architectures in this object file. 126103620Sgrehan /// 127103620Sgrehan /// The default implementation returns 1 as for object files that 128103620Sgrehan /// contain a single architecture. ObjectContainer instances that 129103620Sgrehan /// contain more than one architecture should override this function 130103620Sgrehan /// and return an appropriate value. 131103620Sgrehan /// 132103620Sgrehan /// @return 133103620Sgrehan /// The number of architectures contained in this object file. 134103620Sgrehan //------------------------------------------------------------------ 135103620Sgrehan virtual size_t GetNumArchitectures() const { return 0; } 136103620Sgrehan 137103620Sgrehan //------------------------------------------------------------------ 138103620Sgrehan /// Attempts to parse the object header. 139103620Sgrehan /// 140103620Sgrehan /// This function is used as a test to see if a given plug-in 141103620Sgrehan /// instance can parse the header data already contained in 142103620Sgrehan /// ObjectContainer::m_data. If an object file parser does not 143103620Sgrehan /// recognize that magic bytes in a header, false should be returned 144103620Sgrehan /// and the next plug-in can attempt to parse an object file. 145103620Sgrehan /// 146103620Sgrehan /// @return 147103620Sgrehan /// Returns \b true if the header was parsed successfully, \b 148103620Sgrehan /// false otherwise. 149103620Sgrehan //------------------------------------------------------------------ 150103620Sgrehan virtual bool ParseHeader() = 0; 151103620Sgrehan 152103620Sgrehan //------------------------------------------------------------------ 153103620Sgrehan /// Selects an architecture in an object file. 154103620Sgrehan /// 155103620Sgrehan /// Object files that contain a single architecture should verify 156103620Sgrehan /// that the specified \a arch matches the architecture in in 157103620Sgrehan /// object file and return \b true or \b false accordingly. 158103620Sgrehan /// 159103620Sgrehan /// Object files that contain more than one architecture should 160103620Sgrehan /// attempt to select that architecture, and if successful, clear 161103620Sgrehan /// out any previous state from any previously selected architecture 162103620Sgrehan /// and prepare to return information for the new architecture. 163103620Sgrehan /// 164103620Sgrehan /// @return 165103620Sgrehan /// Returns a pointer to the object file of the requested \a 166103620Sgrehan /// arch and optional \a name. Returns nullptr of no such object 167103620Sgrehan /// file exists in the container. 168103620Sgrehan //------------------------------------------------------------------ 169103620Sgrehan virtual lldb::ObjectFileSP GetObjectFile(const FileSpec *file) = 0; 170103620Sgrehan 171103620Sgrehan virtual bool ObjectAtIndexIsContainer(uint32_t object_idx) { return false; } 172103620Sgrehan 173103620Sgrehan virtual ObjectFile *GetObjectFileAtIndex(uint32_t object_idx) { 174103620Sgrehan return nullptr; 175103620Sgrehan } 176103620Sgrehan 177103620Sgrehan virtual ObjectContainer *GetObjectContainerAtIndex(uint32_t object_idx) { 178103620Sgrehan return nullptr; 179103620Sgrehan } 180103620Sgrehan 181103620Sgrehan virtual const char *GetObjectNameAtIndex(uint32_t object_idx) const { 182103620Sgrehan return nullptr; 183103620Sgrehan } 184103620Sgrehan 185103620Sgrehanprotected: 186103620Sgrehan //------------------------------------------------------------------ 187103620Sgrehan // Member variables. 188103620Sgrehan //------------------------------------------------------------------ 189103620Sgrehan FileSpec m_file; ///< The file that represents this container objects (which 190103620Sgrehan ///can be different from the module's file). 191103620Sgrehan lldb::addr_t 192103620Sgrehan m_offset; ///< The offset in bytes into the file, or the address in memory 193183882Snwhitehorn lldb::addr_t m_length; ///< The size in bytes if known (can be zero). 194103620Sgrehan DataExtractor 195103620Sgrehan m_data; ///< The data for this object file so things can be parsed lazily. 196103620Sgrehan 197103620Sgrehanprivate: 198103620Sgrehan DISALLOW_COPY_AND_ASSIGN(ObjectContainer); 199103620Sgrehan}; 200103620Sgrehan 201103620Sgrehan} // namespace lldb_private 202103620Sgrehan 203103620Sgrehan#endif // liblldb_ObjectContainer_h_ 204103620Sgrehan