gdb patch for 64-bit enum values on 64-bit hosts (ia64-linux)

James Wilson wilson@wilson.cygnus.com
Mon Jun 19 18:06:00 GMT 2000


	In dwarf2read.c:read_array_type, I see two ifs that appear to handle
	DW_FORM_udata, DW_FORM_data1, DW_FORM_data2, and DW_FORM_data4, but
	not DW_FORM_data8, apparently assuming that DW_UNSND can't handle the
	latter.  With your change, this is no longer true on platforms with
	64-bit longs.

I can trigger this problem with the following testcase.

char array[0x100000001];

main()
{
}

If I compile this with gcc -g, load it into gdb, and say "ptype array",
I get a complaint about an ignored array bound, and gdb says the array has
length two.

Making this work requires changing some internal types to use long, and
hence the result ends up changing a lot of files not just dwarf2read.c.

With the following patch, gdb reports the correct array size.  Unfortunately,
I can't use "ptype array", I had to use "info variables".  "ptype array"
tries to read the variable value, which requires allocating 4GB+1 bytes of
memory, which I don't have, so I get an internal out-of-memory error.

This has not been tested against the gdb testsuite.  I am currently unable
to run the gdb testsuite.  I need gdb to work, so I will be investigating
this problem, though I expect it will take some time.

2000-06-19  James E. Wilson  <wilson@cygnus.com>

	* c-typeprint.c (c_type_print_varspec_suffix): Use %ld for TYPE_LENGTH.
	* ch-valprint.c (chill_val_print): Likewise.
	* f-typeprint.c (print_equivalent_f77_float_type, f_type_print_base):
	Likewise.
	* gdbtypes.c (recursive_dump_type): Likewise.
	* symmisc.c (print_symbol): Likewise.
	* tracepoint.c (scope_info): Likewise.
	* c-typeprint.c (c_type_print_base): Use %ld for TYPE_FIELD_BITPOS.
	* ch-typeprint.c (chill_type_print_base, chill_type_print_base):
	Likewise.
	* gdbtypes.c (recursive_dump_type): Likewise.
	* dwarf2read.c (read_array_type): Change type of low and high to long.
	Accept DW_FORM_data8 attributes.
	* gdbtypes.c (create_range_type): Change type of low_bound and
	high_bound to long.
	* gdbtypes.h (struct type): Change type of length and bitpos fields to
	long.
	(create_range_type): Change prototype to use long.
	
