This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Show registers as live in better way in amd64-pseudo.c


Hi.

This test is failing on clang because clang uses $eax as a temp register here
(grep for <<<<):

(gdb) disas /m main
...
66	  /* amd64-dword.exp writes eax-edi here.
67	     Tell gcc they're clobbered so it doesn't try to keep "data" in
68	     one of them.  */
69	  asm (""

70	       : /* no outputs */
71	       : /* no inputs */
72	       : "eax", "ebx", "ecx", "edx", "esi", "edi");
73	
74	  asm ("mov %%eax, 0(%0)\n\t"
   0x00000000004006c7 <+119>:	mov    $0x402020,%eax <<<<
   0x00000000004006cc <+124>:	mov    %eax,%r8d
   0x00000000004006cf <+127>:	mov    %eax,(%r8)
   0x00000000004006d2 <+130>:	mov    %ebx,0x4(%r8)
   0x00000000004006d6 <+134>:	mov    %ecx,0x8(%r8)
   0x00000000004006da <+138>:	mov    %edx,0xc(%r8)
   0x00000000004006de <+142>:	mov    %esi,0x10(%r8)
   0x00000000004006e2 <+146>:	mov    %edi,0x14(%r8)

FAIL: gdb.arch/amd64-word.exp: check contents of %ax
FAIL: gdb.arch/amd64-word.exp: check contents of %r8w
FAIL: gdb.arch/i386-word.exp: check contents of %ax
[the {amd64,i386}-byte.exp and amd64-dword.exp tests fail similarly]

This patch uses a different mechanism to indicate that eax,etc.
are live across the two asms.

Regression tested with gcc 4.8.x-google and clang (trunk r215195).

2014-08-25  Doug Evans  <dje@google.com>

	* gdb.arch/amd64-pseudo.c (main): Rewrite to better specify when
	eax,etc. are live with values set by gdb and thus the compiler can't
	use them.
	* gdb.arch/i386-pseudo.c (main): Ditto.

diff --git a/gdb/testsuite/gdb.arch/amd64-pseudo.c b/gdb/testsuite/gdb.arch/amd64-pseudo.c
index 4dac1f1..87dc725 100644
--- a/gdb/testsuite/gdb.arch/amd64-pseudo.c
+++ b/gdb/testsuite/gdb.arch/amd64-pseudo.c
@@ -39,6 +39,21 @@ int data[] = {
 int
 main (int argc, char **argv)
 {
+  register int eax asm ("eax");
+  register int ebx asm ("ebx");
+  register int ecx asm ("ecx");
+  register int edx asm ("edx");
+  register int esi asm ("esi");
+  register int edi asm ("edi");
+  register long r8 asm ("r8");
+  register long r9 asm ("r9");
+  register long r10 asm ("r10");
+  register long r11 asm ("r11");
+  register long r12 asm ("r12");
+  register long r13 asm ("r13");
+  register long r14 asm ("r14");
+  register long r15 asm ("r15");
+
   asm ("mov 0(%0), %%eax\n\t"
        "mov 4(%0), %%ebx\n\t"
        "mov 8(%0), %%ecx\n\t"
@@ -63,13 +78,12 @@ main (int argc, char **argv)
        : "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15");
   asm ("nop"); /* second breakpoint here */
 
-  /* amd64-dword.exp writes eax-edi here.
-     Tell gcc they're clobbered so it doesn't try to keep "data" in
-     one of them.  */
+  /* amd64-{byte,word,dword}.exp write eax-edi here.
+     Tell gcc/clang they're live.  */
   asm (""
-       : /* no outputs */
-       : /* no inputs */
-       : "eax", "ebx", "ecx", "edx", "esi", "edi");
+       : "=r" (eax), "=r" (ebx), "=r" (ecx),
+	 "=r" (edx), "=r" (esi), "=r" (edi)
+       : /* no inputs */);
 
   asm ("mov %%eax, 0(%0)\n\t"
        "mov %%ebx, 4(%0)\n\t"
@@ -78,17 +92,19 @@ main (int argc, char **argv)
        "mov %%esi, 16(%0)\n\t"
        "mov %%edi, 20(%0)\n\t"
        : /* no output operands */
-       : "r" (data) 
-       : "eax", "ebx", "ecx", "edx", "esi", "edi");
+       : "r" (data),
+	 /* Mark these as inputs so that gcc/clang won't try to use them as
+	    a temp to build %0.  */
+	 "r" (eax), "r" (ebx), "r" (ecx),
+	 "r" (edx), "r" (esi), "r" (edi));
   asm ("nop"); /* third breakpoint here */
 
-  /* amd64-dword.exp writes r8-r15 here.
-     Tell gcc they're clobbered so it doesn't try to keep "data" in
-     one of them.  */
+  /* amd64-{byte,word,dword}.exp write r8-r15 here.
+     Tell gcc/clang they're live.  */
   asm (""
-       : /* no outputs */
-       : /* no inputs */
-       : "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15");
+       : "=r" (r8), "=r" (r9), "=r" (r10), "=r" (r11),
+	 "=r" (r12), "=r" (r13), "=r" (r14), "=r" (r15)
+       : /* no inputs */);
 
   asm ("mov %%r8d, 24(%0)\n\t"
        "mov %%r9d, 28(%0)\n\t"
@@ -99,8 +115,11 @@ main (int argc, char **argv)
        "mov %%r14d, 48(%0)\n\t"
        "mov %%r15d, 52(%0)\n\t"
        : /* no output operands */
-       : "r" (data) 
-       : "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15");
+       : "r" (data),
+	 /* Mark these as inputs so that gcc/clang won't try to use them as
+	    a temp to build %0.  */
+	 "r" (r8), "r" (r9), "r" (r10), "r" (r11),
+	 "r" (r12), "r" (r13), "r" (r14), "r" (r15));
   puts ("Bye!"); /* forth breakpoint here */
 
   return 0;
