Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: <gdb-patches@sourceware.org>
Subject: [RFA] Fix display of array of unspecified length inside structures
Date: Fri, 18 Feb 2011 11:34:00 -0000	[thread overview]
Message-ID: <00ac01cbcf5c$31f5bc00$95e13400$@muller@ics-cnrs.unistra.fr> (raw)

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  <muller@ics.u-strasbg.fr>

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



             reply	other threads:[~2011-02-18 11:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18 11:34 Pierre Muller [this message]
2011-02-18 11:59 ` Pedro Alves
2011-02-18 15:01   ` Pierre Muller
2011-02-18 15:38     ` Pedro Alves
2011-02-18 17:39       ` Pierre Muller
2011-02-18 17:41         ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='00ac01cbcf5c$31f5bc00$95e13400$@muller@ics-cnrs.unistra.fr' \
    --to=pierre.muller@ics-cnrs.unistra.fr \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox