Ejemplo n.º 1
0
static int
gccgo_string_p (struct type *type)
{
  /* gccgo strings don't necessarily have a name we can use.  */

  if (TYPE_NFIELDS (type) == 2)
    {
      struct type *type0 = TYPE_FIELD_TYPE (type, 0);
      struct type *type1 = TYPE_FIELD_TYPE (type, 1);

      CHECK_TYPEDEF (type0);
      CHECK_TYPEDEF (type1);

      if (TYPE_CODE (type0) == TYPE_CODE_PTR
	  && strcmp (TYPE_FIELD_NAME (type, 0), "__data") == 0
	  && TYPE_CODE (type1) == TYPE_CODE_INT
	  && strcmp (TYPE_FIELD_NAME (type, 1), "__length") == 0)
	{
	  struct type *target_type = TYPE_TARGET_TYPE (type0);

	  CHECK_TYPEDEF (target_type);

	  if (TYPE_CODE (target_type) == TYPE_CODE_INT
	      && TYPE_LENGTH (target_type) == 1
	      && strcmp (TYPE_NAME (target_type), "uint8") == 0)
	    return 1;
	}
    }

  return 0;
}
Ejemplo n.º 2
0
static void
m2_print_array_contents (struct type *type, const gdb_byte *valaddr,
			 int embedded_offset, CORE_ADDR address,
			 struct ui_file *stream, int recurse,
			 const struct value_print_options *options,
			 int len)
{
  int eltlen;
  CHECK_TYPEDEF (type);

  if (TYPE_LENGTH (type) > 0)
    {
      eltlen = TYPE_LENGTH (type);
      if (options->prettyprint_arrays)
	print_spaces_filtered (2 + 2 * recurse, stream);
      /* For an array of chars, print with string syntax.  */
      if (eltlen == 1 &&
	  ((TYPE_CODE (type) == TYPE_CODE_INT)
	   || ((current_language->la_language == language_m2)
	       && (TYPE_CODE (type) == TYPE_CODE_CHAR)))
	  && (options->format == 0 || options->format == 's'))
	val_print_string (type, address, len+1, stream, options);
      else
	{
	  fprintf_filtered (stream, "{");
	  val_print_array_elements (type, valaddr + embedded_offset,
				    address, stream, recurse, options, 0);
	  fprintf_filtered (stream, "}");
	}
    }
}
Ejemplo n.º 3
0
/* Returns non-zero if the value is a structured type */
int
structured_type (struct type *type)
{
    CHECK_TYPEDEF (type);
    switch (current_language->la_language)
    {
    case language_c:
    case language_cplus:
    case language_objc:
        return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
               (TYPE_CODE (type) == TYPE_CODE_UNION) ||
               (TYPE_CODE (type) == TYPE_CODE_ARRAY);
    case language_pascal:
        return (TYPE_CODE(type) == TYPE_CODE_STRUCT) ||
               (TYPE_CODE(type) == TYPE_CODE_UNION) ||
               (TYPE_CODE(type) == TYPE_CODE_SET) ||
               (TYPE_CODE(type) == TYPE_CODE_ARRAY);
    case language_m2:
        return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
               (TYPE_CODE (type) == TYPE_CODE_SET) ||
               (TYPE_CODE (type) == TYPE_CODE_ARRAY);
    default:
        return (0);
    }
}
Ejemplo n.º 4
0
static void
m2_print_unbounded_array (struct type *type, const gdb_byte *valaddr,
			  int embedded_offset, CORE_ADDR address,
			  struct ui_file *stream, int recurse,
			  const struct value_print_options *options)
{
  struct type *content_type;
  CORE_ADDR addr;
  LONGEST len;
  struct value *val;

  CHECK_TYPEDEF (type);
  content_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0));

  addr = unpack_pointer (TYPE_FIELD_TYPE (type, 0),
			 (TYPE_FIELD_BITPOS (type, 0) / 8) +
			 valaddr + embedded_offset);

  val = value_at_lazy (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)),
		       addr);
  len = unpack_field_as_long (type, valaddr + embedded_offset, 1);

  fprintf_filtered (stream, "{");  
  m2_print_array_contents (value_type (val), value_contents(val),
			   value_embedded_offset (val), addr, stream,
			   recurse, options, len);
  fprintf_filtered (stream, ", HIGH = %d}", (int) len);
}
Ejemplo n.º 5
0
void
c_print_type (struct type *type,
	      const char *varstring,
	      struct ui_file *stream,
	      int show, int level,
	      const struct type_print_options *flags)
{
  enum type_code code;
  int demangled_args;
  int need_post_space;
  const char *local_name;

  if (show > 0)
    CHECK_TYPEDEF (type);

  local_name = find_typedef_in_hash (flags, type);
  if (local_name != NULL)
    {
      fputs_filtered (local_name, stream);
      if (varstring != NULL && *varstring != '\0')
	fputs_filtered (" ", stream);
    }
  else
    {
      c_type_print_base (type, stream, show, level, flags);
      code = TYPE_CODE (type);
      if ((varstring != NULL && *varstring != '\0')
	  /* Need a space if going to print stars or brackets;
	     but not if we will print just a type name.  */
	  || ((show > 0 || TYPE_NAME (type) == 0)
	      && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
		  || code == TYPE_CODE_METHOD
		  || (code == TYPE_CODE_ARRAY
		      && !TYPE_VECTOR (type))
		  || code == TYPE_CODE_MEMBERPTR
		  || code == TYPE_CODE_METHODPTR
		  || code == TYPE_CODE_REF)))
	fputs_filtered (" ", stream);
      need_post_space = (varstring != NULL && strcmp (varstring, "") != 0);
      c_type_print_varspec_prefix (type, stream, show, 0, need_post_space,
				   flags);
    }

  if (varstring != NULL)
    {
      fputs_filtered (varstring, stream);

      /* For demangled function names, we have the arglist as part of
         the name, so don't print an additional pair of ()'s.  */
      if (local_name == NULL)
	{
	  demangled_args = strchr (varstring, '(') != NULL;
	  c_type_print_varspec_suffix (type, stream, show,
				       0, demangled_args,
				       flags);
	}
    }
}
Ejemplo n.º 6
0
void
pascal_print_typedef (struct type *type, struct symbol *new_symbol,
		      struct ui_file *stream)
{
  CHECK_TYPEDEF (type);
  fprintf_filtered (stream, "type ");
  fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol));
  type_print (type, "", stream, 0);
  fprintf_filtered (stream, ";\n");
}
Ejemplo n.º 7
0
/* Return a sequence of all fields.  Each field is a dictionary with
   some pre-defined keys.  */