diff --git a/gdb/testsuite/gdb.arch/i386-pseudo.c b/gdb/testsuite/gdb.arch/i386-pseudo.c
index 11cbcd5..2acd062 100644
--- a/gdb/testsuite/gdb.arch/i386-pseudo.c
+++ b/gdb/testsuite/gdb.arch/i386-pseudo.c
@@ -29,6 +29,11 @@ int data[] = {
 int
 main (int argc, char **argv)
 {
+  register int eax asm ("eax");
+  register int ebx asm ("ebx");
+  register int ecx asm ("ecx");
+  register int edx asm ("edx");
+
   asm ("mov 0(%0), %%eax\n\t"
        "mov 4(%0), %%ebx\n\t"
        "mov 8(%0), %%ecx\n\t"
@@ -38,13 +43,21 @@ main (int argc, char **argv)
        : "eax", "ebx", "ecx", "edx");
   asm ("nop"); /* first breakpoint here */
 
+  /* i386-{byte,word}.exp write eax-edx here.
+     Tell gcc/clang they're live.  */
+  asm (""
+       : "=r" (eax), "=r" (ebx), "=r" (ecx), "=r" (edx)
+       : /* no inputs */);
+
   asm ("mov %%eax, 0(%0)\n\t"
        "mov %%ebx, 4(%0)\n\t"
        "mov %%ecx, 8(%0)\n\t"
        "mov %%edx, 12(%0)\n\t"
        : /* no output operands */
-       : "r" (data) 
-       : "eax", "ebx", "ecx", "edx");
+       : "r" (data),
+	 /* Mark these as inputs so that gcc/clang won't try to use them as
+	    a temp to build %0.  */
+	 "r" (eax), "r" (ebx), "r" (ecx), "r" (edx));
   puts ("Bye!"); /* second breakpoint here */
 
   return 0;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]