This is an archive of the discontinued LLVM Phabricator instance.

[lldb] [lit] Introduce tests for reading x86 general purpose registers
ClosedPublic

Authored by mgorny on Apr 26 2019, 1:39 PM.

Details

Summary

Introduce tests for reading the eight x86 general purpose registers,
i.e. RAX/RBX/RCX/RDX/RBP/RSP/RSI/RDI and their shorter counterparts.
The test comes in separate 32-bit and 64-bit variant, targeting
appropriate processors.

While technically the 32-bit test could run on amd64, it would be
redundant to the 64-bit version, so just run one of them on each arch.

Diff Detail

Event Timeline

mgorny created this revision.Apr 26 2019, 1:39 PM

GCC refuses to build this with:

Inputs/x86-64-gp-read.cpp: In function ‘int main()’:
Inputs/x86-64-gp-read.cpp:31:1: error: bp cannot be used in asm here
 }
 ^
Inputs/x86-gp-read.cpp: In function ‘int main()’:
Inputs/x86-gp-read.cpp:31:1: error: bp cannot be used in asm here
 }
 ^

Clang doesn't complain but it also seems to generally exhibit special assumptions about *bp not being touched by assembly. In this particular case, it seems to generate correct code (with push/pop for rbp around my code).

Oh wait, that push/pop doesn't really work when I modify the stack pointer ;-). I suppose this doesn't really cause any problems because we don't continue the program past int3 though.

mgorny updated this revision to Diff 196950.Apr 27 2019, 1:20 AM

Updated to avoid returning to the program with corrupt RSP/RBP. In the 64-bit version, I'm saving the initial values in %r8 and %r9; in the 32-bit version, I'm using %mm0 and %mm1.

mgorny updated this revision to Diff 196952.Apr 27 2019, 1:24 AM

Also included -fomit-frame-pointer, for CLI compatibility with gcc (i.e. in case clang becomes more strict in the future).

Looks good to me. In your place, I wouldn't bother with making sure that the process can correctly terminate after we have read the registers, but now that you have done it, there's no reason to take it out. :)

labath accepted this revision.Apr 29 2019, 12:53 AM
This revision is now accepted and ready to land.Apr 29 2019, 12:53 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2019, 4:36 AM
Herald added a subscriber: teemperor. · View Herald Transcript