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