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 
9 #include "SymbolFileDWARFDwo.h"
10 
11 #include "lldb/Core/Section.h"
13 #include "lldb/Symbol/ObjectFile.h"
15 #include "llvm/Support/Casting.h"
16 
17 #include "DWARFCompileUnit.h"
18 #include "DWARFDebugInfo.h"
19 #include "DWARFUnit.h"
20 #include <optional>
21 
22 using namespace lldb;
23 using 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  SetID(user_id_t(id) << 32);
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->getOffset32()));
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 
121 lldb::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 
133 llvm::Expected<lldb::TypeSystemSP>
135  return GetBaseSymbolFile().GetTypeSystemForLanguage(language);
136 }
137 
138 DWARFDIE
140  if (die_ref.dwo_num() == GetDwoNum())
141  return DebugInfo().GetDIE(die_ref);
142  return GetBaseSymbolFile().GetDIE(die_ref);
143 }
SymbolFileDWARFDwo::GetBaseSymbolFile
SymbolFileDWARF & GetBaseSymbolFile() const
Definition: SymbolFileDWARFDwo.h:74
SymbolFileDWARFDwo::ID
static char ID
LLVM RTTI support.
Definition: SymbolFileDWARFDwo.h:17
DWARFDebugInfo::ContainsTypeUnits
bool ContainsTypeUnits()
Definition: DWARFDebugInfo.cpp:179
SymbolFileDWARF::SymbolFileDWARFDwo
friend class SymbolFileDWARFDwo
Definition: SymbolFileDWARF.h:76
DIERef
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:26
DWARFCompileUnit.h
SymbolFileDWARFDwo::GetDIEToVariable
DIEToVariableSP & GetDIEToVariable() override
Definition: SymbolFileDWARFDwo.cpp:97
SymbolFileDWARF::GetForwardDeclDieToClangType
virtual DIEToClangType & GetForwardDeclDieToClangType()
Definition: SymbolFileDWARF.h:513
SymbolFileDWARF::GetVendorDWARFOpcodeSize
virtual lldb::offset_t GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const
Definition: SymbolFileDWARF.h:335
DWARFDebugInfo
Definition: DWARFDebugInfo.h:26
DWARFDebugInfo::GetNumUnits
size_t GetNumUnits()
Definition: DWARFDebugInfo.cpp:113
SymbolFileDWARFDwo::GetDIEToType
DIEToTypePtr & GetDIEToType() override
Definition: SymbolFileDWARFDwo.cpp:93
SymbolFileDWARF::DIEToClangType
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb::opaque_compiler_type_t > DIEToClangType
Definition: SymbolFileDWARF.h:357
SymbolFileDWARF
Definition: SymbolFileDWARF.h:61
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:443
SymbolFileDWARFDwo::GetTypeSystemForLanguage
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
Definition: SymbolFileDWARFDwo.cpp:134
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
SymbolFileDWARFDwo::GetObjCMethods
void GetObjCMethods(lldb_private::ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback) override
Definition: SymbolFileDWARFDwo.cpp:111
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext
virtual lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die)
Definition: SymbolFileDWARF.cpp:2965
SymbolFileDWARFDwo::GetDwoNum
std::optional< uint32_t > GetDwoNum() override
Definition: SymbolFileDWARFDwo.h:44
lldb_private::UserID::SetID
void SetID(lldb::user_id_t uid)
Set accessor for the user ID.
Definition: UserID.h:53
SymbolFileDWARF::GetDIEToVariable
virtual DIEToVariableSP & GetDIEToVariable()
Definition: SymbolFileDWARF.h:511
Section.h
SymbolFileDWARF::GetObjCMethods
virtual void GetObjCMethods(lldb_private::ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback)
Definition: SymbolFileDWARF.cpp:1659
DWARFDIE
Definition: DWARFDIE.h:16
SymbolFileDWARFDwo.h
DWARFCompileUnit
Definition: DWARFCompileUnit.h:15
lldb_private::DWARFContext::GetAsLLVM
llvm::DWARFContext & GetAsLLVM()
Definition: DWARFContext.cpp:127
SymbolFileDWARF::GetForwardDeclClangTypeToDie
virtual ClangTypeToDIE & GetForwardDeclClangTypeToDie()
Definition: SymbolFileDWARF.h:517
SymbolFileDWARF::ParseVendorDWARFOpcode
virtual bool ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes, lldb::offset_t &offset, std::vector< lldb_private::Value > &stack) const
Definition: SymbolFileDWARF.h:342
LLDBAssert.h
lldb_private::DataExtractor
Definition: DataExtractor.h:48
SymbolFileDWARFDwo::FindSingleCompileUnit
DWARFCompileUnit * FindSingleCompileUnit()
If this file contains exactly one compile unit, this function will return it.
Definition: SymbolFileDWARFDwo.cpp:59
DWARFDebugInfo::GetUnitAtIndex
DWARFUnit * GetUnitAtIndex(size_t idx)
Definition: DWARFDebugInfo.cpp:118
lldb_private::ConstString
Definition: ConstString.h:39
SymbolFileDWARF::DIEToTypePtr
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb_private::Type * > DIEToTypePtr
Definition: SymbolFileDWARF.h:352
SymbolFileDWARF::GetDIEToType
virtual DIEToTypePtr & GetDIEToType()
Definition: SymbolFileDWARF.h:509
SymbolFileDWARFDwo::GetForwardDeclDieToClangType
DIEToClangType & GetForwardDeclDieToClangType() override
Definition: SymbolFileDWARFDwo.cpp:102
SymbolFileDWARF::ClangTypeToDIE
llvm::DenseMap< lldb::opaque_compiler_type_t, DIERef > ClangTypeToDIE
Definition: SymbolFileDWARF.h:358
DWARFDebugInfo.h
DWARFUnit.h
DWARFUnit::GetDWOId
std::optional< uint64_t > GetDWOId()
Definition: DWARFUnit.cpp:367
UniqueDWARFASTTypeMap
Definition: UniqueDWARFASTType.h:71
DIERef::dwo_num
std::optional< uint32_t > dwo_num() const
Definition: DIERef.h:37
ObjectFile.h
SymbolFileDWARFDwo::ParseVendorDWARFOpcode
bool ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes, lldb::offset_t &offset, std::vector< lldb_private::Value > &stack) const override
Definition: SymbolFileDWARFDwo.cpp:87
SymbolFileDWARF::m_context
lldb_private::DWARFContext m_context
Definition: SymbolFileDWARF.h:545
SymbolFileDWARFDwo::GetDIE
DWARFDIE GetDIE(const DIERef &die_ref) override
Definition: SymbolFileDWARFDwo.cpp:139
SymbolFileDWARFDwo::GetDWOCompileUnitForHash
DWARFCompileUnit * GetDWOCompileUnitForHash(uint64_t hash)
Definition: SymbolFileDWARFDwo.cpp:39
SymbolFileDWARF::DIEToVariableSP
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb::VariableSP > DIEToVariableSP
Definition: SymbolFileDWARF.h:354
SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) override
Definition: SymbolFileDWARFDwo.cpp:122
SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap
UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap() override
Definition: SymbolFileDWARFDwo.cpp:117
uint32_t
SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie
ClangTypeToDIE & GetForwardDeclClangTypeToDie() override
Definition: SymbolFileDWARFDwo.cpp:107
SymbolFileDWARFDwo::FindCompleteObjCDefinitionTypeForDIE
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation) override
Definition: SymbolFileDWARFDwo.cpp:126
SymbolFileDWARF::DebugInfo
DWARFDebugInfo & DebugInfo()
Definition: SymbolFileDWARF.cpp:636
SymbolFileDWARF::GetTypeSystemForLanguage
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
Definition: SymbolFileDWARF.cpp:436
DWARFExpression.h
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE
virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation)
Definition: SymbolFileDWARF.cpp:2822
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
SymbolFileDWARF::GetUniqueDWARFASTTypeMap
virtual UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap()
Definition: SymbolFileDWARF.cpp:427
Entry
FormatEntity::Entry Entry
Definition: FormatEntity.cpp:82
SymbolFileDWARF::GetDIE
virtual DWARFDIE GetDIE(const DIERef &die_ref)
Definition: SymbolFileDWARF.cpp:1695
lldb
Definition: SBAddress.h:15
DWARFDebugInfo::GetDIE
DWARFDIE GetDIE(const DIERef &die_ref)
Definition: DWARFDebugInfo.cpp:188
SymbolFileDWARFDwo::GetVendorDWARFOpcodeSize
lldb::offset_t GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const override
Definition: SymbolFileDWARFDwo.cpp:81