From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1180 invoked by alias); 18 Dec 2009 12:41:41 -0000 Received: (qmail 1167 invoked by uid 22791); 18 Dec 2009 12:41:39 -0000 X-SWARE-Spam-Status: No, hits=0.2 required=5.0 tests=AWL,BAYES_00,KAM_STOCKTIP,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Dec 2009 12:41:35 +0000 Received: (qmail 15770 invoked from network); 18 Dec 2009 12:41:33 -0000 Received: from unknown (HELO wind.localnet) (vladimir@127.0.0.2) by mail.codesourcery.com with ESMTPA; 18 Dec 2009 12:41:33 -0000 From: Vladimir Prus To: gdb-patches@sourceware.org Subject: RFA: unbreak typedefed bitfield Date: Fri, 18 Dec 2009 12:41:00 -0000 User-Agent: KMail/1.12.2 (Linux/2.6.31-14-generic-pae; KDE/4.3.2; i686; ; ) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <200912181541.30891.vladimir@codesourcery.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-12/txt/msg00250.txt.bz2 GDB presently crashes on any attempt to get a value of a bitfield that has typedefed type. The bugzilla report is here: http://sourceware.org/bugzilla/show_bug.cgi?id=10884 An easier reproducer is this program: typedef unsigned int uint; struct Data { int alloc; int begin; int end; uint sharable : 1; }; int main() { Data d = {1, 2, 3, 1}; return 0; } and this session: ~"Breakpoint 1, main () at div.cpp:13\n" ~"13\t Data d = {1, 2, 3, 1};\n" *stopped,frame={addr="0x0804849a",func="main",args=[],file="div.cpp",fullname="/home/ghost/Build/gdb-git/gdb/div.cpp",line="13"},thread-id="1",stopped-threads="all",core="1" (gdb) n &"n\n" &"During symbol reading, incomplete CFI data; unspecified registers (e.g., eax) at 0x8048497.\n" ^running *running,thread-id="1" (gdb) ~"14\t return 0;\n" *stopped,frame={addr="0x080484b9",func="main",args=[],file="div.cpp",fullname="/home/ghost/Build/gdb-git/gdb/div.cpp",line="14"},thread-id="1",stopped-threads="all",core="1" (gdb) -var-create V * d ^done,name="V",numchild="1",value="{...}",type="Data",thread-id="1",has_more="0" (gdb) -var-list-children V ^done,numchild="1",children=[child={name="V.public",exp="public",numchild="4",thread-id="1"}],has_more="0" (gdb) -var-list-children --all-values V.public Program received signal SIGFPE, Arithmetic exception. 0x0813add3 in value_primitive_field (arg1=0x8644840, offset=0, fieldno=3, arg_type=0x85a9d7c) at /home/ghost/Work/CodeSourcery/Projects/egdb/gdb-git/gdb/value.c:1892 1892 if ((bitpos % container_bitsize) + v->bitsize <= container_bitsize And here's a trivial patch to fix this problem. I would claim this clearly indicates a design bug in GDB type mechanism -- and it bites us repeatedly, but I'm not ready to propose a specific way to fix it, yet. OK to commit? - Volodya --- a/gdb/value.c +++ b/gdb/value.c @@ -1873,6 +1873,7 @@ value_primitive_field (struct value *arg1, int offset, CHECK_TYPEDEF (arg_type); type = TYPE_FIELD_TYPE (arg_type, fieldno); + check_typedef (type); /* Handle packed fields */