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;
24
26
28 ObjectFileSP objfile, uint32_t id)
29 : SymbolFileDWARF(objfile, objfile->GetSectionList(
30 /*update_module_section_list*/ false)),
31 m_base_symbol_file(base_symbol_file) {
32 SetFileIndex(id);
33
34 // Parsing of the dwarf unit index is not thread-safe, so we need to prime it
35 // to enable subsequent concurrent lookups.
36 m_context.GetAsLLVM().getCUIndex();
37}
38
40 if (const llvm::DWARFUnitIndex &index = m_context.GetAsLLVM().getCUIndex()) {
41 if (const llvm::DWARFUnitIndex::Entry *entry = index.getFromHash(hash)) {
42 if (auto *unit_contrib = entry->getContribution())
43 return llvm::dyn_cast_or_null<DWARFCompileUnit>(
44 DebugInfo().GetUnitAtOffset(DIERef::Section::DebugInfo,
45 unit_contrib->getOffset()));
46 }
47 return nullptr;
48 }
49
51 if (!cu)
52 return nullptr;
53 std::optional<uint64_t> dwo_id = cu->GetDWOId();
54 if (!dwo_id || hash != *dwo_id)
55 return nullptr;
56 return cu;
57}
58
60 DWARFDebugInfo &debug_info = DebugInfo();
61
62 // Right now we only support dwo files with one compile unit. If we don't have
63 // type units, we can just check for the unit count.
64 if (!debug_info.ContainsTypeUnits() && debug_info.GetNumUnits() == 1)
65 return llvm::cast<DWARFCompileUnit>(debug_info.GetUnitAtIndex(0));
66
67 // Otherwise, we have to run through all units, and find the compile unit that
68 // way.
69 DWARFCompileUnit *cu = nullptr;
70 for (size_t i = 0; i < debug_info.GetNumUnits(); ++i) {
71 if (auto *candidate =
72 llvm::dyn_cast<DWARFCompileUnit>(debug_info.GetUnitAtIndex(i))) {
73 if (cu)
74 return nullptr; // More that one CU found.
75 cu = candidate;
76 }
77 }
78 return cu;
79}
80
82 const lldb_private::DataExtractor &data, const lldb::offset_t data_offset,
83 const uint8_t op) const {
84 return GetBaseSymbolFile().GetVendorDWARFOpcodeSize(data, data_offset, op);
85}
86
88 uint8_t op, const lldb_private::DataExtractor &opcodes,
89 lldb::offset_t &offset, std::vector<lldb_private::Value> &stack) const {
90 return GetBaseSymbolFile().ParseVendorDWARFOpcode(op, opcodes, offset, stack);
91}
92
95}
96
99}
100
104}
105
109}
110
112 lldb_private::ConstString class_name,
113 llvm::function_ref<bool(DWARFDIE die)> callback) {
114 GetBaseSymbolFile().GetObjCMethods(class_name, callback);
115}
116
119}
120
121lldb::TypeSP
124}
125
127 const DWARFDIE &die, lldb_private::ConstString type_name,
128 bool must_be_implementation) {
130 die, type_name, must_be_implementation);
131}
132
133llvm::Expected<lldb::TypeSystemSP>
136}
137
140 if (die_ref.file_index() == GetFileIndex())
141 return DebugInfo().GetDIE(die_ref);
142 return GetBaseSymbolFile().GetDIE(die_ref);
143}
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:28
std::optional< uint32_t > file_index() const
Definition: DIERef.h:57
@ DebugInfo
Definition: DIERef.h:30
DWARFDIE GetDIE(const DIERef &die_ref)
DWARFUnit * GetUnitAtIndex(size_t idx)
std::optional< uint64_t > GetDWOId()
Definition: DWARFUnit.cpp:367
DIEToClangType & GetForwardDeclDieToClangType() override
UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap() override
ClangTypeToDIE & GetForwardDeclClangTypeToDie() override
SymbolFileDWARF & GetBaseSymbolFile() const
DWARFCompileUnit * FindSingleCompileUnit()
If this file contains exactly one compile unit, this function will return it.
void GetObjCMethods(lldb_private::ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback) override
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation) override
DIEToTypePtr & GetDIEToType() override
DIEToVariableSP & GetDIEToVariable() override
bool ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes, lldb::offset_t &offset, std::vector< lldb_private::Value > &stack) const override
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) override
DWARFDIE GetDIE(const DIERef &die_ref) override
lldb::offset_t GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const override
DWARFCompileUnit * GetDWOCompileUnitForHash(uint64_t hash)
static char ID
LLVM RTTI support.
virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation)
virtual DIEToVariableSP & GetDIEToVariable()
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb::VariableSP > DIEToVariableSP
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb_private::Type * > DIEToTypePtr
virtual lldb::offset_t GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const
friend class SymbolFileDWARFDwo
virtual DIEToClangType & GetForwardDeclDieToClangType()
std::optional< uint64_t > GetFileIndex() const
virtual DWARFDIE GetDIE(const DIERef &die_ref)
void SetFileIndex(std::optional< uint64_t > file_index)
virtual bool ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes, lldb::offset_t &offset, std::vector< lldb_private::Value > &stack) const
lldb_private::DWARFContext m_context
DWARFDebugInfo & DebugInfo()
virtual lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die)
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb::opaque_compiler_type_t > DIEToClangType
virtual void GetObjCMethods(lldb_private::ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback)
virtual DIEToTypePtr & GetDIEToType()
virtual ClangTypeToDIE & GetForwardDeclClangTypeToDie()
llvm::DenseMap< lldb::opaque_compiler_type_t, DIERef > ClangTypeToDIE
virtual UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap()
A uniqued constant string class.
Definition: ConstString.h:39
llvm::DWARFContext & GetAsLLVM()
An data extractor class.
Definition: DataExtractor.h:48
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
uint64_t offset_t
Definition: lldb-types.h:83
LanguageType
Programming language type.