1//===-- SymbolFileJSON.cpp ----------------------------------------------===//
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#include "SymbolFileJSON.h"
10
11#include "Plugins/ObjectFile/JSON/ObjectFileJSON.h"
12#include "lldb/Core/Module.h"
13#include "lldb/Core/PluginManager.h"
14#include "lldb/Symbol/CompileUnit.h"
15#include "lldb/Symbol/Function.h"
16#include "lldb/Symbol/ObjectFile.h"
17#include "lldb/Symbol/Symbol.h"
18#include "lldb/Symbol/SymbolContext.h"
19#include "lldb/Symbol/Symtab.h"
20#include "lldb/Symbol/TypeList.h"
21#include "lldb/Utility/LLDBLog.h"
22#include "lldb/Utility/Log.h"
23#include "lldb/Utility/RegularExpression.h"
24#include "lldb/Utility/Timer.h"
25#include "llvm/Support/MemoryBuffer.h"
26
27#include <memory>
28#include <optional>
29
30using namespace llvm;
31using namespace lldb;
32using namespace lldb_private;
33
34LLDB_PLUGIN_DEFINE(SymbolFileJSON)
35
36char SymbolFileJSON::ID;
37
38SymbolFileJSON::SymbolFileJSON(lldb::ObjectFileSP objfile_sp)
39 : SymbolFileCommon(std::move(objfile_sp)) {}
40
41void SymbolFileJSON::Initialize() {
42 PluginManager::RegisterPlugin(name: GetPluginNameStatic(),
43 description: GetPluginDescriptionStatic(), create_callback: CreateInstance);
44}
45
46void SymbolFileJSON::Terminate() {
47 PluginManager::UnregisterPlugin(create_callback: CreateInstance);
48}
49
50llvm::StringRef SymbolFileJSON::GetPluginDescriptionStatic() {
51 return "Reads debug symbols from a JSON symbol table.";
52}
53
54SymbolFile *SymbolFileJSON::CreateInstance(ObjectFileSP objfile_sp) {
55 return new SymbolFileJSON(std::move(objfile_sp));
56}
57
58uint32_t SymbolFileJSON::CalculateAbilities() {
59 if (!m_objfile_sp || !llvm::isa<ObjectFileJSON>(Val: *m_objfile_sp))
60 return 0;
61
62 return GlobalVariables | Functions;
63}
64
65uint32_t SymbolFileJSON::ResolveSymbolContext(const Address &so_addr,
66 SymbolContextItem resolve_scope,
67 SymbolContext &sc) {
68 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
69 if (m_objfile_sp->GetSymtab() == nullptr)
70 return 0;
71
72 uint32_t resolved_flags = 0;
73 if (resolve_scope & eSymbolContextSymbol) {
74 sc.symbol = m_objfile_sp->GetSymtab()->FindSymbolContainingFileAddress(
75 file_addr: so_addr.GetFileAddress());
76 if (sc.symbol)
77 resolved_flags |= eSymbolContextSymbol;
78 }
79 return resolved_flags;
80}
81
82CompUnitSP SymbolFileJSON::ParseCompileUnitAtIndex(uint32_t idx) { return {}; }
83
84void SymbolFileJSON::GetTypes(SymbolContextScope *sc_scope, TypeClass type_mask,
85 lldb_private::TypeList &type_list) {}
86
87void SymbolFileJSON::AddSymbols(Symtab &symtab) {
88 if (!m_objfile_sp)
89 return;
90
91 Symtab *json_symtab = m_objfile_sp->GetSymtab();
92 if (!json_symtab)
93 return;
94
95 if (&symtab == json_symtab)
96 return;
97
98 // Merge the two symbol tables.
99 const size_t num_new_symbols = json_symtab->GetNumSymbols();
100 for (size_t i = 0; i < num_new_symbols; ++i) {
101 Symbol *s = json_symtab->SymbolAtIndex(idx: i);
102 symtab.AddSymbol(symbol: *s);
103 }
104 symtab.Finalize();
105}
106

source code of lldb/source/Plugins/SymbolFile/JSON/SymbolFileJSON.cpp