From 887503049333627249f06ae0c7c44d66dc62ffc6 Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Tue, 29 Mar 2005 20:37:19 +0000 Subject: [PATCH] * c-valprint.c (c_value_print): Fix up some formatting. Use check_typedef. testsuite/ * gdb.base/ptr-typedef.exp, gdb.base/ptr-typedef.c: New files. --- gdb/ChangeLog | 5 +++ gdb/c-valprint.c | 25 ++++++++------- gdb/testsuite/ChangeLog | 4 +++ gdb/testsuite/gdb.base/ptr-typedef.c | 44 ++++++++++++++++++++++++++ gdb/testsuite/gdb.base/ptr-typedef.exp | 41 ++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 gdb/testsuite/gdb.base/ptr-typedef.c create mode 100644 gdb/testsuite/gdb.base/ptr-typedef.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 75b86ac7da6..c2de1fd9b6a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2005-03-29 Daniel Jacobowitz + + * c-valprint.c (c_value_print): Fix up some formatting. Use + check_typedef. + 2005-03-29 Daniel Jacobowitz * arm-linux-nat.c (store_register, store_regs): Handle diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 0e06ca6f555..0a4255eebd5 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -491,8 +491,7 @@ int c_value_print (struct value *val, struct ui_file *stream, int format, enum val_prettyprint pretty) { - struct type *type = value_type (val); - struct type *real_type; + struct type *type, *real_type; int full, top, using_enc; /* If it is a pointer, indicate what it points to. @@ -501,15 +500,18 @@ c_value_print (struct value *val, struct ui_file *stream, int format, C++: if it is a member pointer, we will take care of that when we print it. */ - if (TYPE_CODE (type) == TYPE_CODE_PTR || - TYPE_CODE (type) == TYPE_CODE_REF) + + type = check_typedef (value_type (val)); + + if (TYPE_CODE (type) == TYPE_CODE_PTR + || TYPE_CODE (type) == TYPE_CODE_REF) { /* Hack: remove (char *) for char strings. Their type is indicated by the quoted string anyway. */ - if (TYPE_CODE (type) == TYPE_CODE_PTR && - TYPE_NAME (type) == NULL && - TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL && - strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0) + if (TYPE_CODE (type) == TYPE_CODE_PTR + && TYPE_NAME (type) == NULL + && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL + && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0) { /* Print nothing */ } @@ -556,11 +558,12 @@ c_value_print (struct value *val, struct ui_file *stream, int format, { /* normal case */ fprintf_filtered (stream, "("); - type_print (type, "", stream, -1); + type_print (value_type (val), "", stream, -1); fprintf_filtered (stream, ") "); } } - if (objectprint && (TYPE_CODE (value_type (val)) == TYPE_CODE_CLASS)) + + if (objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS)) { /* Attempt to determine real type of object */ real_type = value_rtti_type (val, &full, &top, &using_enc); @@ -578,7 +581,7 @@ c_value_print (struct value *val, struct ui_file *stream, int format, /* Note: When we look up RTTI entries, we don't get any information on const or volatile attributes */ } - else if (type != value_enclosing_type (val)) + else if (type != check_typedef (value_enclosing_type (val))) { /* No RTTI information, so let's do our best */ fprintf_filtered (stream, "(%s ?) ", diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 9d3f4690423..0e8dfdf2a34 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-03-29 Daniel Jacobowitz + + * gdb.base/ptr-typedef.exp, gdb.base/ptr-typedef.c: New files. + 2005-03-27 Andreas Schwab * gdb.base/bigcore.c (main): Add missing mode argument in open diff --git a/gdb/testsuite/gdb.base/ptr-typedef.c b/gdb/testsuite/gdb.base/ptr-typedef.c new file mode 100644 index 00000000000..6cf2fd43c4f --- /dev/null +++ b/gdb/testsuite/gdb.base/ptr-typedef.c @@ -0,0 +1,44 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2005 + Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + +struct foo { + int x; +}; + +typedef struct foo *foz; + +struct foo *foo_ptr; +foz foz_ptr; + +int +marker1 (void) +{ + return foo_ptr == foz_ptr; +} + +int +main (void) +{ + struct foo the_foo; + foo_ptr = &the_foo; + foz_ptr = &the_foo; + + return marker1 (); +} diff --git a/gdb/testsuite/gdb.base/ptr-typedef.exp b/gdb/testsuite/gdb.base/ptr-typedef.exp new file mode 100644 index 00000000000..c91c23c6fe8 --- /dev/null +++ b/gdb/testsuite/gdb.base/ptr-typedef.exp @@ -0,0 +1,41 @@ +# Copyright 2005 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +if $tracelevel then { + strace $tracelevel +} + +set testfile ptr-typedef +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto marker1] { + untested "Couldn't run to marker1" +} + +gdb_test "print foo_ptr" "\\\$$decimal = \\\(struct foo \\\*\\\) $hex" +gdb_test "print foz_ptr" "\\\$$decimal = \\\(foz\\\) $hex" -- 2.30.2