LLDB mainline
ObjectContainerBSDArchive.h
Go to the documentation of this file.
1//===-- ObjectContainerBSDArchive.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_SOURCE_PLUGINS_OBJECTCONTAINER_BSD_ARCHIVE_OBJECTCONTAINERBSDARCHIVE_H
10#define LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_BSD_ARCHIVE_OBJECTCONTAINERBSDARCHIVE_H
11
19
20#include "llvm/Object/Archive.h"
21#include "llvm/Support/Chrono.h"
22#include "llvm/Support/Path.h"
23
24#include <map>
25#include <memory>
26#include <mutex>
27
29
31public:
33 lldb::DataBufferSP &data_sp,
34 lldb::offset_t data_offset,
35 const lldb_private::FileSpec *file,
36 lldb::offset_t offset, lldb::offset_t length,
37 ArchiveType archive_type);
38
40
41 // Static Functions
42 static void Initialize();
43
44 static void Terminate();
45
46 static llvm::StringRef GetPluginNameStatic() { return "bsd-archive"; }
47
48 static llvm::StringRef GetPluginDescriptionStatic() {
49 return "BSD Archive object container reader.";
50 }
51
53 CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
54 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
55 lldb::offset_t offset, lldb::offset_t length);
56
57 static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
58 lldb::DataBufferSP &data_sp,
59 lldb::offset_t data_offset,
60 lldb::offset_t file_offset,
61 lldb::offset_t length,
63
64 static ArchiveType
66
67 // Member Functions
68 bool ParseHeader() override;
69
70 size_t GetNumObjects() const override {
71 if (m_archive_sp)
72 return m_archive_sp->GetNumObjects();
73 return 0;
74 }
75
77
78 // PluginInterface protocol
79 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
80
81protected:
82 struct Object {
83 Object();
84
85 void Clear();
86
88 lldb::offset_t offset,
89 llvm::StringRef stringTable);
90
92 lldb::offset_t offset);
93 /// Object name in the archive.
95
96 /// Object modification time in the archive.
97 uint32_t modification_time = 0;
98
99 /// Object size in bytes in the archive.
100 uint32_t size = 0;
101
102 /// File offset in bytes from the beginning of the file of the object data.
104
105 /// Length of the object data.
107
108 void Dump() const;
109 };
110
111 class Archive {
112 public:
113 typedef std::shared_ptr<Archive> shared_ptr;
114 typedef std::multimap<lldb_private::FileSpec, shared_ptr> Map;
115
117 const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
118 lldb::DataExtractorSP extractor_sp, ArchiveType archive_type);
119
121
122 static Map &GetArchiveCache();
123
124 static std::recursive_mutex &GetArchiveCacheMutex();
125
127 const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch,
128 const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset);
129
131 const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch,
132 const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
133 lldb::DataExtractorSP extractor_sp, ArchiveType archive_type);
134
135 size_t GetNumObjects() const { return m_objects.size(); }
136
137 const Object *GetObjectAtIndex(size_t idx) {
138 if (idx < m_objects.size())
139 return &m_objects[idx];
140 return nullptr;
141 }
142
143 size_t ParseObjects();
144
146 const llvm::sys::TimePoint<> &object_mod_time);
147
149
150 const llvm::sys::TimePoint<> &GetModificationTime() {
151 return m_modification_time;
152 }
153
155
156 void SetArchitecture(const lldb_private::ArchSpec &arch) { m_arch = arch; }
157
159
162
164
165 protected:
167 // Member Variables
169 llvm::sys::TimePoint<> m_modification_time;
171 std::vector<Object> m_objects;
173 /// The data for this object container so we don't lose data if the .a files
174 /// gets modified.
177 };
178
179 void SetArchive(Archive::shared_ptr &archive_sp);
180
182
184};
185
186#endif // LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_BSD_ARCHIVE_OBJECTCONTAINERBSDARCHIVE_H
const lldb_private::ArchSpec & GetArchitecture() const
Object * FindObject(lldb_private::ConstString object_name, const llvm::sys::TimePoint<> &object_mod_time)
lldb_private::UniqueCStringMap< uint32_t > ObjectNameToIndexMap
lldb::DataExtractorSP m_extractor_sp
The data for this object container so we don't lose data if the .a files gets modified.
static std::recursive_mutex & GetArchiveCacheMutex()
static Archive::shared_ptr ParseAndCacheArchiveForFile(const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch, const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset, lldb::DataExtractorSP extractor_sp, ArchiveType archive_type)
std::multimap< lldb_private::FileSpec, shared_ptr > Map
const llvm::sys::TimePoint & GetModificationTime()
lldb_private::DataExtractor & GetData()
void SetArchitecture(const lldb_private::ArchSpec &arch)
Archive(const lldb_private::ArchSpec &arch, const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset, lldb::DataExtractorSP extractor_sp, ArchiveType archive_type)
static Archive::shared_ptr FindCachedArchive(const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch, const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset)
static lldb_private::ObjectContainer * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t offset, lldb::offset_t length)
size_t GetNumObjects() const override
Get the number of objects within this object file (archives).
llvm::StringRef GetPluginName() override
static llvm::StringRef GetPluginNameStatic()
lldb::ObjectFileSP GetObjectFile(const lldb_private::FileSpec *file) override
Selects an architecture in an object file.
bool ParseHeader() override
Attempts to parse the object header.
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, lldb::offset_t file_offset, lldb::offset_t length, lldb_private::ModuleSpecList &specs)
static llvm::StringRef GetPluginDescriptionStatic()
static ArchiveType MagicBytesMatch(const lldb_private::DataExtractor &extractor)
~ObjectContainerBSDArchive() override
void SetArchive(Archive::shared_ptr &archive_sp)
ObjectContainerBSDArchive(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t offset, lldb::offset_t length, ArchiveType archive_type)
An architecture specification class.
Definition ArchSpec.h:31
A uniqued constant string class.
Definition ConstString.h:40
An data extractor class.
A file utility class.
Definition FileSpec.h:57
A plug-in interface definition class for object containers.
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
lldb::offset_t ExtractFromThin(const lldb_private::DataExtractor &extractor, lldb::offset_t offset, llvm::StringRef stringTable)
uint32_t size
Object size in bytes in the archive.
uint32_t modification_time
Object modification time in the archive.
lldb_private::ConstString ar_name
Object name in the archive.
lldb::offset_t Extract(const lldb_private::DataExtractor &extractor, lldb::offset_t offset)
lldb::offset_t file_size
Length of the object data.
lldb::offset_t file_offset
File offset in bytes from the beginning of the file of the object data.