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

Fred Fish fnf@specifix.com
Mon Feb 20 15:47:00 GMT 2006


On Thursday 16 February 2006 19:16, Fred Fish wrote:
> (2) Make ptype and whatis handle printing types specified in a given
> context using 'file'::type.  I have a fix that involves a fairly
> minor change to the parser and makes the patch you are commenting on
> obsolete.

OK, here is a patch. I'm not entirely happy with it but I'm not familiar
enough with parser generator input and output to see any obviously 
better way.

The basic problem is that it's easy to handle 'file'::variable.  The
existing code for this is:

  block :  block COLONCOLON name
                  { struct symbol *tem
                      = lookup_symbol (copy_name ($3), $1,
                                        VAR_DOMAIN, (int *) NULL,
                                        (struct symtab **) NULL);

What happens is that "name" is handled by a lookup_symbol call with
no context block specified, and then the above calls lookup_symbol
again with the context specified by $1 (block).

But for types, the parser generator input is:

  type    :       ptype
          |       block COLONCOLON ptype
                        { $$ = $3; }

Setting expression_context_block for the duration of parsing the
input expression was the only obvious way I saw to work around
not being able to call lookup_symbol again, with the right block.

I tried setting expression_context_block on the lexer code when it
returned BLOCKNAME or FILENAME and that broke some other stuff.

Any suggestions on better ways to handle this would be great.

-Fred

GDB ChangeLog:

 	2006-02-19  Fred Fish  <fnf@specifix.com>
	* c-exp.y (type): Recognize "block COLONCOLON ptype" as a type.
	(block): Set expression_context_block for lookup_symbol to use.

Testsuite ChangeLog:

	2006-02-19  Fred Fish  <fnf@specifix.com>
	* gdb.base/ptype.c (afoo): Add variable using foo typedef.
	* gdb.base/ptype1.c (afoo): Ditto.

	* gdb.base/ptype.exp: Add tests using 'file':: prefix
	to specify scope for variables and types.  Add tests for
	printing type of last value history entry.
	* gdb.base/whatis.exp: Ditto.
	
Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.33
diff -c -p -r1.33 c-exp.y
*** c-exp.y	14 Feb 2006 19:05:40 -0000	1.33
--- c-exp.y	20 Feb 2006 14:35:42 -0000
*************** exp     :       FALSEKEYWORD   
*** 556,562 ****
  block	:	BLOCKNAME
  			{
  			  if ($1.sym)
! 			    $$ = SYMBOL_BLOCK_VALUE ($1.sym);
  			  else
  			    error ("No file or function \"%s\".",
  				   copy_name ($1.stoken));
--- 556,565 ----
  block	:	BLOCKNAME
  			{
  			  if ($1.sym)
! 			    {
! 			      $$ = SYMBOL_BLOCK_VALUE ($1.sym);
! 			      expression_context_block = $$;
! 			    }
  			  else
  			    error ("No file or function \"%s\".",
  				   copy_name ($1.stoken));
*************** block	:	BLOCKNAME
*** 564,569 ****
--- 567,573 ----
  	|	FILENAME
  			{
  			  $$ = $1;
+ 			  expression_context_block = $$;
  			}
  	;
  
*************** block	:	block COLONCOLON name
*** 575,581 ****
  			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  			    error ("No function \"%s\" in specified context.",
  				   copy_name ($3));
! 			  $$ = SYMBOL_BLOCK_VALUE (tem); }
  	;
  
  variable:	block COLONCOLON name
--- 579,586 ----
  			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  			    error ("No function \"%s\" in specified context.",
  				   copy_name ($3));
! 			  $$ = SYMBOL_BLOCK_VALUE (tem);
! 			  expression_context_block = $$; }
  	;
  
  variable:	block COLONCOLON name
*************** func_mod:	'(' ')'
*** 799,804 ****
--- 804,811 ----
     is a pointer to member type.  Stroustrup loses again!  */
  
  type	:	ptype
+ 	|	block COLONCOLON ptype
+ 			{ $$ = $3; }
  	|	typebase COLONCOLON '*'
  			{ $$ = lookup_member_type (builtin_type (current_gdbarch)->builtin_int, $1); }
  	;
Index: testsuite/gdb.base/ptype.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/ptype.c,v
retrieving revision 1.4
diff -c -p -r1.4 ptype.c
*** testsuite/gdb.base/ptype.c	4 Jan 2006 14:46:17 -0000	1.4
--- testsuite/gdb.base/ptype.c	20 Feb 2006 14:45:25 -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: /cvs/src/src/gdb/testsuite/gdb.base/ptype.exp,v
retrieving revision 1.8
diff -c -p -r1.8 ptype.exp
*** testsuite/gdb.base/ptype.exp	4 Jan 2006 14:46:17 -0000	1.8
--- testsuite/gdb.base/ptype.exp	20 Feb 2006 14:45:49 -0000
*************** gdb_test "ptype foo" "type = int" "ptype
*** 594,599 ****
--- 594,613 ----
  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 value history type
+ 
+ gdb_test "p (long)1" ""
+ gdb_test "ptype" "type = long" "ptype long value from value history"
+ gdb_test "p (short)1" ""
+ gdb_test "ptype" "type = short" "ptype short value from value history"
+ 
  # Test printing type of string constants and array constants, but
  # requires a running process.  These call malloc, and can take a long
  # time to execute over a slow serial link, so increase the timeout.
Index: testsuite/gdb.base/ptype1.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/ptype1.c,v
retrieving revision 1.1
diff -c -p -r1.1 ptype1.c
*** testsuite/gdb.base/ptype1.c	4 Jan 2006 14:46:17 -0000	1.1
--- testsuite/gdb.base/ptype1.c	20 Feb 2006 14:45:49 -0000
***************
*** 1,4 ****
--- 1,5 ----
  typedef char foo;
+ static foo afoo = 1;
  
  foo charfoo (afoo)
  {
Index: testsuite/gdb.base/whatis.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/whatis.exp,v
retrieving revision 1.7
diff -c -p -r1.7 whatis.exp
*** testsuite/gdb.base/whatis.exp	18 Feb 2006 20:01:17 -0000	1.7
--- testsuite/gdb.base/whatis.exp	20 Feb 2006 14:45:49 -0000
*************** gdb_test "whatis v_struct1" \
*** 273,300 ****
--- 273,324 ----
      "type = struct t_struct" \
      "whatis named structure"
  
+ gdb_test "whatis 'whatis.c'::v_struct1" \
+     "type = struct t_struct" \
+     "whatis named structure in explicit scope"
+ 
  gdb_test "whatis struct t_struct" \
      "type = struct t_struct" \
      "whatis named structure using type name"
  
+ gdb_test "whatis 'whatis.c'::struct t_struct" \
+     "type = struct t_struct" \
+     "whatis named structure using type name and explicit scope"
+ 
  gdb_test "whatis v_struct2" \
      "type = struct \{$unstruct\}" \
      "whatis unnamed structure"
  
+ gdb_test "whatis 'whatis.c'::v_struct2" \
+     "type = struct \{$unstruct\}" \
+     "whatis unnamed structure in explicit scope"
+ 
  
  # test whatis command with union types
  gdb_test "whatis v_union" \
      "type = union t_union" \
      "whatis named union"
  
+ gdb_test "whatis 'whatis.c'::v_union" \
+     "type = union t_union" \
+     "whatis named union in explicit scope"
+ 
  gdb_test "whatis union t_union" \
      "type = union t_union" \
      "whatis named union using type name"
  
+ gdb_test "whatis 'whatis.c'::union t_union" \
+     "type = union t_union" \
+     "whatis named union using type name and explicit scope"
+ 
  gdb_test "whatis v_union2" \
      "type = union \{$ununion\}" \
      "whatis unnamed union"
  
+ gdb_test "whatis 'whatis.c'::v_union2" \
+     "type = union \{$ununion\}" \
+     "whatis unnamed union in explicit scope"
+ 
  
  # HP-UX: HP aCC compiler w/ +objdebug option detects language as
  # c++, so we need the 'void' pattern here.
*************** gdb_test "whatis char_addr" \
*** 421,426 ****
--- 445,465 ----
      "type = char \\*" \
      "whatis using typedef type name"
  
+ gdb_test "whatis 'whatis.c'::char_addr" \
+     "type = char \\*" \
+     "whatis using typedef type name and explicit scope"
+ 
  gdb_test "whatis a_char_addr" \
      "type = char_addr" \
      "whatis applied to variable defined by typedef"
+ 
+ gdb_test "whatis 'whatis.c'::a_char_addr" \
+     "type = char_addr" \
+     "whatis applied to variable defined by typedef in explicit scope"
+ 
+ # Test printing value history type
+ 
+ gdb_test "p (long)1" ""
+ gdb_test "whatis" "type = long" "whatis long value from value history"
+ gdb_test "p (short)1" ""
+ gdb_test "whatis" "type = short" "whatis short value from value history"



More information about the Gdb-patches mailing list