]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/AddressRange.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / AddressRange.h
1 //===-- AddressRange.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 liblldb_AddressRange_h_
10 #define liblldb_AddressRange_h_
11
12 #include "lldb/Core/Address.h"
13 #include "lldb/lldb-forward.h"
14 #include "lldb/lldb-types.h"
15
16 #include <stddef.h>
17
18 namespace lldb_private {
19 class SectionList;
20 class Stream;
21 class Target;
22
23 /// \class AddressRange AddressRange.h "lldb/Core/AddressRange.h"
24 /// A section + offset based address range class.
25 class AddressRange {
26 public:
27   /// Default constructor.
28   ///
29   /// Initialize with a invalid section (NULL), an invalid offset
30   /// (LLDB_INVALID_ADDRESS), and zero byte size.
31   AddressRange();
32
33   /// Construct with a section pointer, offset, and byte_size.
34   ///
35   /// Initialize the address with the supplied \a section, \a offset and \a
36   /// byte_size.
37   ///
38   /// \param[in] section
39   ///     A section pointer to a valid lldb::Section, or NULL if the
40   ///     address doesn't have a section or will get resolved later.
41   ///
42   /// \param[in] offset
43   ///     The offset in bytes into \a section.
44   ///
45   /// \param[in] byte_size
46   ///     The size in bytes of the address range.
47   AddressRange(const lldb::SectionSP &section, lldb::addr_t offset,
48                lldb::addr_t byte_size);
49
50   /// Construct with a virtual address, section list and byte size.
51   ///
52   /// Initialize and resolve the address with the supplied virtual address \a
53   /// file_addr, and byte size \a byte_size.
54   ///
55   /// \param[in] file_addr
56   ///     A virtual address.
57   ///
58   /// \param[in] byte_size
59   ///     The size in bytes of the address range.
60   ///
61   /// \param[in] section_list
62   ///     A list of sections, one of which may contain the \a vaddr.
63   AddressRange(lldb::addr_t file_addr, lldb::addr_t byte_size,
64                const SectionList *section_list = nullptr);
65
66   /// Construct with a Address object address and byte size.
67   ///
68   /// Initialize by copying the section offset address in \a so_addr, and
69   /// setting the byte size to \a byte_size.
70   ///
71   /// \param[in] so_addr
72   ///     A section offset address object.
73   ///
74   /// \param[in] byte_size
75   ///     The size in bytes of the address range.
76   AddressRange(const Address &so_addr, lldb::addr_t byte_size);
77
78   /// Destructor.
79   ///
80   /// The destructor is virtual in case this class is subclassed.
81   ~AddressRange();
82
83   /// Clear the object's state.
84   ///
85   /// Sets the section to an invalid value (NULL), an invalid offset
86   /// (LLDB_INVALID_ADDRESS) and a zero byte size.
87   void Clear();
88
89   /// Check if a section offset address is contained in this range.
90   ///
91   /// \param[in] so_addr
92   ///     A section offset address object reference.
93   ///
94   /// \return
95   ///     Returns \b true if \a so_addr is contained in this range,
96   ///     \b false otherwise.
97   //    bool
98   //    Contains (const Address &so_addr) const;
99
100   /// Check if a section offset address is contained in this range.
101   ///
102   /// \param[in] so_addr_ptr
103   ///     A section offset address object pointer.
104   ///
105   /// \return
106   ///     Returns \b true if \a so_addr is contained in this range,
107   ///     \b false otherwise.
108   //    bool
109   //    Contains (const Address *so_addr_ptr) const;
110
111   /// Check if a section offset \a so_addr when represented as a file address
112   /// is contained within this object's file address range.
113   ///
114   /// \param[in] so_addr
115   ///     A section offset address object reference.
116   ///
117   /// \return
118   ///     Returns \b true if both \a this and \a so_addr have
119   ///     resolvable file address values and \a so_addr is contained
120   ///     in the address range, \b false otherwise.
121   bool ContainsFileAddress(const Address &so_addr) const;
122
123   /// Check if the resolved file address \a file_addr is contained within this
124   /// object's file address range.
125   ///
126   /// \param[in] so_addr
127   ///     A section offset address object reference.
128   ///
129   /// \return
130   ///     Returns \b true if both \a this has a resolvable file
131   ///     address value and \a so_addr is contained in the address
132   ///     range, \b false otherwise.
133   bool ContainsFileAddress(lldb::addr_t file_addr) const;
134
135   /// Check if a section offset \a so_addr when represented as a load address
136   /// is contained within this object's load address range.
137   ///
138   /// \param[in] so_addr
139   ///     A section offset address object reference.
140   ///
141   /// \return
142   ///     Returns \b true if both \a this and \a so_addr have
143   ///     resolvable load address values and \a so_addr is contained
144   ///     in the address range, \b false otherwise.
145   bool ContainsLoadAddress(const Address &so_addr, Target *target) const;
146
147   /// Check if the resolved load address \a load_addr is contained within this
148   /// object's load address range.
149   ///
150   /// \param[in] so_addr
151   ///     A section offset address object reference.
152   ///
153   /// \return
154   ///     Returns \b true if both \a this has a resolvable load
155   ///     address value and \a so_addr is contained in the address
156   ///     range, \b false otherwise.
157   bool ContainsLoadAddress(lldb::addr_t load_addr, Target *target) const;
158
159   //------------------------------------------------------------------
160   /// Extends this range with \b rhs_range if it overlaps this range on the
161   /// right side. The range overlaps on the right side if the base address
162   /// of \b rhs_range lies within this range or if it's contiguous on its
163   /// right side.
164   ///
165   /// @param[in] rhs_range
166   ///     The range to extend at the right side.
167   ///
168   /// @return
169   ///     Returns \b true if this range was extended, \b false otherwise.
170   //------------------------------------------------------------------
171   bool Extend(const AddressRange &rhs_range);
172
173   /// Dump a description of this object to a Stream.
174   ///
175   /// Dump a description of the contents of this object to the supplied stream
176   /// \a s. There are many ways to display a section offset based address
177   /// range, and \a style lets the user choose how the base address gets
178   /// displayed.
179   ///
180   /// \param[in] s
181   ///     The stream to which to dump the object description.
182   ///
183   /// \param[in] style
184   ///     The display style for the address.
185   ///
186   /// \return
187   ///     Returns \b true if the address was able to be displayed.
188   ///     File and load addresses may be unresolved and it may not be
189   ///     possible to display a valid value, \b false will be returned
190   ///     in such cases.
191   ///
192   /// \see Address::DumpStyle
193   bool
194   Dump(Stream *s, Target *target, Address::DumpStyle style,
195        Address::DumpStyle fallback_style = Address::DumpStyleInvalid) const;
196
197   /// Dump a debug description of this object to a Stream.
198   ///
199   /// Dump a debug description of the contents of this object to the supplied
200   /// stream \a s.
201   ///
202   /// The debug description contains verbose internal state such and pointer
203   /// values, reference counts, etc.
204   ///
205   /// \param[in] s
206   ///     The stream to which to dump the object description.
207   void DumpDebug(Stream *s) const;
208
209   /// Get accessor for the base address of the range.
210   ///
211   /// \return
212   ///     A reference to the base address object.
213   Address &GetBaseAddress() { return m_base_addr; }
214
215   /// Get const accessor for the base address of the range.
216   ///
217   /// \return
218   ///     A const reference to the base address object.
219   const Address &GetBaseAddress() const { return m_base_addr; }
220
221   /// Get accessor for the byte size of this range.
222   ///
223   /// \return
224   ///     The size in bytes of this address range.
225   lldb::addr_t GetByteSize() const { return m_byte_size; }
226
227   /// Get the memory cost of this object.
228   ///
229   /// \return
230   ///     The number of bytes that this object occupies in memory.
231   size_t MemorySize() const {
232     // Noting special for the memory size of a single AddressRange object, it
233     // is just the size of itself.
234     return sizeof(AddressRange);
235   }
236
237   /// Set accessor for the byte size of this range.
238   ///
239   /// \param[in] byte_size
240   ///     The new size in bytes of this address range.
241   void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
242
243 protected:
244   // Member variables
245   Address m_base_addr;      ///< The section offset base address of this range.
246   lldb::addr_t m_byte_size; ///< The size in bytes of this address range.
247 };
248
249 // bool operator== (const AddressRange& lhs, const AddressRange& rhs);
250
251 } // namespace lldb_private
252
253 #endif // liblldb_AddressRange_h_