Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/JSON/SymbolFileJSON.cpp
39642 views
//===-- SymbolFileJSON.cpp ----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "SymbolFileJSON.h"910#include "Plugins/ObjectFile/JSON/ObjectFileJSON.h"11#include "lldb/Core/Module.h"12#include "lldb/Core/PluginManager.h"13#include "lldb/Symbol/CompileUnit.h"14#include "lldb/Symbol/Function.h"15#include "lldb/Symbol/ObjectFile.h"16#include "lldb/Symbol/Symbol.h"17#include "lldb/Symbol/SymbolContext.h"18#include "lldb/Symbol/Symtab.h"19#include "lldb/Symbol/TypeList.h"20#include "lldb/Utility/LLDBLog.h"21#include "lldb/Utility/Log.h"22#include "lldb/Utility/RegularExpression.h"23#include "lldb/Utility/Timer.h"24#include "llvm/Support/MemoryBuffer.h"2526#include <memory>27#include <optional>2829using namespace llvm;30using namespace lldb;31using namespace lldb_private;3233LLDB_PLUGIN_DEFINE(SymbolFileJSON)3435char SymbolFileJSON::ID;3637SymbolFileJSON::SymbolFileJSON(lldb::ObjectFileSP objfile_sp)38: SymbolFileCommon(std::move(objfile_sp)) {}3940void SymbolFileJSON::Initialize() {41PluginManager::RegisterPlugin(GetPluginNameStatic(),42GetPluginDescriptionStatic(), CreateInstance);43}4445void SymbolFileJSON::Terminate() {46PluginManager::UnregisterPlugin(CreateInstance);47}4849llvm::StringRef SymbolFileJSON::GetPluginDescriptionStatic() {50return "Reads debug symbols from a JSON symbol table.";51}5253SymbolFile *SymbolFileJSON::CreateInstance(ObjectFileSP objfile_sp) {54return new SymbolFileJSON(std::move(objfile_sp));55}5657uint32_t SymbolFileJSON::CalculateAbilities() {58if (!m_objfile_sp || !llvm::isa<ObjectFileJSON>(*m_objfile_sp))59return 0;6061return GlobalVariables | Functions;62}6364uint32_t SymbolFileJSON::ResolveSymbolContext(const Address &so_addr,65SymbolContextItem resolve_scope,66SymbolContext &sc) {67std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());68if (m_objfile_sp->GetSymtab() == nullptr)69return 0;7071uint32_t resolved_flags = 0;72if (resolve_scope & eSymbolContextSymbol) {73sc.symbol = m_objfile_sp->GetSymtab()->FindSymbolContainingFileAddress(74so_addr.GetFileAddress());75if (sc.symbol)76resolved_flags |= eSymbolContextSymbol;77}78return resolved_flags;79}8081CompUnitSP SymbolFileJSON::ParseCompileUnitAtIndex(uint32_t idx) { return {}; }8283void SymbolFileJSON::GetTypes(SymbolContextScope *sc_scope, TypeClass type_mask,84lldb_private::TypeList &type_list) {}8586void SymbolFileJSON::AddSymbols(Symtab &symtab) {87if (!m_objfile_sp)88return;8990Symtab *json_symtab = m_objfile_sp->GetSymtab();91if (!json_symtab)92return;9394if (&symtab == json_symtab)95return;9697// Merge the two symbol tables.98const size_t num_new_symbols = json_symtab->GetNumSymbols();99for (size_t i = 0; i < num_new_symbols; ++i) {100Symbol *s = json_symtab->SymbolAtIndex(i);101symtab.AddSymbol(*s);102}103symtab.Finalize();104}105106107