1 //===-- NameToDIE.cpp -------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 #include "DWARFUnit.h"
11 #include "lldb/Symbol/ObjectFile.h"
12 #include "lldb/Utility/ConstString.h"
13 #include "lldb/Utility/RegularExpression.h"
14 #include "lldb/Utility/Stream.h"
15 #include "lldb/Utility/StreamString.h"
18 using namespace lldb_private;
20 void NameToDIE::Finalize() {
25 void NameToDIE::Insert(ConstString name, const DIERef &die_ref) {
26 m_map.Append(name, die_ref);
29 size_t NameToDIE::Find(ConstString name, DIEArray &info_array) const {
30 return m_map.GetValues(name, info_array);
33 size_t NameToDIE::Find(const RegularExpression ®ex,
34 DIEArray &info_array) const {
35 return m_map.GetValues(regex, info_array);
38 size_t NameToDIE::FindAllEntriesForUnit(const DWARFUnit &unit,
39 DIEArray &info_array) const {
40 const size_t initial_size = info_array.size();
41 const uint32_t size = m_map.GetSize();
42 for (uint32_t i = 0; i < size; ++i) {
43 const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
44 if (unit.GetSymbolFileDWARF().GetDwoNum() == die_ref.dwo_num() &&
45 unit.GetDebugSection() == die_ref.section() &&
46 unit.GetOffset() <= die_ref.die_offset() &&
47 die_ref.die_offset() < unit.GetNextUnitOffset())
48 info_array.push_back(die_ref);
50 return info_array.size() - initial_size;
53 void NameToDIE::Dump(Stream *s) {
54 const uint32_t size = m_map.GetSize();
55 for (uint32_t i = 0; i < size; ++i) {
56 s->Format("{0} \"{1}\"\n", m_map.GetValueAtIndexUnchecked(i),
57 m_map.GetCStringAtIndexUnchecked(i));
61 void NameToDIE::ForEach(
62 std::function<bool(ConstString name, const DIERef &die_ref)> const
64 const uint32_t size = m_map.GetSize();
65 for (uint32_t i = 0; i < size; ++i) {
66 if (!callback(m_map.GetCStringAtIndexUnchecked(i),
67 m_map.GetValueAtIndexUnchecked(i)))
72 void NameToDIE::Append(const NameToDIE &other) {
73 const uint32_t size = other.m_map.GetSize();
74 for (uint32_t i = 0; i < size; ++i) {
75 m_map.Append(other.m_map.GetCStringAtIndexUnchecked(i),
76 other.m_map.GetValueAtIndexUnchecked(i));