Index: c-typeprint.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/c-typeprint.c,v
retrieving revision 2.42
diff -p -r2.42 c-typeprint.c
*** c-typeprint.c	2000/02/04 19:48:52	2.42
--- c-typeprint.c	2000/06/20 00:50:45
*************** c_type_print_varspec_suffix (type, strea
*** 591,597 ****
        fprintf_filtered (stream, "[");
        if (TYPE_LENGTH (type) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
  	&& TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
! 	fprintf_filtered (stream, "%d",
  			  (TYPE_LENGTH (type)
  			   / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
        fprintf_filtered (stream, "]");
--- 591,597 ----
        fprintf_filtered (stream, "[");
        if (TYPE_LENGTH (type) >= 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
  	&& TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
! 	fprintf_filtered (stream, "%ld",
  			  (TYPE_LENGTH (type)
  			   / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
        fprintf_filtered (stream, "]");
*************** c_type_print_base (type, stream, show, l
*** 1146,1152 ****
  	      fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  	      if (lastval != TYPE_FIELD_BITPOS (type, i))
  		{
! 		  fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
  		  lastval = TYPE_FIELD_BITPOS (type, i);
  		}
  	      lastval++;
--- 1146,1152 ----
  	      fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  	      if (lastval != TYPE_FIELD_BITPOS (type, i))
  		{
! 		  fprintf_filtered (stream, " = %ld", TYPE_FIELD_BITPOS (type, i));
  		  lastval = TYPE_FIELD_BITPOS (type, i);
  		}
  	      lastval++;
Index: ch-typeprint.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/ch-typeprint.c,v
retrieving revision 2.24
diff -p -r2.24 ch-typeprint.c
*** ch-typeprint.c	2000/02/01 03:09:00	2.24
--- ch-typeprint.c	2000/06/20 00:50:45
*************** chill_type_print_base (type, stream, sho
*** 146,152 ****
        break;
  
      case TYPE_CODE_BITSTRING:
!       fprintf_filtered (stream, "BOOLS (%d)",
  		      TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE (type, 0), 1) + 1);
        break;
  
--- 146,152 ----
        break;
  
      case TYPE_CODE_BITSTRING:
!       fprintf_filtered (stream, "BOOLS (%ld)",
  		      TYPE_FIELD_BITPOS (TYPE_FIELD_TYPE (type, 0), 1) + 1);
        break;
  
*************** chill_type_print_base (type, stream, sho
*** 311,317 ****
  	    fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  	    if (lastval != TYPE_FIELD_BITPOS (type, i))
  	      {
! 		fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
  		lastval = TYPE_FIELD_BITPOS (type, i);
  	      }
  	    lastval++;
--- 311,317 ----
  	    fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  	    if (lastval != TYPE_FIELD_BITPOS (type, i))
  	      {
! 		fprintf_filtered (stream, " = %ld", TYPE_FIELD_BITPOS (type, i));
  		lastval = TYPE_FIELD_BITPOS (type, i);
  	      }
  	    lastval++;
Index: ch-valprint.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/ch-valprint.c,v
retrieving revision 2.42
diff -p -r2.42 ch-valprint.c
*** ch-valprint.c	2000/02/01 03:09:00	2.42
--- ch-valprint.c	2000/06/20 00:50:45
*************** chill_val_print (type, valaddr, embedded
*** 427,433 ****
  	      if (length > TYPE_LENGTH (type) - 2)
  		{
  		  fprintf_filtered (stream,
! 			"<dynamic length %ld > static length %d> *invalid*",
  				    length, TYPE_LENGTH (type));
  
  		  /* Don't print the string; doing so might produce a
--- 427,433 ----
  	      if (length > TYPE_LENGTH (type) - 2)
  		{
  		  fprintf_filtered (stream,
! 			"<dynamic length %ld > static length %ld> *invalid*",
  				    length, TYPE_LENGTH (type));
  
  		  /* Don't print the string; doing so might produce a
Index: dwarf2read.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/dwarf2read.c,v
retrieving revision 2.46
diff -p -r2.46 dwarf2read.c
*** dwarf2read.c	2000/06/19 22:19:53	2.46
--- dwarf2read.c	2000/06/20 00:50:45
*************** read_array_type (die, objfile)
*** 2415,2421 ****
      {
        if (child_die->tag == DW_TAG_subrange_type)
  	{
! 	  unsigned int low, high;
  
  	  /* Default bounds to an array with unspecified length.  */
  	  low = 0;
--- 2415,2421 ----
      {
        if (child_die->tag == DW_TAG_subrange_type)
  	{
! 	  unsigned long int low, high;
  
  	  /* Default bounds to an array with unspecified length.  */
  	  low = 0;
*************** read_array_type (die, objfile)
*** 2437,2443 ****
  	      else if (attr->form == DW_FORM_udata
  		       || attr->form == DW_FORM_data1
  		       || attr->form == DW_FORM_data2
! 		       || attr->form == DW_FORM_data4)
  		{
  		  low = DW_UNSND (attr);
  		}
--- 2437,2444 ----
  	      else if (attr->form == DW_FORM_udata
  		       || attr->form == DW_FORM_data1
  		       || attr->form == DW_FORM_data2
! 		       || attr->form == DW_FORM_data4
! 		       || attr->form == DW_FORM_data8)
  		{
  		  low = DW_UNSND (attr);
  		}
*************** read_array_type (die, objfile)
*** 2463,2469 ****
  	      else if (attr->form == DW_FORM_udata
  		       || attr->form == DW_FORM_data1
  		       || attr->form == DW_FORM_data2
! 		       || attr->form == DW_FORM_data4)
  		{
  		  high = DW_UNSND (attr);
  		}
--- 2464,2471 ----
  	      else if (attr->form == DW_FORM_udata
  		       || attr->form == DW_FORM_data1
  		       || attr->form == DW_FORM_data2
! 		       || attr->form == DW_FORM_data4
! 		       || attr->form == DW_FORM_data8)
  		{
  		  high = DW_UNSND (attr);
  		}
Index: f-typeprint.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/f-typeprint.c,v
retrieving revision 2.14
diff -p -r2.14 f-typeprint.c
*** f-typeprint.c	2000/02/01 03:09:00	2.14
--- f-typeprint.c	2000/06/20 00:50:45
*************** print_equivalent_f77_float_type (type, s
*** 320,326 ****
       appropriate real. XLC stupidly outputs -12 as a type
       for real when it really should be outputting -18 */
  
!   fprintf_filtered (stream, "real*%d", TYPE_LENGTH (type));
  }
  
  /* Print the name of the type (or the ultimate pointer target,
--- 320,326 ----
       appropriate real. XLC stupidly outputs -12 as a type
       for real when it really should be outputting -18 */
  
!   fprintf_filtered (stream, "real*%ld", TYPE_LENGTH (type));
  }
  
  /* Print the name of the type (or the ultimate pointer target,
*************** f_type_print_base (type, stream, show, l
*** 420,426 ****
        break;
  
      case TYPE_CODE_COMPLEX:
!       fprintf_filtered (stream, "complex*%d", TYPE_LENGTH (type));
        break;
  
      case TYPE_CODE_FLT:
--- 420,426 ----
        break;
  
      case TYPE_CODE_COMPLEX:
!       fprintf_filtered (stream, "complex*%ld", TYPE_LENGTH (type));
        break;
  
      case TYPE_CODE_FLT:
Index: gdbtypes.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/gdbtypes.c,v
retrieving revision 2.109
diff -p -r2.109 gdbtypes.c
*** gdbtypes.c	2000/05/28 01:25:29	2.109
--- gdbtypes.c	2000/06/20 00:50:45
*************** struct type *
*** 450,457 ****
  create_range_type (result_type, index_type, low_bound, high_bound)
       struct type *result_type;
       struct type *index_type;
!      int low_bound;
!      int high_bound;
  {
    if (result_type == NULL)
      {
--- 450,457 ----
  create_range_type (result_type, index_type, low_bound, high_bound)
       struct type *result_type;
       struct type *index_type;
!      long low_bound;
!      long high_bound;
  {
    if (result_type == NULL)
      {
*************** recursive_dump_type (type, spaces)
*** 2798,2804 ****
        break;
      }
    puts_filtered ("\n");
!   printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
    printfi_filtered (spaces, "objfile ");
    gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
    printf_filtered ("\n");
--- 2798,2804 ----
        break;
      }
    puts_filtered ("\n");
!   printfi_filtered (spaces, "length %ld\n", TYPE_LENGTH (type));
    printfi_filtered (spaces, "objfile ");
    gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
    printf_filtered ("\n");
*************** recursive_dump_type (type, spaces)
*** 2831,2837 ****
    for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
      {
        printfi_filtered (spaces + 2,
! 			"[%d] bitpos %d bitsize %d type ",
  			idx, TYPE_FIELD_BITPOS (type, idx),
  			TYPE_FIELD_BITSIZE (type, idx));
        gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
--- 2831,2837 ----
    for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
      {
        printfi_filtered (spaces + 2,
! 			"[%d] bitpos %ld bitsize %d type ",
  			idx, TYPE_FIELD_BITPOS (type, idx),
  			TYPE_FIELD_BITSIZE (type, idx));
        gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
Index: gdbtypes.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/gdbtypes.h,v
retrieving revision 2.83
diff -p -r2.83 gdbtypes.h
*** gdbtypes.h	2000/05/28 01:25:29	2.83
--- gdbtypes.h	2000/06/20 00:50:45
*************** struct type
*** 241,247 ****
         TARGET_CHAR_BIT)--the other choice would be to make it
         consistently in units of HOST_CHAR_BIT.  */
  
!     unsigned length;
  
      /* FIXME, these should probably be restricted to a Fortran-specific
         field in some fashion.  */
--- 241,247 ----
         TARGET_CHAR_BIT)--the other choice would be to make it
         consistently in units of HOST_CHAR_BIT.  */
  
!     unsigned long length;
  
      /* FIXME, these should probably be restricted to a Fortran-specific
         field in some fashion.  */
*************** struct type
*** 333,339 ****
  	       of this argument.
  	       For a range bound or enum value, this is the value itself. */
  
! 	    int bitpos;
  
  	    /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
  	       is the location (in the target) of the static field.
--- 333,339 ----
  	       of this argument.
  	       For a range bound or enum value, this is the value itself. */
  
! 	    long bitpos;
  
  	    /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
  	       is the location (in the target) of the static field.
*************** extern struct type *make_function_type (
*** 983,990 ****
  
  extern struct type *lookup_function_type (struct type *);
  
! extern struct type *create_range_type (struct type *, struct type *, int,
! 				       int);
  
  extern struct type *create_array_type (struct type *, struct type *,
  				       struct type *);
--- 983,990 ----
  
  extern struct type *lookup_function_type (struct type *);
  
! extern struct type *create_range_type (struct type *, struct type *, long,
! 				       long);
  
  extern struct type *create_array_type (struct type *, struct type *,
  				       struct type *);
Index: symmisc.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/symmisc.c,v
retrieving revision 1.87
diff -p -r1.87 symmisc.c
*** symmisc.c	2000/05/28 01:25:35	1.87
--- symmisc.c	2000/06/20 00:50:45
*************** print_symbol (args)
*** 623,629 ****
  	  {
  	    unsigned i;
  	    struct type *type = check_typedef (SYMBOL_TYPE (symbol));
! 	    fprintf_filtered (outfile, "const %u hex bytes:",
  			      TYPE_LENGTH (type));
  	    for (i = 0; i < TYPE_LENGTH (type); i++)
  	      fprintf_filtered (outfile, " %02x",
--- 623,629 ----
  	  {
  	    unsigned i;
  	    struct type *type = check_typedef (SYMBOL_TYPE (symbol));
! 	    fprintf_filtered (outfile, "const %lu hex bytes:",
  			      TYPE_LENGTH (type));
  	    for (i = 0; i < TYPE_LENGTH (type); i++)
  	      fprintf_filtered (outfile, " %02x",
Index: tracepoint.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/tracepoint.c,v
retrieving revision 2.58
diff -p -r2.58 tracepoint.c
*** tracepoint.c	2000/06/04 00:35:17	2.58
--- tracepoint.c	2000/06/20 00:50:45
*************** scope_info (args, from_tty)
*** 2519,2525 ****
  	      continue;
  	    }
  	  if (SYMBOL_TYPE (sym))
! 	    printf_filtered (", length %d.\n",
  			   TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))));
  	}
        if (BLOCK_FUNCTION (block))
--- 2519,2525 ----
  	      continue;
  	    }
  	  if (SYMBOL_TYPE (sym))
! 	    printf_filtered (", length %ld.\n",
  			   TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))));
  	}
        if (BLOCK_FUNCTION (block))


More information about the Gdb-patches mailing list