1//===-- ObjectFileJSON.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_OBJECTFILE_JSON_OBJECTFILEJSON_H
10#define LLDB_SOURCE_PLUGINS_OBJECTFILE_JSON_OBJECTFILEJSON_H
11
12#include "lldb/Symbol/ObjectFile.h"
13#include "lldb/Utility/ArchSpec.h"
14#include "llvm/Support/JSON.h"
15
16namespace lldb_private {
17
18class ObjectFileJSON : public ObjectFile {
19public:
20 static void Initialize();
21 static void Terminate();
22
23 static llvm::StringRef GetPluginNameStatic() { return "JSON"; }
24
25 static const char *GetPluginDescriptionStatic() {
26 return "JSON object file reader.";
27 }
28
29 static ObjectFile *
30 CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
31 lldb::offset_t data_offset, const FileSpec *file,
32 lldb::offset_t file_offset, lldb::offset_t length);
33
34 static ObjectFile *CreateMemoryInstance(const lldb::ModuleSP &module_sp,
35 lldb::WritableDataBufferSP data_sp,
36 const lldb::ProcessSP &process_sp,
37 lldb::addr_t header_addr);
38
39 static size_t GetModuleSpecifications(const FileSpec &file,
40 lldb::DataBufferSP &data_sp,
41 lldb::offset_t data_offset,
42 lldb::offset_t file_offset,
43 lldb::offset_t length,
44 ModuleSpecList &specs);
45
46 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
47
48 // LLVM RTTI support
49 static char ID;
50 bool isA(const void *ClassID) const override {
51 return ClassID == &ID || ObjectFile::isA(ClassID);
52 }
53 static bool classof(const ObjectFile *obj) { return obj->isA(ClassID: &ID); }
54
55 bool ParseHeader() override;
56
57 lldb::ByteOrder GetByteOrder() const override {
58 return m_arch.GetByteOrder();
59 }
60
61 bool IsExecutable() const override { return false; }
62
63 uint32_t GetAddressByteSize() const override {
64 return m_arch.GetAddressByteSize();
65 }
66
67 AddressClass GetAddressClass(lldb::addr_t file_addr) override {
68 return AddressClass::eInvalid;
69 }
70
71 void ParseSymtab(lldb_private::Symtab &symtab) override;
72
73 bool IsStripped() override { return false; }
74
75 void CreateSections(SectionList &unified_section_list) override;
76
77 void Dump(Stream *s) override {}
78
79 ArchSpec GetArchitecture() override { return m_arch; }
80
81 UUID GetUUID() override { return m_uuid; }
82
83 uint32_t GetDependentModules(FileSpecList &files) override { return 0; }
84
85 Type CalculateType() override { return m_type; }
86
87 Strata CalculateStrata() override { return eStrataUser; }
88
89 static bool MagicBytesMatch(lldb::DataBufferSP data_sp, lldb::addr_t offset,
90 lldb::addr_t length);
91
92 struct Header {
93 std::string triple;
94 std::string uuid;
95 std::optional<ObjectFile::Type> type;
96 };
97
98 struct Body {
99 std::vector<JSONSection> sections;
100 std::vector<JSONSymbol> symbols;
101 };
102
103private:
104 ArchSpec m_arch;
105 UUID m_uuid;
106 ObjectFile::Type m_type;
107 std::optional<uint64_t> m_size;
108 std::vector<JSONSymbol> m_symbols;
109 std::vector<JSONSection> m_sections;
110
111 ObjectFileJSON(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
112 lldb::offset_t data_offset, const FileSpec *file,
113 lldb::offset_t offset, lldb::offset_t length, ArchSpec arch,
114 UUID uuid, Type type, std::vector<JSONSymbol> symbols,
115 std::vector<JSONSection> sections);
116};
117
118bool fromJSON(const llvm::json::Value &value, ObjectFileJSON::Header &header,
119 llvm::json::Path path);
120
121bool fromJSON(const llvm::json::Value &value, ObjectFileJSON::Body &body,
122 llvm::json::Path path);
123
124} // namespace lldb_private
125#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_JSON_OBJECTFILEJSON_H
126

source code of lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.h