1 //===-- DWARFDIECollection.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 "DWARFDIECollection.h"
11 
12 #include <algorithm>
13 
14 #include "lldb/Core/Stream.h"
15 
16 using namespace lldb_private;
17 using namespace std;
18 
19 bool
20 DWARFDIECollection::Insert(const DWARFDIE &die)
21 {
22     iterator end_pos = m_dies.end();
23     iterator insert_pos = upper_bound(m_dies.begin(), end_pos, die);
24     if (insert_pos != end_pos && (*insert_pos == die))
25         return false;
26     m_dies.insert(insert_pos, die);
27     return true;
28 }
29 
30 void
31 DWARFDIECollection::Append (const DWARFDIE &die)
32 {
33     m_dies.push_back (die);
34 }
35 
36 DWARFDIE
37 DWARFDIECollection::GetDIEAtIndex(uint32_t idx) const
38 {
39     if (idx < m_dies.size())
40         return m_dies[idx];
41     return DWARFDIE();
42 }
43 
44 
45 size_t
46 DWARFDIECollection::Size() const
47 {
48     return m_dies.size();
49 }
50 
51 void
52 DWARFDIECollection::Dump(Stream *s, const char* title) const
53 {
54     if (title && title[0] != '\0')
55         s->Printf( "%s\n", title);
56     for (const auto &die : m_dies)
57         s->Printf( "0x%8.8x\n", die.GetOffset());
58 }
59