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
59 lldb::DataExtractorSP &extractor_sp,
60 lldb::offset_t file_offset, lldb::offset_t length);
61
62 static ArchiveType
64
65 // Member Functions
66 bool ParseHeader() override;
67
68 size_t GetNumObjects() const override {
69 if (m_archive_sp)
70 return m_archive_sp->GetNumObjects();
71 return 0;
72 }
73
75
76 // PluginInterface protocol
77 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
78
79protected:
80 struct Object {
81 Object();
82
83 void Clear();
84
85 /// Object name in the archive.
86 std::string ar_name;
87
88 /// Object modification time in the archive.
89 uint32_t modification_time = 0;
90
91 /// Object size in bytes in the archive.
92 uint32_t size = 0;
93
94 /// File offset in bytes from the beginning of the file of the object data.
96
97 /// Length of the object data.
99
100 void Dump() const;
101 };
102
103 class Archive;
104 typedef std::shared_ptr<Archive> ArchiveSP;
105
106 class Archive {
107 public:
108 typedef std::multimap<lldb_private::FileSpec, ArchiveSP> Map;
109
111 const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
112 lldb::DataExtractorSP extractor_sp, ArchiveType archive_type);
113
115
116 static Map &GetArchiveCache();
117
118 static std::recursive_mutex &GetArchiveCacheMutex();
119
121 const lldb_private::ArchSpec &arch,
122 const llvm::sys::TimePoint<> &mod_time,
123 lldb::offset_t file_offset);
124
126 const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch,
127 const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
128 lldb::DataExtractorSP extractor_sp, ArchiveType archive_type);
129
130 size_t GetNumObjects() const { return m_objects.size(); }
131
132 const Object *GetObjectAtIndex(size_t idx) {
133 if (idx < m_objects.size())
134 return &m_objects[idx];
135 return nullptr;
136 }
137
138 size_t ParseObjects();
139
140 Object *FindObject(llvm::StringRef object_name,
141 const llvm::sys::TimePoint<> &object_mod_time);
142
144
145 const llvm::sys::TimePoint<> &GetModificationTime() {
146 return m_modification_time;
147 }
148
150
151 void SetArchitecture(const lldb_private::ArchSpec &arch) { m_arch = arch; }
152
154
157
159
160 protected:
161 typedef llvm::StringMap<llvm::SmallVector<uint32_t, 1>>
163 // Member Variables
165 llvm::sys::TimePoint<> m_modification_time;
167 std::vector<Object> m_objects;
169 /// The data for this object container so we don't lose data if the .a files
170 /// gets modified.
173 };
174
175 void SetArchive(ArchiveSP &archive_sp);
176
178
180};
181
182#endif // LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_BSD_ARCHIVE_OBJECTCONTAINERBSDARCHIVE_H
const lldb_private::ArchSpec & GetArchitecture() const
Object * FindObject(llvm::StringRef object_name, const llvm::sys::TimePoint<> &object_mod_time)
llvm::StringMap< llvm::SmallVector< uint32_t, 1 > > 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()
std::multimap< lldb_private::FileSpec, ArchiveSP > Map
static ArchiveSP FindCachedArchive(const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch, const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset)
const llvm::sys::TimePoint & GetModificationTime()
lldb_private::DataExtractor & GetData()
static ArchiveSP 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)
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 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()
static lldb_private::ModuleSpecList GetModuleSpecifications(const lldb_private::FileSpec &file, lldb::DataExtractorSP &extractor_sp, lldb::offset_t file_offset, lldb::offset_t length)
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.
void SetArchive(ArchiveSP &archive_sp)
static llvm::StringRef GetPluginDescriptionStatic()
static ArchiveType MagicBytesMatch(const lldb_private::DataExtractor &extractor)
~ObjectContainerBSDArchive() override
std::shared_ptr< Archive > ArchiveSP
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:32
An data extractor class.
A file utility class.
Definition FileSpec.h:56
A plug-in interface definition class for object containers.
uint64_t offset_t
Definition lldb-types.h:86
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
std::string ar_name
Object name in the archive.
uint32_t size
Object size in bytes in the archive.
uint32_t modification_time
Object modification time in the archive.
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.