Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sources.redhat.com
Subject: RFC: Print the type of a C value in one more case
Date: Sun, 06 Mar 2005 17:45:00 -0000	[thread overview]
Message-ID: <20050306174529.GA20867@nevyn.them.org> (raw)

This is something that constantly bugs me when debugging GCC.  GCC has
typedefs for "tree" and "rtx" which are both pointers to structs.  When
you print either, you just get "$1 = 0xbf000100" without any indication of
the type of the variable; but normally GDB prints types for pointers.
This comes from a missing check_typedef in c_value_print.

There were a couple of ways to fix it; I chose to print the typedef rather
than what the typedef pointed to.  The only difference in the testsuite is
in one objc test, which perfectly illustrates the desired change:

-$1 = 0x0
+$1 = (id) 0x0

Any comments?

-- 
Daniel Jacobowitz
CodeSourcery, LLC

2005-03-06  Daniel Jacobowitz  <dan@codesourcery.com>

	* c-valprint.c (c_value_print): Fix up some formatting.  Use
	check_typedef.

2005-03-06  Daniel Jacobowitz  <dan@codesourcery.com>

	* gdb.base/ptr-typedef.exp, gdb.base/ptr-typedef.c: New files.

Index: c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.35
diff -u -p -r1.35 c-valprint.c
--- c-valprint.c	28 Feb 2005 17:00:48 -0000	1.35
+++ c-valprint.c	6 Mar 2005 17:42:16 -0000
@@ -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
 
      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
 	{
 	  /* 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
           /* 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 ?) ",
--- /dev/null	1969-12-31 19:00:00.000000000 -0500
+++ testsuite/gdb.base/ptr-typedef.exp	2005-03-06 12:41:52.000000000 -0500
@@ -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"
--- /dev/null	1969-12-31 19:00:00.000000000 -0500
+++ testsuite/gdb.base/ptr-typedef.c	2005-03-06 12:35:44.000000000 -0500
@@ -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 ();
+}


             reply	other threads:[~2005-03-06 17:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-06 17:45 Daniel Jacobowitz [this message]
2005-03-10 22:14 ` Kevin Buettner
2005-03-07 20:57 Paul Schlie
2005-03-29  5:13 ` Paul Schlie
2005-03-29 20:37   ` Daniel Jacobowitz

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=20050306174529.GA20867@nevyn.them.org \
    --to=drow@false.org \
    --cc=gdb-patches@sources.redhat.com \
    /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