From owner-freebsd-numerics@FreeBSD.ORG Wed May 22 03:16:27 2013 Return-Path: Delivered-To: numerics@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C1E1AA25; Wed, 22 May 2013 03:16:27 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail106.syd.optusnet.com.au (mail106.syd.optusnet.com.au [211.29.132.42]) by mx1.freebsd.org (Postfix) with ESMTP id 6A0CA2A7; Wed, 22 May 2013 03:16:24 +0000 (UTC) Received: from c122-106-156-23.carlnfd1.nsw.optusnet.com.au (c122-106-156-23.carlnfd1.nsw.optusnet.com.au [122.106.156.23]) by mail106.syd.optusnet.com.au (Postfix) with ESMTPS id DF9253C123D; Wed, 22 May 2013 13:16:15 +1000 (EST) Date: Wed, 22 May 2013 13:16:14 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: numerics@freebsd.org Subject: gdb displays xmm registers poorly on amd64, but works on i386 Message-ID: <20130522122836.H1038@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.0 cv=e4Ne0tV/ c=1 sm=1 a=DCffsqWhnkgA:10 a=kj9zAlcOel0A:10 a=PO7r1zJSAAAA:8 a=JzwRw_2MAAAA:8 a=Gn94XqwyB2YA:10 a=UNQmailsU6rZeZswHywA:9 a=CjuIK1q_8ugA:10 a=ebeQFi2P/qHVC0Yw9JDJ4g==:117 Cc: kib@freebsd.org X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 May 2013 03:16:27 -0000 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 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' , 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