1 //===-- NameToDIE.cpp -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
17 #include "DWARFCompileUnit.h"
18 #include "DWARFDebugInfo.h"
19 #include "DWARFDebugInfoEntry.h"
20 #include "SymbolFileDWARF.h"
23 using namespace lldb_private;
33 NameToDIE::Insert (const ConstString& name, const DIERef& die_ref)
35 m_map.Append(name.GetCString(), die_ref);
39 NameToDIE::Find (const ConstString &name, DIEArray &info_array) const
41 return m_map.GetValues (name.GetCString(), info_array);
45 NameToDIE::Find (const RegularExpression& regex, DIEArray &info_array) const
47 return m_map.GetValues (regex, info_array);
51 NameToDIE::FindAllEntriesForCompileUnit (dw_offset_t cu_offset, DIEArray &info_array) const
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)
57 const DIERef& die_ref = m_map.GetValueAtIndexUnchecked(i);
58 if (cu_offset == die_ref.cu_offset)
59 info_array.push_back (die_ref);
61 return info_array.size() - initial_size;
65 NameToDIE::Dump (Stream *s)
67 const uint32_t size = m_map.GetSize();
68 for (uint32_t i=0; i<size; ++i)
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);
77 NameToDIE::ForEach (std::function <bool(const char *name, const DIERef& die_ref)> const &callback) const
79 const uint32_t size = m_map.GetSize();
80 for (uint32_t i=0; i<size; ++i)
82 if (!callback(m_map.GetCStringAtIndexUnchecked(i), m_map.GetValueAtIndexUnchecked (i)))
88 NameToDIE::Append (const NameToDIE& other)
90 const uint32_t size = other.m_map.GetSize();
91 for (uint32_t i = 0; i < size; ++i)
93 m_map.Append(other.m_map.GetCStringAtIndexUnchecked (i),
94 other.m_map.GetValueAtIndexUnchecked (i));