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]

Fix %eflags register index on Solaris/amd64


When investigating a set of GCC testsuite failures on 64-bit Solaris 10/11

	PR target/51753
	Many gcc.dg/simultate-thread tests fail on Solaris 10+/x86
	http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51753

it turned out that they were cause by a gdb bug.  The test boils down to
single-stepping the program under test under gdb, calling a function
before and after every single step:

	gcc/testsuite/gcc.dg/simulate-thread/simulate-thread.gdb

When I compared the execution trace between Solaris/x64 and
Linux/x86_64, I found that the Solaris gdb behaved completely
nonsensical: e.g. in this code snippet

  ret = __atomic_exchange_n (&value, max, __ATOMIC_SEQ_CST);
  if (ret != zero || value != max)
    test_abort();

both conditions were false, still test_abort was entered, but left again
without doing anything.  When I looked at %eflags in gdb, I found that
it was always shown as 0/empty, which makes no sense.  Digging around in
gdb, I found the culprit: in both amd64-sol2-tdep.c
(amd64_sol2_gregset_reg_offset) and i386-sol2-nat.c
(amd64_sol2_gregset64_reg_offs, amd64_sol2_gregset32_reg_offs) the
offset for %eflags was wrong: <sys/regset.h> has 

#define	EFL		16

for the 32-bit case, but

#define	REG_RFL		19

for 64-bit, while 16 in 64-bit is

#define	REG_ERR		16

This explains what I was seeing: when printing $eflags, I was actually
seeing the %err value (always 0, it seems), and when restoring registers
after a call, %eflags was effectively cleared, explaining the
nonsensical control flow I was seeing.

The following patch fixes this and fixes all but one of the
gcc.dg/simulate-thread tests.  I still have to investigate that last
one.

Ok for mainline?

	Rainer


2012-02-07  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* amd64-sol2-tdep.c (amd64_sol2_gregset_reg_offset): Correct
	%eflags offset.
	* i386-sol2-nat.c (amd64_sol2_gregset64_reg_offs)
	(amd64_sol2_gregset32_reg_offs): Likewise.

--- amd64-sol2-tdep.c~	2012-01-06 05:43:04.000000000 +0100
+++ amd64-sol2-tdep.c	2012-02-04 22:03:31.871802194 +0100
@@ -54,7 +54,7 @@ static int amd64_sol2_gregset_reg_offset
   1 * 8,
   0 * 8,			/* ... %r15 */
   17 * 8,			/* %rip */
-  16 * 8,			/* %eflags */
+  19 * 8,			/* %eflags */
   18 * 8,			/* %cs */
   21 * 8,			/* %ss */
   25 * 8,			/* %ds */
--- i386-sol2-nat.c~	2012-01-06 05:43:15.000000000 +0100
+++ i386-sol2-nat.c	2012-02-04 22:04:27.661124884 +0100
@@ -68,7 +68,7 @@ static int amd64_sol2_gregset64_reg_offs
   1 * 8,
   0 * 8,			/* ... %r15 */
   17 * 8,			/* %rip */
-  16 * 8,			/* %eflags */
+  19 * 8,			/* %eflags */
   18 * 8,			/* %cs */
   21 * 8,			/* %ss */
   25 * 8,			/* %ds */
@@ -89,7 +89,7 @@ static int amd64_sol2_gregset32_reg_offs
   9 * 8,			/* %esi */
   8 * 8,			/* %edi */
   17 * 8,			/* %eip */
-  16 * 8,			/* %eflags */
+  19 * 8,			/* %eflags */
   18 * 8,			/* %cs */
   21 * 8,			/* %ss */
   25 * 8,			/* %ds */

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

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