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  const DWARFUnit &unit,
49  llvm::function_ref<bool(DIERef ref)> callback) const {
50  const uint32_t size = m_map.GetSize();
51  for (uint32_t i = 0; i < size; ++i) {
52  const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
53  if (unit.GetSymbolFileDWARF().GetDwoNum() == die_ref.dwo_num() &&
54  unit.GetDebugSection() == die_ref.section() &&
55  unit.GetOffset() <= die_ref.die_offset() &&
56  die_ref.die_offset() < unit.GetNextUnitOffset()) {
57  if (!callback(die_ref))
58  return;
59  }
60  }
61 }
62 
64  const uint32_t size = m_map.GetSize();
65  for (uint32_t i = 0; i < size; ++i) {
66  s->Format("{0} \"{1}\"\n", m_map.GetValueAtIndexUnchecked(i),
67  m_map.GetCStringAtIndexUnchecked(i));
68  }
69 }
70 
72  std::function<bool(ConstString name, const DIERef &die_ref)> const
73  &callback) const {
74  const uint32_t size = m_map.GetSize();
75  for (uint32_t i = 0; i < size; ++i) {
76  if (!callback(m_map.GetCStringAtIndexUnchecked(i),
77  m_map.GetValueAtIndexUnchecked(i)))
78  break;
79  }
80 }
81 
82 void NameToDIE::Append(const NameToDIE &other) {
83  const uint32_t size = other.m_map.GetSize();
84  for (uint32_t i = 0; i < size; ++i) {
85  m_map.Append(other.m_map.GetCStringAtIndexUnchecked(i),
87  }
88 }
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
NameToDIE::FindAllEntriesForUnit
void FindAllEntriesForUnit(const DWARFUnit &unit, llvm::function_ref< bool(DIERef ref)> callback) const
Definition: NameToDIE.cpp:47
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:80
DWARFUnit::GetNextUnitOffset
dw_offset_t GetNextUnitOffset() const
Definition: DWARFUnit.h:146
lldb_private::UniqueCStringMap::GetSize
size_t GetSize() const
Definition: UniqueCStringMap.h:148
StreamString.h
lldb_private::ConstString
Definition: ConstString.h:40
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:130
uint32_t
DIERef::section
Section section() const
Definition: DIERef.h:43
NameToDIE::Append
void Append(const NameToDIE &other)
Definition: NameToDIE.cpp:82
NameToDIE::m_map
lldb_private::UniqueCStringMap< DIERef > m_map
Definition: NameToDIE.h:51
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:63
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:194
NameToDIE::Finalize
void Finalize()
Definition: NameToDIE.cpp:20
DWARFUnit::GetDebugSection
DIERef::Section GetDebugSection() const
Definition: DWARFUnit.h:220
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:71
lldb_private::UniqueCStringMap::GetCStringAtIndexUnchecked
ConstString GetCStringAtIndexUnchecked(uint32_t idx) const
Definition: UniqueCStringMap.h:62