LLDB mainline
SymbolFileDWARFDwo.cpp
Go to the documentation of this file.
1//===-- SymbolFileDWARFDwo.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
10
11#include "lldb/Core/Section.h"
15#include "llvm/Support/Casting.h"
16
17#include "DWARFCompileUnit.h"
18#include "DWARFDebugInfo.h"
19#include "DWARFUnit.h"
20#include <optional>
21
22using namespace lldb;
23using namespace lldb_private;
24using namespace lldb_private::plugin::dwarf;
25
27
29 ObjectFileSP objfile, uint32_t id)
30 : SymbolFileDWARF(objfile, objfile->GetSectionList(
31 /*update_module_section_list*/ false)),
32 m_base_symbol_file(base_symbol_file) {
33 SetFileIndex(id);
34
35 // Parsing of the dwarf unit index is not thread-safe, so we need to prime it
36 // to enable subsequent concurrent lookups.
37 m_context.GetAsLLVM().getCUIndex();
38}
39
41 if (const llvm::DWARFUnitIndex &index = m_context.GetAsLLVM().getCUIndex()) {
42 if (const llvm::DWARFUnitIndex::Entry *entry = index.getFromHash(hash)) {
43 if (auto *unit_contrib = entry->getContribution())
44 return llvm::dyn_cast_or_null<DWARFCompileUnit>(
45 DebugInfo().GetUnitAtOffset(DIERef::Section::DebugInfo,
46 unit_contrib->getOffset()));
47 }
48 return nullptr;
49 }
50
52 if (!cu)
53 return nullptr;
54 std::optional<uint64_t> dwo_id = cu->GetDWOId();
55 if (!dwo_id || hash != *dwo_id)
56 return nullptr;
57 return cu;
58}
59
61 DWARFDebugInfo &debug_info = DebugInfo();
62
63 // Right now we only support dwo files with one compile unit. If we don't have
64 // type units, we can just check for the unit count.
65 if (!debug_info.ContainsTypeUnits() && debug_info.GetNumUnits() == 1)
66 return llvm::cast<DWARFCompileUnit>(debug_info.GetUnitAtIndex(0));
67
68 // Otherwise, we have to run through all units, and find the compile unit that
69 // way.
70 DWARFCompileUnit *cu = nullptr;
71 for (size_t i = 0; i < debug_info.GetNumUnits(); ++i) {
72 if (auto *candidate =
73 llvm::dyn_cast<DWARFCompileUnit>(debug_info.GetUnitAtIndex(i))) {
74 if (cu)
75 return nullptr; // More that one CU found.
76 cu = candidate;
77 }
78 }
79 return cu;
80}
81
83 const lldb_private::DataExtractor &data, const lldb::offset_t data_offset,
84 const uint8_t op) const {
85 return GetBaseSymbolFile().GetVendorDWARFOpcodeSize(data, data_offset, op);
86}
87
88uint64_t SymbolFileDWARFDwo::GetDebugInfoSize(bool load_all_debug_info) {
89 // Directly get debug info from current dwo object file's section list
90 // instead of asking SymbolFileCommon::GetDebugInfo() which parses from
91 // owning module which is wrong.
92 SectionList *section_list =
93 m_objfile_sp->GetSectionList(/*update_module_section_list=*/false);
94 if (section_list)
95 return section_list->GetDebugInfoSize();
96 return 0;
97}
98
100 uint8_t op, const lldb_private::DataExtractor &opcodes,
101 lldb::offset_t &offset, std::vector<lldb_private::Value> &stack) const {
102 return GetBaseSymbolFile().ParseVendorDWARFOpcode(op, opcodes, offset, stack);
103}
104
107}
108
111}
112
113llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
116}
117
119 lldb_private::ConstString class_name,
120 llvm::function_ref<bool(DWARFDIE die)> callback) {
121 GetBaseSymbolFile().GetObjCMethods(class_name, callback);
122}
123
126}
127
130}
131
133 const DWARFDIE &die, lldb_private::ConstString type_name,
134 bool must_be_implementation) {
136 die, type_name, must_be_implementation);
137}
138
139llvm::Expected<lldb::TypeSystemSP>
142}
143
146 if (die_ref.file_index() == GetFileIndex())
147 return DebugInfo().GetDIE(die_ref.section(), die_ref.die_offset());
148 return GetBaseSymbolFile().GetDIE(die_ref);
149}
150
152 ConstString name, const CompilerDeclContext &parent_decl_ctx,
153 uint32_t max_matches, VariableList &variables) {
154 GetBaseSymbolFile().FindGlobalVariables(name, parent_decl_ctx, max_matches,
155 variables);
156}
157
160}
163}
166}
169}
172}
175}
176
179 return GetBaseSymbolFile().GetDIERefSymbolFile(die_ref);
180}
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition: ConstString.h:40
An data extractor class.
Definition: DataExtractor.h:48
uint64_t GetDebugInfoSize() const
Get the debug information size from all sections that contain debug information.
Definition: Section.cpp:669
bool GetDebugInfoHadFrameVariableErrors() const override
Accessors for the bool that indicates if there was debug info, but errors stopped variables from bein...
Definition: SymbolFile.h:567
void SetDebugInfoIndexWasLoadedFromCache() override
Definition: SymbolFile.h:558
bool GetDebugInfoIndexWasSavedToCache() const override
Definition: SymbolFile.h:561
lldb::ObjectFileSP m_objfile_sp
Definition: SymbolFile.h:609
void SetDebugInfoIndexWasSavedToCache() override
Definition: SymbolFile.h:564
void SetDebugInfoHadFrameVariableErrors() override
Definition: SymbolFile.h:570
bool GetDebugInfoIndexWasLoadedFromCache() const override
Accessors for the bool that indicates if the debug info index was loaded from, or saved to the module...
Definition: SymbolFile.h:555
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:30
std::optional< uint32_t > file_index() const
Definition: DIERef.h:59
dw_offset_t die_offset() const
Definition: DIERef.h:67
DWARFDIE GetDIE(DIERef::Section section, dw_offset_t die_offset)
std::optional< uint64_t > GetDWOId()
Get the DWO ID from the DWARFUnitHeader for DWARF5, or from the unit DIE's DW_AT_dwo_id or DW_AT_GNU_...
Definition: DWARFUnit.cpp:376
SymbolFileDWARFDwo(SymbolFileDWARF &m_base_symbol_file, lldb::ObjectFileSP objfile, uint32_t id)
llvm::DenseMap< lldb::opaque_compiler_type_t, DIERef > & GetForwardDeclCompilerTypeToDIE() override
bool GetDebugInfoIndexWasLoadedFromCache() const override
Accessors for the bool that indicates if the debug info index was loaded from, or saved to the module...
UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap() override
uint64_t GetDebugInfoSize(bool load_all_debug_info=false) override
Metrics gathering functions.
DWARFCompileUnit * FindSingleCompileUnit()
If this file contains exactly one compile unit, this function will return it.
DWARFDIE FindDefinitionDIE(const DWARFDIE &die) override
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, ConstString type_name, bool must_be_implementation) override
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
SymbolFileDWARF * GetDIERefSymbolFile(const DIERef &die_ref) override
Given a DIERef, find the correct SymbolFileDWARF.
bool GetDebugInfoHadFrameVariableErrors() const override
Accessors for the bool that indicates if there was debug info, but errors stopped variables from bein...
DWARFDIE GetDIE(const DIERef &die_ref) override
DWARFCompileUnit * GetDWOCompileUnitForHash(uint64_t hash)
void GetObjCMethods(ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback) override
bool ParseVendorDWARFOpcode(uint8_t op, const DataExtractor &opcodes, lldb::offset_t &offset, std::vector< Value > &stack) const override
lldb::offset_t GetVendorDWARFOpcodeSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const override
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
virtual DWARFDIE FindDefinitionDIE(const DWARFDIE &die)
llvm::DenseMap< const DWARFDebugInfoEntry *, Type * > DIEToTypePtr
virtual llvm::DenseMap< lldb::opaque_compiler_type_t, DIERef > & GetForwardDeclCompilerTypeToDIE()
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb::VariableSP > DIEToVariableSP
virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, ConstString type_name, bool must_be_implementation)
virtual bool ParseVendorDWARFOpcode(uint8_t op, const DataExtractor &opcodes, lldb::offset_t &offset, std::vector< Value > &stack) const
virtual void GetObjCMethods(ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback)
virtual DWARFDIE GetDIE(const DIERef &die_ref)
virtual lldb::offset_t GetVendorDWARFOpcodeSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const
void SetFileIndex(std::optional< uint64_t > file_index)
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
virtual SymbolFileDWARF * GetDIERefSymbolFile(const DIERef &die_ref)
Given a DIERef, find the correct SymbolFileDWARF.
virtual DIEToVariableSP & GetDIEToVariable()
std::optional< uint64_t > GetFileIndex() const
virtual UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap()
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
uint64_t offset_t
Definition: lldb-types.h:85
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
Definition: lldb-forward.h:373
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Type > TypeSP
Definition: lldb-forward.h:457