Skip to content

Commit ec177a0

Browse files
committed
Add AddressRange to SB API
Summary: 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. Test Plan: Reviewers: clayborg Subscribers: lldb-commits Tasks: Tags:
1 parent a037d88 commit ec177a0

23 files changed

+531
-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: 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
#endif
13+
}

lldb/bindings/interfaces.swig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686

8787
/* API headers */
8888
%include "lldb/API/SBAddress.h"
89+
%include "lldb/API/SBAddressRange.h"
90+
%include "lldb/API/SBAddressRangeList.h"
8991
%include "lldb/API/SBAttachInfo.h"
9092
%include "lldb/API/SBBlock.h"
9193
%include "lldb/API/SBBreakpoint.h"

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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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::addr_t file_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+
bool IsValid() const;
31+
32+
/// Get the base address of the range.
33+
///
34+
/// \return
35+
/// Base address object.
36+
lldb::SBAddress GetBaseAddress() const;
37+
38+
/// Get the byte size of this range.
39+
///
40+
/// \return
41+
/// The size in bytes of this address range.
42+
lldb::addr_t GetByteSize() const;
43+
44+
protected:
45+
friend class SBAddressRangeList;
46+
friend class SBBlock;
47+
friend class SBFunction;
48+
49+
lldb_private::AddressRange &ref();
50+
51+
const lldb_private::AddressRange &ref() const;
52+
53+
private:
54+
AddressRangeUP m_opaque_up;
55+
};
56+
57+
#ifndef SWIG
58+
bool LLDB_API operator==(const SBAddressRange &lhs, const SBAddressRange &rhs);
59+
#endif
60+
61+
} // namespace lldb
62+
63+
#endif // LLDB_API_SBADDRESSRANGE_H
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
class AddressRangeListImpl;
17+
18+
namespace lldb {
19+
20+
class LLDB_API SBAddressRangeList {
21+
public:
22+
SBAddressRangeList();
23+
24+
SBAddressRangeList(const lldb::SBAddressRangeList &rhs);
25+
26+
~SBAddressRangeList();
27+
28+
const lldb::SBAddressRangeList &
29+
operator=(const lldb::SBAddressRangeList &rhs);
30+
31+
uint32_t GetSize() const;
32+
33+
void Clear();
34+
35+
bool GetAddressRangeAtIndex(uint64_t idx, SBAddressRange &addr_range);
36+
37+
void Append(const lldb::SBAddressRange &addr_range);
38+
39+
void Append(const lldb::SBAddressRangeList &addr_range_list);
40+
41+
protected:
42+
const AddressRangeListImpl *operator->() const;
43+
44+
const AddressRangeListImpl &operator*() const;
45+
46+
private:
47+
friend class SBProcess;
48+
49+
lldb_private::AddressRanges &ref();
50+
51+
const lldb_private::AddressRanges &ref() const;
52+
53+
std::unique_ptr<AddressRangeListImpl> m_opaque_up;
54+
};
55+
56+
} // namespace lldb
57+
58+
#endif // LLDB_API_SBADDRESSRANGELIST_H

lldb/include/lldb/API/SBBlock.h

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

12+
#include "lldb/API/SBAddressRange.h"
1213
#include "lldb/API/SBDefines.h"
1314
#include "lldb/API/SBFrame.h"
1415
#include "lldb/API/SBTarget.h"
@@ -52,6 +53,8 @@ class LLDB_API SBBlock {
5253

5354
lldb::SBAddress GetRangeEndAddress(uint32_t idx);
5455

56+
lldb::SBAddressRange GetRangeAtIndex(uint32_t idx);
57+
5558
uint32_t GetRangeIndexForBlockAddress(lldb::SBAddress block_addr);
5659

5760
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/SBAddressRange.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::SBAddressRange GetRange();
49+
4750
const char *GetArgumentName(uint32_t arg_idx);
4851

4952
uint32_t GetPrologueByteSize();

lldb/include/lldb/Core/AddressRange.h

Lines changed: 8 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
@@ -242,6 +244,12 @@ class AddressRange {
242244
lldb::addr_t m_byte_size = 0; ///< The size in bytes of this address range.
243245
};
244246

247+
// Forward-declarable wrapper.
248+
class AddressRanges : public std::vector<lldb_private::AddressRange> {
249+
public:
250+
using std::vector<lldb_private::AddressRange>::vector;
251+
};
252+
245253
} // namespace lldb_private
246254

