[lldb] Remove non-address bits from read/write addresses in lldb
authorDavid Spickett <david.spickett@linaro.org>
Fri, 28 Jan 2022 13:47:30 +0000 (13:47 +0000)
committerDavid Spickett <david.spickett@linaro.org>
Wed, 18 May 2022 11:59:34 +0000 (12:59 +0100)
commitd9398a91e2a6b8837a47a5fda2164c9160e86199
treeb5de15dd7a92db3a9567122ae3fdfe4cacbc6259
parent3e928c4b9dfb01efd2cb968795e605760828e873
[lldb] Remove non-address bits from read/write addresses in lldb

Non-address bits are not part of the virtual address in a pointer.
So they must be removed before passing to interfaces like ptrace.

Some of them we get way with not removing, like AArch64's top byte.
However this is only because of a hardware feature that ignores them.

This change updates all the Process/Target Read/Write memory methods
to remove non-address bits before using addresses.

Doing it in this way keeps lldb-server simple and also fixes the
memory caching when differently tagged pointers for the same location
are read.

Removing the bits is done at the ReadMemory level not DoReadMemory
because particualrly for process, many subclasses override DoReadMemory.

Tests have been added for read/write at the command and API level,
for process and target. This includes variants like
Read<sometype>FromMemory. Commands are tested to make sure we remove
at the command and API level.

"memory find" is not included because:
* There is no API for it.
* It already has its own address handling tests.

Software breakpoints do use these methods but they are not tested
here because there are bigger issues to fix with those. This will
happen in another change.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D118794
lldb/source/Target/Process.cpp
lldb/source/Target/ProcessTrace.cpp
lldb/source/Target/Target.cpp
lldb/test/API/linux/aarch64/non_address_bit_memory_access/Makefile [new file with mode: 0644]
lldb/test/API/linux/aarch64/non_address_bit_memory_access/TestAArch64LinuxNonAddressBitMemoryAccess.py [new file with mode: 0644]
lldb/test/API/linux/aarch64/non_address_bit_memory_access/main.c [new file with mode: 0644]