LLDB  mainline
NameToDIE.cpp
Go to the documentation of this file.
1 //===-- NameToDIE.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 "NameToDIE.h"
10 #include "DWARFUnit.h"
11 #include "lldb/Symbol/ObjectFile.h"
14 #include "lldb/Utility/Stream.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
21  m_map.Sort();
22  m_map.SizeToFit();
23 }
24 
25 void NameToDIE::Insert(ConstString name, const DIERef &die_ref) {
26  m_map.Append(name, die_ref);
27 }
28 
30  llvm::function_ref<bool(DIERef ref)> callback) const {
31  for (const auto &entry : m_map.equal_range(name))
32  if (!callback(entry.value))
33  return false;
34  return true;
35 }
36 
38  llvm::function_ref<bool(DIERef ref)> callback) const {
39  for (const auto &entry : m_map)
40  if (regex.Execute(entry.cstring.GetCString())) {
41  if (!callback(entry.value))
42  return false;
43  }
44  return true;
45 }
46 
48  DWARFUnit &s_unit, llvm::function_ref<bool(DIERef ref)> callback) const {
50  const DWARFUnit &ns_unit = s_unit.GetNonSkeletonUnit();
51  const uint32_t size = m_map.GetSize();
52  for (uint32_t i = 0; i < size; ++i) {
53  const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
54  if (ns_unit.GetSymbolFileDWARF().GetDwoNum() == die_ref.dwo_num() &&
55  ns_unit.GetDebugSection() == die_ref.section() &&
56  ns_unit.GetOffset() <= die_ref.die_offset() &&
57  die_ref.die_offset() < ns_unit.GetNextUnitOffset()) {
58  if (!callback(die_ref))
59  return;
60  }
61  }
62 }
63 
65  const uint32_t size = m_map.GetSize();
66  for (uint32_t i = 0; i < size; ++i) {
67  s->Format("{0} \"{1}\"\n", m_map.GetValueAtIndexUnchecked(i),
68  m_map.GetCStringAtIndexUnchecked(i));
69  }
70 }
71 
73  std::function<bool(ConstString name, const DIERef &die_ref)> const
74  &callback) const {
75  const uint32_t size = m_map.GetSize();
76  for (uint32_t i = 0; i < size; ++i) {
77  if (!callback(m_map.GetCStringAtIndexUnchecked(i),
78  m_map.GetValueAtIndexUnchecked(i)))
79  break;
80  }
81 }
82 
83 void NameToDIE::Append(const NameToDIE &other) {
84  const uint32_t size = other.m_map.GetSize();
85  for (uint32_t i = 0; i < size; ++i) {
86  m_map.Append(other.m_map.GetCStringAtIndexUnchecked(i),
88  }
89 }
RegularExpression.h
lldb_private::Stream::Format
void Format(const char *format, Args &&... args)
Definition: Stream.h:309
DIERef
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:26
lldb_private::RegularExpression
Definition: RegularExpression.h:18
lldb_private::Stream
Definition: Stream.h:28
DIERef::die_offset
dw_offset_t die_offset() const
Definition: DIERef.h:45
lldb_private::UniqueCStringMap::GetValueAtIndexUnchecked
T GetValueAtIndexUnchecked(uint32_t idx) const
Definition: UniqueCStringMap.h:68
DWARFUnit
Definition: DWARFUnit.h:81
DWARFUnit::GetNextUnitOffset
dw_offset_t GetNextUnitOffset() const
Definition: DWARFUnit.h:147
lldb_private::UniqueCStringMap::GetSize
size_t GetSize() const
Definition: UniqueCStringMap.h:148
StreamString.h
lldb_private::ConstString
Definition: ConstString.h:40
NameToDIE::FindAllEntriesForUnit
void FindAllEntriesForUnit(DWARFUnit &unit, llvm::function_ref< bool(DIERef ref)> callback) const
unit must be the skeleton unit if possible, not GetNonSkeletonUnit().
Definition: NameToDIE.cpp:47
DWARFUnit.h
NameToDIE::Insert
void Insert(lldb_private::ConstString name, const DIERef &die_ref)
Definition: NameToDIE.cpp:25
NameToDIE::Find
bool Find(lldb_private::ConstString name, llvm::function_ref< bool(DIERef ref)> callback) const
Definition: NameToDIE.cpp:29
ObjectFile.h
DWARFUnit::GetOffset
dw_offset_t GetOffset() const
Definition: DWARFUnit.h:131
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
uint32_t
DIERef::section
Section section() const
Definition: DIERef.h:43
NameToDIE::Append
void Append(const NameToDIE &other)
Definition: NameToDIE.cpp:83
DWARFUnit::GetNonSkeletonUnit
DWARFUnit & GetNonSkeletonUnit()
Definition: DWARFUnit.cpp:627
NameToDIE::m_map
lldb_private::UniqueCStringMap< DIERef > m_map
Definition: NameToDIE.h:52
DIERef::dwo_num
llvm::Optional< uint32_t > dwo_num() const
Definition: DIERef.h:37
NameToDIE.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
NameToDIE::Dump
void Dump(lldb_private::Stream *s)
Definition: NameToDIE.cpp:64
lldb_private::RegularExpression::Execute
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
Definition: RegularExpression.cpp:23
SymbolFileDWARF::GetDwoNum
virtual llvm::Optional< uint32_t > GetDwoNum()
Definition: SymbolFileDWARF.h:279
ConstString.h
Stream.h
DWARFUnit::GetSymbolFileDWARF
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:195
NameToDIE::Finalize
void Finalize()
Definition: NameToDIE.cpp:20
DWARFUnit::GetDebugSection
DIERef::Section GetDebugSection() const
Definition: DWARFUnit.h:217
lldb
Definition: SBAddress.h:15
NameToDIE
Definition: NameToDIE.h:21
NameToDIE::ForEach
void ForEach(std::function< bool(lldb_private::ConstString name, const DIERef &die_ref)> const &callback) const
Definition: NameToDIE.cpp:72
lldb_private::UniqueCStringMap::GetCStringAtIndexUnchecked
ConstString GetCStringAtIndexUnchecked(uint32_t idx) const
Definition: UniqueCStringMap.h:62