From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31687 invoked by alias); 18 Feb 2011 11:08:49 -0000 Received: (qmail 31678 invoked by uid 22791); 18 Feb 2011 11:08:47 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT,TW_CP X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.156) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Feb 2011 11:08:42 +0000 Received: from md2.u-strasbg.fr (md2.u-strasbg.fr [IPv6:2001:660:2402::187]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id p1IB8cIW004721 for ; Fri, 18 Feb 2011 12:08:38 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms1.u-strasbg.fr [130.79.204.10]) by md2.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p1IB8bNJ039932 for ; Fri, 18 Feb 2011 12:08:38 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p1IB8aWv056099 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Fri, 18 Feb 2011 12:08:37 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: Subject: [RFA] Fix display of array of unspecified length inside structures Date: Fri, 18 Feb 2011 11:34:00 -0000 Message-ID: <00ac01cbcf5c$31f5bc00$95e13400$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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: 2011-02/txt/msg00452.txt.bz2 The following code shows a problem in current display of char arrays of zero length, the embedded_offset parameter in c_val_print gets forgotten, resulting in wrong display. typedef struct test_struct { int x,y; char name[0]; } test_t; test_t * test; #define TESTNAME "dummy test" int main () { test = alloca (sizeof (test_t) + sizeof (TESTNAME) + 1); test->x = 7; test->y = -6; strcpy (test->name, TESTNAME); return 0; } I had to debug gdb using 'set print infrun 1' to understand that the value of the name filed was read at the address of test.x, rather than test.name. The patch below fixes that problem. Tested on x86_64-unknown-linux-gnu no regression found. c_val_print and p_val_print functions are the two only occurrences of this print_unpacked_pointer 'goto', but I am not sure if this problem can also arise for other languages. When you look at the source, you will see that just before the print_unpacked_pointer label, addr is calculated with the use of embedded_offset. Pierre Muller GDB pascal language maintainer PS: It could be wise to add some test in the testsuite for this, but I have no idea where I could insert this kind of test, any ideas? PS2: It is probably impossible to make such a test without alloca or some other memory allocation function, no? Are there any system restriction for this? 2011-02-18 Pierre Muller * c-valprint.c (c_val_print): Add embedded_offset to address for arrays of unspecified length. * p-valprint.c (pascal_val_print): Likewise. Index: src/gdb/c-valprint.c =================================================================== RCS file: /cvs/src/src/gdb/c-valprint.c,v retrieving revision 1.85 diff -u -p -r1.85 c-valprint.c --- src/gdb/c-valprint.c 14 Feb 2011 11:33:24 -0000 1.85 +++ src/gdb/c-valprint.c 18 Feb 2011 10:27:41 -0000 @@ -240,7 +240,7 @@ c_val_print (struct type *type, const gd } /* Array of unspecified length: treat like pointer to first elt. */ - addr = address; + addr = address + embedded_offset; goto print_unpacked_pointer; case TYPE_CODE_MEMBERPTR: Index: src/gdb/p-valprint.c =================================================================== RCS file: /cvs/src/src/gdb/p-valprint.c,v retrieving revision 1.87 diff -u -p -r1.87 p-valprint.c --- src/gdb/p-valprint.c 14 Feb 2011 11:35:45 -0000 1.87 +++ src/gdb/p-valprint.c 18 Feb 2011 10:27:41 -0000 @@ -128,7 +128,7 @@ pascal_val_print (struct type *type, con break; } /* Array of unspecified length: treat like pointer to first elt. */ - addr = address; + addr = address + embedded_offset; goto print_unpacked_pointer; case TYPE_CODE_PTR: