LLDB mainline
ObjectFileJSON.h
Go to the documentation of this file.
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
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 *CreateInstance(const lldb::ModuleSP &module_sp,
30 lldb::DataExtractorSP extractor_sp,
31 lldb::offset_t data_offset,
32 const FileSpec *file,
33 lldb::offset_t file_offset,
34 lldb::offset_t length);
35
36 static ObjectFile *CreateMemoryInstance(const lldb::ModuleSP &module_sp,
38 const lldb::ProcessSP &process_sp,
39 lldb::addr_t header_addr);
40
41 static size_t GetModuleSpecifications(const FileSpec &file,
42 lldb::DataBufferSP &data_sp,
43 lldb::offset_t data_offset,
44 lldb::offset_t file_offset,
45 lldb::offset_t length,
46 ModuleSpecList &specs);
47
48 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
49
50 // LLVM RTTI support
51 static char ID;
52 bool isA(const void *ClassID) const override {
53 return ClassID == &ID || ObjectFile::isA(ClassID);
54 }
55 static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }
56
57 bool ParseHeader() override;
58
59 lldb::ByteOrder GetByteOrder() const override {
60 return m_arch.GetByteOrder();
61 }
62
63 bool IsExecutable() const override { return false; }
64
65 uint32_t GetAddressByteSize() const override {
66 return m_arch.GetAddressByteSize();
67 }
68
71 }
72
73 void ParseSymtab(lldb_private::Symtab &symtab) override;
74
75 bool IsStripped() override { return false; }
76
77 void CreateSections(SectionList &unified_section_list) override;
78
79 void Dump(Stream *s) override {}
80
81 ArchSpec GetArchitecture() override { return m_arch; }
82
83 UUID GetUUID() override { return m_uuid; }
84
85 uint32_t GetDependentModules(FileSpecList &files) override { return 0; }
86
87 Type CalculateType() override { return m_type; }
88
89 Strata CalculateStrata() override { return eStrataUser; }
90
91 bool SetLoadAddress(Target &target, lldb::addr_t value,
92 bool value_is_offset) override;
93
94 static bool MagicBytesMatch(lldb::DataBufferSP data_sp, lldb::addr_t offset,
95 lldb::addr_t length);
96
97 struct Header {
98 std::string triple;
99 std::string uuid;
100 std::optional<ObjectFile::Type> type;
101 };
102
103 struct Body {
104 std::vector<JSONSection> sections;
105 std::vector<JSONSymbol> symbols;
106 };
107
108private:
112 std::optional<uint64_t> m_size;
113 std::vector<JSONSymbol> m_symbols;
114 std::vector<JSONSection> m_sections;
115
116 ObjectFileJSON(const lldb::ModuleSP &module_sp,
117 lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset,
118 const FileSpec *file, lldb::offset_t offset,
119 lldb::offset_t length, ArchSpec arch, UUID uuid, Type type,
120 std::vector<JSONSymbol> symbols,
121 std::vector<JSONSection> sections);
122};
123
124bool fromJSON(const llvm::json::Value &value, ObjectFileJSON::Header &header,
125 llvm::json::Path path);
126
127bool fromJSON(const llvm::json::Value &value, ObjectFileJSON::Body &body,
128 llvm::json::Path path);
129
130} // namespace lldb_private
131#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_JSON_OBJECTFILEJSON_H
An architecture specification class.
Definition ArchSpec.h:31
A file collection class.
A file utility class.
Definition FileSpec.h:57
uint32_t GetDependentModules(FileSpecList &files) override
Extract the dependent modules from an object file.
std::vector< JSONSection > m_sections
bool SetLoadAddress(Target &target, lldb::addr_t value, bool value_is_offset) override
Sets the load address for an entire module, assuming a rigid slide of sections, if possible in the im...
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
llvm::StringRef GetPluginName() override
ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
ObjectFileJSON(const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t offset, lldb::offset_t length, ArchSpec arch, UUID uuid, Type type, std::vector< JSONSymbol > symbols, std::vector< JSONSection > sections)
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
void Dump(Stream *s) override
Dump a description of this object to a Stream.
void ParseSymtab(lldb_private::Symtab &symtab) override
Parse the symbol table into the provides symbol table object.
static bool MagicBytesMatch(lldb::DataBufferSP data_sp, lldb::addr_t offset, lldb::addr_t length)
UUID GetUUID() override
Gets the UUID for this object file.
static const char * GetPluginDescriptionStatic()
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
static size_t GetModuleSpecifications(const FileSpec &file, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, lldb::offset_t file_offset, lldb::offset_t length, ModuleSpecList &specs)
std::optional< uint64_t > m_size
Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
void CreateSections(SectionList &unified_section_list) override
static bool classof(const ObjectFile *obj)
bool isA(const void *ClassID) const override
bool ParseHeader() override
Attempts to parse the object header.
static ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
std::vector< JSONSymbol > m_symbols
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
static ObjectFile * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
Type CalculateType() override
The object file should be able to calculate its type by looking at its file header and possibly the s...
static llvm::StringRef GetPluginNameStatic()
AddressClass GetAddressClass(lldb::addr_t file_addr) override
Get the address type given a file address in an object file.
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
virtual bool isA(const void *ClassID) const
Definition ObjectFile.h:218
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
A stream class that can stream formatted output to a file.
Definition Stream.h:28
Represents UUID's of various sizes.
Definition UUID.h:27
A class that represents a running process on the host machine.
bool fromJSON(const llvm::json::Value &value, TraceSupportedResponse &info, llvm::json::Path path)
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::vector< JSONSymbol > symbols
std::vector< JSONSection > sections
std::optional< ObjectFile::Type > type