247255
#endif // LLDB_CORE_ADDRESSRANGE_H

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;

lldb/source/API/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ add_custom_target(lldb-sbapi-dwarf-enums
3838

3939
add_lldb_library(liblldb SHARED ${option_framework}
4040
SBAddress.cpp
41+
SBAddressRange.cpp
42+
SBAddressRangeList.cpp
4143
SBAttachInfo.cpp
4244
SBBlock.cpp
4345
SBBreakpoint.cpp

lldb/source/API/SBAddressRange.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//===-- SBAddressRange.cpp ------------------------------------------------===//
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+
#include "lldb/API/SBAddressRange.h"
10+
#include "Utils.h"
11+
#include "lldb/API/SBAddress.h"
12+
#include "lldb/Core/AddressRange.h"
13+
#include "lldb/Utility/Instrumentation.h"
14+
#include <cstddef>
15+
#include <memory>
16+
17+
using namespace lldb;
18+
using namespace lldb_private;
19+
20+
SBAddressRange::SBAddressRange()
21+
: m_opaque_up(std::make_unique<AddressRange>()) {
22+
LLDB_INSTRUMENT_VA(this);
23+
}
24+
25+
SBAddressRange::SBAddressRange(const SBAddressRange &rhs) {
26+
LLDB_INSTRUMENT_VA(this, rhs);
27+
28+
m_opaque_up = clone(rhs.m_opaque_up);
29+
}
30+
31+
SBAddressRange::SBAddressRange(lldb::addr_t file_addr, lldb::addr_t byte_size)
32+
: m_opaque_up(std::make_unique<AddressRange>(file_addr, byte_size)) {
33+
LLDB_INSTRUMENT_VA(this, file_addr, byte_size);
34+
}
35+
36+
SBAddressRange::~SBAddressRange() = default;
37+
38+
const SBAddressRange &SBAddressRange::operator=(const SBAddressRange &rhs) {
39+
LLDB_INSTRUMENT_VA(this, rhs);
40+
41+
if (this != &rhs)
42+
m_opaque_up = clone(rhs.m_opaque_up);
43+
return *this;
44+
}
45+
46+
void SBAddressRange::Clear() {
47+
LLDB_INSTRUMENT_VA(this);
48+
49+
m_opaque_up.reset();
50+
}
51+
52+
bool SBAddressRange::IsValid() const {
53+
return m_opaque_up && m_opaque_up->IsValid();
54+
}
55+
56+
lldb::SBAddress SBAddressRange::GetBaseAddress() const {
57+
LLDB_INSTRUMENT_VA(this);
58+
59+
assert(m_opaque_up.get() && "AddressRange is NULL");
60+
return lldb::SBAddress(m_opaque_up->GetBaseAddress());
61+
}
62+
63+
lldb::addr_t SBAddressRange::GetByteSize() const {
64+
LLDB_INSTRUMENT_VA(this);
65+
66+
assert(m_opaque_up.get() && "AddressRange is NULL");
67+
return m_opaque_up->GetByteSize();
68+
}
69+
70+
AddressRange &SBAddressRange::ref() {
71+
assert(m_opaque_up.get() && "AddressRange is NULL");
72+
return *m_opaque_up;
73+
}
74+
75+
const AddressRange &SBAddressRange::ref() const {
76+
assert(m_opaque_up.get() && "AddressRange is NULL");
77+
return *m_opaque_up;
78+
}

0 commit comments

Comments
 (0)