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