Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Fix %eflags register index on Solaris/amd64
@ 2012-02-07 18:01 Rainer Orth
  2012-02-07 19:36 ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Rainer Orth @ 2012-02-07 18:01 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1919 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: solx64-eflags.patch --]
[-- Type: text/x-patch, Size: 968 bytes --]

--- 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 */

[-- Attachment #3: Type: text/plain, Size: 144 bytes --]



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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-08 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-07 18:01 Fix %eflags register index on Solaris/amd64 Rainer Orth
2012-02-07 19:36 ` Pedro Alves
2012-02-08 14:40   ` Rainer Orth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox