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