18#include "llvm/ADT/DenseSet.h"
45 if (!extractor_sp || !extractor_sp->HasData()) {
49 extractor_sp = std::make_shared<DataExtractor>(data_sp);
54 extractor_sp->GetByteSize()))
58 if (extractor_sp->GetByteSize() < length) {
62 extractor_sp->SetData(data_sp);
68 auto text = llvm::StringRef(
reinterpret_cast<const char *
>(
69 extractor_sp->GetSharedDataBuffer()->GetBytes()));
71 Expected<json::Value>
json = json::parse(text);
74 "failed to parse JSON object file: {0}");
78 json::Path::Root root;
82 "failed to parse JSON object file header: {0}");
94 "failed to parse JSON object file body: {0}");
98 return new ObjectFileJSON(module_sp, extractor_sp, data_offset, file,
99 file_offset, length, std::move(arch),
100 std::move(uuid), type, std::move(body.
symbols),
118 if (data_sp->GetByteSize() < length) {
128 llvm::StringRef(
reinterpret_cast<const char *
>(data_sp->GetBytes()));
130 Expected<json::Value>
json = json::parse(text);
133 "failed to parse JSON object file: {0}");
137 json::Path::Root root;
141 "failed to parse JSON object file header: {0}");
150 spec.
GetUUID() = std::move(uuid);
160 std::vector<JSONSymbol> symbols,
161 std::vector<JSONSection> sections)
162 :
ObjectFile(module_sp, file, offset, length, extractor_sp, data_offset),
175 llvm::Expected<Symbol> symbol =
Symbol::FromJSON(json_symbol, section_list);
196 auto sect_id = section.
user_id.value_or(
id + 1);
197 if (!section.
user_id.has_value())
201 const auto vm_addr = section.
address.value_or(0);
202 const auto vm_size = section.
size.value_or(0);
203 const auto file_offset = section.
file_offset.value_or(0);
204 const auto file_size = section.
file_size.value_or(0);
205 const auto log2align = section.
log2align.value_or(0);
206 const auto flags = section.
flags.value_or(0);
207 if (parent_section_sp) {
208 section_sp = std::make_shared<Section>(
209 parent_section_sp,
GetModule(),
this, sect_id, name, sect_type,
210 vm_addr - parent_section_sp->GetFileAddress(), vm_size, file_offset,
211 file_size, log2align, flags);
214 section_sp = std::make_shared<Section>(
215 GetModule(),
this, sect_id, name, sect_type, vm_addr, vm_size,
216 file_offset, file_size, log2align, flags);
219 uint32_t permissions = 0;
220 if (section.
read.value_or(0))
221 permissions |= lldb::ePermissionsReadable;
222 if (section.
write.value_or(0))
223 permissions |= lldb::ePermissionsWritable;
224 if (section.
execute.value_or(0))
225 permissions |= lldb::ePermissionsExecutable;
227 section_sp->SetPermissions(permissions);
228 section_sp->SetIsFake(section.
fake.value_or(
false));
229 section_sp->SetIsEncrypted(section.
encrypted.value_or(
false));
230 section_sp->SetIsThreadSpecific(section.
thread_specific.value_or(
false));
233 auto section_sp = make_section(json_section);
234 for (
const auto &subsection : json_section.subsections) {
235 SectionSP subsection_sp = make_section(subsection, section_sp);
236 section_sp->GetChildren().AddSection(subsection_sp);
245 bool value_is_offset) {
251 if (!value_is_offset) {
254 addr_t section_load_addr = section_sp->GetFileAddress();
255 lowest_addr = std::min(lowest_addr, section_load_addr);
259 slide = value - lowest_addr;
264 addr_t section_load_addr = section_sp->GetFileAddress();
268 "ObjectFileJSON::SetLoadAddress section %s to load addr 0x%" PRIx64,
269 section_sp->GetName().AsCString(), section_load_addr + slide);
282 data.
SetData(data_sp, data_offset, data_length);
284 uint32_t magic = data.
GetU8(&offset);
292 json::ObjectMapper o(value, path);
293 return o && o.map(
"triple", header.
triple) && o.map(
"uuid", header.
uuid) &&
294 o.map(
"type", header.
type);
299 json::ObjectMapper o(value, path);
300 return o && o.mapOptional(
"symbols", body.
symbols) &&
301 o.mapOptional(
"sections", body.
sections);
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
An architecture specification class.
A uniqued constant string class.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
void Append(const ModuleSpec &spec)
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...
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)
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)
static const char * GetPluginDescriptionStatic()
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)
void CreateSections(SectionList &unified_section_list) 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
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)
static llvm::StringRef GetPluginNameStatic()
std::unique_ptr< lldb_private::SectionList > m_sections_up
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
@ eTypeDebugInfo
An object file that contains only debug information.
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.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
size_t AddSection(const lldb::SectionSP §ion_sp)
static llvm::Expected< Symbol > FromJSON(const JSONSymbol &symbol, SectionList *section_list)
uint32_t AddSymbol(const Symbol &symbol)
bool SetSectionLoadAddress(const lldb::SectionSP §ion, lldb::addr_t load_addr, bool warn_multiple=false)
Represents UUID's of various sizes.
bool SetFromStringRef(llvm::StringRef str)
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
bool fromJSON(const llvm::json::Value &value, TraceSupportedResponse &info, llvm::json::Path path)
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::optional< lldb::user_id_t > user_id
std::optional< uint64_t > log2align
std::optional< uint64_t > size
std::optional< uint64_t > flags
std::optional< bool > encrypted
std::optional< bool > fake
std::optional< lldb::SectionType > type
std::optional< bool > write
std::optional< bool > execute
std::optional< uint64_t > file_offset
std::optional< uint64_t > address
std::optional< bool > thread_specific
std::optional< uint64_t > file_size
std::optional< bool > read
std::vector< JSONSymbol > symbols
std::vector< JSONSection > sections