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
17
18#include "llvm/Object/Archive.h"
19#include "llvm/Support/Chrono.h"
20#include "llvm/Support/Path.h"
21
22#include <map>
23#include <memory>
24#include <mutex>
25
27
29public:
31 lldb::DataBufferSP &data_sp,
32 lldb::offset_t data_offset,
33 const lldb_private::FileSpec *file,
34 lldb::offset_t offset, lldb::offset_t length,
35 ArchiveType archive_type);
36
38
39 // Static Functions
40 static void Initialize();
41
42 static void Terminate();
43
44 static llvm::StringRef GetPluginNameStatic() { return "bsd-archive"; }
45
46 static llvm::StringRef GetPluginDescriptionStatic() {
47 return "BSD Archive object container reader.";
48 }
49
51 CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
52 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
53 lldb::offset_t offset, lldb::offset_t length);
54
55 static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
56 lldb::DataBufferSP &data_sp,
57 lldb::offset_t data_offset,
58 lldb::offset_t file_offset,
59 lldb::offset_t length,
61
63
64 // Member Functions
65 bool ParseHeader() override;
66
67 size_t GetNumObjects() const override {
68 if (m_archive_sp)
69 return m_archive_sp->GetNumObjects();
70 return 0;
71 }
72
74
75 // PluginInterface protocol
76 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
77
78protected:
79 struct Object {
80 Object();
81
82 void Clear();
83
85 lldb::offset_t offset,
86 llvm::StringRef stringTable);
87
89 lldb::offset_t offset);
90 /// Object name in the archive.
92
93 /// Object modification time in the archive.
94 uint32_t modification_time = 0;
95
96 /// Object size in bytes in the archive.
97 uint32_t size = 0;
98
99 /// File offset in bytes from the beginning of the file of the object data.
101
102 /// Length of the object data.
104
105 void Dump() const;
106 };
107
108 class Archive {
109 public:
110 typedef std::shared_ptr<Archive> shared_ptr;
111 typedef std::multimap<lldb_private::FileSpec, shared_ptr> Map;
112
114 const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
115 lldb_private::DataExtractor &data, ArchiveType archive_type);
116
118
119 static Map &GetArchiveCache();
120
121 static std::recursive_mutex &GetArchiveCacheMutex();
122
124 const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch,
125 const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset);
126
128 const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch,
129 const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
130 lldb_private::DataExtractor &data, ArchiveType archive_type);
131
132 size_t GetNumObjects() const { return m_objects.size(); }
133
134 const Object *GetObjectAtIndex(size_t idx) {
135 if (idx < m_objects.size())
136 return &m_objects[idx];
137 return nullptr;
138 }
139
140 size_t ParseObjects();
141
143 const llvm::sys::TimePoint<> &object_mod_time);
144
146
147 const llvm::sys::TimePoint<> &GetModificationTime() {
148 return m_modification_time;
149 }
150
152
153 void SetArchitecture(const lldb_private::ArchSpec &arch) { m_arch = arch; }
154
156
158
160
161 protected:
163 // Member Variables
165 llvm::sys::TimePoint<> m_modification_time;
167 std::vector<Object> m_objects;
169 lldb_private::DataExtractor m_data; ///< The data for this object container
170 ///so we don't lose data if the .a files
171 ///gets modified
173 };
174
175 void SetArchive(Archive::shared_ptr &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
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_private::DataExtractor &data, ArchiveType archive_type)
std::multimap< lldb_private::FileSpec, shared_ptr > Map
lldb_private::DataExtractor m_data
The data for this object container so we don't lose data if the .a files gets modified.
const llvm::sys::TimePoint & GetModificationTime()
lldb_private::DataExtractor & GetData()
void SetArchitecture(const lldb_private::ArchSpec &arch)
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 ArchiveType MagicBytesMatch(const lldb_private::DataExtractor &data)
static llvm::StringRef GetPluginDescriptionStatic()
~ObjectContainerBSDArchive() override
void SetArchive(Archive::shared_ptr &archive_sp)
An architecture specification class.
Definition: ArchSpec.h:31
A uniqued constant string class.
Definition: ConstString.h:40
An data extractor class.
Definition: DataExtractor.h:48
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:85
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
Definition: lldb-forward.h:367
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:328
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:365
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 &data, lldb::offset_t offset)
lldb::offset_t ExtractFromThin(const lldb_private::DataExtractor &data, lldb::offset_t offset, llvm::StringRef stringTable)
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.