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 22 using namespace lldb; 23 using namespace lldb_private; 24 25 void 26 NameToDIE::Finalize() 27 { 28 m_map.Sort (); 29 m_map.SizeToFit (); 30 } 31 32 void 33 NameToDIE::Insert (const ConstString& name, const DIERef& die_ref) 34 { 35 m_map.Append(name.GetCString(), die_ref); 36 } 37 38 size_t 39 NameToDIE::Find (const ConstString &name, DIEArray &info_array) const 40 { 41 return m_map.GetValues (name.GetCString(), info_array); 42 } 43 44 size_t 45 NameToDIE::Find (const RegularExpression& regex, DIEArray &info_array) const 46 { 47 return m_map.GetValues (regex, info_array); 48 } 49 50 size_t 51 NameToDIE::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 64 void 65 NameToDIE::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", cstr, die_ref.cu_offset, die_ref.die_offset, cstr); 73 } 74 } 75 76 void 77 NameToDIE::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