NameToDIE.cpp revision 296417
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/Stream.h"
13#include "lldb/Core/StreamString.h"
14#include "lldb/Core/RegularExpression.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
22using namespace lldb;
23using namespace lldb_private;
24
25void
26NameToDIE::Finalize()
27{
28    m_map.Sort ();
29    m_map.SizeToFit ();
30}
31
32void
33NameToDIE::Insert (const ConstString& name, const DIERef& die_ref)
34{
35    m_map.Append(name.GetCString(), die_ref);
36}
37
38size_t
39NameToDIE::Find (const ConstString &name, DIEArray &info_array) const
40{
41    return m_map.GetValues (name.GetCString(), info_array);
42}
43
44size_t
45NameToDIE::Find (const RegularExpression& regex, DIEArray &info_array) const
46{
47    return m_map.GetValues (regex, info_array);
48}
49
50size_t
51NameToDIE::FindAllEntriesForCompileUnit (dw_offset_t cu_offset, DIEArray &info_array) const
52{
53    const size_t initial_size = info_array.size();
54    const uint32_t size = m_map.GetSize();
55    for (uint32_t i=0; i<size; ++i)
56    {
57        const DIERef& die_ref = m_map.GetValueAtIndexUnchecked(i);
58        if (cu_offset == die_ref.cu_offset)
59            info_array.push_back (die_ref);
60    }
61    return info_array.size() - initial_size;
62}
63
64void
65NameToDIE::Dump (Stream *s)
66{
67    const uint32_t size = m_map.GetSize();
68    for (uint32_t i=0; i<size; ++i)
69    {
70        const char *cstr = m_map.GetCStringAtIndex(i);
71        const DIERef& die_ref = m_map.GetValueAtIndexUnchecked(i);
72        s->Printf("%p: {0x%8.8x/0x%8.8x} \"%s\"\n", (const void*) cstr, die_ref.cu_offset, die_ref.die_offset, cstr);
73    }
74}
75
76void
77NameToDIE::ForEach (std::function <bool(const char *name, const DIERef& die_ref)> const &callback) const
78{
79    const uint32_t size = m_map.GetSize();
80    for (uint32_t i=0; i<size; ++i)
81    {
82        if (!callback(m_map.GetCStringAtIndexUnchecked(i), m_map.GetValueAtIndexUnchecked (i)))
83            break;
84    }
85}
86
87void
88NameToDIE::Append (const NameToDIE& other)
89{
90    const uint32_t size = other.m_map.GetSize();
91    for (uint32_t i = 0; i < size; ++i)
92    {
93        m_map.Append(other.m_map.GetCStringAtIndexUnchecked (i),
94                     other.m_map.GetValueAtIndexUnchecked (i));
95    }
96}
97