[Lldb-commits] [PATCH] D142792: Add SBValue::GetValueAsAddress(), strip off ptrauth, TBI, MTE bits on AArch64 systems

Jason Molenda via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 27 16:41:56 PST 2023


jasonmolenda created this revision.
jasonmolenda added a reviewer: DavidSpickett.
jasonmolenda added a project: LLDB.
Herald added subscribers: omjavaid, JDevlieghere, kristof.beyls.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch adds a new method to SBValue, `GetValueAsAddress()`, which will take the uint64_t value in the SBValue and run it through the ABI's FixAddress method to clear any TBI/MTE/ptrauth bits on AArch64 targets.  Script authors may want access to both the actual uint64_t value, and the address that will be accessed, in an SBValue, so I added a new method in addition to GetValueAsUnsigned to provide this.

I currently have SBValue::GetValueAsAddress NOT perform a type check, and possibly I should have it check the type's IsPointerType() before doing this, but at the same time if the script/driver is calling this method, it's probably best to just do that.

There's also changes to methods like `ValueObject::CreateValueObjectFromAddress` so we can get SBValue::Dereference and such to behave correct when you have an SBValue created from a signed pointer.

I have the attached test case set to run on any AArch64 system; on Darwin we do the same pointer stripping on any process regardless if it is using pointer auth (that is, for both "arm64" and "arm64e").  On Linux, a non-ptrauth process may not have an address mask and this test may fail because the bits I mask into the top nibble in the test program are not removed by GetValueAsAddress().  I'm not sure exactly, but I can remove this test from running on Linux, or add a check for `isAArch64PAuth` or something.  This program never actually dereferences this pointer value with bits in the high nibble set, it's only set up for lldb to manipulate.

We've used this API inside Apple for a bit and it has worked well for our API users; of course if there is consensus that it should be done differently we'll find a way to handle that internally.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142792

Files:
  lldb/bindings/interface/SBValue.i
  lldb/include/lldb/API/SBValue.h
  lldb/include/lldb/Core/ValueObject.h
  lldb/source/API/SBValue.cpp
  lldb/source/Core/ValueObject.cpp
  lldb/source/DataFormatters/ValueObjectPrinter.cpp
  lldb/test/API/api/clear-sbvalue-nonadressable-bits/Makefile
  lldb/test/API/api/clear-sbvalue-nonadressable-bits/TestClearSBValueNonAddressableBits.py
  lldb/test/API/api/clear-sbvalue-nonadressable-bits/main.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142792.492947.patch
Type: text/x-patch
Size: 8286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230128/a44e52fa/attachment-0001.bin>


More information about the lldb-commits mailing list