This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix ptype problem printing typedefs defined differently in different compilation units


On Monday 23 January 2006 15:45, Jim Blandy wrote:
> On 1/23/06, Fred Fish <fnf@specifix.com> wrote:
> > This is why I think the correct and complete solution is to allow the
> > user to directly specify the context.
> 
> Sure.  That would entail extending the 'type_exp' non-terminal to have
> a FILENAME COLONCOLON TYPE production.  Sounds like the right thing.

The below patch seems to fix ptype and whatis to allow the
'file'::typename syntax, without breaking anything else and also
simplifying ptype_command.

Comments?

-Fred

================================================================================

Gdb ChangeLog entry:

	2006-02-10  Fred Fish  <fnf@specifix.com>

	* typeprint.c (whatis_exp): Initialize type to NULL.  Call
	ptype_eval for special cases, before evaluate_type.  Call
	value_type only if we haven't found a type already.
	(ptype_eval): Handle OP_VAR_VALUE as a special case, in addition
	to OP_TYPE.  This handles 'file'::typename expressions.
	(ptype_command): Replace entire function body with call to
	whatis_exp.
	

Testsuite ChangeLog entry:

	2006-02-10  Fred Fish  <fnf@specifix.com>

	* gdb.base/ptype.c: Add afoo for typedef checks.
	* gdb.base/ptype1.c: Add afoo for typedef checks.
	* gdb.base/whatis.c: Add typedef foo and var afoo.

	* gdb.base/ptype.exp: Add tests for 'file'::symbol
	and 'file'::typename syntax.
	* gdb.base/whatis.exp: Ditto.
 

Index: typeprint.c
===================================================================
RCS file: /cvsroots/latest/src/gdb/gdb/typeprint.c,v
retrieving revision 1.1.1.2
diff -c -p -r1.1.1.2 typeprint.c
*** typeprint.c	30 Dec 2005 18:53:06 -0000	1.1.1.2
--- typeprint.c	10 Feb 2006 23:20:45 -0000
*************** whatis_exp (char *exp, int show)
*** 119,125 ****
    struct value *val;
    struct cleanup *old_chain = NULL;
    struct type *real_type = NULL;
!   struct type *type;
    int full = 0;
    int top = -1;
    int using_enc = 0;
--- 119,125 ----
    struct value *val;
    struct cleanup *old_chain = NULL;
    struct type *real_type = NULL;
!   struct type *type = NULL;
    int full = 0;
    int top = -1;
    int using_enc = 0;
*************** whatis_exp (char *exp, int show)
*** 128,139 ****
      {
        expr = parse_expression (exp);
        old_chain = make_cleanup (free_current_contents, &expr);
!       val = evaluate_type (expr);
      }
    else
      val = access_value_history (0);
  