static PyObject *
typy_fields (PyObject *self, PyObject *args)
{
    PyObject *result;
    int i;
    struct type *type = ((type_object *) self)->type;
    volatile struct gdb_exception except;

    TRY_CATCH (except, RETURN_MASK_ALL)
    {
        CHECK_TYPEDEF (type);
    }
Ejemplo n.º 8
0
void
c_print_typedef (struct type *type, struct symbol *new_symbol,
		 struct ui_file *stream)
{
  CHECK_TYPEDEF (type);
  fprintf_filtered (stream, "typedef ");
  type_print (type, "", stream, 0);
  if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0
      || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))),
		 SYMBOL_LINKAGE_NAME (new_symbol)) != 0)
    fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol));
  fprintf_filtered (stream, ";\n");
}
Ejemplo n.º 9
0
enum go_type
go_classify_struct_type (struct type *type)
{
  CHECK_TYPEDEF (type);

  /* Recognize strings as they're useful to be able to print without
     pretty-printers.  */
  if (gccgo_string_p (type)
      || sixg_string_p (type))
    return GO_TYPE_STRING;

  return GO_TYPE_NONE;
}
Ejemplo n.º 10
0
/* Returns non-zero if the value is numeric */
int
numeric_type (struct type *type)
{
    CHECK_TYPEDEF (type);
    switch (TYPE_CODE (type))
    {
    case TYPE_CODE_INT:
    case TYPE_CODE_FLT:
        return 1;

    default:
        return 0;
    }
}
Ejemplo n.º 11
0
void
m2_print_typedef (struct type *type, struct symbol *new_symbol,
		  struct ui_file *stream)
{
  CHECK_TYPEDEF (type);
  fprintf_filtered (stream, "TYPE ");
  if (!TYPE_NAME (SYMBOL_TYPE (new_symbol))
      || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))),
		 SYMBOL_LINKAGE_NAME (new_symbol)) != 0)
    fprintf_filtered (stream, "%s = ", SYMBOL_PRINT_NAME (new_symbol));
  else
    fprintf_filtered (stream, "<builtin> = ");
  type_print (type, "", stream, 0);
  fprintf_filtered (stream, ";\n");
}
Ejemplo n.º 12
0
/* Returns non-zero if the two types are the same */
int
same_type (struct type *arg1, struct type *arg2)
{
    CHECK_TYPEDEF (type);
    if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2))
        /* One is structured and one isn't */
        return 0;
    else if (structured_type (arg1) && structured_type (arg2))
        return arg1 == arg2;
    else if (numeric_type (arg1) && numeric_type (arg2))
        return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) &&
               (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2))
               ? 1 : 0;
    else
        return arg1 == arg2;
}
static void
print_record (struct type *type, char *valaddr, struct ui_file *stream,
	      int format, int recurse, enum val_prettyprint pretty)
{
  CHECK_TYPEDEF (type);

  fprintf_filtered (stream, "(");

  if (print_field_values (type, valaddr, stream, format, recurse, pretty,
			  0, type, valaddr) != 0 && pretty)
    {
      fprintf_filtered (stream, "\n");
      print_spaces_filtered (2 * recurse, stream);
    }

  fprintf_filtered (stream, ")");
}
Ejemplo n.º 14
0
/* Returns non-zero if its argument is of an ordered type.
   An ordered type is one in which the elements can be tested for the
   properties of "greater than", "less than", etc, or for which the
   operations "increment" or "decrement" make sense. */
