summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/lit/Register/Inputs/x86-64-gp-write.cpp55
-rw-r--r--lldb/lit/Register/Inputs/x86-gp-write.cpp61
-rw-r--r--lldb/lit/Register/x86-64-gp-write.test26
-rw-r--r--lldb/lit/Register/x86-gp-write.test26
4 files changed, 168 insertions, 0 deletions
diff --git a/lldb/lit/Register/Inputs/x86-64-gp-write.cpp b/lldb/lit/Register/Inputs/x86-64-gp-write.cpp
new file mode 100644
index 00000000000..1ce904d3d2b
--- /dev/null
+++ b/lldb/lit/Register/Inputs/x86-64-gp-write.cpp
@@ -0,0 +1,55 @@
+#include <cinttypes>
+#include <cstdint>
+#include <cstdio>
+
+int main() {
+ constexpr uint64_t fill = 0x0F0F0F0F0F0F0F0F;
+
+ uint64_t rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi;
+
+ asm volatile(
+ // save rsp & rbp
+ "movq %%rsp, %%mm0\n\t"
+ "movq %%rbp, %%mm1\n\t"
+ "\n\t"
+ "movq %8, %%rax\n\t"
+ "movq %8, %%rbx\n\t"
+ "movq %8, %%rcx\n\t"
+ "movq %8, %%rdx\n\t"
+ "movq %8, %%rsp\n\t"
+ "movq %8, %%rbp\n\t"
+ "movq %8, %%rsi\n\t"
+ "movq %8, %%rdi\n\t"
+ "\n\t"
+ "int3\n\t"
+ "\n\t"
+ "movq %%rax, %0\n\t"
+ "movq %%rbx, %1\n\t"
+ "movq %%rcx, %2\n\t"
+ "movq %%rdx, %3\n\t"
+ "movq %%rsp, %4\n\t"
+ "movq %%rbp, %5\n\t"
+ "movq %%rsi, %6\n\t"
+ "movq %%rdi, %7\n\t"
+ "\n\t"
+ // restore rsp & rbp
+ "movq %%mm0, %%rsp\n\t"
+ "movq %%mm1, %%rbp\n\t"
+ : "=r"(rax), "=r"(rbx), "=r"(rcx), "=r"(rdx), "=r"(rsp), "=r"(rbp),
+ "=r"(rsi), "=r"(rdi)
+ : "g"(fill)
+ : "%rax", "%rbx", "%rcx", "%rdx", "%rsp", "%rbp", "%rsi", "%rdi", "%mm0",
+ "%mm1"
+ );
+
+ printf("rax = 0x%016" PRIx64 "\n", rax);
+ printf("rbx = 0x%016" PRIx64 "\n", rbx);
+ printf("rcx = 0x%016" PRIx64 "\n", rcx);
+ printf("rdx = 0x%016" PRIx64 "\n", rdx);
+ printf("rsp = 0x%016" PRIx64 "\n", rsp);
+ printf("rbp = 0x%016" PRIx64 "\n", rbp);
+ printf("rsi = 0x%016" PRIx64 "\n", rsi);
+ printf("rdi = 0x%016" PRIx64 "\n", rdi);
+
+ return 0;
+}
diff --git a/lldb/lit/Register/Inputs/x86-gp-write.cpp b/lldb/lit/Register/Inputs/x86-gp-write.cpp
new file mode 100644
index 00000000000..460dbec50f6
--- /dev/null
+++ b/lldb/lit/Register/Inputs/x86-gp-write.cpp
@@ -0,0 +1,61 @@
+#include <cinttypes>
+#include <cstdint>
+#include <cstdio>
+
+int main() {
+ constexpr uint32_t fill = 0x0F0F0F0F;
+
+ uint32_t eax, ebx, ecx, edx, esp, ebp, esi, edi;
+
+ asm volatile(
+ // save esp & ebp
+ "movd %%esp, %%mm0\n\t"
+ "movd %%ebp, %%mm1\n\t"
+ "\n\t"
+ "movl %8, %%eax\n\t"
+ "movl %8, %%ebx\n\t"
+ "movl %8, %%ecx\n\t"
+ "movl %8, %%edx\n\t"
+ "movl %8, %%esp\n\t"
+ "movl %8, %%ebp\n\t"
+ "movl %8, %%esi\n\t"
+ "movl %8, %%edi\n\t"
+ "\n\t"
+ "int3\n\t"
+ "\n\t"
+ // first save new esp & ebp, and restore their original values, so that
+ // we can output values via memory
+ "movd %%esp, %%mm2\n\t"
+ "movd %%ebp, %%mm3\n\t"
+ "movd %%mm0, %%esp\n\t"
+ "movd %%mm1, %%ebp\n\t"
+ "\n\t"
+ // output values via memory
+ "movl %%eax, %0\n\t"
+ "movl %%ebx, %1\n\t"
+ "movl %%ecx, %2\n\t"
+ "movl %%edx, %3\n\t"
+ "movl %%esi, %6\n\t"
+ "movl %%edi, %7\n\t"
+ "\n\t"
+ // output saved esp & ebp
+ "movd %%mm2, %4\n\t"
+ "movd %%mm3, %5\n\t"
+ : "=m"(eax), "=m"(ebx), "=m"(ecx), "=m"(edx), "=a"(esp), "=b"(ebp),
+ "=m"(esi), "=m"(edi)
+ : "i"(fill)
+ : "%ecx", "%edx", "%esp", "%ebp", "%esi", "%edi", "%mm0", "%mm1", "%mm2",
+ "%mm3"
+ );
+
+ printf("eax = 0x%08" PRIx32 "\n", eax);
+ printf("ebx = 0x%08" PRIx32 "\n", ebx);
+ printf("ecx = 0x%08" PRIx32 "\n", ecx);
+ printf("edx = 0x%08" PRIx32 "\n", edx);
+ printf("esp = 0x%08" PRIx32 "\n", esp);
+ printf("ebp = 0x%08" PRIx32 "\n", ebp);
+ printf("esi = 0x%08" PRIx32 "\n", esi);
+ printf("edi = 0x%08" PRIx32 "\n", edi);
+
+ return 0;
+}
diff --git a/lldb/lit/Register/x86-64-gp-write.test b/lldb/lit/Register/x86-64-gp-write.test
new file mode 100644
index 00000000000..685fe1942a1
--- /dev/null
+++ b/lldb/lit/Register/x86-64-gp-write.test
@@ -0,0 +1,26 @@
+# XFAIL: system-windows
+# REQUIRES: native && target-x86_64
+# RUN: %clangxx -fomit-frame-pointer %p/Inputs/x86-64-gp-read.cpp -o %t
+# RUN: %lldb -b -s %s %t | FileCheck %s
+process launch
+
+register write rax 0x0102030405060708
+register write rbx 0x1112131415161718
+register write rcx 0x2122232425262728
+register write rdx 0x3132333435363738
+register write rsp 0x4142434445464748
+register write rbp 0x5152535455565758
+register write rsi 0x6162636465666768
+register write rdi 0x7172737475767778
+
+process continue
+# CHECK-DAG: rax = 0x0102030405060708
+# CHECK-DAG: rbx = 0x1112131415161718
+# CHECK-DAG: rcx = 0x2122232425262728
+# CHECK-DAG: rdx = 0x3132333435363738
+# CHECK-DAG: rsp = 0x4142434445464748
+# CHECK-DAG: rbp = 0x5152535455565758
+# CHECK-DAG: rsi = 0x6162636465666768
+# CHECK-DAG: rdi = 0x7172737475767778
+
+# CHECK: Process {{[0-9]+}} exited with status = 0
diff --git a/lldb/lit/Register/x86-gp-write.test b/lldb/lit/Register/x86-gp-write.test
new file mode 100644
index 00000000000..faa3676d6fb
--- /dev/null
+++ b/lldb/lit/Register/x86-gp-write.test
@@ -0,0 +1,26 @@
+# XFAIL: system-windows
+# REQUIRES: native && target-x86
+# RUN: %clangxx -fomit-frame-pointer %p/Inputs/x86-64-gp-read.cpp -o %t
+# RUN: %lldb -b -s %s %t | FileCheck %s
+process launch
+
+register write eax 0x01020304
+register write ebx 0x11121314
+register write ecx 0x21222324
+register write edx 0x31323334
+register write esp 0x41424344
+register write ebp 0x51525354
+register write esi 0x61626364
+register write edi 0x71727374
+
+process continue
+# CHECK-DAG: eax = 0x01020304
+# CHECK-DAG: ebx = 0x11121314
+# CHECK-DAG: ecx = 0x21222324
+# CHECK-DAG: edx = 0x31323334
+# CHECK-DAG: esp = 0x41424344
+# CHECK-DAG: ebp = 0x51525354
+# CHECK-DAG: esi = 0x61626364
+# CHECK-DAG: edi = 0x71727374
+
+# CHECK: Process {{[0-9]+}} exited with status = 0
OpenPOWER on IntegriCloud