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