Пример #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;
    }
}
Пример #2
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);
    }
}
Пример #3
0
static int
print_optional_low_bound (struct ui_file *stream, struct type *type,
			  const struct value_print_options *options)
{
  struct type *index_type;
  LONGEST low_bound;
  LONGEST high_bound;

  if (options->print_array_indexes)
    return 0;

  if (!get_array_bounds (type, &low_bound, &high_bound))
    return 0;

  /* If this is an empty array, then don't print the lower bound.
     That would be confusing, because we would print the lower bound,
     followed by... nothing!  */
  if (low_bound > high_bound)
    return 0;

  index_type = TYPE_INDEX_TYPE (type);

  while (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
    {
      /* We need to know what the base type is, in order to do the
         appropriate check below.  Otherwise, if this is a subrange
         of an enumerated type, where the underlying value of the
         first element is typically 0, we might test the low bound
         against the wrong value.  */
      index_type = TYPE_TARGET_TYPE (index_type);
    }

  switch (TYPE_CODE (index_type))
    {
    case TYPE_CODE_BOOL:
      if (low_bound == 0)
	return 0;
      break;
    case TYPE_CODE_ENUM:
      if (low_bound == TYPE_FIELD_ENUMVAL (index_type, 0))
	return 0;
      break;
    case TYPE_CODE_UNDEF:
      index_type = NULL;
      /* FALL THROUGH */
    default:
      if (low_bound == 1)
	return 0;
      break;
    }

  ada_print_scalar (index_type, low_bound, stream);
  fprintf_filtered (stream, " => ");
  return 1;
}
Пример #4
0
static char *
ada_varobj_scalar_image (struct type *type, LONGEST val)
{
  struct ui_file *buf = mem_fileopen ();
  struct cleanup *cleanups = make_cleanup_ui_file_delete (buf);
  char *result;

  ada_print_scalar (type, val, buf);
  result = ui_file_xstrdup (buf, NULL);
  do_cleanups (cleanups);

  return result;
}
Пример #5
0
static void
print_dynamic_range_bound (struct type *type, const char *name, int name_len,
                           const char *suffix, struct ui_file *stream)
{
    static char *name_buf = NULL;
    static size_t name_buf_len = 0;
    LONGEST B;
    int OK;

    GROW_VECT (name_buf, name_buf_len, name_len + strlen (suffix) + 1);
    strncpy (name_buf, name, name_len);
    strcpy (name_buf + name_len, suffix);

    B = get_int_var_value (name_buf, &OK);
    if (OK)
        ada_print_scalar (type, B, stream);
    else
        fprintf_filtered (stream, "?");
}
static int
print_optional_low_bound (struct ui_file *stream, struct type *type)
{
  struct type *index_type;
  long low_bound;

  if (print_array_indexes_p ())
    return 0;

  if (!get_array_low_bound (type, &low_bound))
    return 0;

  index_type = TYPE_INDEX_TYPE (type);

  if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
    {
      /* We need to know what the base type is, in order to do the
         appropriate check below.  Otherwise, if this is a subrange
         of an enumerated type, where the underlying value of the
         first element is typically 0, we might test the low bound
         against the wrong value.  */
      index_type = TYPE_TARGET_TYPE (index_type);
    }

  switch (TYPE_CODE (index_type))
    {
    case TYPE_CODE_ENUM:
      if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
	return 0;
      break;
    case TYPE_CODE_UNDEF:
      index_type = builtin_type_long;
      /* FALL THROUGH */
    default:
      if (low_bound == 1)
	return 0;
      break;
    }

  ada_print_scalar (index_type, (LONGEST) low_bound, stream);
  fprintf_filtered (stream, " => ");
  return 1;
}
Пример #7
0
static void
print_range_bound (struct type *type, char *bounds, int *n,
                   struct ui_file *stream)
{
    LONGEST B;

    if (ada_scan_number (bounds, *n, &B, n))
    {
        /* STABS decodes all range types which bounds are 0 .. -1 as
           unsigned integers (ie. the type code is TYPE_CODE_INT, not
           TYPE_CODE_RANGE).  Unfortunately, ada_print_scalar() relies
           on the unsigned flag to determine whether the bound should
           be printed as a signed or an unsigned value.  This causes
           the upper bound of the 0 .. -1 range types to be printed as
           a very large unsigned number instead of -1.
           To workaround this stabs deficiency, we replace the TYPE by NULL
           to indicate default output when we detect that the bound is negative,
           and the type is a TYPE_CODE_INT.  The bound is negative when
           'm' is the last character of the number scanned in BOUNDS.  */
        if (bounds[*n - 1] == 'm' && TYPE_CODE (type) == TYPE_CODE_INT)
            type = NULL;
        ada_print_scalar (type, B, stream);
        if (bounds[*n] == '_')
            *n += 2;
    }
    else
    {
        int bound_len;
        char *bound = bounds + *n;
        char *pend;

        pend = strstr (bound, "__");
        if (pend == NULL)
            *n += bound_len = strlen (bound);
        else
        {
            bound_len = pend - bound;
            *n += bound_len + 2;
        }
        fprintf_filtered (stream, "%.*s", bound_len, bound);
    }
}
static int
print_optional_low_bound (struct ui_file *stream, struct type *type)
{
  struct type *index_type;
  long low_bound;

  index_type = TYPE_INDEX_TYPE (type);
  low_bound = 0;

  if (index_type == NULL)
    return 0;
  if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
    {
      low_bound = TYPE_LOW_BOUND (index_type);
      if (low_bound > TYPE_HIGH_BOUND (index_type))
	return 0;
      index_type = TYPE_TARGET_TYPE (index_type);
    }
  else
    return 0;

  switch (TYPE_CODE (index_type))
    {
    case TYPE_CODE_ENUM:
      if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
	return 0;
      break;
    case TYPE_CODE_UNDEF:
      index_type = builtin_type_long;
      /* FALL THROUGH */
    default:
      if (low_bound == 1)
	return 0;
      break;
    }

  ada_print_scalar (index_type, (LONGEST) low_bound, stream);
  fprintf_filtered (stream, " => ");
  return 1;
}
Пример #9
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;
    }
