Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 May 2013 13:16:14 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        numerics@freebsd.org
Cc:        kib@freebsd.org
Subject:   gdb displays xmm registers poorly on amd64, but works on i386
Message-ID:  <20130522122836.H1038@besplex.bde.org>

next in thread | raw e-mail | index | archive | help
Debugging log* reminded me of some bugs in gdb.

First, gdb is still broken on pipelines, so it is harder to demonstrate
bugs in it non-interactively:

@ Script started on Wed May 22 02:37:41 2013
@ pts/2:bde@freefall:~/s> echo 'p 1' | gdb
@ GNU gdb 6.1.1 [FreeBSD]
@ Copyright 2004 Free Software Foundation, Inc.
@ GDB is free software, covered by the GNU General Public License, and you are
@ welcome to change it and/or distribute copies of it under certain conditions.
@ Type "show copying" to see the conditions.
@ There is absolutely no warranty for GDB.  Type "show warranty" for details.
@ This GDB was configured as "amd64-marcel-freebsd".
@ (gdb) Hangup detected on fd 0
@ error detected on stdin

This is because gdb doesn't understand poll(2).  It quits when it sees
POLLHUP, before reading all the input (FreeBSD sets both POLLIN and
POLLHUP when there is hangup but unread input.  IIRC, -current is still
missing one of my fixes in this area -- when there is hangup but no
unread input, POLLHUP should remain set of course, but POLLIN should be
declared).

@ pts/2:bde@freefall:~/s> cat z
@ echo 'p 1'
@ echo 'p 2'
@ pts/2:bde@freefall:~/s> gdb <z
@ GNU gdb 6.1.1 [FreeBSD]
@ Copyright 2004 Free Software Foundation, Inc.
@ GDB is free software, covered by the GNU General Public License, and you are
@ welcome to change it and/or distribute copies of it under certain conditions.
@ Type "show copying" to see the conditions.
@ There is absolutely no warranty for GDB.  Type "show warranty" for details.
@ This GDB was configured as "amd64-marcel-freebsd".
@ (gdb) 'p 1'(gdb) 'p 2'(gdb) pts/2:bde@freefall:~/s> exit

It is even more broken when the input is from a regular file.  Now it sees
the input and doesn't see hangup, but it messes up the output.

@ 
@ Script done on Wed May 22 02:38:12 2013

gdb used to work for at least piped input when it used select(2) instead
of poll(2).  With select(), there is no POLLHUP to confuse it, so it must
use read() to try to detect EOF.  It makes the usual assumption that
read() only returns 0 at EOF.  This has races in general, but works in
simple situations when nothing else can eat the input.  A read() is needed
for poll() too when POLLIN indicates input too.  If poll() is broken and
keeps returning POLLIN after hangup when there is no input, then the
application must either make the same assumption as for select() and try
to detect EOF using read(), or it must assume that poll() is broken in a
different way and doesn't set POLLHUP while there is unread input -- then
the gdb method works.

Now for the xmm display bugs:

@ Script started on Wed May 22 02:43:16 2013
@ pts/2:bde@freefall:~/s> gdb /bin/cat
@ GNU gdb 6.1.1 [FreeBSD]
@ Copyright 2004 Free Software Foundation, Inc.
@ GDB is free software, covered by the GNU General Public License, and you are
@ welcome to change it and/or distribute copies of it under certain conditions.
@ Type "show copying" to see the conditions.
@ There is absolutely no warranty for GDB.  Type "show warranty" for details.
@ This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
@ (gdb) r
@ Starting program: /bin/cat 
@ (no debugging symbols found)...(no debugging symbols found)...^Z
@ Program received signal SIGTSTP, Stopped (user).
@ 0x00000008009422f8 in read () from /lib/libc.so.7
@ (gdb) p $xmm0
@ $1 = {f = {0, 0, 0, 0}}

gdb cannot know the types of the bits in xmm registers, and it is useful
to display all types, but on amd64 it only displays the float type.

@ (gdb) The program is running.  Exit anyway? (y or n) y
@ pts/2:bde@freefall:~/s> exit
@ 
@ Script done on Wed May 22 02:43:41 2013

@ Script started on Wed May 22 03:02:03 2013
@ pts/6:bde@ref10-i386:~/s> gdb /bin/cat
@ GNU gdb 6.1.1 [FreeBSD]
@ Copyright 2004 Free Software Foundation, Inc.
@ GDB is free software, covered by the GNU General Public License, and you are
@ welcome to change it and/or distribute copies of it under certain conditions.
@ Type "show copying" to see the conditions.
@ There is absolutely no warranty for GDB.  Type "show warranty" for details.
@ This GDB was configured as "i386-marcel-freebsd"...(no debugging symbols found)...
@ (gdb) r
@ Starting program: /bin/cat 
@ (no debugging symbols found)...(no debugging symbols found)...^Z
@ Program received signal SIGTSTP, Stopped (user).
@ 0x2818ca65 in read () from /lib/libc.so.7
@ (gdb) p $xmm0
@ $1 = {v4_float = {0, 0, 0, 0}, v2_double = {0, 0}, 
@   v16_int8 = '\0' <repeats 15 times>, v8_int16 = {0, 0, 0, 0, 0, 0, 0, 0}, 
@   v4_int32 = {0, 0, 0, 0}, v2_int64 = {0, 0}, 
@   uint128 = 0x00000000000000000000000000000000}

gdb displays all the types on i386.  It is bizarre that the xmm display
works better on the arch where xmm is less used.

@ (gdb) The program is running.  Exit anyway? (y or n) y
@ pts/6:bde@ref10-i386:~/s> exit
@ 
@ Script done on Wed May 22 03:02:19 2013

gdb displays all the types even on i386 running FreeBSD-~5.2, where ptrace
stuff for xmm and i387 registers is different and more deficient than now.
I think tags translation for i387 registers is still missing in the kernel.
However, for some versions of the kernel on some arches, gdb never fetches
the i387 registers directly from the kernel, but fetches the xmm registers
and does its own translation of everything including tags to i387.  The
poor display might be caused by ifdef tangles related to this.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130522122836.H1038>