xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
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   virtual uint64_t GetOffset(size_t Index) const = 0;
28 };
29 
30 class DWARFDebugRanges final : public DWARFDebugRangesBase {
31 public:
32   DWARFDebugRanges();
33 
34   void Extract(lldb_private::DWARFContext &context) override;
35   bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
36                   DWARFRangeList &range_list) const override;
37   uint64_t GetOffset(size_t Index) const override;
38 
39   static void Dump(lldb_private::Stream &s,
40                    const lldb_private::DWARFDataExtractor &debug_ranges_data,
41                    lldb::offset_t *offset_ptr, dw_addr_t cu_base_addr);
42 
43 protected:
44   bool Extract(lldb_private::DWARFContext &context, lldb::offset_t *offset_ptr,
45                DWARFRangeList &range_list);
46 
47   typedef std::map<dw_offset_t, DWARFRangeList> range_map;
48   typedef range_map::iterator range_map_iterator;
49   typedef range_map::const_iterator range_map_const_iterator;
50   range_map m_range_map;
51 };
52 
53 // DWARF v5 .debug_rnglists section.
54 class DWARFDebugRngLists final : public DWARFDebugRangesBase {
55   struct RngListEntry {
56     uint8_t encoding;
57     uint64_t value0;
58     uint64_t value1;
59   };
60 
61 public:
62   void Extract(lldb_private::DWARFContext &context) override;
63   bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
64                   DWARFRangeList &range_list) const override;
65   uint64_t GetOffset(size_t Index) const override;
66 
67 protected:
68   bool ExtractRangeList(const lldb_private::DWARFDataExtractor &data,
69                         uint8_t addrSize, lldb::offset_t *offset_ptr,
70                         std::vector<RngListEntry> &list);
71 
72   std::vector<uint64_t> Offsets;
73   std::map<dw_offset_t, std::vector<RngListEntry>> m_range_map;
74 };
75 
76 #endif // SymbolFileDWARF_DWARFDebugRanges_h_
77