1 //===-- DWARFDebugAranges.h -------------------------------------*- 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 #ifndef SymbolFileDWARF_DWARFDebugAranges_h_
11 #define SymbolFileDWARF_DWARFDebugAranges_h_
12 
13 #include "DWARFDebugArangeSet.h"
14 #include <list>
15 
16 class SymbolFileDWARF;
17 
18 class DWARFDebugAranges
19 {
20 public:
21     struct Range
22     {
23         explicit
24         Range (dw_addr_t lo = DW_INVALID_ADDRESS,
25                dw_addr_t hi = DW_INVALID_ADDRESS,
26                dw_offset_t off = DW_INVALID_OFFSET) :
27                 lo_pc  (lo),
28                 length (hi-lo),
29                 offset (off)
30         {
31         }
32 
33         void Clear()
34         {
35             lo_pc = DW_INVALID_ADDRESS;
36             length = 0;
37             offset = DW_INVALID_OFFSET;
38         }
39 
40         void
41         set_hi_pc (dw_addr_t hi_pc)
42         {
43             if (hi_pc == DW_INVALID_ADDRESS || hi_pc <= lo_pc)
44                 length = 0;
45             else
46                 length = hi_pc - lo_pc;
47         }
48         dw_addr_t
49         hi_pc() const
50         {
51             if (length)
52                 return lo_pc + length;
53             return DW_INVALID_ADDRESS;
54         }
55         bool
56         ValidRange() const
57         {
58             return length > 0;
59         }
60 
61         static bool
62         SortedOverlapCheck (const Range& curr_range, const Range& next_range, uint32_t n)
63         {
64             if (curr_range.offset != next_range.offset)
65                 return false;
66             return curr_range.hi_pc() + n >= next_range.lo_pc;
67         }
68 
69         bool Contains(const Range& range) const
70         {
71             return lo_pc <= range.lo_pc && range.hi_pc() <= hi_pc();
72         }
73 
74         void Dump(lldb_private::Stream *s) const;
75         dw_addr_t   lo_pc;      // Start of address range
76         uint32_t    length;      // End of address range (not including this address)
77         dw_offset_t offset;     // Offset of the compile unit or die
78     };
79 
80                 DWARFDebugAranges();
81 
82     void        Clear() { m_aranges.clear(); }
83     bool        AllRangesAreContiguous(dw_addr_t& lo_pc, dw_addr_t& hi_pc) const;
84     bool        GetMaxRange(dw_addr_t& lo_pc, dw_addr_t& hi_pc) const;
85     bool        Extract(const lldb_private::DataExtractor &debug_aranges_data);
86     bool        Generate(SymbolFileDWARF* dwarf2Data);
87 
88                 // Use append range multiple times and then call sort
89     void        AppendRange (dw_offset_t cu_offset, dw_addr_t low_pc, dw_addr_t high_pc);
90     void        Sort (bool minimize, uint32_t n);
91 
92     const Range* RangeAtIndex(uint32_t idx) const
93                 {
94                     if (idx < m_aranges.size())
95                         return &m_aranges[idx];
96                     return NULL;
97                 }
98     void        Dump (lldb_private::Log *log) const;
99     dw_offset_t FindAddress(dw_addr_t address) const;
100     bool        IsEmpty() const { return m_aranges.empty(); }
101 //    void        Dump(lldb_private::Stream *s);
102     uint32_t    NumRanges() const
103                 {
104                     return m_aranges.size();
105                 }
106 
107     dw_offset_t OffsetAtIndex(uint32_t idx) const
108                 {
109                     if (idx < m_aranges.size())
110                         return m_aranges[idx].offset;
111                     return DW_INVALID_OFFSET;
112                 }
113 //  void    AppendDebugRanges(BinaryStreamBuf& debug_ranges, dw_addr_t cu_base_addr, uint32_t addr_size) const;
114 
115     static void Dump(SymbolFileDWARF* dwarf2Data, lldb_private::Stream *s);
116 
117     typedef std::vector<Range>              RangeColl;
118     typedef RangeColl::const_iterator       RangeCollIterator;
119 
120 protected:
121 
122     RangeColl m_aranges;
123 };
124 
125 
126 #endif  // SymbolFileDWARF_DWARFDebugAranges_h_
127