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