[AArch64] Add cost model for @experimental.vector.match (#118512)
[llvm-project.git] / lldb / source / Plugins / SymbolFile / JSON / SymbolFileJSON.cpp
blob1f3ca27417e4abfedaac68005ce356815dc6186f
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 //===----------------------------------------------------------------------===//
9 #include "SymbolFileJSON.h"
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"
27 #include <memory>
28 #include <optional>
30 using namespace llvm;
31 using namespace lldb;
32 using namespace lldb_private;
34 LLDB_PLUGIN_DEFINE(SymbolFileJSON)
36 char SymbolFileJSON::ID;
38 SymbolFileJSON::SymbolFileJSON(lldb::ObjectFileSP objfile_sp)
39 : SymbolFileCommon(std::move(objfile_sp)) {}
41 void SymbolFileJSON::Initialize() {
42 PluginManager::RegisterPlugin(GetPluginNameStatic(),
43 GetPluginDescriptionStatic(), CreateInstance);
46 void SymbolFileJSON::Terminate() {
47 PluginManager::UnregisterPlugin(CreateInstance);
50 llvm::StringRef SymbolFileJSON::GetPluginDescriptionStatic() {
51 return "Reads debug symbols from a JSON symbol table.";
54 SymbolFile *SymbolFileJSON::CreateInstance(ObjectFileSP objfile_sp) {
55 return new SymbolFileJSON(std::move(objfile_sp));
58 uint32_t SymbolFileJSON::CalculateAbilities() {
59 if (!m_objfile_sp || !llvm::isa<ObjectFileJSON>(*m_objfile_sp))
60 return 0;
62 return GlobalVariables | Functions;
65 uint32_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;
72 uint32_t resolved_flags = 0;
73 if (resolve_scope & eSymbolContextSymbol) {
74 sc.symbol = m_objfile_sp->GetSymtab()->FindSymbolContainingFileAddress(
75 so_addr.GetFileAddress());
76 if (sc.symbol)
77 resolved_flags |= eSymbolContextSymbol;
79 return resolved_flags;
82 CompUnitSP SymbolFileJSON::ParseCompileUnitAtIndex(uint32_t idx) { return {}; }
84 void SymbolFileJSON::GetTypes(SymbolContextScope *sc_scope, TypeClass type_mask,
85 lldb_private::TypeList &type_list) {}
87 void SymbolFileJSON::AddSymbols(Symtab &symtab) {
88 if (!m_objfile_sp)
89 return;
91 Symtab *json_symtab = m_objfile_sp->GetSymtab();
92 if (!json_symtab)
93 return;
95 if (&symtab == json_symtab)
96 return;
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(i);
102 symtab.AddSymbol(*s);
104 symtab.Finalize();