[Linux/x86] Fix writing of non-gpr registers on newer processors
authorPavel Labath <pavel@labath.sk>
Mon, 1 Apr 2019 08:11:46 +0000 (08:11 +0000)
committerPavel Labath <pavel@labath.sk>
Mon, 1 Apr 2019 08:11:46 +0000 (08:11 +0000)
commit38a82413210009f6796249a63ae65c15bd548ddd
treeaba65712b7cb8953fec6232bafbe746e560cc194
parent2e1bf89e3a8bc8798d1399f74e47be1a8662455b
[Linux/x86] Fix writing of non-gpr registers on newer processors

Summary:
We're using ptrace(PTRACE_SETREGSET, NT_X86_XSTATE) to write all non-gpt
registers on x86 linux. Unfortunately, this method has a quirk, where
the kernel rejects all attempts to write to this area if one supplies a
buffer which is smaller than the area size (even though the kernel will
happily accept partial reads from it).

This means that if the CPU supports some new registers/extensions that
we don't know about (in my case it was the PKRU extension), we will fail
to write *any* non-gpr registers, even those that we know about.

Since this is a situation that's likely to appear again and again, I add
code to NativeRegisterContextLinux_x86_64 to detect the runtime size of
the area, and allocate an appropriate buffer. This does not mean that we
will start automatically supporting all new extensions, but it does mean
that the new extensions will not prevent the old ones from working.

This fixes tests attempting to write to non-gpr registers on new intel
processors (cca Kaby Lake Refresh).

Reviewers: jankratochvil, davezarzycki

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D59991

llvm-svn: 357376
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h