int
ordered_type (struct type *type)
{
    CHECK_TYPEDEF (type);
    switch (TYPE_CODE (type))
    {
    case TYPE_CODE_INT:
    case TYPE_CODE_CHAR:
    case TYPE_CODE_ENUM:
    case TYPE_CODE_FLT:
    case TYPE_CODE_RANGE:
        return 1;

    default:
        return 0;
    }
}
Ejemplo n.º 15
0
/* Returns non-zero if the type is integral */
int
integral_type (struct type *type)
{
    CHECK_TYPEDEF (type);
    switch (current_language->la_language)
    {
    case language_c:
    case language_cplus:
    case language_objc:
        return (TYPE_CODE (type) != TYPE_CODE_INT) &&
               (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1;
    case language_m2:
    case language_pascal:
        return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1;
    default:
        error ("Language not supported.");
    }
}
static void
pascal_object_print_static_field (struct value *val,
				  struct ui_file *stream,
				  int recurse,
				  const struct value_print_options *options)
{
  struct type *type = value_type (val);
  struct value_print_options opts;

  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
    {
      CORE_ADDR *first_dont_print, addr;
      int i;

      first_dont_print
	= (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
      i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
	- first_dont_print;

      while (--i >= 0)
	{
	  if (value_address (val) == first_dont_print[i])
	    {
	      fputs_filtered ("<same as static member of an already seen type>",
			      stream);
	      return;
	    }
	}

      addr = value_address (val);
      obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
		    sizeof (CORE_ADDR));

      CHECK_TYPEDEF (type);
      pascal_object_print_value_fields (type, value_contents (val), addr,
					stream, recurse, NULL, options,
					NULL, 1);
      return;
    }

  opts = *options;
  opts.deref_ref = 0;
  common_val_print (val, stream, recurse, &opts, current_language);
}
Ejemplo n.º 17
0
void
typedef_print(struct type *type, struct symbol *newsym,
              struct ui_file *stream)
{
  CHECK_TYPEDEF(type);
  switch (current_language->la_language)
    {
#ifdef _LANG_c
    case language_c:
    case language_cplus:
    case language_objc:
    case language_objcplus:
      fprintf_filtered(stream, "typedef ");
      type_print(type, "", stream, 0);
      if ((TYPE_NAME((SYMBOL_TYPE(newsym))) == 0)
	  || (strcmp(TYPE_NAME((SYMBOL_TYPE(newsym))),
                     DEPRECATED_SYMBOL_NAME(newsym)) != 0))
	fprintf_filtered(stream, " %s", SYMBOL_PRINT_NAME(newsym));
      break;
#endif /* _LANG_c */
#ifdef _LANG_m2
    case language_m2:
      fprintf_filtered(stream, "TYPE ");
      if (!TYPE_NAME(SYMBOL_TYPE(newsym))
	  || (strcmp(TYPE_NAME((SYMBOL_TYPE(newsym))),
                     DEPRECATED_SYMBOL_NAME(newsym)) != 0))
	fprintf_filtered(stream, "%s = ", SYMBOL_PRINT_NAME(newsym));
      else
	fprintf_filtered(stream, "<builtin> = ");
      type_print(type, "", stream, 0);
      break;
#endif /* _LANG_m2 */
#ifdef _LANG_pascal
    case language_pascal:
      fprintf_filtered(stream, "type ");
      fprintf_filtered(stream, "%s = ", SYMBOL_PRINT_NAME(newsym));
      type_print(type, "", stream, 0);
      break;
#endif /* _LANG_pascal */
    default:
      error(_("Language not supported."));
    }
  fprintf_filtered(stream, ";\n");
}
Ejemplo n.º 18
0
/* Returns non-zero if the value is a string type */
int
string_type (struct type *type)
{
    CHECK_TYPEDEF (type);
    switch (current_language->la_language)
    {
    case language_m2:
    case language_pascal:
        return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1;

    case language_c:
    case language_cplus:
    case language_objc:
        /* C does not have distinct string type. */
        return (0);
    default:
        return (0);
    }
}
Ejemplo n.º 19
0
/* Returns non-zero if the value is a character type */
int
character_type (struct type *type)
{
    CHECK_TYPEDEF (type);
    switch (current_language->la_language)
    {
    case language_m2:
    case language_pascal:
        return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1;

    case language_c:
    case language_cplus:
    case language_objc:
        return (TYPE_CODE (type) == TYPE_CODE_INT) &&
               TYPE_LENGTH (type) == sizeof (char)
               ? 1 : 0;
    default:
        return (0);
    }
}
Ejemplo n.º 20
0
void
pascal_print_type (struct type *type, char *varstring, struct ui_file *stream,
		   int show, int level)
{
  enum type_code code;
  int demangled_args;

  code = TYPE_CODE (type);

  if (show > 0)
    CHECK_TYPEDEF (type);

  if ((code == TYPE_CODE_FUNC ||
       code == TYPE_CODE_METHOD))
    {
      pascal_type_print_varspec_prefix (type, stream, show, 0);
    }
  /* first the name */
  fputs_filtered (varstring, stream);

  if ((varstring != NULL && *varstring != '\0') &&
      !(code == TYPE_CODE_FUNC ||
	code == TYPE_CODE_METHOD))
    {
      fputs_filtered (" : ", stream);
    }

  if (!(code == TYPE_CODE_FUNC ||
	code == TYPE_CODE_METHOD))
    {
      pascal_type_print_varspec_prefix (type, stream, show, 0);
    }

  pascal_type_print_base (type, stream, show, level);
  /* For demangled function names, we have the arglist as part of the name,
     so don't print an additional pair of ()'s */

  demangled_args = varstring ? strchr (varstring, '(') != NULL : 0;
  pascal_type_print_varspec_suffix (type, stream, show, 0, demangled_args);

}
Ejemplo n.º 21
0
/* Helper for expression_completer which recursively adds field and
   method names from TYPE, a struct or union type, to the array
   OUTPUT.  This function assumes that OUTPUT is correctly-sized.  */
static void
add_struct_fields (struct type *type, int *nextp, char **output,
		   char *fieldname, int namelen)
{
  int i;
  int computed_type_name = 0;
  char *type_name = NULL;

  CHECK_TYPEDEF (type);
  for (i = 0; i < TYPE_NFIELDS (type); ++i)
    {
      if (i < TYPE_N_BASECLASSES (type))
	add_struct_fields (TYPE_BASECLASS (type, i), nextp, output,
			   fieldname, namelen);
      else if (TYPE_FIELD_NAME (type, i)
	       && ! strncmp (TYPE_FIELD_NAME (type, i), fieldname, namelen))
	{
	  output[*nextp] = xstrdup (TYPE_FIELD_NAME (type, i));
	  ++*nextp;
	}
    }

  for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
    {
      char *name = TYPE_FN_FIELDLIST_NAME (type, i);
      if (name && ! strncmp (name, fieldname, namelen))
	{
	  if (!computed_type_name)
	    {
	      type_name = type_name_no_tag (type);
	      computed_type_name = 1;
	    }
	  /* Omit constructors from the completion list.  */
	  if (type_name && strcmp (type_name, name))
	    {
	      output[*nextp] = xstrdup (name);
	      ++*nextp;
	    }
	}
    }
}
Ejemplo n.º 22
0
int
m2_get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
{
  CHECK_TYPEDEF (type);
  switch (TYPE_CODE (type))
    {
    case TYPE_CODE_CHAR:
      if (TYPE_LENGTH (type) < sizeof (LONGEST))
	{
	  if (!TYPE_UNSIGNED (type))
	    {
	      *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
	      *highp = -*lowp - 1;
	      return 0;
	    }
	}
      /* fall through */
    default:
      return get_discrete_bounds (type, lowp, highp);
    }
}
Ejemplo n.º 23
0
/* Returns non-zero if the value is a boolean type */
int
boolean_type (struct type *type)
{
    CHECK_TYPEDEF (type);
    if (TYPE_CODE (type) == TYPE_CODE_BOOL)
        return 1;
    switch (current_language->la_language)
    {
    case language_c:
    case language_cplus:
    case language_objc:
        /* Might be more cleanly handled by having a
           TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such
           languages, or a TYPE_CODE_INT_OR_BOOL for C.  */
        if (TYPE_CODE (type) == TYPE_CODE_INT)
            return 1;
    default:
        break;
    }
    return 0;
}
Ejemplo n.º 24
0
/* Implements the la_val_print routine for language D.  */
void
d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
             CORE_ADDR address, struct ui_file *stream, int recurse,
	     const struct value *val,
             const struct value_print_options *options)
{
  int ret;

  CHECK_TYPEDEF (type);
  switch (TYPE_CODE (type))
    {
      case TYPE_CODE_STRUCT:
        ret = dynamic_array_type (type, valaddr, embedded_offset, address,
				  stream, recurse, val, options);
	if (ret == 0)
	  break;
      default:
	c_val_print (type, valaddr, embedded_offset, address, stream,
		     recurse, val, options);
    }
}
Ejemplo n.º 25
0
void
c_print_type (struct type *type, char *varstring, struct ui_file *stream,
	      int show, int level)
{
  enum type_code code;
  int demangled_args;
  int need_post_space;

  if (show > 0)
    CHECK_TYPEDEF (type);

  c_type_print_base (type, stream, show, level);
  code = TYPE_CODE (type);
  if ((varstring != NULL && *varstring != '\0')
      ||
  /* Need a space if going to print stars or brackets;
     but not if we will print just a type name.  */
      ((show > 0 || TYPE_NAME (type) == 0)
       &&
       (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
	|| code == TYPE_CODE_METHOD
	|| code == TYPE_CODE_ARRAY
	|| code == TYPE_CODE_MEMBERPTR
	|| code == TYPE_CODE_METHODPTR
	|| code == TYPE_CODE_REF)))
    fputs_filtered (" ", stream);
  need_post_space = (varstring != NULL && strcmp (varstring, "") != 0);
  c_type_print_varspec_prefix (type, stream, show, 0, need_post_space);

  if (varstring != NULL)
    {
      fputs_filtered (varstring, stream);

      /* For demangled function names, we have the arglist as part of the name,
         so don't print an additional pair of ()'s */

      demangled_args = strchr (varstring, '(') != NULL;
      c_type_print_varspec_suffix (type, stream, show, 0, demangled_args);
    }
}
Ejemplo n.º 26
0
int
is_object_type (struct type *type)
{
  CHECK_TYPEDEF (type);
  if (TYPE_CODE (type) == TYPE_CODE_PTR)
    {
      struct type *ttype = check_typedef (TYPE_TARGET_TYPE (type));
      const char *name;
      if (TYPE_CODE (ttype) != TYPE_CODE_STRUCT)
	return 0;
      while (TYPE_N_BASECLASSES (ttype) > 0)
	ttype = TYPE_BASECLASS (ttype, 0);
      name = TYPE_TAG_NAME (ttype);
      if (name != NULL && strcmp (name, "java.lang.Object") == 0)
	return 1;
      name
	= TYPE_NFIELDS (ttype) > 0 ? TYPE_FIELD_NAME (ttype, 0) : (char *) 0;
      if (name != NULL && strcmp (name, "vtable") == 0)
	return 1;
    }
  return 0;
}
Ejemplo n.º 27
0
/* Helper for expression_completer which recursively counts the number
   of named fields and methods in a structure or union type.  */
