This is an archive of the discontinued LLVM Phabricator instance.

[lldb] [Process/FreeBSD] Rework arm64 register access
Needs ReviewPublic

Authored by andrew on Sep 27 2021, 10:33 AM.

Details

Reviewers
mgorny
Summary

To simplify future register access rework the FreeBSD arm64 register
read/write functions to be similar to on Linux.

This will simplify adding more register sets, e.g. for Pointer
Authentication.

Diff Detail

Event Timeline

andrew created this revision.Sep 27 2021, 10:33 AM
andrew requested review of this revision.Sep 27 2021, 10:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2021, 10:33 AM
mgorny requested changes to this revision.Sep 27 2021, 11:03 AM
mgorny added inline comments.
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
73–77

These helpers don't seem very helpful. Isn't it better to use switch on the value returned by GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg)?

133

To be honest, it seems counterproductive to restore the duplication that I've removed before. Is there any real advantage to having two methods here, and calling them separately from inside the if instead of calling ReadRegisterSet(set) before the if?

This revision now requires changes to proceed.Sep 27 2021, 11:03 AM
andrew added inline comments.Sep 28 2021, 3:42 AM
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
73–77

Using a switch will be messy when adding pointer authentication or MTE registers as we need to call RegisterInfoPOSIX_arm64::IsPAuthReg [1] to check if a given register is a pointer authentication register, and similar for MTE. This is because they are dynamically added as needed.

[1] https://github.com/llvm/llvm-project/blob/76e47d4/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp#L392-L396

133

Because of the dynamic nature of the register sets we may not have a usable value to pass into ReadRegisterSet and any logic to decide which register set is being read in ReadRegisterSet would need to be repeated here and below when writing a register.

Calling the function ReadRegisterSet will also be confusing when I add PT_GETREGSET and PT_SETREGSET [1] to FreeBSD. This will be used to access the pointer authentication address masks on FreeBSD (and future registers, e.g. MTE & SVE).

See [2] for a WIP patch with how I plan to extend this for code & data address masks needed by pointer authentication.

[1] https://reviews.freebsd.org/D19831
[2] https://github.com/zxombie/llvm-project/commit/b801eca#diff-3d6a219398418eb59bf8104bda44a111f47d29081e076b4ce69336882e482cc2