Skip to content

Cp/add fixaddress sbprocess apis #8347

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

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
3,218 changes: 3,138 additions & 80 deletions lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Large diffs are not rendered by default.

50 changes: 48 additions & 2 deletions lldb/bindings/python/static-binding/lldb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was automatically generated by SWIG (https://www.swig.org).
# Version 4.1.1
# Version 4.2.1
#
# Do not make changes to this file unless you know what you are doing - modify
# the SWIG interface file instead.
Expand Down Expand Up @@ -99,7 +99,7 @@ class _SwigNonDynamicMeta(type):
#3.0.18.
def _to_int(hex):
return hex // 0x10 % 0x10 * 10 + hex % 0x10
swig_version = (_to_int(0x040101 // 0x10000), _to_int(0x040101 // 0x100), _to_int(0x040101))
swig_version = (_to_int(0x040201 // 0x10000), _to_int(0x040201 // 0x100), _to_int(0x040201))
del _to_int


Expand Down Expand Up @@ -233,6 +233,8 @@ def lldb_iter(obj, getsize, getelem):

LLDB_OPT_SET_12 = _lldb.LLDB_OPT_SET_12

LLDB_INVALID_ADDRESS_MASK = _lldb.LLDB_INVALID_ADDRESS_MASK

eStateInvalid = _lldb.eStateInvalid

eStateUnloaded = _lldb.eStateUnloaded
Expand Down Expand Up @@ -1749,6 +1751,32 @@ def lldb_iter(obj, getsize, getelem):

eCustomCompletion = _lldb.eCustomCompletion

eSymbolDownloadOff = _lldb.eSymbolDownloadOff

eSymbolDownloadBackground = _lldb.eSymbolDownloadBackground

eSymbolDownloadForeground = _lldb.eSymbolDownloadForeground

eAddressMaskTypeCode = _lldb.eAddressMaskTypeCode

eAddressMaskTypeData = _lldb.eAddressMaskTypeData

eAddressMaskTypeAny = _lldb.eAddressMaskTypeAny

eAddressMaskTypeAll = _lldb.eAddressMaskTypeAll

eAddressMaskRangeLow = _lldb.eAddressMaskRangeLow

eAddressMaskRangeHigh = _lldb.eAddressMaskRangeHigh

eAddressMaskRangeAny = _lldb.eAddressMaskRangeAny

eAddressMaskRangeAll = _lldb.eAddressMaskRangeAll

ChildCacheState_eRefetch = _lldb.ChildCacheState_eRefetch

ChildCacheState_eReuse = _lldb.ChildCacheState_eReuse

class SBAddress(object):
r"""
A section + offset based address class.
Expand Down Expand Up @@ -4347,6 +4375,8 @@ def disassemble_instructions (insts):

eBroadcastBitError = _lldb.SBDebugger_eBroadcastBitError

eBroadcastBitProgressCategory = _lldb.SBDebugger_eBroadcastBitProgressCategory


def __init__(self, *args):
r"""
Expand Down Expand Up @@ -8964,6 +8994,22 @@ def GetCoreFile(self):
r"""GetCoreFile(SBProcess self) -> SBFileSpec"""
return _lldb.SBProcess_GetCoreFile(self)

def GetAddressMask(self, *args):
r"""GetAddressMask(SBProcess self, lldb::AddressMaskType type, lldb::AddressMaskRange addr_range=eAddressMaskRangeLow) -> lldb::addr_t"""
return _lldb.SBProcess_GetAddressMask(self, *args)

def SetAddressMask(self, *args):
r"""SetAddressMask(SBProcess self, lldb::AddressMaskType type, lldb::addr_t mask, lldb::AddressMaskRange addr_range=eAddressMaskRangeLow)"""
return _lldb.SBProcess_SetAddressMask(self, *args)

def SetAddressableBits(self, *args):
r"""SetAddressableBits(SBProcess self, lldb::AddressMaskType type, uint32_t num_bits, lldb::AddressMaskRange addr_range=eAddressMaskRangeLow)"""
return _lldb.SBProcess_SetAddressableBits(self, *args)

def FixAddress(self, *args):
r"""FixAddress(SBProcess self, lldb::addr_t addr, lldb::AddressMaskType type=eAddressMaskTypeAny) -> lldb::addr_t"""
return _lldb.SBProcess_FixAddress(self, *args)

def AllocateMemory(self, size, permissions, error):
r"""

Expand Down
114 changes: 114 additions & 0 deletions lldb/include/lldb/API/SBProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,120 @@ class LLDB_API SBProcess {
/// the process isn't loaded from a core file.
lldb::SBFileSpec GetCoreFile();

/// \{
/// \group Mask Address Methods
///
/// \a type
/// All of the methods in this group take \a type argument
/// which is an AddressMaskType enum value.
/// There can be different address masks for code addresses and
/// data addresses, this argument can select which to get/set,
/// or to use when clearing non-addressable bits from an address.
/// This choice of mask can be important for example on AArch32
/// systems. Where instructions where instructions start on even addresses,
/// the 0th bit may be used to indicate that a function is thumb code. On
/// such a target, the eAddressMaskTypeCode may clear the 0th bit from an
/// address to get the actual address Whereas eAddressMaskTypeData would not.
///
/// \a addr_range
/// Many of the methods in this group take an \a addr_range argument
/// which is an AddressMaskRange enum value.
/// Needing to specify the address range is highly unusual, and the
/// default argument can be used in nearly all circumstances.
/// On some architectures (e.g., AArch64), it is possible to have
/// different page table setups for low and high memory, so different
/// numbers of bits relevant to addressing. It is possible to have
/// a program running in one half of memory and accessing the other
/// as heap, so we need to maintain two different sets of address masks
/// to debug this correctly.

/// Get the current address mask that will be applied to addresses
/// before reading from memory.
///
/// \param[in] type
/// See \ref Mask Address Methods description of this argument.
/// eAddressMaskTypeAny is often a suitable value when code and
/// data masks are the same on a given target.
///
/// \param[in] addr_range
/// See \ref Mask Address Methods description of this argument.
/// This will default to eAddressMaskRangeLow which is the
/// only set of masks used normally.
///
/// \return
/// The address mask currently in use. Bits which are not used
/// for addressing will be set to 1 in the mask.
lldb::addr_t GetAddressMask(
lldb::AddressMaskType type,
lldb::AddressMaskRange addr_range = lldb::eAddressMaskRangeLow);

/// Set the current address mask that can be applied to addresses
/// before reading from memory.
///
/// \param[in] type
/// See \ref Mask Address Methods description of this argument.
/// eAddressMaskTypeAll is often a suitable value when the
/// same mask is being set for both code and data.
///
/// \param[in] mask
/// The address mask to set. Bits which are not used for addressing
/// should be set to 1 in the mask.
///
/// \param[in] addr_range
/// See \ref Mask Address Methods description of this argument.
/// This will default to eAddressMaskRangeLow which is the
/// only set of masks used normally.
void SetAddressMask(
lldb::AddressMaskType type, lldb::addr_t mask,
lldb::AddressMaskRange addr_range = lldb::eAddressMaskRangeLow);

/// Set the number of bits used for addressing in this Process.
///
/// On Darwin and similar systems, the addressable bits are expressed
/// as the number of low order bits that are relevant to addressing,
/// instead of a more general address mask.
/// This method calculates the correct mask value for a given number
/// of low order addressable bits.
///
/// \param[in] type
/// See \ref Mask Address Methods description of this argument.
/// eAddressMaskTypeAll is often a suitable value when the
/// same mask is being set for both code and data.
///
/// \param[in] num_bits
/// Number of bits that are used for addressing.
/// For example, a value of 42 indicates that the low 42 bits
/// are relevant for addressing, and that higher-order bits may
/// be used for various metadata like pointer authentication,
/// Type Byte Ignore, etc.
///
/// \param[in] addr_range
/// See \ref Mask Address Methods description of this argument.
/// This will default to eAddressMaskRangeLow which is the
/// only set of masks used normally.
void
SetAddressableBits(AddressMaskType type, uint32_t num_bits,
AddressMaskRange addr_range = lldb::eAddressMaskRangeLow);

/// Clear the non-address bits of an \a addr value and return a
/// virtual address in memory.
///
/// Bits that are not used in addressing may be used for other purposes;
/// pointer authentication, or metadata in the top byte, or the 0th bit
/// of armv7 code addresses to indicate arm/thumb are common examples.
///
/// \param[in] addr
/// The address that should be cleared of non-address bits.
///
/// \param[in] type
/// See \ref Mask Address Methods description of this argument.
/// eAddressMaskTypeAny is the default value, correct when it
/// is unknown if the address is a code or data address.
lldb::addr_t
FixAddress(lldb::addr_t addr,
lldb::AddressMaskType type = lldb::eAddressMaskTypeAny);
/// \}

/// Allocate memory within the process.
///
/// This function will allocate memory in the process's address space.
Expand Down
8 changes: 2 additions & 6 deletions lldb/include/lldb/Target/ABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class ABI : public PluginInterface {
/// ARM uses bit zero to signify a code address is thumb, so any ARM ABI
/// plug-ins would strip those bits.
/// @{
virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc) { return pc; }
virtual lldb::addr_t FixDataAddress(lldb::addr_t pc) { return pc; }
virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc);
virtual lldb::addr_t FixDataAddress(lldb::addr_t pc);
/// @}

/// Use this method when you do not know, or do not care what kind of address
Expand Down Expand Up @@ -166,10 +166,6 @@ class ABI : public PluginInterface {
lldb::ProcessWP m_process_wp;
std::unique_ptr<llvm::MCRegisterInfo> m_mc_register_info_up;

virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc, lldb::addr_t mask) {
return pc;
}

private:
ABI(const ABI &) = delete;
const ABI &operator=(const ABI &) = delete;
Expand Down
36 changes: 27 additions & 9 deletions lldb/include/lldb/Target/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -1386,9 +1386,23 @@ class Process : public std::enable_shared_from_this<Process>,

virtual void DidExit() {}

/// Get the current address mask in the Process
///
/// This mask can used to set/clear non-address bits in an addr_t.
///
/// \return
/// The current address mask.
/// Bits which are set to 1 are not used for addressing.
/// An address mask of 0 means all bits are used for addressing.
/// An address mask of LLDB_INVALID_ADDRESS_MASK (all 1's) means
/// that no mask has been set.
lldb::addr_t GetCodeAddressMask();
lldb::addr_t GetDataAddressMask();

/// The highmem masks are for targets where we may have different masks
/// for low memory versus high memory addresses, and they will be left
/// as LLDB_INVALID_ADDRESS_MASK normally, meaning the base masks
/// should be applied to all addresses.
lldb::addr_t GetHighmemCodeAddressMask();
lldb::addr_t GetHighmemDataAddressMask();

Expand Down Expand Up @@ -3070,16 +3084,20 @@ void PruneThreadPlans();
/// from looking up or creating things during or after a finalize call.
std::atomic<bool> m_finalizing;

/// Mask for code an data addresses. The default value (0) means no mask is
/// set. The bits set to 1 indicate bits that are NOT significant for
/// addressing.
/// The highmem versions are for targets where we may have different masks
/// for low memory versus high memory addresses.
/// Mask for code an data addresses.
/// The default value LLDB_INVALID_ADDRESS_MASK means no mask has been set,
/// and addresses values should not be modified.
/// In these masks, the bits are set to 1 indicate bits that are not
/// significant for addressing.
/// The highmem masks are for targets where we may have different masks
/// for low memory versus high memory addresses, and they will be left
/// as LLDB_INVALID_ADDRESS_MASK normally, meaning the base masks
/// should be applied to all addresses.
/// @{
lldb::addr_t m_code_address_mask = 0;
lldb::addr_t m_data_address_mask = 0;
lldb::addr_t m_highmem_code_address_mask = 0;
lldb::addr_t m_highmem_data_address_mask = 0;
lldb::addr_t m_code_address_mask = LLDB_INVALID_ADDRESS_MASK;
lldb::addr_t m_data_address_mask = LLDB_INVALID_ADDRESS_MASK;
lldb::addr_t m_highmem_code_address_mask = LLDB_INVALID_ADDRESS_MASK;
lldb::addr_t m_highmem_data_address_mask = LLDB_INVALID_ADDRESS_MASK;
/// @}

bool m_clear_thread_plans_on_stop;
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/Utility/AddressableBits.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLDB_UTILITY_ADDRESSABLEBITS_H

#include "lldb/lldb-forward.h"
#include "lldb/lldb-public.h"

namespace lldb_private {

Expand All @@ -33,6 +34,8 @@ class AddressableBits {

void SetHighmemAddressableBits(uint32_t highmem_addressing_bits);

static lldb::addr_t AddressableBitToMask(uint32_t addressable_bits);

void SetProcessMasks(lldb_private::Process &process);

private:
Expand Down
5 changes: 5 additions & 0 deletions lldb/include/lldb/lldb-defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
#define MAX_PATH 260
#endif

/// Address Mask
/// Bits not used for addressing are set to 1 in the mask;
/// all mask bits set is an invalid value.
#define LLDB_INVALID_ADDRESS_MASK UINT64_MAX

// ignore GCC function attributes
#if defined(_MSC_VER) && !defined(__clang__)
#define __attribute__(X)
Expand Down
16 changes: 16 additions & 0 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,22 @@ enum SymbolDownload {
eSymbolDownloadForeground = 2,
};

/// Used in the SBProcess AddressMask/FixAddress methods.
enum AddressMaskType {
eAddressMaskTypeCode = 0,
eAddressMaskTypeData,
eAddressMaskTypeAny,
eAddressMaskTypeAll = eAddressMaskTypeAny
};

/// Used in the SBProcess AddressMask/FixAddress methods.
enum AddressMaskRange {
eAddressMaskRangeLow = 0,
eAddressMaskRangeHigh,
eAddressMaskRangeAny,
eAddressMaskRangeAll = eAddressMaskRangeAny,
};

/// Specifies if children need to be re-computed
/// after a call to \ref SyntheticChildrenFrontEnd::Update.
enum class ChildCacheState {
Expand Down
Loading