static int
count_struct_fields (struct type *type)
{
  int i, result = 0;

  CHECK_TYPEDEF (type);
  for (i = 0; i < TYPE_NFIELDS (type); ++i)
    {
      if (i < TYPE_N_BASECLASSES (type))
	result += count_struct_fields (TYPE_BASECLASS (type, i));
      else if (TYPE_FIELD_NAME (type, i))
	++result;
    }

  for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
    {
      if (TYPE_FN_FIELDLIST_NAME (type, i))
	++result;
    }

  return result;
}
static void
pascal_object_print_static_field (struct value *val,
				  struct ui_file *stream, int format,
				  int recurse, enum val_prettyprint pretty)
{
  struct type *type = value_type (val);

  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
    {
      CORE_ADDR *first_dont_print;
      int i;

      first_dont_print
	= (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
      i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
	- first_dont_print;

      while (--i >= 0)
	{
	  if (VALUE_ADDRESS (val) == first_dont_print[i])
	    {
	      fputs_filtered ("<same as static member of an already seen type>",
			      stream);
	      return;
	    }
	}

      obstack_grow (&dont_print_statmem_obstack, (char *) &VALUE_ADDRESS (val),
		    sizeof (CORE_ADDR));

      CHECK_TYPEDEF (type);
      pascal_object_print_value_fields (type, value_contents (val), VALUE_ADDRESS (val),
				  stream, format, recurse, pretty, NULL, 1);
      return;
    }
  common_val_print (val, stream, format, 0, recurse, pretty);
}
Ejemplo n.º 29
0
void
go_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
	      CORE_ADDR address, struct ui_file *stream, int recurse,
	      const struct value *val,
	      const struct value_print_options *options)
{
  CHECK_TYPEDEF (type);

  switch (TYPE_CODE (type))
    {
      case TYPE_CODE_STRUCT:
	{
	  enum go_type go_type = go_classify_struct_type (type);

	  switch (go_type)
	    {
	    case GO_TYPE_STRING:
	      if (! options->raw)
		{
		  print_go_string (type, valaddr, embedded_offset, address,
				   stream, recurse, val, options);
		  return;
		}
	      break;
	    default:
	      break;
	    }
	}
	/* Fall through.  */

      default:
	c_val_print (type, valaddr, embedded_offset, address, stream,
		     recurse, val, options);
	break;
    }
}
Ejemplo n.º 30
0
static struct type *
gnuv2_value_rtti_type (struct value *v, int *full, int *top, int *using_enc)
{
  struct type *known_type;
  struct type *rtti_type;
  CORE_ADDR vtbl;
  struct minimal_symbol *minsym;
  char *demangled_name;
  struct type *btype;

  if (full)
    *full = 0;
  if (top)
    *top = -1;
  if (using_enc)
    *using_enc = 0;

  /* Get declared type */
  known_type = value_type (v);
  CHECK_TYPEDEF (known_type);
  /* RTTI works only or class objects */
  if (TYPE_CODE (known_type) != TYPE_CODE_CLASS)
    return NULL;

  /* Plan on this changing in the future as i get around to setting
     the vtables properly for G++ compiled stuff.  Also, I'll be using
     the type info functions, which are always right.  Deal with it
     until then.
     JCI - This pretty much useless.  This gets the "true" type 
     correctly when there is single inheritance - but in all such  
     cases that I could find gdb already knows that.  In cases 
     where this points INTO the object (like non-virtual diamond 
     graphs) the demangled name is something like OUTER::INNER 
     and this is not a symbol gdb can resolve, so we fail & return 
     NULL anyway.  Seems like this really isn't going to work till 
     we actually call the RTTI function & parse it. 
*/

  /* If the type has no vptr fieldno, try to get it filled in */
  if (TYPE_VPTR_FIELDNO(known_type) < 0)
    fill_in_vptr_fieldno(known_type);

  /* If we still can't find one, give up */
  if (TYPE_VPTR_FIELDNO(known_type) < 0)
    return NULL;

  /* Make sure our basetype and known type match, otherwise, cast
     so we can get at the vtable properly.
  */
  btype = TYPE_VPTR_BASETYPE (known_type);
  CHECK_TYPEDEF (btype);
  if (btype != known_type )
    {
      v = value_cast (btype, v);
      if (using_enc)
        *using_enc=1;
    }
  /*
    We can't use value_ind here, because it would want to use RTTI, and
    we'd waste a bunch of time figuring out we already know the type.
    Besides, we don't care about the type, just the actual pointer
  */
  if (VALUE_ADDRESS (value_field (v, TYPE_VPTR_FIELDNO (known_type))) == 0)
    return NULL;

  vtbl=value_as_address(value_field(v,TYPE_VPTR_FIELDNO(known_type)));

  /* Try to find a symbol that is the vtable */
  minsym=lookup_minimal_symbol_by_pc(vtbl);
  if (minsym==NULL
      || (demangled_name=DEPRECATED_SYMBOL_NAME (minsym))==NULL
      || !is_vtable_name (demangled_name))
    return NULL;

  /* If we just skip the prefix, we get screwed by namespaces */
  demangled_name=cplus_demangle(demangled_name,DMGL_PARAMS|DMGL_ANSI);
  *(strchr(demangled_name,' '))=0;

  /* Lookup the type for the name */
  /* FIXME: chastain/2003-11-26: block=NULL is bogus.  See pr gdb/1465. */
  rtti_type = cp_lookup_rtti_type (demangled_name, NULL);
  if (rtti_type == NULL)
    return NULL;

  if (TYPE_N_BASECLASSES(rtti_type) > 1 &&  full && (*full) != 1)
    {
      if (top)
        *top=TYPE_BASECLASS_BITPOS(rtti_type,TYPE_VPTR_FIELDNO(rtti_type))/8;
      if (top && ((*top) >0))
        {
          if (TYPE_LENGTH(rtti_type) > TYPE_LENGTH(known_type))
            {
              if (full)
                *full=0;
            }
          else
            {
              if (full)
                *full=1;
            }
        }
    }
  else
    {
      if (full)
        *full=1;
    }

  return rtti_type;
}