LLDB  mainline
NameToDIE.cpp
Go to the documentation of this file.
1 //===-- NameToDIE.cpp -------------------------------------------*- C++ -*-===//
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 "lldb/Symbol/ObjectFile.h"
13 #include "lldb/Utility/Stream.h"
15 
16 #include "DWARFDebugInfo.h"
17 #include "DWARFDebugInfoEntry.h"
18 #include "SymbolFileDWARF.h"
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
24  m_map.Sort();
25  m_map.SizeToFit();
26 }
27 
28 void NameToDIE::Insert(ConstString name, const DIERef &die_ref) {
29  m_map.Append(name, die_ref);
30 }
31 
32 size_t NameToDIE::Find(ConstString name, DIEArray &info_array) const {
33  return m_map.GetValues(name, info_array);
34 }
35 
36 size_t NameToDIE::Find(const RegularExpression &regex,
37  DIEArray &info_array) const {
38  return m_map.GetValues(regex, info_array);
39 }
40 
42  DIEArray &info_array) const {
43  const size_t initial_size = info_array.size();
44  const uint32_t size = m_map.GetSize();
45  for (uint32_t i = 0; i < size; ++i) {
46  const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
47  if (cu_offset == die_ref.cu_offset)
48  info_array.push_back(die_ref);
49  }
50  return info_array.size() - initial_size;
51 }
52 
54  const uint32_t size = m_map.GetSize();
55  for (uint32_t i = 0; i < size; ++i) {
56  ConstString cstr = m_map.GetCStringAtIndex(i);
57  const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
58  s->Printf("%p: {0x%8.8x/0x%8.8x} \"%s\"\n", (const void *)cstr.GetCString(),
59  die_ref.cu_offset, die_ref.die_offset, cstr.GetCString());
60  }
61 }
62 
64  std::function<bool(ConstString name, const DIERef &die_ref)> const
65  &callback) const {
66  const uint32_t size = m_map.GetSize();
67  for (uint32_t i = 0; i < size; ++i) {
68  if (!callback(m_map.GetCStringAtIndexUnchecked(i),
69  m_map.GetValueAtIndexUnchecked(i)))
70  break;
71  }
72 }
73 
74 void NameToDIE::Append(const NameToDIE &other) {
75  const uint32_t size = other.m_map.GetSize();
76  for (uint32_t i = 0; i < size; ++i) {
77  m_map.Append(other.m_map.GetCStringAtIndexUnchecked(i),
79  }
80 }
void Append(const NameToDIE &other)
Definition: NameToDIE.cpp:74
void Finalize()
Definition: NameToDIE.cpp:23
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t FindAllEntriesForCompileUnit(dw_offset_t cu_offset, DIEArray &info_array) const
Definition: NameToDIE.cpp:41
ConstString GetCStringAtIndexUnchecked(uint32_t idx) const
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
Definition: DIERef.h:18
std::vector< DIERef > DIEArray
Definition: DIERef.h:51
dw_offset_t die_offset
Definition: DIERef.h:48
lldb_private::UniqueCStringMap< DIERef > m_map
Definition: NameToDIE.h:50
T GetValueAtIndexUnchecked(uint32_t idx) const
void Insert(lldb_private::ConstString name, const DIERef &die_ref)
Definition: NameToDIE.cpp:28
void Dump(lldb_private::Stream *s)
Definition: NameToDIE.cpp:53
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
void ForEach(std::function< bool(lldb_private::ConstString name, const DIERef &die_ref)> const &callback) const
Definition: NameToDIE.cpp:63
dw_offset_t cu_offset
Definition: DIERef.h:47
A uniqued constant string class.
Definition: ConstString.h:38
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:247
Definition: SBAddress.h:15
size_t Find(lldb_private::ConstString name, DIEArray &info_array) const
Definition: NameToDIE.cpp:32