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