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
20
21#include "llvm/Object/Archive.h"
22#include "llvm/Support/Chrono.h"
23#include "llvm/Support/Path.h"
24
25#include <map>
26#include <memory>
27#include <mutex>
28
30
32public:
34 lldb::DataBufferSP &data_sp,
35 lldb::offset_t data_offset,
36 const lldb_private::FileSpec *file,
37 lldb::offset_t offset, lldb::offset_t length,
38 ArchiveType archive_type);
39
41
42 // Static Functions
43 static void Initialize();
44
45 static void Terminate();
46
47 static llvm::StringRef GetPluginNameStatic() { return "bsd-archive"; }
48
49 static llvm::StringRef GetPluginDescriptionStatic() {
50 return "BSD Archive object container reader.";
51 }
52
54 CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
55 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
56 lldb::offset_t offset, lldb::offset_t length);
57
60 lldb::DataExtractorSP &extractor_sp,
61 lldb::offset_t file_offset, lldb::offset_t length);
62
63 static ArchiveType
65
66 // Member Functions
67 bool ParseHeader() override;
68
69 size_t GetNumObjects() const override {
70 if (m_archive_sp)
71 return m_archive_sp->GetNumObjects();
72 return 0;
73 }
74
76
77 // PluginInterface protocol
78 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
79
80protected:
81 struct Object {
82 Object();
83
84 void Clear();
85
86 /// Object name in the archive.
88
89 /// Object modification time in the archive.
90 uint32_t modification_time = 0;
91
92 /// Object size in bytes in the archive.
93 uint32_t size = 0;
94
95 /// File offset in bytes from the beginning of the file of the object data.
97
98 /// Length of the object data.
100
101 void Dump() const;
102 };
103
104 class Archive;
105 typedef std::shared_ptr<Archive> ArchiveSP;
106
107 class Archive {
108 public:
109 typedef std::multimap<lldb_private::FileSpec, ArchiveSP> Map;
110
112 const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
113 lldb::DataExtractorSP extractor_sp, ArchiveType archive_type);
114
116
117 static Map &GetArchiveCache();
118
119 static std::recursive_mutex &GetArchiveCacheMutex();
120
122 const lldb_private::ArchSpec &arch,
123 const llvm::sys::TimePoint<> &mod_time,
124 lldb::offset_t file_offset);
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 lldb::DataExtractorSP extractor_sp, ArchiveType archive_type);
130
131 size_t GetNumObjects() const { return m_objects.size(); }
132
133 const Object *GetObjectAtIndex(size_t idx) {
134 if (idx < m_objects.size())
135 return &m_objects[idx];
136 return nullptr;
137 }
138
139 size_t ParseObjects();
140
142 const llvm::sys::TimePoint<> &object_mod_time);
143
145
146 const llvm::sys::TimePoint<> &GetModificationTime() {
147 return m_modification_time;
148 }
149
151
152 void SetArchitecture(const lldb_private::ArchSpec &arch) { m_arch = arch; }
153
155
158
160
161 protected:
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(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()
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
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
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 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.