1*bdd1243dSDimitry Andric //===-- ObjectContainerMachOFileset.h ---------------------------*- C++ -*-===//
2*bdd1243dSDimitry Andric //
3*bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*bdd1243dSDimitry Andric //
7*bdd1243dSDimitry Andric //===----------------------------------------------------------------------===//
8*bdd1243dSDimitry Andric 
9*bdd1243dSDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_MACH_O_FILESET_OBJECTCONTAINERMADCHOFILESET_H
10*bdd1243dSDimitry Andric #define LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_MACH_O_FILESET_OBJECTCONTAINERMADCHOFILESET_H
11*bdd1243dSDimitry Andric 
12*bdd1243dSDimitry Andric #include "lldb/Host/SafeMachO.h"
13*bdd1243dSDimitry Andric #include "lldb/Symbol/ObjectContainer.h"
14*bdd1243dSDimitry Andric #include "lldb/Utility/FileSpec.h"
15*bdd1243dSDimitry Andric 
16*bdd1243dSDimitry Andric namespace lldb_private {
17*bdd1243dSDimitry Andric 
18*bdd1243dSDimitry Andric class ObjectContainerMachOFileset : public lldb_private::ObjectContainer {
19*bdd1243dSDimitry Andric public:
20*bdd1243dSDimitry Andric   ObjectContainerMachOFileset(const lldb::ModuleSP &module_sp,
21*bdd1243dSDimitry Andric                               lldb::DataBufferSP &data_sp,
22*bdd1243dSDimitry Andric                               lldb::offset_t data_offset,
23*bdd1243dSDimitry Andric                               const lldb_private::FileSpec *file,
24*bdd1243dSDimitry Andric                               lldb::offset_t offset, lldb::offset_t length);
25*bdd1243dSDimitry Andric 
26*bdd1243dSDimitry Andric   ObjectContainerMachOFileset(const lldb::ModuleSP &module_sp,
27*bdd1243dSDimitry Andric                               lldb::WritableDataBufferSP data_sp,
28*bdd1243dSDimitry Andric                               const lldb::ProcessSP &process_sp,
29*bdd1243dSDimitry Andric                               lldb::addr_t header_addr);
30*bdd1243dSDimitry Andric 
31*bdd1243dSDimitry Andric   ~ObjectContainerMachOFileset() override;
32*bdd1243dSDimitry Andric 
33*bdd1243dSDimitry Andric   static void Initialize();
34*bdd1243dSDimitry Andric   static void Terminate();
35*bdd1243dSDimitry Andric 
GetPluginNameStatic()36*bdd1243dSDimitry Andric   static llvm::StringRef GetPluginNameStatic() { return "mach-o-fileset"; }
37*bdd1243dSDimitry Andric 
GetPluginDescriptionStatic()38*bdd1243dSDimitry Andric   static llvm::StringRef GetPluginDescriptionStatic() {
39*bdd1243dSDimitry Andric     return "Mach-O Fileset container reader.";
40*bdd1243dSDimitry Andric   }
41*bdd1243dSDimitry Andric 
42*bdd1243dSDimitry Andric   static lldb_private::ObjectContainer *
43*bdd1243dSDimitry Andric   CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
44*bdd1243dSDimitry Andric                  lldb::offset_t data_offset, const lldb_private::FileSpec *file,
45*bdd1243dSDimitry Andric                  lldb::offset_t offset, lldb::offset_t length);
46*bdd1243dSDimitry Andric 
47*bdd1243dSDimitry Andric   static lldb_private::ObjectContainer *CreateMemoryInstance(
48*bdd1243dSDimitry Andric       const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
49*bdd1243dSDimitry Andric       const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
50*bdd1243dSDimitry Andric 
51*bdd1243dSDimitry Andric   static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
52*bdd1243dSDimitry Andric                                         lldb::DataBufferSP &data_sp,
53*bdd1243dSDimitry Andric                                         lldb::offset_t data_offset,
54*bdd1243dSDimitry Andric                                         lldb::offset_t file_offset,
55*bdd1243dSDimitry Andric                                         lldb::offset_t length,
56*bdd1243dSDimitry Andric                                         lldb_private::ModuleSpecList &specs);
57*bdd1243dSDimitry Andric 
58*bdd1243dSDimitry Andric   static bool MagicBytesMatch(const lldb_private::DataExtractor &data);
59*bdd1243dSDimitry Andric   static bool MagicBytesMatch(lldb::DataBufferSP data_sp,
60*bdd1243dSDimitry Andric                               lldb::addr_t data_offset,
61*bdd1243dSDimitry Andric                               lldb::addr_t data_length);
62*bdd1243dSDimitry Andric 
63*bdd1243dSDimitry Andric   bool ParseHeader() override;
64*bdd1243dSDimitry Andric 
GetNumObjects()65*bdd1243dSDimitry Andric   size_t GetNumObjects() const override { return m_entries.size(); }
66*bdd1243dSDimitry Andric 
67*bdd1243dSDimitry Andric   lldb::ObjectFileSP GetObjectFile(const lldb_private::FileSpec *file) override;
68*bdd1243dSDimitry Andric 
GetPluginName()69*bdd1243dSDimitry Andric   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
70*bdd1243dSDimitry Andric 
71*bdd1243dSDimitry Andric   struct Entry {
EntryEntry72*bdd1243dSDimitry Andric     Entry(uint64_t vmaddr, uint64_t fileoff, std::string id)
73*bdd1243dSDimitry Andric         : vmaddr(vmaddr), fileoff(fileoff), id(id) {}
74*bdd1243dSDimitry Andric     uint64_t vmaddr;
75*bdd1243dSDimitry Andric     uint64_t fileoff;
76*bdd1243dSDimitry Andric     std::string id;
77*bdd1243dSDimitry Andric   };
78*bdd1243dSDimitry Andric 
79*bdd1243dSDimitry Andric   Entry *FindEntry(llvm::StringRef id);
80*bdd1243dSDimitry Andric 
81*bdd1243dSDimitry Andric private:
82*bdd1243dSDimitry Andric   static bool ParseHeader(lldb_private::DataExtractor &data,
83*bdd1243dSDimitry Andric                           const lldb_private::FileSpec &file,
84*bdd1243dSDimitry Andric                           lldb::offset_t file_offset,
85*bdd1243dSDimitry Andric                           std::vector<Entry> &entries);
86*bdd1243dSDimitry Andric 
87*bdd1243dSDimitry Andric   std::vector<Entry> m_entries;
88*bdd1243dSDimitry Andric   lldb::ProcessWP m_process_wp;
89*bdd1243dSDimitry Andric   const lldb::addr_t m_memory_addr;
90*bdd1243dSDimitry Andric };
91*bdd1243dSDimitry Andric 
92*bdd1243dSDimitry Andric } // namespace lldb_private
93*bdd1243dSDimitry Andric 
94*bdd1243dSDimitry Andric #endif // LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_MACH_O_FILESET_OBJECTCONTAINERMADCHOFILESET_H
95