Skip to content

Commit c3c9f61

Browse files
mbuckovg0204
authored andcommitted
Add SBAddressRange and SBAddressRangeList to SB API (llvm#92014)
This adds new SB API calls and classes to allow a user of the SB API to obtain an address ranges from SBFunction and SBBlock.
1 parent c761191 commit c3c9f61

31 files changed

+859
-0
lines changed

lldb/bindings/headers.swig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
%{
99
#include "lldb/lldb-public.h"
1010
#include "lldb/API/SBAddress.h"
11+
#include "lldb/API/SBAddressRange.h"
12+
#include "lldb/API/SBAddressRangeList.h"
1113
#include "lldb/API/SBAttachInfo.h"
1214
#include "lldb/API/SBBlock.h"
1315
#include "lldb/API/SBBreakpoint.h"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%feature("docstring",
2+
"API clients can get address range information."
3+
) lldb::SBAddressRange;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%extend lldb::SBAddressRange {
2+
#ifdef SWIGPYTHON
3+
%pythoncode%{
4+
def __repr__(self):
5+
import lldb
6+
stream = lldb.SBStream()
7+
self.GetDescription(stream, lldb.target if lldb.target else lldb.SBTarget())
8+
return stream.GetData()
9+
%}
10+
#endif
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%feature("docstring",
2+
"Represents a list of :py:class:`SBAddressRange`."
3+
) lldb::SBAddressRangeList;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
%extend lldb::SBAddressRangeList {
2+
#ifdef SWIGPYTHON
3+
%pythoncode%{
4+
def __len__(self):
5+
'''Return the number of address ranges in a lldb.SBAddressRangeList object.'''
6+
return self.GetSize()
7+
8+
def __iter__(self):
9+
'''Iterate over all the address ranges in a lldb.SBAddressRangeList object.'''
10+
return lldb_iter(self, 'GetSize', 'GetAddressRangeAtIndex')
11+
12+
def __getitem__(self, idx):
13+
'''Get the address range at a given index in an lldb.SBAddressRangeList object.'''
14+
if not isinstance(idx, int):
15+
raise TypeError("unsupported index type: %s" % type(idx))
16+
count = len(self)
17+
if not (-count <= idx < count):
18+
raise IndexError("list index out of range")
19+
idx %= count
20+
return self.GetAddressRangeAtIndex(idx)
21+
22+
def __repr__(self):
23+
import lldb
24+
stream = lldb.SBStream()
25+
self.GetDescription(stream, lldb.target if lldb.target else lldb.SBTarget())
26+
return stream.GetData()
27+
%}
28+
#endif
29+
}

lldb/bindings/interfaces.swig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
/* Docstrings for SB classes and methods */
1414
%include "./interface/SBAddressDocstrings.i"
15+
%include "./interface/SBAddressRangeDocstrings.i"
16+
%include "./interface/SBAddressRangeListDocstrings.i"
1517
%include "./interface/SBAttachInfoDocstrings.i"
1618
%include "./interface/SBBlockDocstrings.i"
1719
%include "./interface/SBBreakpointDocstrings.i"
@@ -86,6 +88,8 @@
8688

8789
/* API headers */
8890
%include "lldb/API/SBAddress.h"
91+
%include "lldb/API/SBAddressRange.h"
92+
%include "lldb/API/SBAddressRangeList.h"
8993
%include "lldb/API/SBAttachInfo.h"
9094
%include "lldb/API/SBBlock.h"
9195
%include "lldb/API/SBBreakpoint.h"
@@ -163,6 +167,8 @@
163167

164168
/* Extensions for SB classes */
165169
%include "./interface/SBAddressExtensions.i"
170+
%include "./interface/SBAddressRangeExtensions.i"
171+
%include "./interface/SBAddressRangeListExtensions.i"
166172
%include "./interface/SBBlockExtensions.i"
167173
%include "./interface/SBBreakpointExtensions.i"
168174
%include "./interface/SBBreakpointListExtensions.i"

lldb/include/lldb/API/LLDB.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#define LLDB_API_LLDB_H
1111

1212
#include "lldb/API/SBAddress.h"
13+
#include "lldb/API/SBAddressRange.h"
14+
#include "lldb/API/SBAddressRangeList.h"
1315
#include "lldb/API/SBAttachInfo.h"
1416
#include "lldb/API/SBBlock.h"
1517
#include "lldb/API/SBBreakpoint.h"

lldb/include/lldb/API/SBAddress.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class LLDB_API SBAddress {
8686
lldb::SBLineEntry GetLineEntry();
8787

8888
protected:
89+
friend class SBAddressRange;
8990
friend class SBBlock;
9091
friend class SBBreakpoint;
9192
friend class SBBreakpointLocation;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===-- SBAddressRange.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 LLDB_API_SBADDRESSRANGE_H
10+
#define LLDB_API_SBADDRESSRANGE_H
11+
12+
#include "lldb/API/SBDefines.h"
13+
14+
namespace lldb {
15+
16+
class LLDB_API SBAddressRange {
17+
public:
18+
SBAddressRange();
19+
20+
SBAddressRange(const lldb::SBAddressRange &rhs);
21+
22+
SBAddressRange(lldb::SBAddress addr, lldb::addr_t byte_size);
23+
24+
~SBAddressRange();
25+
26+
const lldb::SBAddressRange &operator=(const lldb::SBAddressRange &rhs);
27+
28+
void Clear();
29+
30+
/// Check the address range refers to a valid base address and has a byte
31+
/// size greater than zero.
32+
///
33+
/// \return
34+
/// True if the address range is valid, false otherwise.
35+
bool IsValid() const;
36+
37+
/// Get the base address of the range.
38+
///
39+
/// \return
40+
/// Base address object.
41+
lldb::SBAddress GetBaseAddress() const;
42+
43+
/// Get the byte size of this range.
44+
///
45+
/// \return
46+
/// The size in bytes of this address range.
47+
lldb::addr_t GetByteSize() const;
48+
49+
bool operator==(const SBAddressRange &rhs);
50+
51+
bool operator!=(const SBAddressRange &rhs);
52+
53+
bool GetDescription(lldb::SBStream &description, const SBTarget target);
54+
55+
private:
56+
friend class SBAddressRangeList;
57+
friend class SBBlock;
58+
friend class SBFunction;
59+
friend class SBProcess;
60+
61+
AddressRangeUP m_opaque_up;
62+
};
63+
64+
} // namespace lldb
65+
66+
#endif // LLDB_API_SBADDRESSRANGE_H
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===-- SBAddressRangeList.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 LLDB_API_SBADDRESSRANGELIST_H
10+
#define LLDB_API_SBADDRESSRANGELIST_H
11+
12+
#include <memory>
13+
14+
#include "lldb/API/SBDefines.h"
15+
16+
namespace lldb_private {
17+
class AddressRangeListImpl;
18+
}
19+
20+
namespace lldb {
21+
22+
class LLDB_API SBAddressRangeList {
23+
public:
24+
SBAddressRangeList();
25+
26+
SBAddressRangeList(const lldb::SBAddressRangeList &rhs);
27+
28+
~SBAddressRangeList();
29+
30+
const lldb::SBAddressRangeList &
31+
operator=(const lldb::SBAddressRangeList &rhs);
32+
33+
uint32_t GetSize() const;
34+
35+
void Clear();
36+
37+
SBAddressRange GetAddressRangeAtIndex(uint64_t idx);
38+
39+
void Append(const lldb::SBAddressRange &addr_range);
40+
41+
void Append(const lldb::SBAddressRangeList &addr_range_list);
42+
43+
bool GetDescription(lldb::SBStream &description, const SBTarget &target);
44+
45+
private:
46+
friend class SBBlock;
47+
friend class SBProcess;
48+
49+
std::unique_ptr<lldb_private::AddressRangeListImpl> m_opaque_up;
50+
};
51+
52+
} // namespace lldb
53+
54+
#endif // LLDB_API_SBADDRESSRANGELIST_H

lldb/include/lldb/API/SBBlock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef LLDB_API_SBBLOCK_H
1010
#define LLDB_API_SBBLOCK_H
1111

12+
#include "lldb/API/SBAddressRange.h"
13+
#include "lldb/API/SBAddressRangeList.h"
1214
#include "lldb/API/SBDefines.h"
1315
#include "lldb/API/SBFrame.h"
1416
#include "lldb/API/SBTarget.h"
@@ -52,6 +54,8 @@ class LLDB_API SBBlock {
5254

5355
lldb::SBAddress GetRangeEndAddress(uint32_t idx);
5456

57+
lldb::SBAddressRangeList GetRanges();
58+
5559
uint32_t GetRangeIndexForBlockAddress(lldb::SBAddress block_addr);
5660

5761
lldb::SBValueList GetVariables(lldb::SBFrame &frame, bool arguments,

lldb/include/lldb/API/SBDefines.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
namespace lldb {
4444

4545
class LLDB_API SBAddress;
46+
class LLDB_API SBAddressRange;
47+
class LLDB_API SBAddressRangeList;
4648
class LLDB_API SBAttachInfo;
4749
class LLDB_API SBBlock;
4850
class LLDB_API SBBreakpoint;

lldb/include/lldb/API/SBFunction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLDB_API_SBFUNCTION_H
1111

1212
#include "lldb/API/SBAddress.h"
13+
#include "lldb/API/SBAddressRangeList.h"
1314
#include "lldb/API/SBDefines.h"
1415
#include "lldb/API/SBInstructionList.h"
1516

@@ -44,6 +45,8 @@ class LLDB_API SBFunction {
4445

4546
lldb::SBAddress GetEndAddress();
4647

48+
lldb::SBAddressRangeList GetRanges();
49+
4750
const char *GetArgumentName(uint32_t arg_idx);
4851

4952
uint32_t GetPrologueByteSize();

lldb/include/lldb/API/SBStream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class LLDB_API SBStream {
6262

6363
protected:
6464
friend class SBAddress;
65+
friend class SBAddressRange;
66+
friend class SBAddressRangeList;
6567
friend class SBBlock;
6668
friend class SBBreakpoint;
6769
friend class SBBreakpointLocation;

lldb/include/lldb/API/SBTarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ class LLDB_API SBTarget {
943943

944944
protected:
945945
friend class SBAddress;
946+
friend class SBAddressRange;
946947
friend class SBBlock;
947948
friend class SBBreakpoint;
948949
friend class SBBreakpointList;

lldb/include/lldb/Core/AddressRange.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class AddressRange {
8686
/// (LLDB_INVALID_ADDRESS) and a zero byte size.
8787
void Clear();
8888

89+
bool IsValid() const;
90+
8991
/// Check if a section offset address is contained in this range.
9092
///
9193
/// \param[in] so_addr
@@ -236,12 +238,24 @@ class AddressRange {
236238
/// The new size in bytes of this address range.
237239
void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
238240

241+
bool GetDescription(Stream *s, Target *target) const;
242+
243+
bool operator==(const AddressRange &rhs);
244+
245+
bool operator!=(const AddressRange &rhs);
246+
239247
protected:
240248
// Member variables
241249
Address m_base_addr; ///< The section offset base address of this range.
242250
lldb::addr_t m_byte_size = 0; ///< The size in bytes of this address range.
243251
};
244252

253+
// Forward-declarable wrapper.
254+
class AddressRanges : public std::vector<lldb_private::AddressRange> {
255+
public:
256+
using std::vector<lldb_private::AddressRange>::vector;
257+
};
258+
245259
} // namespace lldb_private
246260

247261
#endif // LLDB_CORE_ADDRESSRANGE_H
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===-- AddressRangeListImpl.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 LLDB_CORE_ADDRESSRANGELISTIMPL_H
10+
#define LLDB_CORE_ADDRESSRANGELISTIMPL_H
11+
12+
#include "lldb/Core/AddressRange.h"
13+
#include <cstddef>
14+
15+
namespace lldb {
16+
class SBBlock;
17+
}
18+
19+
namespace lldb_private {
20+
21+
class AddressRangeListImpl {
22+
public:
23+
AddressRangeListImpl();
24+
25+
AddressRangeListImpl(const AddressRangeListImpl &rhs) = default;
26+
27+
AddressRangeListImpl &operator=(const AddressRangeListImpl &rhs);
28+
29+
size_t GetSize() const;
30+
31+
void Reserve(size_t capacity);
32+
33+
void Append(const AddressRange &sb_region);
34+
35+
void Append(const AddressRangeListImpl &list);
36+
37+
void Clear();
38+
39+
lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
40+
41+
private:
42+
friend class lldb::SBBlock;
43+
44+
AddressRanges &ref();
45+
46+
AddressRanges m_ranges;
47+
};
48+
49+
} // namespace lldb_private
50+
51+
#endif // LLDB_CORE_ADDRESSRANGE_H

lldb/include/lldb/Symbol/Block.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ class Block : public UserID, public SymbolContextScope {
355355
// be able to get at any of the address ranges in a block.
356356
bool GetRangeAtIndex(uint32_t range_idx, AddressRange &range);
357357

358+
AddressRanges GetRanges();
359+
358360
bool GetStartAddress(Address &addr);
359361

360362
void SetDidParseVariables(bool b, bool set_children);

lldb/include/lldb/lldb-forward.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class ASTResultSynthesizer;
1919
class ASTStructExtractor;
2020
class Address;
2121
class AddressRange;
22+
class AddressRanges;
23+
class AddressRangeList;
2224
class AddressResolver;
2325
class ArchSpec;
2426
class Architecture;
@@ -308,6 +310,7 @@ template <unsigned N> class StreamBuffer;
308310
namespace lldb {
309311

310312
typedef std::shared_ptr<lldb_private::ABI> ABISP;
313+
typedef std::unique_ptr<lldb_private::AddressRange> AddressRangeUP;
311314
typedef std::shared_ptr<lldb_private::Baton> BatonSP;
312315
typedef std::shared_ptr<lldb_private::Block> BlockSP;
313316
typedef std::shared_ptr<lldb_private::Breakpoint> BreakpointSP;

0 commit comments

Comments
 (0)