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