Пример #10
0
void
ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
{
  unsigned int i;
  unsigned len;

  if (!type)
    {
      print_longest (stream, 'd', 0, val);
      return;
    }

  type = ada_check_typedef (type);

  switch (TYPE_CODE (type))
    {

    case TYPE_CODE_ENUM:
      len = TYPE_NFIELDS (type);
      for (i = 0; i < len; i++)
	{
	  if (TYPE_FIELD_ENUMVAL (type, i) == val)
	    {
	      break;
	    }
	}
      if (i < len)
	{
	  fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream);
	}
      else
	{
	  print_longest (stream, 'd', 0, val);
	}
      break;

    case TYPE_CODE_INT:
      print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
      break;

    case TYPE_CODE_CHAR:
      LA_PRINT_CHAR (val, type, stream);
      break;

    case TYPE_CODE_BOOL:
      fprintf_filtered (stream, val ? "true" : "false");
      break;

    case TYPE_CODE_RANGE:
      ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
      return;

    case TYPE_CODE_UNDEF:
    case TYPE_CODE_PTR:
    case TYPE_CODE_ARRAY:
    case TYPE_CODE_STRUCT:
    case TYPE_CODE_UNION:
    case TYPE_CODE_FUNC:
    case TYPE_CODE_FLT:
    case TYPE_CODE_VOID:
    case TYPE_CODE_SET:
    case TYPE_CODE_STRING:
    case TYPE_CODE_ERROR:
    case TYPE_CODE_MEMBERPTR:
    case TYPE_CODE_METHODPTR:
    case TYPE_CODE_METHOD:
    case TYPE_CODE_REF:
      warning (_("internal error: unhandled type in ada_print_scalar"));
      break;

    default:
      error (_("Invalid type code in symbol table."));
    }
  gdb_flush (stream);
}
Пример #11
0
static int
print_choices (struct type *type, int field_num, struct ui_file *stream,
               struct type *val_type)
{
    int have_output;
    int p;
    const char *name = TYPE_FIELD_NAME (type, field_num);

    have_output = 0;

    /* Skip over leading 'V': NOTE soon to be obsolete.  */
    if (name[0] == 'V')
    {
        if (!ada_scan_number (name, 1, NULL, &p))
            goto Huh;
    }
    else
        p = 0;

    while (1)
    {
        switch (name[p])
        {
        default:
            goto Huh;
        case '_':
        case '\0':
            fprintf_filtered (stream, " =>");
            return 1;
        case 'S':
        case 'R':
        case 'O':
            if (have_output)
                fprintf_filtered (stream, " | ");
            have_output = 1;
            break;
        }

        switch (name[p])
        {
        case 'S':
        {
            LONGEST W;

            if (!ada_scan_number (name, p + 1, &W, &p))
                goto Huh;
            ada_print_scalar (val_type, W, stream);
            break;
        }
        case 'R':
        {
            LONGEST L, U;

            if (!ada_scan_number (name, p + 1, &L, &p)
                    || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p))
                goto Huh;
            ada_print_scalar (val_type, L, stream);
            fprintf_filtered (stream, " .. ");
            ada_print_scalar (val_type, U, stream);
            break;
        }
        case 'O':
            fprintf_filtered (stream, "others");
            p += 1;
            break;
        }
    }

Huh:
    fprintf_filtered (stream, "?? =>");
    return 0;
}