Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AddressRange to SB API #92014

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
11 changes: 11 additions & 0 deletions lldb/bindings/interface/SBAddressRangeExtensions.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%extend lldb::SBAddressRange {
#ifdef SWIGPYTHON
%pythoncode%{
def __repr__(self):
import lldb
bulbazord marked this conversation as resolved.
Show resolved Hide resolved
stream = lldb.SBStream()
self.GetDescription(stream, lldb.target if lldb.target else lldb.SBTarget())
return stream.GetData()
%}
#endif
}
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;
29 changes: 29 additions & 0 deletions lldb/bindings/interface/SBAddressRangeListExtensions.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%extend lldb::SBAddressRangeList {
mbucko marked this conversation as resolved.
Show resolved Hide resolved
#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 not isinstance(idx, int):
raise TypeError("unsupported index type: %s" % type(idx))
count = len(self)
if not (-count <= idx < count):
raise IndexError("list index out of range")
idx %= count
return self.GetAddressRangeAtIndex(idx)

def __repr__(self):
import lldb
bulbazord marked this conversation as resolved.
Show resolved Hide resolved
stream = lldb.SBStream()
self.GetDescription(stream, lldb.target if lldb.target else lldb.SBTarget())
return stream.GetData()
%}
mbucko marked this conversation as resolved.
Show resolved Hide resolved
#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 @@ -163,6 +167,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
66 changes: 66 additions & 0 deletions lldb/include/lldb/API/SBAddressRange.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//===-- 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;
mbucko marked this conversation as resolved.
Show resolved Hide resolved

/// 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, const SBTarget target);

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

AddressRangeUP m_opaque_up;
};

} // namespace lldb

#endif // LLDB_API_SBADDRESSRANGE_H
54 changes: 54 additions & 0 deletions lldb/include/lldb/API/SBAddressRangeList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//===-- 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"

namespace lldb_private {
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);
bulbazord marked this conversation as resolved.
Show resolved Hide resolved

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

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

bool GetDescription(lldb::SBStream &description, const SBTarget &target);

private:
friend class SBBlock;
friend class SBProcess;

std::unique_ptr<lldb_private::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/SBAddressRangeList.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::SBAddressRangeList GetRanges();

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
1 change: 1 addition & 0 deletions lldb/include/lldb/API/SBTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ class LLDB_API SBTarget {

protected:
friend class SBAddress;
friend class SBAddressRange;
friend class SBBlock;
friend class SBBreakpoint;
friend class SBBreakpointList;
Expand Down
14 changes: 14 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,24 @@ class AddressRange {
/// The new size in bytes of this address range.
void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }

bool GetDescription(Stream *s, Target *target) const;

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;
};
mbucko marked this conversation as resolved.
Show resolved Hide resolved

} // namespace lldb_private

#endif // LLDB_CORE_ADDRESSRANGE_H
51 changes: 51 additions & 0 deletions lldb/include/lldb/Core/AddressRangeListImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//===-- AddressRangeListImpl.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_CORE_ADDRESSRANGELISTIMPL_H
#define LLDB_CORE_ADDRESSRANGELISTIMPL_H

#include "lldb/Core/AddressRange.h"
#include <cstddef>

namespace lldb {
class SBBlock;
}

namespace lldb_private {

class AddressRangeListImpl {
public:
AddressRangeListImpl();

AddressRangeListImpl(const AddressRangeListImpl &rhs) = default;

AddressRangeListImpl &operator=(const AddressRangeListImpl &rhs);

size_t GetSize() const;

void Reserve(size_t capacity);

void Append(const AddressRange &sb_region);

void Append(const AddressRangeListImpl &list);

void Clear();

lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);

private:
friend class lldb::SBBlock;

AddressRanges &ref();

AddressRanges m_ranges;
};

} // 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
Loading
Loading