!   type = value_type (val);
  
    if (objectprint)
      {
--- 128,142 ----
      {
        expr = parse_expression (exp);
        old_chain = make_cleanup (free_current_contents, &expr);
!       type = ptype_eval (expr);
!       if (type == NULL)
! 	val = evaluate_type (expr);
      }
    else
      val = access_value_history (0);
  
!   if (type == NULL)
!     type = value_type (val);
  
    if (objectprint)
      {
*************** ptype_eval (struct expression *exp)
*** 191,196 ****
--- 194,203 ----
      {
        return (exp->elts[1].type);
      }
+   else if (exp->elts[0].opcode == OP_VAR_VALUE)
+     {
+       return (SYMBOL_TYPE (exp->elts[2].symbol));
+     }
    else
      {
        return (NULL);
*************** ptype_eval (struct expression *exp)
*** 202,236 ****
  static void
  ptype_command (char *typename, int from_tty)
  {
!   struct type *type;
!   struct expression *expr;
!   struct cleanup *old_chain;
! 
!   if (typename == NULL)
!     {
!       /* Print type of last thing in value history. */
!       whatis_exp (typename, 1);
!     }
!   else
!     {
!       expr = parse_expression (typename);
!       old_chain = make_cleanup (free_current_contents, &expr);
!       type = ptype_eval (expr);
!       if (type != NULL)
! 	{
! 	  /* User did "ptype <typename>" */
! 	  printf_filtered ("type = ");
! 	  type_print (type, "", gdb_stdout, 1);
! 	  printf_filtered ("\n");
! 	  do_cleanups (old_chain);
! 	}
!       else
! 	{
! 	  /* User did "ptype <symbolname>" */
! 	  do_cleanups (old_chain);
! 	  whatis_exp (typename, 1);
! 	}
!     }
  }
  
  /* Print integral scalar data VAL, of type TYPE, onto stdio stream STREAM.
--- 209,215 ----
  static void
  ptype_command (char *typename, int from_tty)
  {
!   whatis_exp (typename, 1);
  }
  
  /* Print integral scalar data VAL, of type TYPE, onto stdio stream STREAM.
Index: testsuite/gdb.base/ptype.c
===================================================================
RCS file: /cvsroots/latest/src/gdb/gdb/testsuite/gdb.base/ptype.c,v
retrieving revision 1.1.1.2
diff -c -p -r1.1.1.2 ptype.c
*** testsuite/gdb.base/ptype.c	8 Jan 2006 20:37:18 -0000	1.1.1.2
--- testsuite/gdb.base/ptype.c	10 Feb 2006 21:38:14 -0000
*************** func_type v_func_type;
*** 260,265 ****
--- 260,266 ----
  /***********/
  
  typedef int foo;
+ static foo afoo = 2;
  
  foo intfoo (afoo)
  {
Index: testsuite/gdb.base/ptype.exp
===================================================================
RCS file: /cvsroots/latest/src/gdb/gdb/testsuite/gdb.base/ptype.exp,v
retrieving revision 1.1.1.2
diff -c -p -r1.1.1.2 ptype.exp
*** testsuite/gdb.base/ptype.exp	8 Jan 2006 20:37:19 -0000	1.1.1.2
--- testsuite/gdb.base/ptype.exp	10 Feb 2006 21:41:38 -0000
*************** gdb_test "list intfoo" ""
*** 593,598 ****
--- 593,603 ----
  gdb_test "ptype foo" "type = int" "ptype foo typedef after second list of intfoo"
  gdb_test "list charfoo" ""
  gdb_test "ptype foo" "type = char" "ptype foo typedef after second list of charfoo"
+ # Test the 'file'::exp syntax for variables and types
+ gdb_test "ptype 'ptype.c'::afoo" "type = int" "ptype 'file'::symbol"
+ gdb_test "ptype 'ptype.c'::foo" "type = int" "ptype 'file'::typename"
+ gdb_test "ptype 'ptype1.c'::afoo" "type = char" "ptype 'file'::symbol"
+ gdb_test "ptype 'ptype1.c'::foo" "type = char" "ptype 'file'::typename"
  
  # Test printing type of string constants and array constants, but
  # requires a running process.  These call malloc, and can take a long
Index: testsuite/gdb.base/ptype1.c
===================================================================
RCS file: /cvsroots/latest/src/gdb/gdb/testsuite/gdb.base/ptype1.c,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 ptype1.c
*** testsuite/gdb.base/ptype1.c	8 Jan 2006 20:37:18 -0000	1.1.1.1
--- testsuite/gdb.base/ptype1.c	10 Feb 2006 21:37:55 -0000
***************
*** 1,4 ****
--- 1,5 ----
  typedef char foo;
+ static foo afoo = 1;
  
  foo charfoo (afoo)
  {
Index: testsuite/gdb.base/whatis.c
===================================================================
RCS file: /cvsroots/latest/src/gdb/gdb/testsuite/gdb.base/whatis.c,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 whatis.c
*** testsuite/gdb.base/whatis.c	8 Oct 2005 19:36:19 -0000	1.1.1.1
--- testsuite/gdb.base/whatis.c	10 Feb 2006 21:35:00 -0000
*************** unsigned long	v_unsigned_long;
*** 46,51 ****
--- 46,54 ----
  float		v_float;
  double		v_double;
  
+ typedef int foo;
+ static foo afoo = 1;
+ 
  /*
   *	Now some derived types, which are arrays, functions-returning,
   *	pointers, structures, unions, and enumerations.
Index: testsuite/gdb.base/whatis.exp
===================================================================
RCS file: /cvsroots/latest/src/gdb/gdb/testsuite/gdb.base/whatis.exp,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 whatis.exp
*** testsuite/gdb.base/whatis.exp	8 Oct 2005 19:36:19 -0000	1.1.1.1
--- testsuite/gdb.base/whatis.exp	10 Feb 2006 21:35:51 -0000
*************** gdb_test "whatis nested_su.inner_union_i
*** 402,404 ****
--- 402,414 ----
  gdb_test "whatis nested_su.inner_union_instance.inner_union_int" \
      "type = int" \
      "whatis inner union member"
+ 
+ # Test the 'file'::exp syntax for variables and types
+ 
+ gdb_test "whatis 'whatis.c'::afoo" \
+     "type = foo" \
+     "whatis 'file'::symbol"
+ 
+ gdb_test "whatis 'whatis.c'::foo" \
+     "type = int" \
+     "whatis 'file'::typename"



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]