ObjectContainerBSDArchive.h revision 314564
1254721Semaste//===-- ObjectContainerBSDArchive.h -----------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#ifndef liblldb_ObjectContainerBSDArchive_h_ 11254721Semaste#define liblldb_ObjectContainerBSDArchive_h_ 12254721Semaste 13296417Sdim// Project includes 14254721Semaste#include "lldb/Core/ArchSpec.h" 15254721Semaste#include "lldb/Core/ConstString.h" 16314564Sdim#include "lldb/Core/UniqueCStringMap.h" 17254721Semaste#include "lldb/Host/FileSpec.h" 18314564Sdim#include "lldb/Symbol/ObjectContainer.h" 19254721Semaste 20314564Sdim// Other libraries and framework includes 21314564Sdim#include "llvm/Support/Chrono.h" 22314564Sdim 23314564Sdim// C Includes 24314564Sdim// C++ Includes 25314564Sdim#include <mutex> 26314564Sdim 27314564Sdimclass ObjectContainerBSDArchive : public lldb_private::ObjectContainer { 28254721Semastepublic: 29314564Sdim ObjectContainerBSDArchive(const lldb::ModuleSP &module_sp, 30314564Sdim lldb::DataBufferSP &data_sp, 31314564Sdim lldb::offset_t data_offset, 32314564Sdim const lldb_private::FileSpec *file, 33314564Sdim lldb::offset_t offset, lldb::offset_t length); 34254721Semaste 35314564Sdim ~ObjectContainerBSDArchive() override; 36296417Sdim 37314564Sdim //------------------------------------------------------------------ 38314564Sdim // Static Functions 39314564Sdim //------------------------------------------------------------------ 40314564Sdim static void Initialize(); 41254721Semaste 42314564Sdim static void Terminate(); 43254721Semaste 44314564Sdim static lldb_private::ConstString GetPluginNameStatic(); 45254721Semaste 46314564Sdim static const char *GetPluginDescriptionStatic(); 47254721Semaste 48314564Sdim static lldb_private::ObjectContainer * 49314564Sdim CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, 50314564Sdim lldb::offset_t data_offset, const lldb_private::FileSpec *file, 51314564Sdim lldb::offset_t offset, lldb::offset_t length); 52254721Semaste 53314564Sdim static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, 54314564Sdim lldb::DataBufferSP &data_sp, 55314564Sdim lldb::offset_t data_offset, 56314564Sdim lldb::offset_t file_offset, 57314564Sdim lldb::offset_t length, 58314564Sdim lldb_private::ModuleSpecList &specs); 59254721Semaste 60314564Sdim static bool MagicBytesMatch(const lldb_private::DataExtractor &data); 61254721Semaste 62314564Sdim //------------------------------------------------------------------ 63314564Sdim // Member Functions 64314564Sdim //------------------------------------------------------------------ 65314564Sdim bool ParseHeader() override; 66254721Semaste 67314564Sdim size_t GetNumObjects() const override { 68314564Sdim if (m_archive_sp) 69314564Sdim return m_archive_sp->GetNumObjects(); 70314564Sdim return 0; 71314564Sdim } 72254721Semaste 73314564Sdim void Dump(lldb_private::Stream *s) const override; 74254721Semaste 75314564Sdim lldb::ObjectFileSP GetObjectFile(const lldb_private::FileSpec *file) override; 76296417Sdim 77314564Sdim //------------------------------------------------------------------ 78314564Sdim // PluginInterface protocol 79314564Sdim //------------------------------------------------------------------ 80314564Sdim lldb_private::ConstString GetPluginName() override; 81254721Semaste 82314564Sdim uint32_t GetPluginVersion() override; 83254721Semaste 84254721Semasteprotected: 85314564Sdim struct Object { 86314564Sdim Object(); 87254721Semaste 88314564Sdim void Clear(); 89254721Semaste 90314564Sdim lldb::offset_t Extract(const lldb_private::DataExtractor &data, 91314564Sdim lldb::offset_t offset); 92254721Semaste 93314564Sdim lldb_private::ConstString ar_name; // name 94314564Sdim uint32_t ar_date; // modification time 95314564Sdim uint16_t ar_uid; // user id 96314564Sdim uint16_t ar_gid; // group id 97314564Sdim uint16_t ar_mode; // octal file permissions 98314564Sdim uint32_t ar_size; // size in bytes 99314564Sdim lldb::offset_t ar_file_offset; // file offset in bytes from the beginning of 100314564Sdim // the file of the object data 101314564Sdim lldb::offset_t ar_file_size; // length of the object data 102254721Semaste 103314564Sdim typedef std::vector<Object> collection; 104314564Sdim typedef collection::iterator iterator; 105314564Sdim typedef collection::const_iterator const_iterator; 106314564Sdim }; 107254721Semaste 108314564Sdim class Archive { 109314564Sdim public: 110314564Sdim typedef std::shared_ptr<Archive> shared_ptr; 111314564Sdim typedef std::multimap<lldb_private::FileSpec, shared_ptr> Map; 112254721Semaste 113314564Sdim Archive(const lldb_private::ArchSpec &arch, 114314564Sdim const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset, 115314564Sdim lldb_private::DataExtractor &data); 116296417Sdim 117314564Sdim ~Archive(); 118296417Sdim 119314564Sdim static Map &GetArchiveCache(); 120254721Semaste 121314564Sdim static std::recursive_mutex &GetArchiveCacheMutex(); 122254721Semaste 123314564Sdim static Archive::shared_ptr FindCachedArchive( 124314564Sdim const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch, 125314564Sdim const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset); 126254721Semaste 127314564Sdim static Archive::shared_ptr ParseAndCacheArchiveForFile( 128314564Sdim const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch, 129314564Sdim const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset, 130314564Sdim lldb_private::DataExtractor &data); 131254721Semaste 132314564Sdim size_t GetNumObjects() const { return m_objects.size(); } 133254721Semaste 134314564Sdim const Object *GetObjectAtIndex(size_t idx) { 135314564Sdim if (idx < m_objects.size()) 136314564Sdim return &m_objects[idx]; 137314564Sdim return NULL; 138314564Sdim } 139254721Semaste 140314564Sdim size_t ParseObjects(); 141254721Semaste 142314564Sdim Object *FindObject(const lldb_private::ConstString &object_name, 143314564Sdim const llvm::sys::TimePoint<> &object_mod_time); 144254721Semaste 145314564Sdim lldb::offset_t GetFileOffset() const { return m_file_offset; } 146254721Semaste 147314564Sdim const llvm::sys::TimePoint<> &GetModificationTime() { return m_time; } 148254721Semaste 149314564Sdim const lldb_private::ArchSpec &GetArchitecture() const { return m_arch; } 150254721Semaste 151314564Sdim void SetArchitecture(const lldb_private::ArchSpec &arch) { m_arch = arch; } 152254721Semaste 153314564Sdim bool HasNoExternalReferences() const; 154254721Semaste 155314564Sdim lldb_private::DataExtractor &GetData() { return m_data; } 156254721Semaste 157314564Sdim protected: 158314564Sdim typedef lldb_private::UniqueCStringMap<uint32_t> ObjectNameToIndexMap; 159314564Sdim //---------------------------------------------------------------------- 160314564Sdim // Member Variables 161314564Sdim //---------------------------------------------------------------------- 162314564Sdim lldb_private::ArchSpec m_arch; 163314564Sdim llvm::sys::TimePoint<> m_time; 164314564Sdim lldb::offset_t m_file_offset; 165314564Sdim Object::collection m_objects; 166314564Sdim ObjectNameToIndexMap m_object_name_to_index_map; 167314564Sdim lldb_private::DataExtractor m_data; ///< The data for this object container 168314564Sdim ///so we don't lose data if the .a files 169314564Sdim ///gets modified 170314564Sdim }; 171254721Semaste 172314564Sdim void SetArchive(Archive::shared_ptr &archive_sp); 173254721Semaste 174314564Sdim Archive::shared_ptr m_archive_sp; 175254721Semaste}; 176254721Semaste 177296417Sdim#endif // liblldb_ObjectContainerBSDArchive_h_ 178