]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / source / Plugins / SymbolFile / DWARF / NameToDIE.cpp
1 //===-- NameToDIE.cpp -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "NameToDIE.h"
11 #include "lldb/Core/ConstString.h"
12 #include "lldb/Core/RegularExpression.h"
13 #include "lldb/Core/Stream.h"
14 #include "lldb/Core/StreamString.h"
15 #include "lldb/Symbol/ObjectFile.h"
16
17 #include "DWARFCompileUnit.h"
18 #include "DWARFDebugInfo.h"
19 #include "DWARFDebugInfoEntry.h"
20 #include "SymbolFileDWARF.h"
21
22 using namespace lldb;
23 using namespace lldb_private;
24
25 void NameToDIE::Finalize() {
26   m_map.Sort();
27   m_map.SizeToFit();
28 }
29
30 void NameToDIE::Insert(const ConstString &name, const DIERef &die_ref) {
31   m_map.Append(name.GetStringRef(), die_ref);
32 }
33
34 size_t NameToDIE::Find(const ConstString &name, DIEArray &info_array) const {
35   return m_map.GetValues(name.GetStringRef(), info_array);
36 }
37
38 size_t NameToDIE::Find(const RegularExpression &regex,
39                        DIEArray &info_array) const {
40   return m_map.GetValues(regex, info_array);
41 }
42
43 size_t NameToDIE::FindAllEntriesForCompileUnit(dw_offset_t cu_offset,
44                                                DIEArray &info_array) const {
45   const size_t initial_size = info_array.size();
46   const uint32_t size = m_map.GetSize();
47   for (uint32_t i = 0; i < size; ++i) {
48     const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
49     if (cu_offset == die_ref.cu_offset)
50       info_array.push_back(die_ref);
51   }
52   return info_array.size() - initial_size;
53 }
54
55 void NameToDIE::Dump(Stream *s) {
56   const uint32_t size = m_map.GetSize();
57   for (uint32_t i = 0; i < size; ++i) {
58     llvm::StringRef cstr = m_map.GetCStringAtIndex(i);
59     const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
60     s->Printf("%p: {0x%8.8x/0x%8.8x} \"%s\"\n", (const void *)cstr.data(),
61               die_ref.cu_offset, die_ref.die_offset, cstr.str().c_str());
62   }
63 }
64
65 void NameToDIE::ForEach(
66     std::function<bool(llvm::StringRef name, const DIERef &die_ref)> const
67         &callback) const {
68   const uint32_t size = m_map.GetSize();
69   for (uint32_t i = 0; i < size; ++i) {
70     if (!callback(m_map.GetCStringAtIndexUnchecked(i),
71                   m_map.GetValueAtIndexUnchecked(i)))
72       break;
73   }
74 }
75
76 void NameToDIE::Append(const NameToDIE &other) {
77   const uint32_t size = other.m_map.GetSize();
78   for (uint32_t i = 0; i < size; ++i) {
79     m_map.Append(other.m_map.GetCStringAtIndexUnchecked(i),
80                  other.m_map.GetValueAtIndexUnchecked(i));
81   }
82 }