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 
21 using namespace lldb;
22 using namespace lldb_private;
23 
25 
27  ObjectFileSP objfile, uint32_t id)
28  : SymbolFileDWARF(objfile, objfile->GetSectionList(
29  /*update_module_section_list*/ false)),
30  m_base_symbol_file(base_symbol_file) {
31  SetID(user_id_t(id) << 32);
32 
33  // Parsing of the dwarf unit index is not thread-safe, so we need to prime it
34  // to enable subsequent concurrent lookups.
35  m_context.GetAsLLVM().getCUIndex();
36 }
37 
39  if (const llvm::DWARFUnitIndex &index = m_context.GetAsLLVM().getCUIndex()) {
40  if (const llvm::DWARFUnitIndex::Entry *entry = index.getFromHash(hash)) {
41  if (auto *unit_contrib = entry->getContribution())
42  return llvm::dyn_cast_or_null<DWARFCompileUnit>(
43  DebugInfo().GetUnitAtOffset(DIERef::Section::DebugInfo,
44  unit_contrib->Offset));
45  }
46  return nullptr;
47  }
48 
50  if (!cu)
51  return nullptr;
52  if (hash != cu->GetDWOId())
53  return nullptr;
54  return cu;
55 }
56 
58  DWARFDebugInfo &debug_info = DebugInfo();
59 
60  // Right now we only support dwo files with one compile unit. If we don't have
61  // type units, we can just check for the unit count.
62  if (!debug_info.ContainsTypeUnits() && debug_info.GetNumUnits() == 1)
63  return llvm::cast<DWARFCompileUnit>(debug_info.GetUnitAtIndex(0));
64 
65  // Otherwise, we have to run through all units, and find the compile unit that
66  // way.
67  DWARFCompileUnit *cu = nullptr;
68  for (size_t i = 0; i < debug_info.GetNumUnits(); ++i) {
69  if (auto *candidate =
70  llvm::dyn_cast<DWARFCompileUnit>(debug_info.GetUnitAtIndex(i))) {
71  if (cu)
72  return nullptr; // More that one CU found.
73  cu = candidate;
74  }
75  }
76  return cu;
77 }
78 
81 }
82 
85 }
86 
90 }
91 
95 }
96 
98  lldb_private::ConstString class_name,
99  llvm::function_ref<bool(DWARFDIE die)> callback) {
100  GetBaseSymbolFile().GetObjCMethods(class_name, callback);
101 }
102 
105 }
106 
108  const DWARFDeclContext &die_decl_ctx) {
110  die_decl_ctx);
111 }
112 
114  const DWARFDIE &die, lldb_private::ConstString type_name,
115  bool must_be_implementation) {
117  die, type_name, must_be_implementation);
118 }
119 
120 llvm::Expected<TypeSystem &>
122  return GetBaseSymbolFile().GetTypeSystemForLanguage(language);
123 }
124 
125 DWARFDIE
127  if (die_ref.dwo_num() == GetDwoNum())
128  return DebugInfo().GetDIE(die_ref);
129  return GetBaseSymbolFile().GetDIE(die_ref);
130 }
SymbolFileDWARFDwo::ID
static char ID
LLVM RTTI support.
Definition: SymbolFileDWARFDwo.h:16
DWARFDebugInfo::ContainsTypeUnits
bool ContainsTypeUnits()
Definition: DWARFDebugInfo.cpp:172
SymbolFileDWARF::SymbolFileDWARFDwo
friend class SymbolFileDWARFDwo
Definition: SymbolFileDWARF.h:74
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:83
SymbolFileDWARFDwo::GetBaseSymbolFile
SymbolFileDWARF & GetBaseSymbolFile()
Definition: SymbolFileDWARFDwo.h:63
SymbolFileDWARF::GetForwardDeclDieToClangType
virtual DIEToClangType & GetForwardDeclDieToClangType()
Definition: SymbolFileDWARF.h:494
SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx) override
Definition: SymbolFileDWARFDwo.cpp:107
SymbolFileDWARFDwo::GetDwoNum
llvm::Optional< uint32_t > GetDwoNum() override
Definition: SymbolFileDWARFDwo.h:43
DWARFUnit::GetDWOId
uint64_t GetDWOId()
Definition: DWARFUnit.cpp:347
DWARFDebugInfo
Definition: DWARFDebugInfo.h:26
DWARFDebugInfo::GetNumUnits
size_t GetNumUnits()
Definition: DWARFDebugInfo.cpp:106
SymbolFileDWARFDwo::GetDIEToType
DIEToTypePtr & GetDIEToType() override
Definition: SymbolFileDWARFDwo.cpp:79
SymbolFileDWARF::DIEToClangType
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb::opaque_compiler_type_t > DIEToClangType
Definition: SymbolFileDWARF.h:339
SymbolFileDWARF
Definition: SymbolFileDWARF.h:59
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
SymbolFileDWARFDwo::GetObjCMethods
void GetObjCMethods(lldb_private::ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback) override
Definition: SymbolFileDWARFDwo.cpp:97
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:492
Section.h
SymbolFileDWARF::GetObjCMethods
virtual void GetObjCMethods(lldb_private::ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback)
Definition: SymbolFileDWARF.cpp:1633
DWARFDIE
Definition: DWARFDIE.h:16
SymbolFileDWARF::GetTypeSystemForLanguage
llvm::Expected< lldb_private::TypeSystem & > GetTypeSystemForLanguage(lldb::LanguageType language) override
Definition: SymbolFileDWARF.cpp:433
SymbolFileDWARFDwo.h
DWARFCompileUnit
Definition: DWARFCompileUnit.h:15
lldb_private::DWARFContext::GetAsLLVM
llvm::DWARFContext & GetAsLLVM()
Definition: DWARFContext.cpp:126
SymbolFileDWARF::GetForwardDeclClangTypeToDie
virtual ClangTypeToDIE & GetForwardDeclClangTypeToDie()
Definition: SymbolFileDWARF.h:498
LLDBAssert.h
SymbolFileDWARFDwo::GetTypeSystemForLanguage
llvm::Expected< lldb_private::TypeSystem & > GetTypeSystemForLanguage(lldb::LanguageType language) override
Definition: SymbolFileDWARFDwo.cpp:121
SymbolFileDWARFDwo::FindSingleCompileUnit
DWARFCompileUnit * FindSingleCompileUnit()
If this file contains exactly one compile unit, this function will return it.
Definition: SymbolFileDWARFDwo.cpp:57
DWARFDebugInfo::GetUnitAtIndex
DWARFUnit * GetUnitAtIndex(size_t idx)
Definition: DWARFDebugInfo.cpp:111
lldb_private::ConstString
Definition: ConstString.h:40
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext
virtual lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx)
Definition: SymbolFileDWARF.cpp:2835
SymbolFileDWARF::DIEToTypePtr
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb_private::Type * > DIEToTypePtr
Definition: SymbolFileDWARF.h:334
SymbolFileDWARF::GetDIEToType
virtual DIEToTypePtr & GetDIEToType()
Definition: SymbolFileDWARF.h:490
SymbolFileDWARFDwo::GetForwardDeclDieToClangType
DIEToClangType & GetForwardDeclDieToClangType() override
Definition: SymbolFileDWARFDwo.cpp:88
SymbolFileDWARF::ClangTypeToDIE
llvm::DenseMap< lldb::opaque_compiler_type_t, DIERef > ClangTypeToDIE
Definition: SymbolFileDWARF.h:340
DWARFDebugInfo.h
DWARFUnit.h
UniqueDWARFASTTypeMap
Definition: UniqueDWARFASTType.h:71
ObjectFile.h
SymbolFileDWARF::m_context
lldb_private::DWARFContext m_context
Definition: SymbolFileDWARF.h:526
SymbolFileDWARFDwo::GetDIE
DWARFDIE GetDIE(const DIERef &die_ref) override
Definition: SymbolFileDWARFDwo.cpp:126
SymbolFileDWARFDwo::GetDWOCompileUnitForHash
DWARFCompileUnit * GetDWOCompileUnitForHash(uint64_t hash)
Definition: SymbolFileDWARFDwo.cpp:38
SymbolFileDWARF::DIEToVariableSP
llvm::DenseMap< const DWARFDebugInfoEntry *, lldb::VariableSP > DIEToVariableSP
Definition: SymbolFileDWARF.h:336
SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap
UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap() override
Definition: SymbolFileDWARFDwo.cpp:103
uint32_t
SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie
ClangTypeToDIE & GetForwardDeclClangTypeToDie() override
Definition: SymbolFileDWARFDwo.cpp:93
SymbolFileDWARFDwo::FindCompleteObjCDefinitionTypeForDIE
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation) override
Definition: SymbolFileDWARFDwo.cpp:113
SymbolFileDWARF::DebugInfo
DWARFDebugInfo & DebugInfo()
Definition: SymbolFileDWARF.cpp:635
DIERef::dwo_num
llvm::Optional< uint32_t > dwo_num() const
Definition: DIERef.h:37
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:2693
DWARFDeclContext
Definition: DWARFDeclContext.h:23
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:424
Entry
FormatEntity::Entry Entry
Definition: FormatEntity.cpp:82
SymbolFileDWARF::GetDIE
virtual DWARFDIE GetDIE(const DIERef &die_ref)
Definition: SymbolFileDWARF.cpp:1669
lldb
Definition: SBAddress.h:15
DWARFDebugInfo::GetDIE
DWARFDIE GetDIE(const DIERef &die_ref)
Definition: DWARFDebugInfo.cpp:181