Skip to content

Commit 48175a5

Browse files
author
Miro Bucko
authored
[lldb] Add SBAddressRange and SBAddressRangeList to SB API (llvm#93836)
This adds new SB API calls and classes to allow a user of the SB API to obtain an address range from SBFunction and SBBlock. This is a second attempt to land the reverted PR llvm#92014.
1 parent 5f243b3 commit 48175a5

31 files changed

+865
-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

0 commit comments

Comments
 (0)