mgorny updated this revision to Diff 295500.
mgorny retitled this revision from "[lldb] [test/Register] Add partial
read/write tests for x87 regs" to "[lldb] [test/Register] Add read/write tests
for x87 regs".
mgorny edited the summary of this revision.
mgorny added a comment.
Done as requested + improved the tests:
- switch to `FDIV` on memory operand, to be able to test FDP
- added disassembly-based test for FIP and print-based test for FDP (assuming
Linux behavior for fiseg/fioff/foseg/fooff, this certainly breaks NetBSD and
might break some more platforms)
- figured out how to make write test work while restoring exception state
- added FXSAVE-based check whether writing other registers works (this also
includes potential future support for MXCSR)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88583/new/
https://reviews.llvm.org/D88583
Files:
lldb/test/Shell/Register/Inputs/x86-fp-read.cpp
lldb/test/Shell/Register/Inputs/x86-fp-write.cpp
lldb/test/Shell/Register/x86-fp-read.test
lldb/test/Shell/Register/x86-fp-write.test
Index: lldb/test/Shell/Register/x86-fp-write.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/x86-fp-write.test
@@ -0,0 +1,47 @@
+# REQUIRES: native && (target-x86 || target-x86_64)
+# RUN: %clangxx_host %p/Inputs/x86-fp-write.cpp -o %t
+# RUN: %lldb -b -s %s %t | FileCheck %s
+process launch
+
+register write fctrl 0x037b
+register write fstat 0x8884
+# note: this needs to enable all registers for writes to be effective
+# TODO: fix it to use proper ftag values instead of 'abridged'
+register write ftag 0x00ff
+register write fop 0x0033
+# the exact addresses do not matter, we want just to verify FXSAVE
+register write fiseg 0x01234567
+register write fioff 0x89abcdef
+register write foseg 0xfedcba98
+register write fooff 0x76543210
+
+register write st0 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x00 0x40}"
+register write st1 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3f 0x00 0x00}"
+register write st2 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}"
+register write st3 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80}"
+register write st4 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0x7f}"
+register write st5 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0xff}"
+register write st6 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xc0 0xff 0xff}"
+register write st7 "{0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}"
+
+process continue
+
+# CHECK: process continue
+# CHECK-DAG: fctrl = 0x037b
+# CHECK-DAG: fstat = 0x8884
+# CHECK-DAG: ftag = 0xa961
+# CHECK-DAG: fop = 0x0033
+# TODO: bug?
+# CHECK-DAG: fip = 0x0000000089abcdef
+# CHECK-DAG: fdp = 0x0000000076543210
+
+# CHECK-DAG: st0 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x00 0x40 }
+# CHECK-DAG: st1 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3f 0x00 0x00 }
+# CHECK-DAG: st2 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 }
+# CHECK-DAG: st3 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 }
+# CHECK-DAG: st4 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0x7f }
+# CHECK-DAG: st5 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0xff }
+# CHECK-DAG: st6 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xc0 0xff 0xff }
+# CHECK-DAG: st7 = { 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 }
+
+# CHECK: Process {{[0-9]+}} exited with status = 0
Index: lldb/test/Shell/Register/x86-fp-read.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/x86-fp-read.test
@@ -0,0 +1,31 @@
+# REQUIRES: native && (target-x86 || target-x86_64)
+# RUN: %clangxx_host %p/Inputs/x86-fp-read.cpp -o %t
+# RUN: %lldb -b -s %s %t | FileCheck %s
+process launch
+# CHECK: Process {{.*}} stopped
+
+register read --all
+# CHECK-DAG: fctrl = 0x037b
+# CHECK-DAG: fstat = 0x8884
+# TODO: the following value is incorrect, it's a bug in the way
+# FXSAVE/XSAVE is interpreted; it should be 0xa963 once fixed
+# CHECK-DAG: ftag = 0x00fe
+# CHECK-DAG: fop = 0x0033
+
+# CHECK-DAG: st0 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x00 0x40}
+# CHECK-DAG: st1 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3f 0x00 0x00}
+# CHECK-DAG: st2 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}
+# CHECK-DAG: st3 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80}
+# CHECK-DAG: st4 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0x7f}
+# CHECK-DAG: st5 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0xff 0xff}
+# CHECK-DAG: st6 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xc0 0xff 0xff}
+# CHECK-DAG: st7 = {0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}
+
+# TODO: we probably should not split it like this
+disassemble -s '$fiseg*0x100000000 + $fioff' -c 1
+# CHECK: fdivs (%{{[er]}}bx)
+print *(uint32_t*)($foseg * 0x100000000 + $fooff)
+# CHECK: (uint32_t) $1 = 0
+
+process continue
+# CHECK: Process {{[0-9]+}} exited with status = 0
Index: lldb/test/Shell/Register/Inputs/x86-fp-write.cpp
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/Inputs/x86-fp-write.cpp
@@ -0,0 +1,59 @@
+#include <cassert>
+#include <cinttypes>
+#include <cstdint>
+#include <cstdio>
+
+struct alignas(16) float80_raw {
+ uint8_t data[10];
+};
+
+int main() {
+ float80_raw st[8];
+ uint16_t env[14];
+ union {
+ uint16_t i16[256];
+ uint32_t i32[128];
+ uint64_t i64[64];
+ } fxsave;
+
+ asm volatile(
+ "finit\n\t"
+ "int3\n\t"
+ "rex.w = 1\n\t"
+ "fxsave %2\n\t"
+ "fnstenv %1\n\t"
+ "fnclex\n\t"
+ "fstpt 0x00(%0)\n\t"
+ "fstpt 0x10(%0)\n\t"
+ "fstpt 0x20(%0)\n\t"
+ "fstpt 0x30(%0)\n\t"
+ "fstpt 0x40(%0)\n\t"
+ "fstpt 0x50(%0)\n\t"
+ "fstpt 0x60(%0)\n\t"
+ "fstpt 0x70(%0)\n\t"
+ :
+ : "a"(st), "m"(env), "m"(fxsave)
+ : "st"
+ );
+
+ assert(env[0] == fxsave.i16[0]);
+ assert(env[2] == fxsave.i16[1]);
+
+ printf("fctrl = 0x%04" PRIx16 "\n", env[0]);
+ printf("fstat = 0x%04" PRIx16 "\n", env[2]);
+ printf("ftag = 0x%04" PRIx16 "\n", env[4]);
+ printf("fop = 0x%04" PRIx16 "\n", fxsave.i16[3]);
+ printf("fip = 0x%016" PRIx64 "\n", fxsave.i64[1]);
+ printf("fdp = 0x%016" PRIx64 "\n", fxsave.i64[2]);
+ printf("mxcsr = 0x%08" PRIx32 "\n", fxsave.i32[6]);
+ printf("mxcsr_mask = 0x%08" PRIx32 "\n", fxsave.i32[7]);
+
+ for (int i = 0; i < 8; ++i) {
+ printf("st%d = { ", i);
+ for (int j = 0; j < sizeof(st->data); ++j)
+ printf("0x%02" PRIx8 " ", st[i].data[j]);
+ printf("}\n");
+ }
+
+ return 0;
+}
Index: lldb/test/Shell/Register/Inputs/x86-fp-read.cpp
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/Inputs/x86-fp-read.cpp
@@ -0,0 +1,45 @@
+#include <cstdint>
+
+struct alignas(16) float80_raw {
+ uint64_t mantissa;
+ uint16_t sign_exp;
+};
+
+int main() {
+ float80_raw st[] = {
+ {0x8000000000000000, 0x4000}, // +2.0
+ {0x3f00000000000000, 0x0000}, // 1.654785e-4932 (denormal)
+ {0x0000000000000000, 0x0000}, // +0
+ {0x0000000000000000, 0x8000}, // -0
+ {0x8000000000000000, 0x7fff}, // +inf
+ {0x8000000000000000, 0xffff}, // -inf
+ {0xc000000000000000, 0xffff}, // nan
+ // leave st7 empty to test tag word better
+ };
+
+ // unmask invalid op exception
+ uint16_t cw = 0x037b;
+ // used as single-precision float
+ uint32_t zero = 0;
+
+ asm volatile(
+ "finit\n\t"
+ "fldcw %1\n\t"
+ // load on stack in reverse order to make the result easier to read
+ "fldt 0x60(%0)\n\t"
+ "fldt 0x50(%0)\n\t"
+ "fldt 0x40(%0)\n\t"
+ "fldt 0x30(%0)\n\t"
+ "fldt 0x20(%0)\n\t"
+ "fldt 0x10(%0)\n\t"
+ "fldt 0x00(%0)\n\t"
+ // this should trigger a divide-by-zero
+ "fdivs (%2)\n\t"
+ "int3\n\t"
+ :
+ : "a"(st), "m"(cw), "b"(&zero)
+ : "st"
+ );
+
+ return 0;
+}
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits