NameToDIE.cpp revision 321369
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/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"
16
17#include "DWARFCompileUnit.h"
18#include "DWARFDebugInfo.h"
19#include "DWARFDebugInfoEntry.h"
20#include "SymbolFileDWARF.h"
21
22using namespace lldb;
23using namespace lldb_private;
24
25void NameToDIE::Finalize() {
26  m_map.Sort();
27  m_map.SizeToFit();
28}
29
30void NameToDIE::Insert(const ConstString &name, const DIERef &die_ref) {
31  m_map.Append(name, die_ref);
32}
33
34size_t NameToDIE::Find(const ConstString &name, DIEArray &info_array) const {
35  return m_map.GetValues(name, info_array);
36}
37
38size_t NameToDIE::Find(const RegularExpression &regex,
39                       DIEArray &info_array) const {
40  return m_map.GetValues(regex, info_array);
41}
42
43size_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
55void NameToDIE::Dump(Stream *s) {
56  const uint32_t size = m_map.GetSize();
57  for (uint32_t i = 0; i < size; ++i) {
58    ConstString 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.GetCString(),
61              die_ref.cu_offset, die_ref.die_offset, cstr.GetCString());
62  }
63}
64
65void NameToDIE::ForEach(
66    std::function<bool(ConstString 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
76void 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}
83