Exemplo n.º 1
0
static void
print_range (struct type *type, struct ui_file *stream)
{
    switch (TYPE_CODE (type))
    {
    case TYPE_CODE_RANGE:
    case TYPE_CODE_ENUM:
    {
        struct type *target_type;
        target_type = TYPE_TARGET_TYPE (type);
        if (target_type == NULL)
            target_type = type;
        ada_print_scalar (target_type, ada_discrete_type_low_bound (type),
                          stream);
        fprintf_filtered (stream, " .. ");
        ada_print_scalar (target_type, ada_discrete_type_high_bound (type),
                          stream);
    }
    break;
    default:
        fprintf_filtered (stream, "%.*s",
                          ada_name_prefix_len (TYPE_NAME (type)),
                          TYPE_NAME (type));
        break;
    }
}
Exemplo n.º 2
0
void
ada_typedef_print(struct type *the_type, struct symbol *newsym,
		  struct ui_file *stream)
{
   /* XXX: type_sprint */
  fprintf_filtered(stream, "type %.*s is ",
		   ada_name_prefix_len(SYMBOL_PRINT_NAME(newsym)),
		   SYMBOL_PRINT_NAME(newsym));
  type_print(the_type, "", stream, 1);
}
Exemplo n.º 3
0
static void
print_range(struct type *the_type, struct ui_file *stream)
{
  struct type *target_type;
  target_type = TYPE_TARGET_TYPE(the_type);
  if (target_type == NULL)
    target_type = the_type;

  switch (TYPE_CODE(target_type))
    {
    case TYPE_CODE_RANGE:
    case TYPE_CODE_INT:
    case TYPE_CODE_BOOL:
    case TYPE_CODE_CHAR:
    case TYPE_CODE_ENUM:
      break;
    default:
      target_type = builtin_type_int;
      break;
    }

  if (TYPE_NFIELDS(the_type) < 2)
    {
      /* A range needs at least 2 bounds to be printed.  If there are less
         than 2, just print the type name instead of the range itself.
         This check handles cases such as characters, for example.

         Note that if the name is not defined, then we don't print anything.
       */
      fprintf_filtered(stream, "%.*s",
                       ada_name_prefix_len(TYPE_NAME(the_type)),
                       TYPE_NAME(the_type));
    }
  else
    {
      /* We extract the range type bounds respectively from the first element
         and the last element of the type->fields array */
      const LONGEST lower_bound = (LONGEST)TYPE_LOW_BOUND(the_type);
      const LONGEST upper_bound =
	(LONGEST)TYPE_FIELD_BITPOS(the_type, TYPE_NFIELDS(the_type) - 1);

      ada_print_scalar(target_type, lower_bound, stream);
      fprintf_filtered(stream, " .. ");
      ada_print_scalar(target_type, upper_bound, stream);
    }
}
Exemplo n.º 4
0
static void
ada_varobj_describe_simple_array_child (struct value *parent_value,
					struct type *parent_type,
					const char *parent_name,
					const char *parent_path_expr,
					int child_index,
					char **child_name,
					struct value **child_value,
					struct type **child_type,
					char **child_path_expr)
{
  struct type *index_type;
  int real_index;

  gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_ARRAY);

  index_type = TYPE_INDEX_TYPE (parent_type);
  real_index = child_index + ada_discrete_type_low_bound (index_type);

  if (child_name)
    *child_name = ada_varobj_scalar_image (index_type, real_index);

  if (child_value && parent_value)
    ada_varobj_simple_array_elt (parent_value, parent_type, real_index,
				 child_value, NULL);

  if (child_type)
    ada_varobj_simple_array_elt (parent_value, parent_type, real_index,
				 NULL, child_type);

  if (child_path_expr)
    {
      char *index_img = ada_varobj_scalar_image (index_type, real_index);
      struct cleanup *cleanups = make_cleanup (xfree, index_img);

      /* Enumeration litterals by themselves are potentially ambiguous.
	 For instance, consider the following package spec:

	    package Pck is
	       type Color is (Red, Green, Blue, White);
	       type Blood_Cells is (White, Red);
	    end Pck;

	 In this case, the litteral "red" for instance, or even
	 the fully-qualified litteral "pck.red" cannot be resolved
	 by itself.  Type qualification is needed to determine which
	 enumeration litterals should be used.

	 The following variable will be used to contain the name
	 of the array index type when such type qualification is
	 needed.  */
      const char *index_type_name = NULL;

      /* If the index type is a range type, find the base type.  */
      while (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
	index_type = TYPE_TARGET_TYPE (index_type);

      if (TYPE_CODE (index_type) == TYPE_CODE_ENUM
	  || TYPE_CODE (index_type) == TYPE_CODE_BOOL)
	{
	  index_type_name = ada_type_name (index_type);
	  if (index_type_name)
	    index_type_name = ada_decode (index_type_name);
	}

      if (index_type_name != NULL)
	*child_path_expr =
	  xstrprintf ("(%s)(%.*s'(%s))", parent_path_expr,
		      ada_name_prefix_len (index_type_name),
		      index_type_name, index_img);
      else
	*child_path_expr =
	  xstrprintf ("(%s)(%s)", parent_path_expr, index_img);
      do_cleanups (cleanups);
    }
}
Exemplo n.º 5
0
static void
ada_varobj_describe_struct_child (struct value *parent_value,
				  struct type *parent_type,
				  const char *parent_name,
				  const char *parent_path_expr,
				  int child_index,
				  char **child_name,
				  struct value **child_value,
				  struct type **child_type,
				  char **child_path_expr)
{
  int fieldno;
  int childno = 0;

  gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT);

  for (fieldno = 0; fieldno < TYPE_NFIELDS (parent_type); fieldno++)
    {
      if (ada_is_ignored_field (parent_type, fieldno))
	continue;

      if (ada_is_wrapper_field (parent_type, fieldno))
	{
	  struct value *elt_value;
	  struct type *elt_type;
	  int elt_n_children;

	  ada_varobj_struct_elt (parent_value, parent_type, fieldno,
				 &elt_value, &elt_type);
	  if (ada_is_tagged_type (elt_type, 0))
	    {
	      /* Same as in ada_varobj_get_struct_number_of_children:
		 For tagged types, we must be careful to not call
		 ada_varobj_get_number_of_children, to prevent our
		 element from being fixed back into the parent.  */
	      elt_n_children = ada_varobj_get_struct_number_of_children
		(elt_value, elt_type);
	    }
	  else
	    elt_n_children =
	      ada_varobj_get_number_of_children (elt_value, elt_type);

	  /* Is the child we're looking for one of the children
	     of this wrapper field?  */
	  if (child_index - childno < elt_n_children)
	    {
	      if (ada_is_tagged_type (elt_type, 0))
		{
		  /* Same as in ada_varobj_get_struct_number_of_children:
		     For tagged types, we must be careful to not call
		     ada_varobj_describe_child, to prevent our element
		     from being fixed back into the parent.  */
		  ada_varobj_describe_struct_child
		    (elt_value, elt_type, parent_name, parent_path_expr,
		     child_index - childno, child_name, child_value,
		     child_type, child_path_expr);
		}
	      else
		ada_varobj_describe_child (elt_value, elt_type,
					   parent_name, parent_path_expr,
					   child_index - childno,
					   child_name, child_value,
					   child_type, child_path_expr);
	      return;
	    }

	  /* The child we're looking for is beyond this wrapper
	     field, so skip all its children.  */
	  childno += elt_n_children;
	  continue;
	}
      else if (ada_is_variant_part (parent_type, fieldno))
	{
	  /* In normal situations, the variant part of the record should
	     have been "fixed". Or, in other words, it should have been
	     replaced by the branch of the variant part that is relevant
	     for our value.  But there are still situations where this
	     can happen, however (Eg. when our parent is a NULL pointer).
	     We do not support showing this part of the record for now,
	     so just pretend this field does not exist.  */
	  continue;
	}

      if (childno == child_index)
	{
	  if (child_name)
	    {
	      /* The name of the child is none other than the field's
		 name, except that we need to strip suffixes from it.
		 For instance, fields with alignment constraints will
		 have an __XVA suffix added to them.  */
	      const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno);
	      int child_name_len = ada_name_prefix_len (field_name);

	      *child_name = xstrprintf ("%.*s", child_name_len, field_name);
	    }

	  if (child_value && parent_value)
	    ada_varobj_struct_elt (parent_value, parent_type, fieldno,
				   child_value, NULL);

	  if (child_type)
	    ada_varobj_struct_elt (parent_value, parent_type, fieldno,
				   NULL, child_type);

	  if (child_path_expr)
	    {
	      /* The name of the child is none other than the field's
		 name, except that we need to strip suffixes from it.
		 For instance, fields with alignment constraints will
		 have an __XVA suffix added to them.  */
	      const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno);
	      int child_name_len = ada_name_prefix_len (field_name);

	      *child_path_expr =
		xstrprintf ("(%s).%.*s", parent_path_expr,
			    child_name_len, field_name);
	    }

	  return;
	}

      childno++;
    }

  /* Something went wrong.  Either we miscounted the number of
     children, or CHILD_INDEX was too high.  But we should never
     reach here.  We don't have enough information to recover
     nicely, so just raise an assertion failure.  */
  gdb_assert_not_reached ("unexpected code path");
}
Exemplo n.º 6
0
static void
print_range (struct type *type, struct ui_file *stream,
	     int bounds_prefered_p)
{
  if (!bounds_prefered_p)
    {
      /* Try stripping all TYPE_CODE_RANGE layers whose bounds
	 are identical to the bounds of their subtype.  When
	 the bounds of both types match, it can allow us to
	 print a range using the name of its base type, which
	 is easier to read.  For instance, we would print...

	     array (character) of ...

	 ... instead of...

	     array ('["00"]' .. '["ff"]') of ...  */
      while (type_is_full_subrange_of_target_type (type))
	type = TYPE_TARGET_TYPE (type);
    }

  switch (TYPE_CODE (type))
    {
    case TYPE_CODE_RANGE:
    case TYPE_CODE_ENUM:
      {
	struct type *target_type;
	volatile struct gdb_exception e;
	LONGEST lo = 0, hi = 0; /* init for gcc -Wall */

	target_type = TYPE_TARGET_TYPE (type);
	if (target_type == NULL)
	  target_type = type;

	TRY_CATCH (e, RETURN_MASK_ERROR)
	  {
	    lo = ada_discrete_type_low_bound (type);
	    hi = ada_discrete_type_high_bound (type);
	  }
	if (e.reason < 0)
	  {
	    /* This can happen when the range is dynamic.  Sometimes,
	       resolving dynamic property values requires us to have
	       access to an actual object, which is not available
	       when the user is using the "ptype" command on a type.
	       Print the range as an unbounded range.  */
	    fprintf_filtered (stream, "<>");
	  }
	else
	  {
	    ada_print_scalar (target_type, lo, stream);
	    fprintf_filtered (stream, " .. ");
	    ada_print_scalar (target_type, hi, stream);
	  }
      }
      break;
    default:
      fprintf_filtered (stream, "%.*s",
			ada_name_prefix_len (TYPE_NAME (type)),
			TYPE_NAME (type));
      break;
    }
Exemplo n.º 7
0
static int
print_field_values (struct type *type, const gdb_byte *valaddr,
		    int offset, struct ui_file *stream, int recurse,
		    struct value *val,
		    const struct value_print_options *options,
		    int comma_needed,
		    struct type *outer_type, int outer_offset,
		    const struct language_defn *language)
{
  int i, len;

  len = TYPE_NFIELDS (type);

  for (i = 0; i < len; i += 1)
    {
      if (ada_is_ignored_field (type, i))
	continue;

      if (ada_is_wrapper_field (type, i))
	{
	  comma_needed =
	    print_field_values (TYPE_FIELD_TYPE (type, i),
				valaddr,
				(offset
				 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
				stream, recurse, val, options,
				comma_needed, type, offset, language);
	  continue;
	}
      else if (ada_is_variant_part (type, i))
	{
	  comma_needed =
	    print_variant_part (type, i, valaddr,
				offset, stream, recurse, val,
				options, comma_needed,
				outer_type, outer_offset, language);
	  continue;
	}

      if (comma_needed)
	fprintf_filtered (stream, ", ");
      comma_needed = 1;

      if (options->prettyformat)
	{
	  fprintf_filtered (stream, "\n");
	  print_spaces_filtered (2 + 2 * recurse, stream);
	}
      else
	{
	  wrap_here (n_spaces (2 + 2 * recurse));
	}

      annotate_field_begin (TYPE_FIELD_TYPE (type, i));
      fprintf_filtered (stream, "%.*s",
			ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
			TYPE_FIELD_NAME (type, i));
      annotate_field_name_end ();
      fputs_filtered (" => ", stream);
      annotate_field_value ();

      if (TYPE_FIELD_PACKED (type, i))
	{
	  /* Bitfields require special handling, especially due to byte
	     order problems.  */
	  if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
	    {
	      fputs_filtered (_("<optimized out or zero length>"), stream);
	    }
	  else
	    {
	      struct value *v;
	      int bit_pos = TYPE_FIELD_BITPOS (type, i);
	      int bit_size = TYPE_FIELD_BITSIZE (type, i);
	      struct value_print_options opts;

	      adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
	      v = ada_value_primitive_packed_val
		    (NULL, valaddr,
		     offset + bit_pos / HOST_CHAR_BIT,
		     bit_pos % HOST_CHAR_BIT,
		     bit_size, TYPE_FIELD_TYPE (type, i));
	      opts = *options;
	      opts.deref_ref = 0;
	      val_print (TYPE_FIELD_TYPE (type, i),
			 value_embedded_offset (v), 0,
			 stream, recurse + 1, v,
			 &opts, language);
	    }
	}
      else
	{
	  struct value_print_options opts = *options;

	  opts.deref_ref = 0;
	  val_print (TYPE_FIELD_TYPE (type, i),
		     (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
		     0, stream, recurse + 1, val, &opts, language);
	}
      annotate_field_end ();
    }

  return comma_needed;
}
static int
print_field_values (struct type *type, char *valaddr, struct ui_file *stream,
		    int format, int recurse, enum val_prettyprint pretty,
		    int comma_needed, struct type *outer_type,
		    char *outer_valaddr)
{
  int i, len;

  len = TYPE_NFIELDS (type);

  for (i = 0; i < len; i += 1)
    {
      if (ada_is_ignored_field (type, i))
	continue;

      if (ada_is_wrapper_field (type, i))
	{
	  comma_needed =
	    print_field_values (TYPE_FIELD_TYPE (type, i),
				valaddr
				+ TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
				stream, format, recurse, pretty,
				comma_needed, type, valaddr);
	  continue;
	}
      else if (ada_is_variant_part (type, i))
	{
	  comma_needed =
	    print_variant_part (type, i, valaddr,
				stream, format, recurse, pretty, comma_needed,
				outer_type, outer_valaddr);
	  continue;
	}

      if (comma_needed)
	fprintf_filtered (stream, ", ");
      comma_needed = 1;

      if (pretty)
	{
	  fprintf_filtered (stream, "\n");
	  print_spaces_filtered (2 + 2 * recurse, stream);
	}
      else
	{
	  wrap_here (n_spaces (2 + 2 * recurse));
	}
      if (inspect_it)
	{
	  if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
	    fputs_filtered ("\"( ptr \"", stream);
	  else
	    fputs_filtered ("\"( nodef \"", stream);
	  fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
				   language_cplus, DMGL_NO_OPTS);
	  fputs_filtered ("\" \"", stream);
	  fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
				   language_cplus, DMGL_NO_OPTS);
	  fputs_filtered ("\") \"", stream);
	}
      else
	{
	  annotate_field_begin (TYPE_FIELD_TYPE (type, i));
	  fprintf_filtered (stream, "%.*s",
			    ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
			    TYPE_FIELD_NAME (type, i));
	  annotate_field_name_end ();
	  fputs_filtered (" => ", stream);
	  annotate_field_value ();
	}

      if (TYPE_FIELD_PACKED (type, i))
	{
	  struct value *v;

	  /* Bitfields require special handling, especially due to byte
	     order problems.  */
	  if (TYPE_CPLUS_SPECIFIC (type) != NULL
	      && TYPE_FIELD_IGNORE (type, i))
	    {
	      fputs_filtered ("<optimized out or zero length>", stream);
	    }
	  else
	    {
	      int bit_pos = TYPE_FIELD_BITPOS (type, i);
	      int bit_size = TYPE_FIELD_BITSIZE (type, i);

	      adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
	      v = ada_value_primitive_packed_val (NULL, valaddr,
						  bit_pos / HOST_CHAR_BIT,
						  bit_pos % HOST_CHAR_BIT,
						  bit_size,
						  TYPE_FIELD_TYPE (type, i));
	      val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, 0,
			 stream, format, 0, recurse + 1, pretty);
	    }
	}
      else
	ada_val_print (TYPE_FIELD_TYPE (type, i),
		       valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT,
		       0, 0, stream, format, 0, recurse + 1, pretty);
      annotate_field_end ();
    }

  return comma_needed;
}
Exemplo n.º 9
0
void
ada_print_type (struct type *type0, const char *varstring,
                struct ui_file *stream, int show, int level,
                const struct type_print_options *flags)
{
    struct type *type = ada_check_typedef (ada_get_base_type (type0));
    char *type_name = decoded_type_name (type0);
    int is_var_decl = (varstring != NULL && varstring[0] != '\0');

    if (type == NULL)
    {
        if (is_var_decl)
            fprintf_filtered (stream, "%.*s: ",
                              ada_name_prefix_len (varstring), varstring);
        fprintf_filtered (stream, "<null type?>");
        return;
    }

    if (show > 0)
        type = ada_check_typedef (type);

    if (is_var_decl && TYPE_CODE (type) != TYPE_CODE_FUNC)
        fprintf_filtered (stream, "%.*s: ",
                          ada_name_prefix_len (varstring), varstring);

    if (type_name != NULL && show <= 0 && !ada_is_aligner_type (type))
    {
        fprintf_filtered (stream, "%.*s",
                          ada_name_prefix_len (type_name), type_name);
        return;
    }

    if (ada_is_aligner_type (type))
        ada_print_type (ada_aligned_type (type), "", stream, show, level, flags);
    else if (ada_is_constrained_packed_array_type (type)
             && TYPE_CODE (type) != TYPE_CODE_PTR)
        print_array_type (type, stream, show, level, flags);
    else
        switch (TYPE_CODE (type))
        {
        default:
            fprintf_filtered (stream, "<");
            c_print_type (type, "", stream, show, level, flags);
            fprintf_filtered (stream, ">");
            break;
        case TYPE_CODE_PTR:
        case TYPE_CODE_TYPEDEF:
            fprintf_filtered (stream, "access ");
            ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                            flags);
            break;
        case TYPE_CODE_REF:
            fprintf_filtered (stream, "<ref> ");
            ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                            flags);
            break;
        case TYPE_CODE_ARRAY:
            print_array_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_BOOL:
            fprintf_filtered (stream, "(false, true)");
            break;
        case TYPE_CODE_INT:
            if (ada_is_fixed_point_type (type))
                print_fixed_point_type (type, stream);
            else
            {
                const char *name = ada_type_name (type);

                if (!ada_is_range_type_name (name))
                    fprintf_filtered (stream, _("<%d-byte integer>"),
                                      TYPE_LENGTH (type));
                else
                {
                    fprintf_filtered (stream, "range ");
                    print_range_type (type, stream);
                }
            }
            break;
        case TYPE_CODE_RANGE:
            if (ada_is_fixed_point_type (type))
                print_fixed_point_type (type, stream);
            else if (ada_is_modular_type (type))
                fprintf_filtered (stream, "mod %s",
                                  int_string (ada_modulus (type), 10, 0, 0, 1));
            else
            {
                fprintf_filtered (stream, "range ");
                print_range (type, stream);
            }
            break;
        case TYPE_CODE_FLT:
            fprintf_filtered (stream, _("<%d-byte float>"), TYPE_LENGTH (type));
            break;
        case TYPE_CODE_ENUM:
            if (show < 0)
                fprintf_filtered (stream, "(...)");
            else
                print_enum_type (type, stream);
            break;
        case TYPE_CODE_STRUCT:
            if (ada_is_array_descriptor_type (type))
                print_array_type (type, stream, show, level, flags);
            else if (ada_is_bogus_array_descriptor (type))
                fprintf_filtered (stream,
                                  _("array (?) of ? (<mal-formed descriptor>)"));
            else
                print_record_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_UNION:
            print_unchecked_union_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_FUNC:
            print_func_type (type, stream, varstring, flags);
            break;
        }
}