Skip to content

Commit

Permalink
Add AddressRange to SB API
Browse files Browse the repository at this point in the history
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:
llvm-lit -sv llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
  • Loading branch information
mbucko committed May 16, 2024
1 parent c675a58 commit 1be2c95
Show file tree
Hide file tree
Showing 27 changed files with 681 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lldb/bindings/headers.swig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
%{
#include "lldb/lldb-public.h"
#include "lldb/API/SBAddress.h"
#include "lldb/API/SBAddressRange.h"
#include "lldb/API/SBAddressRangeList.h"
#include "lldb/API/SBAttachInfo.h"
#include "lldb/API/SBBlock.h"
#include "lldb/API/SBBreakpoint.h"
Expand Down
3 changes: 3 additions & 0 deletions lldb/bindings/interface/SBAddressRangeDocstrings.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%feature("docstring",
"API clients can get address range information."
) lldb::SBAddressRange;
1 change: 1 addition & 0 deletions lldb/bindings/interface/SBAddressRangeExtensions.i
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STRING_EXTENSION_OUTSIDE(SBAddressRange)
3 changes: 3 additions & 0 deletions lldb/bindings/interface/SBAddressRangeListDocstrings.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%feature("docstring",
"Represents a list of :py:class:`SBAddressRange`."
) lldb::SBAddressRangeList;
25 changes: 25 additions & 0 deletions lldb/bindings/interface/SBAddressRangeListExtensions.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
STRING_EXTENSION_OUTSIDE(SBAddressRangeList)

%extend lldb::SBAddressRangeList {
#ifdef SWIGPYTHON
%pythoncode%{
def __len__(self):
'''Return the number of address ranges in a lldb.SBAddressRangeList object.'''
return self.GetSize()

def __iter__(self):
'''Iterate over all the address ranges in a lldb.SBAddressRangeList object.'''
return lldb_iter(self, 'GetSize', 'GetAddressRangeAtIndex')

def __getitem__(self, idx):
'''Get the address range at a given index in an lldb.SBAddressRangeList object.'''
if type(idx) == int:
if idx >= self.GetSize():
raise IndexError("list index out of range")
return self.GetAddressRangeAtIndex(idx)
else:
print("error: unsupported idx type: %s" % type(key))
return None
%}
#endif
}
6 changes: 6 additions & 0 deletions lldb/bindings/interfaces.swig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

/* Docstrings for SB classes and methods */
%include "./interface/SBAddressDocstrings.i"
%include "./interface/SBAddressRangeDocstrings.i"
%include "./interface/SBAddressRangeListDocstrings.i"
%include "./interface/SBAttachInfoDocstrings.i"
%include "./interface/SBBlockDocstrings.i"
%include "./interface/SBBreakpointDocstrings.i"
Expand Down Expand Up @@ -86,6 +88,8 @@

/* API headers */
%include "lldb/API/SBAddress.h"
%include "lldb/API/SBAddressRange.h"
%include "lldb/API/SBAddressRangeList.h"
%include "lldb/API/SBAttachInfo.h"
%include "lldb/API/SBBlock.h"
%include "lldb/API/SBBreakpoint.h"
Expand Down Expand Up @@ -162,6 +166,8 @@

/* Extensions for SB classes */
%include "./interface/SBAddressExtensions.i"
%include "./interface/SBAddressRangeExtensions.i"
%include "./interface/SBAddressRangeListExtensions.i"
%include "./interface/SBBlockExtensions.i"
%include "./interface/SBBreakpointExtensions.i"
%include "./interface/SBBreakpointListExtensions.i"
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/LLDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define LLDB_API_LLDB_H

#include "lldb/API/SBAddress.h"
#include "lldb/API/SBAddressRange.h"
#include "lldb/API/SBAddressRangeList.h"
#include "lldb/API/SBAttachInfo.h"
#include "lldb/API/SBBlock.h"
#include "lldb/API/SBBreakpoint.h"
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/API/SBAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class LLDB_API SBAddress {
lldb::SBLineEntry GetLineEntry();

protected:
friend class SBAddressRange;
friend class SBBlock;
friend class SBBreakpoint;
friend class SBBreakpointLocation;
Expand Down
65 changes: 65 additions & 0 deletions lldb/include/lldb/API/SBAddressRange.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//===-- SBAddressRange.h ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_API_SBADDRESSRANGE_H
#define LLDB_API_SBADDRESSRANGE_H

#include "lldb/API/SBDefines.h"

namespace lldb {

class LLDB_API SBAddressRange {
public:
SBAddressRange();

SBAddressRange(const lldb::SBAddressRange &rhs);

SBAddressRange(lldb::SBAddress addr, lldb::addr_t byte_size);

~SBAddressRange();

const lldb::SBAddressRange &operator=(const lldb::SBAddressRange &rhs);

void Clear();

/// Check the address range refers to a valid base address and has a byte
/// size greater than zero.
///
/// \return
/// True if the address range is valid, false otherwise.
bool IsValid() const;

/// Get the base address of the range.
///
/// \return
/// Base address object.
lldb::SBAddress GetBaseAddress() const;

/// Get the byte size of this range.
///
/// \return
/// The size in bytes of this address range.
lldb::addr_t GetByteSize() const;

bool operator==(const SBAddressRange &rhs);

bool operator!=(const SBAddressRange &rhs);

bool GetDescription(lldb::SBStream &description);

private:
friend class SBAddressRangeList;
friend class SBBlock;
friend class SBFunction;

AddressRangeUP m_opaque_up;
};

} // namespace lldb

#endif // LLDB_API_SBADDRESSRANGE_H
58 changes: 58 additions & 0 deletions lldb/include/lldb/API/SBAddressRangeList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//===-- SBAddressRangeList.h ------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_API_SBADDRESSRANGELIST_H
#define LLDB_API_SBADDRESSRANGELIST_H

#include <memory>

#include "lldb/API/SBDefines.h"

class AddressRangeListImpl;

namespace lldb {

class LLDB_API SBAddressRangeList {
public:
SBAddressRangeList();

SBAddressRangeList(const lldb::SBAddressRangeList &rhs);

~SBAddressRangeList();

const lldb::SBAddressRangeList &
operator=(const lldb::SBAddressRangeList &rhs);

uint32_t GetSize() const;

void Clear();

SBAddressRange GetAddressRangeAtIndex(uint64_t idx);

void Append(const lldb::SBAddressRange &addr_range);

void Append(const lldb::SBAddressRangeList &addr_range_list);

bool GetDescription(lldb::SBStream &description);

private:
const AddressRangeListImpl *operator->() const;

const AddressRangeListImpl &operator*() const;

friend class SBBlock;
friend class SBProcess;

lldb_private::AddressRanges &ref() const;

std::unique_ptr<AddressRangeListImpl> m_opaque_up;
};

} // namespace lldb

#endif // LLDB_API_SBADDRESSRANGELIST_H
4 changes: 4 additions & 0 deletions lldb/include/lldb/API/SBBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef LLDB_API_SBBLOCK_H
#define LLDB_API_SBBLOCK_H

#include "lldb/API/SBAddressRange.h"
#include "lldb/API/SBAddressRangeList.h"
#include "lldb/API/SBDefines.h"
#include "lldb/API/SBFrame.h"
#include "lldb/API/SBTarget.h"
Expand Down Expand Up @@ -52,6 +54,8 @@ class LLDB_API SBBlock {

lldb::SBAddress GetRangeEndAddress(uint32_t idx);

lldb::SBAddressRangeList GetRanges();

uint32_t GetRangeIndexForBlockAddress(lldb::SBAddress block_addr);

lldb::SBValueList GetVariables(lldb::SBFrame &frame, bool arguments,
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
namespace lldb {

class LLDB_API SBAddress;
class LLDB_API SBAddressRange;
class LLDB_API SBAddressRangeList;
class LLDB_API SBAttachInfo;
class LLDB_API SBBlock;
class LLDB_API SBBreakpoint;
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/API/SBFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLDB_API_SBFUNCTION_H

#include "lldb/API/SBAddress.h"
#include "lldb/API/SBAddressRange.h"
#include "lldb/API/SBDefines.h"
#include "lldb/API/SBInstructionList.h"

Expand Down Expand Up @@ -44,6 +45,8 @@ class LLDB_API SBFunction {

lldb::SBAddress GetEndAddress();

lldb::SBAddressRange GetRange();

const char *GetArgumentName(uint32_t arg_idx);

uint32_t GetPrologueByteSize();
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class LLDB_API SBStream {

protected:
friend class SBAddress;
friend class SBAddressRange;
friend class SBAddressRangeList;
friend class SBBlock;
friend class SBBreakpoint;
friend class SBBreakpointLocation;
Expand Down
12 changes: 12 additions & 0 deletions lldb/include/lldb/Core/AddressRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class AddressRange {
/// (LLDB_INVALID_ADDRESS) and a zero byte size.
void Clear();

bool IsValid() const;

/// Check if a section offset address is contained in this range.
///
/// \param[in] so_addr
Expand Down Expand Up @@ -236,12 +238,22 @@ class AddressRange {
/// The new size in bytes of this address range.
void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }

bool operator==(const AddressRange &rhs);

bool operator!=(const AddressRange &rhs);

protected:
// Member variables
Address m_base_addr; ///< The section offset base address of this range.
lldb::addr_t m_byte_size = 0; ///< The size in bytes of this address range.
};

// Forward-declarable wrapper.
class AddressRanges : public std::vector<lldb_private::AddressRange> {
public:
using std::vector<lldb_private::AddressRange>::vector;
};

} // namespace lldb_private

#endif // LLDB_CORE_ADDRESSRANGE_H
2 changes: 2 additions & 0 deletions lldb/include/lldb/Symbol/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ class Block : public UserID, public SymbolContextScope {
// be able to get at any of the address ranges in a block.
bool GetRangeAtIndex(uint32_t range_idx, AddressRange &range);

AddressRanges GetRanges();

bool GetStartAddress(Address &addr);

void SetDidParseVariables(bool b, bool set_children);
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/lldb-forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ASTResultSynthesizer;
class ASTStructExtractor;
class Address;
class AddressRange;
class AddressRanges;
class AddressRangeList;
class AddressResolver;
class ArchSpec;
class Architecture;
Expand Down Expand Up @@ -308,6 +310,7 @@ template <unsigned N> class StreamBuffer;
namespace lldb {

typedef std::shared_ptr<lldb_private::ABI> ABISP;
typedef std::unique_ptr<lldb_private::AddressRange> AddressRangeUP;
typedef std::shared_ptr<lldb_private::Baton> BatonSP;
typedef std::shared_ptr<lldb_private::Block> BlockSP;
typedef std::shared_ptr<lldb_private::Breakpoint> BreakpointSP;
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ add_custom_target(lldb-sbapi-dwarf-enums

add_lldb_library(liblldb SHARED ${option_framework}
SBAddress.cpp
SBAddressRange.cpp
SBAddressRangeList.cpp
SBAttachInfo.cpp
SBBlock.cpp
SBBreakpoint.cpp
Expand Down
Loading

0 comments on commit 1be2c95

Please sign in to comment.