Skip to content

Commit f9fc88d

Browse files
authored
Merge pull request #8347 from jasonmolenda/cp/add-fixaddress-sbprocess-apis
Cp/add fixaddress sbprocess apis
2 parents 62720a3 + 33ff395 commit f9fc88d

File tree

22 files changed

+3708
-133
lines changed

22 files changed

+3708
-133
lines changed

lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 3138 additions & 80 deletions
Large diffs are not rendered by default.

lldb/bindings/python/static-binding/lldb.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file was automatically generated by SWIG (https://www.swig.org).
2-
# Version 4.1.1
2+
# Version 4.2.1
33
#
44
# Do not make changes to this file unless you know what you are doing - modify
55
# the SWIG interface file instead.
@@ -99,7 +99,7 @@ class _SwigNonDynamicMeta(type):
9999
#3.0.18.
100100
def _to_int(hex):
101101
return hex // 0x10 % 0x10 * 10 + hex % 0x10
102-
swig_version = (_to_int(0x040101 // 0x10000), _to_int(0x040101 // 0x100), _to_int(0x040101))
102+
swig_version = (_to_int(0x040201 // 0x10000), _to_int(0x040201 // 0x100), _to_int(0x040201))
103103
del _to_int
104104

105105

@@ -233,6 +233,8 @@ def lldb_iter(obj, getsize, getelem):
233233

234234
LLDB_OPT_SET_12 = _lldb.LLDB_OPT_SET_12
235235

236+
LLDB_INVALID_ADDRESS_MASK = _lldb.LLDB_INVALID_ADDRESS_MASK
237+
236238
eStateInvalid = _lldb.eStateInvalid
237239

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

17501752
eCustomCompletion = _lldb.eCustomCompletion
17511753

1754+
eSymbolDownloadOff = _lldb.eSymbolDownloadOff
1755+
1756+
eSymbolDownloadBackground = _lldb.eSymbolDownloadBackground
1757+
1758+
eSymbolDownloadForeground = _lldb.eSymbolDownloadForeground
1759+
1760+
eAddressMaskTypeCode = _lldb.eAddressMaskTypeCode
1761+
1762+
eAddressMaskTypeData = _lldb.eAddressMaskTypeData
1763+
1764+
eAddressMaskTypeAny = _lldb.eAddressMaskTypeAny
1765+
1766+
eAddressMaskTypeAll = _lldb.eAddressMaskTypeAll
1767+
1768+
eAddressMaskRangeLow = _lldb.eAddressMaskRangeLow
1769+
1770+
eAddressMaskRangeHigh = _lldb.eAddressMaskRangeHigh
1771+
1772+
eAddressMaskRangeAny = _lldb.eAddressMaskRangeAny
1773+
1774+
eAddressMaskRangeAll = _lldb.eAddressMaskRangeAll
1775+
1776+
ChildCacheState_eRefetch = _lldb.ChildCacheState_eRefetch
1777+
1778+
ChildCacheState_eReuse = _lldb.ChildCacheState_eReuse
1779+
17521780
class SBAddress(object):
17531781
r"""
17541782
A section + offset based address class.
@@ -4347,6 +4375,8 @@ def disassemble_instructions (insts):
43474375

43484376
eBroadcastBitError = _lldb.SBDebugger_eBroadcastBitError
43494377

4378+
eBroadcastBitProgressCategory = _lldb.SBDebugger_eBroadcastBitProgressCategory
4379+
43504380

43514381
def __init__(self, *args):
43524382
r"""
@@ -8964,6 +8994,22 @@ def GetCoreFile(self):
89648994
r"""GetCoreFile(SBProcess self) -> SBFileSpec"""
89658995
return _lldb.SBProcess_GetCoreFile(self)
89668996

8997+
def GetAddressMask(self, *args):
8998+
r"""GetAddressMask(SBProcess self, lldb::AddressMaskType type, lldb::AddressMaskRange addr_range=eAddressMaskRangeLow) -> lldb::addr_t"""
8999+
return _lldb.SBProcess_GetAddressMask(self, *args)
9000+
9001+
def SetAddressMask(self, *args):
9002+
r"""SetAddressMask(SBProcess self, lldb::AddressMaskType type, lldb::addr_t mask, lldb::AddressMaskRange addr_range=eAddressMaskRangeLow)"""
9003+
return _lldb.SBProcess_SetAddressMask(self, *args)
9004+
9005+
def SetAddressableBits(self, *args):
9006+
r"""SetAddressableBits(SBProcess self, lldb::AddressMaskType type, uint32_t num_bits, lldb::AddressMaskRange addr_range=eAddressMaskRangeLow)"""
9007+
return _lldb.SBProcess_SetAddressableBits(self, *args)
9008+
9009+
def FixAddress(self, *args):
9010+
r"""FixAddress(SBProcess self, lldb::addr_t addr, lldb::AddressMaskType type=eAddressMaskTypeAny) -> lldb::addr_t"""
9011+
return _lldb.SBProcess_FixAddress(self, *args)
9012+
89679013
def AllocateMemory(self, size, permissions, error):
89689014
r"""
89699015

lldb/include/lldb/API/SBProcess.h

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,120 @@ class LLDB_API SBProcess {
407407
/// the process isn't loaded from a core file.
408408
lldb::SBFileSpec GetCoreFile();
409409

410+
/// \{
411+
/// \group Mask Address Methods
412+
///
413+
/// \a type
414+
/// All of the methods in this group take \a type argument
415+
/// which is an AddressMaskType enum value.
416+
/// There can be different address masks for code addresses and
417+
/// data addresses, this argument can select which to get/set,
418+
/// or to use when clearing non-addressable bits from an address.
419+
/// This choice of mask can be important for example on AArch32
420+
/// systems. Where instructions where instructions start on even addresses,
421+
/// the 0th bit may be used to indicate that a function is thumb code. On
422+
/// such a target, the eAddressMaskTypeCode may clear the 0th bit from an
423+
/// address to get the actual address Whereas eAddressMaskTypeData would not.
424+
///
425+
/// \a addr_range
426+
/// Many of the methods in this group take an \a addr_range argument
427+
/// which is an AddressMaskRange enum value.
428+
/// Needing to specify the address range is highly unusual, and the
429+
/// default argument can be used in nearly all circumstances.
430+
/// On some architectures (e.g., AArch64), it is possible to have
431+
/// different page table setups for low and high memory, so different
432+
/// numbers of bits relevant to addressing. It is possible to have
433+
/// a program running in one half of memory and accessing the other
434+
/// as heap, so we need to maintain two different sets of address masks
435+
/// to debug this correctly.
436+
437+
/// Get the current address mask that will be applied to addresses
438+
/// before reading from memory.
439+
///
440+
/// \param[in] type
441+
/// See \ref Mask Address Methods description of this argument.
442+
/// eAddressMaskTypeAny is often a suitable value when code and
443+
/// data masks are the same on a given target.
444+
///
445+
/// \param[in] addr_range
446+
/// See \ref Mask Address Methods description of this argument.
447+
/// This will default to eAddressMaskRangeLow which is the
448+
/// only set of masks used normally.
449+
///
450+
/// \return
451+
/// The address mask currently in use. Bits which are not used
452+
/// for addressing will be set to 1 in the mask.
453+
lldb::addr_t GetAddressMask(
454+
lldb::AddressMaskType type,
455+
lldb::AddressMaskRange addr_range = lldb::eAddressMaskRangeLow);
456+
457+
/// Set the current address mask that can be applied to addresses
458+
/// before reading from memory.
459+
///
460+
/// \param[in] type
461+
/// See \ref Mask Address Methods description of this argument.
462+
/// eAddressMaskTypeAll is often a suitable value when the
463+
/// same mask is being set for both code and data.
464+
///
465+
/// \param[in] mask
466+
/// The address mask to set. Bits which are not used for addressing
467+
/// should be set to 1 in the mask.
468+
///
469+
/// \param[in] addr_range
470+
/// See \ref Mask Address Methods description of this argument.
471+
/// This will default to eAddressMaskRangeLow which is the
472+
/// only set of masks used normally.
473+
void SetAddressMask(
474+
lldb::AddressMaskType type, lldb::addr_t mask,
475+
lldb::AddressMaskRange addr_range = lldb::eAddressMaskRangeLow);
476+
477+
/// Set the number of bits used for addressing in this Process.
478+
///
479+
/// On Darwin and similar systems, the addressable bits are expressed
480+
/// as the number of low order bits that are relevant to addressing,
481+
/// instead of a more general address mask.
482+
/// This method calculates the correct mask value for a given number
483+
/// of low order addressable bits.
484+
///
485+
/// \param[in] type
486+
/// See \ref Mask Address Methods description of this argument.
487+
/// eAddressMaskTypeAll is often a suitable value when the
488+
/// same mask is being set for both code and data.
489+
///
490+
/// \param[in] num_bits
491+
/// Number of bits that are used for addressing.
492+
/// For example, a value of 42 indicates that the low 42 bits
493+
/// are relevant for addressing, and that higher-order bits may
494+
/// be used for various metadata like pointer authentication,
495+
/// Type Byte Ignore, etc.
496+
///
497+
/// \param[in] addr_range
498+
/// See \ref Mask Address Methods description of this argument.
499+
/// This will default to eAddressMaskRangeLow which is the
500+
/// only set of masks used normally.
501+
void
502+
SetAddressableBits(AddressMaskType type, uint32_t num_bits,
503+
AddressMaskRange addr_range = lldb::eAddressMaskRangeLow);
504+
505+
/// Clear the non-address bits of an \a addr value and return a
506+
/// virtual address in memory.
507+
///
508+
/// Bits that are not used in addressing may be used for other purposes;
509+
/// pointer authentication, or metadata in the top byte, or the 0th bit
510+
/// of armv7 code addresses to indicate arm/thumb are common examples.
511+
///
512+
/// \param[in] addr
513+
/// The address that should be cleared of non-address bits.
514+
///
515+
/// \param[in] type
516+
/// See \ref Mask Address Methods description of this argument.
517+
/// eAddressMaskTypeAny is the default value, correct when it
518+
/// is unknown if the address is a code or data address.
519+
lldb::addr_t
520+
FixAddress(lldb::addr_t addr,
521+
lldb::AddressMaskType type = lldb::eAddressMaskTypeAny);
522+
/// \}
523+
410524
/// Allocate memory within the process.
411525
///
412526
/// This function will allocate memory in the process's address space.

lldb/include/lldb/Target/ABI.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ class ABI : public PluginInterface {
122122
/// ARM uses bit zero to signify a code address is thumb, so any ARM ABI
123123
/// plug-ins would strip those bits.
124124
/// @{
125-
virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc) { return pc; }
126-
virtual lldb::addr_t FixDataAddress(lldb::addr_t pc) { return pc; }
125+
virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc);
126+
virtual lldb::addr_t FixDataAddress(lldb::addr_t pc);
127127
/// @}
128128

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

169-
virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc, lldb::addr_t mask) {
170-
return pc;
171-
}
172-
173169
private:
174170
ABI(const ABI &) = delete;
175171
const ABI &operator=(const ABI &) = delete;

lldb/include/lldb/Target/Process.h

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,9 +1386,23 @@ class Process : public std::enable_shared_from_this<Process>,
13861386

13871387
virtual void DidExit() {}
13881388

1389+
/// Get the current address mask in the Process
1390+
///
1391+
/// This mask can used to set/clear non-address bits in an addr_t.
1392+
///
1393+
/// \return
1394+
/// The current address mask.
1395+
/// Bits which are set to 1 are not used for addressing.
1396+
/// An address mask of 0 means all bits are used for addressing.
1397+
/// An address mask of LLDB_INVALID_ADDRESS_MASK (all 1's) means
1398+
/// that no mask has been set.
13891399
lldb::addr_t GetCodeAddressMask();
13901400
lldb::addr_t GetDataAddressMask();
13911401

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

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

3073-
/// Mask for code an data addresses. The default value (0) means no mask is
3074-
/// set. The bits set to 1 indicate bits that are NOT significant for
3075-
/// addressing.
3076-
/// The highmem versions are for targets where we may have different masks
3077-
/// for low memory versus high memory addresses.
3087+
/// Mask for code an data addresses.
3088+
/// The default value LLDB_INVALID_ADDRESS_MASK means no mask has been set,
3089+
/// and addresses values should not be modified.
3090+
/// In these masks, the bits are set to 1 indicate bits that are not
3091+
/// significant for addressing.
3092+
/// The highmem masks are for targets where we may have different masks
3093+
/// for low memory versus high memory addresses, and they will be left
3094+
/// as LLDB_INVALID_ADDRESS_MASK normally, meaning the base masks
3095+
/// should be applied to all addresses.
30783096
/// @{
3079-
lldb::addr_t m_code_address_mask = 0;
3080-
lldb::addr_t m_data_address_mask = 0;
3081-
lldb::addr_t m_highmem_code_address_mask = 0;
3082-
lldb::addr_t m_highmem_data_address_mask = 0;
3097+
lldb::addr_t m_code_address_mask = LLDB_INVALID_ADDRESS_MASK;
3098+
lldb::addr_t m_data_address_mask = LLDB_INVALID_ADDRESS_MASK;
3099+
lldb::addr_t m_highmem_code_address_mask = LLDB_INVALID_ADDRESS_MASK;
3100+
lldb::addr_t m_highmem_data_address_mask = LLDB_INVALID_ADDRESS_MASK;
30833101
/// @}
30843102

30853103
bool m_clear_thread_plans_on_stop;

lldb/include/lldb/Utility/AddressableBits.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLDB_UTILITY_ADDRESSABLEBITS_H
1111

1212
#include "lldb/lldb-forward.h"
13+
#include "lldb/lldb-public.h"
1314

1415
namespace lldb_private {
1516

@@ -33,6 +34,8 @@ class AddressableBits {
3334

3435
void SetHighmemAddressableBits(uint32_t highmem_addressing_bits);
3536

37+
static lldb::addr_t AddressableBitToMask(uint32_t addressable_bits);
38+
3639
void SetProcessMasks(lldb_private::Process &process);
3740

3841
private:

lldb/include/lldb/lldb-defines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
#define MAX_PATH 260
125125
#endif
126126

127+
/// Address Mask
128+
/// Bits not used for addressing are set to 1 in the mask;
129+
/// all mask bits set is an invalid value.
130+
#define LLDB_INVALID_ADDRESS_MASK UINT64_MAX
131+
127132
// ignore GCC function attributes
128133
#if defined(_MSC_VER) && !defined(__clang__)
129134
#define __attribute__(X)

lldb/include/lldb/lldb-enumerations.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,22 @@ enum SymbolDownload {
13381338
eSymbolDownloadForeground = 2,
13391339
};
13401340

1341+
/// Used in the SBProcess AddressMask/FixAddress methods.
1342+
enum AddressMaskType {
1343+
eAddressMaskTypeCode = 0,
1344+
eAddressMaskTypeData,
1345+
eAddressMaskTypeAny,
1346+
eAddressMaskTypeAll = eAddressMaskTypeAny
1347+
};
1348+
1349+
/// Used in the SBProcess AddressMask/FixAddress methods.
1350+
enum AddressMaskRange {
1351+
eAddressMaskRangeLow = 0,
1352+
eAddressMaskRangeHigh,
1353+
eAddressMaskRangeAny,
1354+
eAddressMaskRangeAll = eAddressMaskRangeAny,
1355+
};
1356+
13411357
/// Specifies if children need to be re-computed
13421358
/// after a call to \ref SyntheticChildrenFrontEnd::Update.
13431359
enum class ChildCacheState {

0 commit comments

Comments
 (0)