public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* embedded_offset missing in c-valprint.c
@ 2010-07-05  1:52 Emmanuel Thomé
  2010-07-14 14:12 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Emmanuel Thomé @ 2010-07-05  1:52 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 905 bytes --]


Hi,

Could you please consider the attached patch to c-valprint.c ?

Unless I am mistaken (which is possible), the function c_val_print does
not correctly track the inferior addresses of struct members. This
affects pretty-printing via python scripting, which may require this
address.

I actually tested the version from the ubuntu package 7.1-1ubuntu2, but
the defect seems also present in the git head version.

Here is an example of a session transcript illustrating the misbehaviour/

$ gdb v
GNU gdb (GDB) 7.1-ubuntu
[...]
(gdb) b 19
Breakpoint 1 at 0x4004fb: file v.c, line 19.
(gdb) r
Starting program: /home/thome/Curves/CM/complex_analytic/regis/v 

Breakpoint 1, main () at v.c:19
19          return 0;
(gdb) p x
$1 = {{l = 42, a = {{{x = 0}}, {{x = 1}}}}}
(gdb) source u.py
(gdb) p x
$2 = {{l = 42, a = {42, 0}}}

v.c and u.py are attached (as well as the patch itself of course).

Best,

E.

[-- Attachment #2: v.c --]
[-- Type: text/x-csrc, Size: 221 bytes --]


struct bar {
    int x;
};

typedef struct bar xbar[1];

struct foo {
    int l;
    xbar a[2];
};

int main()
{
    struct foo x[1];
    x->l = 42;
    for(int i = 0 ; i < 2 ; i++)
        x->a[i]->x=i;
    return 0;
}

[-- Attachment #3: u.py --]
[-- Type: text/x-python, Size: 560 bytes --]

import gdb
from gmpy import mpz,mpf

class bar_printer:
    def __init__(self, val):
        self.val = val
    def to_string(self):
        X = self.val
        # There's apparently a bug in array member of structs. Their
        # starting address seems to be constantly equal to the starting
        # address of the struct itself...
        return str(int(X['x']))


def make_my_printer_objects(val):
    t=str(val.type)
    if t == 'struct bar [1]':
        return bar_printer(val[0])
    return None

gdb.pretty_printers.append(make_my_printer_objects)


[-- Attachment #4: c-valprint-patch --]
[-- Type: text/plain, Size: 415 bytes --]

--- c-valprint.c	2010-07-04 23:06:32.000000000 +0200
+++ /tmp/c-valprint.c	2010-07-05 03:29:39.000000000 +0200
@@ -216,7 +216,7 @@
 		{
 		  i = 0;
 		}
-	      val_print_array_elements (type, valaddr + embedded_offset, address, stream,
+	      val_print_array_elements (type, valaddr + embedded_offset, address + embedded_offset, stream,
 					recurse, options, i);
 	      fprintf_filtered (stream, "}");
 	    }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: embedded_offset missing in c-valprint.c
  2010-07-05  1:52 embedded_offset missing in c-valprint.c Emmanuel Thomé
@ 2010-07-14 14:12 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2010-07-14 14:12 UTC (permalink / raw)
  To: Emmanuel Thomé; +Cc: gdb-patches

>>>>> "Emmanuel" == Emmanuel Thomé <Emmanuel.Thome@gmail.com> writes:

Emmanuel> Could you please consider the attached patch to c-valprint.c ?

Looks good to me.

I updated the existing pretty-printer test case with one based on the
info you provided.

Your patch is small enough not to need any paperwork, but if you plan to
do more work on gdb, I suggest getting started with that process.  If
you want I can send you the form.

Your patch was also missing a ChangeLog entry.

I'm checking in the appended to the trunk and the 7.2 branch.
Thanks!

I built and regtested this on x86-64 (compile farm).

Tom

2010-07-13  Emmanuel Thomé  <Emmanuel.Thome@gmail.com>

	* c-valprint.c (c_val_print): Add embedded_offset to address in
	call to val_print_array_elements.

2010-07-13  Tom Tromey  <tromey@redhat.com>

	* gdb.python/py-prettyprint.c (struct arraystruct): New struct.
	(main): Use it.
	* gdb.python/py-prettyprint.exp (run_lang_tests): Add test.

diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 4e5a95f..f0895a4 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -222,7 +222,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 		{
 		  i = 0;
 		}
-	      val_print_array_elements (type, valaddr + embedded_offset, address, stream,
+	      val_print_array_elements (type, valaddr + embedded_offset,
+					address + embedded_offset, stream,
 					recurse, original_value, options, i);
 	      fprintf_filtered (stream, "}");
 	    }
diff --git a/gdb/testsuite/gdb.python/py-prettyprint.c b/gdb/testsuite/gdb.python/py-prettyprint.c
index f461bb1..66a9014 100644
--- a/gdb/testsuite/gdb.python/py-prettyprint.c
+++ b/gdb/testsuite/gdb.python/py-prettyprint.c
@@ -29,6 +29,12 @@ struct ss
   struct s b;
 };
 
+struct arraystruct
+{
+  int y;
+  struct s x[2];
+};
+
 struct ns {
   const char *null_str;
   int length;
@@ -199,6 +205,7 @@ main ()
 {
   struct ss  ss;
   struct ss  ssa[2];
+  struct arraystruct arraystruct;
   string x = make_string ("this is x");
   zzz_type c = make_container ("container");
   zzz_type c2 = make_container ("container2");
@@ -214,6 +221,10 @@ main ()
   init_ss(ssa+1, 5, 6);
   memset (&nullstr, 0, sizeof nullstr);
 
+  arraystruct.y = 7;
+  init_s (&arraystruct.x[0], 23);
+  init_s (&arraystruct.x[1], 24);
+
   struct ns  ns;
   ns.null_str = "embedded\0null\0string";
   ns.length = 20;
diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
index f435fb7..3b2aadd 100644
--- a/gdb/testsuite/gdb.python/py-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
@@ -76,6 +76,8 @@ proc run_lang_tests {lang} {
     gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>"
     gdb_test "print ssa" " = {a=< a=<3> b=<$hex>> b=< a=<4> b=<$hex>>, a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>}"
     
+    gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = { a=<23> b=<$hex>,  a=<24> b=<$hex>} *$nl *}"
+
     if {$lang == "c++"} {
 	gdb_test "print cps" "=  a=<8> b=<$hex>"
 	gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s =  a=<10> b=<$hex>$nl}"

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-14 14:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-05  1:52 embedded_offset missing in c-valprint.c Emmanuel Thomé
2010-07-14 14:12 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).