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/DataExtractor.h"
13#include "lldb/Core/Stream.h"
14#include "lldb/Core/StreamString.h"
15#include "lldb/Core/RegularExpression.h"
16#include "lldb/Symbol/ObjectFile.h"
17
18#include "DWARFCompileUnit.h"
19#include "DWARFDebugInfo.h"
20#include "DWARFDebugInfoEntry.h"
21#include "SymbolFileDWARF.h"
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, uint32_t die_offset)
34{
35    m_map.Append(name.GetCString(), die_offset);
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 (uint32_t cu_offset,
52                                         uint32_t cu_end_offset,
53                                         DIEArray &info_array) const
54{
55    const size_t initial_size = info_array.size();
56    const uint32_t size = m_map.GetSize();
57    for (uint32_t i=0; i<size; ++i)
58    {
59        const uint32_t die_offset = m_map.GetValueAtIndexUnchecked(i);
60        if (cu_offset < die_offset && die_offset < cu_end_offset)
61            info_array.push_back (die_offset);
62    }
63    return info_array.size() - initial_size;
64}
65
66void
67NameToDIE::Dump (Stream *s)
68{
69    const uint32_t size = m_map.GetSize();
70    for (uint32_t i=0; i<size; ++i)
71    {
72        const char *cstr = m_map.GetCStringAtIndex(i);
73        s->Printf("%p: {0x%8.8x} \"%s\"\n", cstr, m_map.GetValueAtIndexUnchecked(i), cstr);
74    }
75}
76
77void
78NameToDIE::ForEach (std::function <bool(const char *name, uint32_t die_offset)> const &callback) const
79{
80    const uint32_t size = m_map.GetSize();
81    for (uint32_t i=0; i<size; ++i)
82    {
83        if (!callback(m_map.GetCStringAtIndexUnchecked(i),
84                      m_map.GetValueAtIndexUnchecked (i)))
85            break;
86    }
87}
88