1 //===-- DWARFDebugRanges.h --------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef SymbolFileDWARF_DWARFDebugRanges_h_
10 #define SymbolFileDWARF_DWARFDebugRanges_h_
11 
12 #include "lldb/Core/dwarf.h"
13 #include <map>
14 
15 class DWARFUnit;
16 namespace lldb_private {
17 class DWARFContext;
18 }
19 
20 class DWARFDebugRangesBase {
21 public:
22   virtual ~DWARFDebugRangesBase(){};
23 
24   virtual void Extract(lldb_private::DWARFContext &context) = 0;
25   virtual bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
26                           DWARFRangeList &range_list) const = 0;
27 };
28 
29 class DWARFDebugRanges final : public DWARFDebugRangesBase {
30 public:
31   DWARFDebugRanges();
32 
33   void Extract(lldb_private::DWARFContext &context) override;
34   bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
35                   DWARFRangeList &range_list) const override;
36 
37   static void Dump(lldb_private::Stream &s,
38                    const lldb_private::DWARFDataExtractor &debug_ranges_data,
39                    lldb::offset_t *offset_ptr, dw_addr_t cu_base_addr);
40 
41 protected:
42   bool Extract(lldb_private::DWARFContext &context, lldb::offset_t *offset_ptr,
43                DWARFRangeList &range_list);
44 
45   typedef std::map<dw_offset_t, DWARFRangeList> range_map;
46   typedef range_map::iterator range_map_iterator;
47   typedef range_map::const_iterator range_map_const_iterator;
48   range_map m_range_map;
49 };
50 
51 // DWARF v5 .debug_rnglists section.
52 class DWARFDebugRngLists final : public DWARFDebugRangesBase {
53   struct RngListEntry {
54     uint8_t encoding;
55     uint64_t value0;
56     uint64_t value1;
57   };
58 
59 public:
60   void Extract(lldb_private::DWARFContext &context) override;
61   bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
62                   DWARFRangeList &range_list) const override;
63   uint64_t GetOffset(size_t Index) const;
64 
65 protected:
66   bool ExtractRangeList(const lldb_private::DWARFDataExtractor &data,
67                         uint8_t addrSize, lldb::offset_t *offset_ptr,
68                         std::vector<RngListEntry> &list);
69 
70   std::vector<uint64_t> Offsets;
71   std::map<dw_offset_t, std::vector<RngListEntry>> m_range_map;
72 };
73 
74 #endif // SymbolFileDWARF_DWARFDebugRanges_h_
75