Skip to content

Commit b809c4c

Browse files
committed
[lldb] Add FixAnyAddress to ABI plugins
FixAnyAddress is to be used when we don't know or don't care whether we're fixing a code or data address. By using FixAnyAddress over the others, you document that no specific choice was made. On all existing platforms apart from Arm Thumb, you could use either FixCodeAddress or FixDataAddress and be fine. Up until now I've chosen to use FixDataAddress but if I had chosen to use FixCodeAddress that would have broken Arm Thumb. Hence FixAnyAddress, to give you the "safest" option when you're in generic code. Uses of FixDataAddress in memory region code have been changed to FixAnyAddress. The functionality is unchanged. Reviewed By: omjavaid, JDevlieghere Differential Revision: https://reviews.llvm.org/D124000
1 parent 744a837 commit b809c4c

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lldb/include/lldb/Target/ABI.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ class ABI : public PluginInterface {
126126
virtual lldb::addr_t FixDataAddress(lldb::addr_t pc) { return pc; }
127127
/// @}
128128

129+
/// Use this method when you do not know, or do not care what kind of address
130+
/// you are fixing. On platforms where there would be a difference between the
131+
/// two types, it will pick the safest option.
132+
///
133+
/// Its purpose is to signal that no specific choice was made and provide an
134+
/// alternative to randomly picking FixCode/FixData address. Which could break
135+
/// platforms where there is a difference (only Arm Thumb at this time).
136+
virtual lldb::addr_t FixAnyAddress(lldb::addr_t pc) {
137+
// On Arm Thumb fixing a code address zeroes the bottom bit, so FixData is
138+
// the safe choice. On any other platform (so far) code and data addresses
139+
// are fixed in the same way.
140+
return FixDataAddress(pc);
141+
}
142+
129143
llvm::MCRegisterInfo &GetMCRegisterInfo() { return *m_mc_register_info_up; }
130144

131145
virtual void

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ class CommandObjectMemoryRegion : public CommandObjectParsed {
16881688
// address size, etc.), the end of mappable memory will be lower
16891689
// than that. So if we find any non-address bit set, we must be
16901690
// at the end of the mappable range.
1691-
(abi && (abi->FixDataAddress(load_addr) != load_addr))) {
1691+
(abi && (abi->FixAnyAddress(load_addr) != load_addr))) {
16921692
result.AppendErrorWithFormat("'%s' takes one argument:\nUsage: %s\n",
16931693
m_cmd_name.c_str(), m_cmd_syntax.c_str());
16941694
return false;

lldb/source/Target/Process.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5831,7 +5831,7 @@ Process::AdvanceAddressToNextBranchInstruction(Address default_stop_addr,
58315831
Status Process::GetMemoryRegionInfo(lldb::addr_t load_addr,
58325832
MemoryRegionInfo &range_info) {
58335833
if (const lldb::ABISP &abi = GetABI())
5834-
load_addr = abi->FixDataAddress(load_addr);
5834+
load_addr = abi->FixAnyAddress(load_addr);
58355835
return DoGetMemoryRegionInfo(load_addr, range_info);
58365836
}
58375837

@@ -5866,7 +5866,7 @@ Status Process::GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) {
58665866
range_end != LLDB_INVALID_ADDRESS &&
58675867
// If we have non-address bits and some are set then the end
58685868
// is at or beyond the end of mappable memory.
5869-
!(abi && (abi->FixDataAddress(range_end) != range_end)));
5869+
!(abi && (abi->FixAnyAddress(range_end) != range_end)));
58705870

58715871
return error;
58725872
}

0 commit comments

Comments
 (0)