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;
}
static void
val_print_packed_array_elements (struct type *type, char *valaddr,
				 int bitoffset, struct ui_file *stream,
				 int format, int recurse,
				 enum val_prettyprint pretty)
{
  unsigned int i;
  unsigned int things_printed = 0;
  unsigned len;
  struct type *elttype;
  unsigned eltlen;
  unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
  struct value *mark = value_mark ();

  elttype = TYPE_TARGET_TYPE (type);
  eltlen = TYPE_LENGTH (check_typedef (elttype));

  {
    LONGEST low, high;
    if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), &low, &high) < 0)
      len = 1;
    else
      len = high - low + 1;
  }

  i = 0;
  annotate_array_section_begin (i, elttype);

  while (i < len && things_printed < print_max)
    {
      struct value *v0, *v1;
      int i0;

      if (i != 0)
	{
	  if (prettyprint_arrays)
	    {
	      fprintf_filtered (stream, ",\n");
	      print_spaces_filtered (2 + 2 * recurse, stream);
	    }
	  else
	    {
	      fprintf_filtered (stream, ", ");
	    }
	}
      wrap_here (n_spaces (2 + 2 * recurse));

      i0 = i;
      v0 = ada_value_primitive_packed_val (NULL, valaddr,
					   (i0 * bitsize) / HOST_CHAR_BIT,
					   (i0 * bitsize) % HOST_CHAR_BIT,
					   bitsize, elttype);
      while (1)
	{
	  i += 1;
	  if (i >= len)
	    break;
	  v1 = ada_value_primitive_packed_val (NULL, valaddr,
					       (i * bitsize) / HOST_CHAR_BIT,
					       (i * bitsize) % HOST_CHAR_BIT,
					       bitsize, elttype);
	  if (memcmp (VALUE_CONTENTS (v0), VALUE_CONTENTS (v1), eltlen) != 0)
	    break;
	}

      if (i - i0 > repeat_count_threshold)
	{
	  val_print (elttype, VALUE_CONTENTS (v0), 0, 0, stream, format,
		     0, recurse + 1, pretty);
	  annotate_elt_rep (i - i0);
	  fprintf_filtered (stream, " <repeats %u times>", i - i0);
	  annotate_elt_rep_end ();

	}
      else
	{
	  int j;
	  for (j = i0; j < i; j += 1)
	    {
	      if (j > i0)
		{
		  if (prettyprint_arrays)
		    {
		      fprintf_filtered (stream, ",\n");
		      print_spaces_filtered (2 + 2 * recurse, stream);
		    }
		  else
		    {
		      fprintf_filtered (stream, ", ");
		    }
		  wrap_here (n_spaces (2 + 2 * recurse));
		}
	      val_print (elttype, VALUE_CONTENTS (v0), 0, 0, stream, format,
			 0, recurse + 1, pretty);
	      annotate_elt ();
	    }
	}
      things_printed += i - i0;
    }
  annotate_array_section_end ();
  if (i < len)
    {
      fprintf_filtered (stream, "...");
    }

  value_free_to_mark (mark);
}
static int
ada_val_print_1 (struct type *type, char *valaddr0, int embedded_offset,
		 CORE_ADDR address, struct ui_file *stream, int format,
		 int deref_ref, int recurse, enum val_prettyprint pretty)
{
  unsigned int len;
  int i;
  struct type *elttype;
  unsigned int eltlen;
  LONGEST val;
  char *valaddr = valaddr0 + embedded_offset;

  CHECK_TYPEDEF (type);

  if (ada_is_array_descriptor_type (type) || ada_is_packed_array_type (type))
    {
      int retn;
      struct value *mark = value_mark ();
      struct value *val;
      val = value_from_contents_and_address (type, valaddr, address);
      val = ada_coerce_to_simple_array_ptr (val);
      if (val == NULL)
	{
	  fprintf_filtered (stream, "(null)");
	  retn = 0;
	}
      else
	retn = ada_val_print_1 (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
				VALUE_ADDRESS (val), stream, format,
				deref_ref, recurse, pretty);
      value_free_to_mark (mark);
      return retn;
    }

  valaddr = ada_aligned_value_addr (type, valaddr);
  embedded_offset -= valaddr - valaddr0 - embedded_offset;
  type = printable_val_type (type, valaddr);

  switch (TYPE_CODE (type))
    {
    default:
      return c_val_print (type, valaddr0, embedded_offset, address, stream,
			  format, deref_ref, recurse, pretty);

    case TYPE_CODE_PTR:
      {
	int ret = c_val_print (type, valaddr0, embedded_offset, address, 
			       stream, format, deref_ref, recurse, pretty);
	if (ada_is_tag_type (type))
	  {
	    struct value *val = 
	      value_from_contents_and_address (type, valaddr, address);
	    const char *name = ada_tag_name (val);
	    if (name != NULL) 
	      fprintf_filtered (stream, " (%s)", name);
	    return 0;
	}
	return ret;
      }

    case TYPE_CODE_INT:
    case TYPE_CODE_RANGE:
      if (ada_is_fixed_point_type (type))
	{
	  LONGEST v = unpack_long (type, valaddr);
	  int len = TYPE_LENGTH (type);

	  fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g",
			    (double) ada_fixed_to_float (type, v));
	  return 0;
	}
      else if (ada_is_vax_floating_type (type))
	{
	  struct value *val =
	    value_from_contents_and_address (type, valaddr, address);
	  struct value *func = ada_vax_float_print_function (type);
	  if (func != 0)
	    {
	      static struct type *parray_of_char = NULL;
	      struct value *printable_val;

	      if (parray_of_char == NULL)
		parray_of_char =
		  make_pointer_type
		  (create_array_type
		   (NULL, builtin_type_char,
		    create_range_type (NULL, builtin_type_int, 0, 32)), NULL);

	      printable_val =
		value_ind (value_cast (parray_of_char,
				       call_function_by_hand (func, 1,
							      &val)));

	      fprintf_filtered (stream, "%s", VALUE_CONTENTS (printable_val));
	      return 0;
	    }
	  /* No special printing function.  Do as best we can.  */
	}
      else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
	{
	  struct type *target_type = TYPE_TARGET_TYPE (type);
	  if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
	    {
	      /* Obscure case of range type that has different length from
	         its base type.  Perform a conversion, or we will get a
	         nonsense value.  Actually, we could use the same
	         code regardless of lengths; I'm just avoiding a cast.  */
	      struct value *v = value_cast (target_type,
					    value_from_contents_and_address
					    (type, valaddr, 0));
	      return ada_val_print_1 (target_type, VALUE_CONTENTS (v), 0, 0,
				      stream, format, 0, recurse + 1, pretty);
	    }
	  else
	    return ada_val_print_1 (TYPE_TARGET_TYPE (type),
				    valaddr0, embedded_offset,
				    address, stream, format, deref_ref,
				    recurse, pretty);
	}
      else
	{
	  format = format ? format : output_format;
	  if (format)
	    {
	      print_scalar_formatted (valaddr, type, format, 0, stream);
	    }
          else if (ada_is_system_address_type (type))
            {
              /* FIXME: We want to print System.Address variables using
                 the same format as for any access type.  But for some
                 reason GNAT encodes the System.Address type as an int,
                 so we have to work-around this deficiency by handling
                 System.Address values as a special case.  */
              fprintf_filtered (stream, "(");
              type_print (type, "", stream, -1);
              fprintf_filtered (stream, ") ");
              print_address_numeric 
		(extract_typed_address (valaddr, builtin_type_void_data_ptr),
                 1, stream);
            }
	  else
	    {
	      val_print_type_code_int (type, valaddr, stream);
	      if (ada_is_character_type (type))
		{
		  fputs_filtered (" ", stream);
		  ada_printchar ((unsigned char) unpack_long (type, valaddr),
				 stream);
		}
	    }
	  return 0;
	}

    case TYPE_CODE_ENUM:
      if (format)
	{
	  print_scalar_formatted (valaddr, type, format, 0, stream);
	  break;
	}
      len = TYPE_NFIELDS (type);
      val = unpack_long (type, valaddr);
      for (i = 0; i < len; i++)
	{
	  QUIT;
	  if (val == TYPE_FIELD_BITPOS (type, i))
	    {
	      break;
	    }
	}
      if (i < len)
	{
	  const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
	  if (name[0] == '\'')
	    fprintf_filtered (stream, "%ld %s", (long) val, name);
	  else
	    fputs_filtered (name, stream);
	}
      else
	{
	  print_longest (stream, 'd', 0, val);
	}
      break;

    case TYPE_CODE_FLT:
      if (format)
	return c_val_print (type, valaddr0, embedded_offset, address, stream,
			    format, deref_ref, recurse, pretty);
      else
	ada_print_floating (valaddr0 + embedded_offset, type, stream);
      break;

    case TYPE_CODE_UNION:
    case TYPE_CODE_STRUCT:
      if (ada_is_bogus_array_descriptor (type))
	{
	  fprintf_filtered (stream, "(...?)");
	  return 0;
	}
      else
	{
	  print_record (type, valaddr, stream, format, recurse, pretty);
	  return 0;
	}

    case TYPE_CODE_ARRAY:
      elttype = TYPE_TARGET_TYPE (type);
      if (elttype == NULL)
	eltlen = 0;
      else
	eltlen = TYPE_LENGTH (elttype);
      /* FIXME: This doesn't deal with non-empty arrays of
	 0-length items (not a typical case!) */
      if (eltlen == 0)
	len = 0;
      else
	len = TYPE_LENGTH (type) / eltlen;

	  /* For an array of chars, print with string syntax.  */
      if (ada_is_string_type (type) && (format == 0 || format == 's'))
	{
	  if (prettyprint_arrays)
	    {
	      print_spaces_filtered (2 + 2 * recurse, stream);
	    }
	  /* If requested, look for the first null char and only print
	     elements up to it.  */
	  if (stop_print_at_null)
	    {
	      int temp_len;

	      /* Look for a NULL char.  */
	      for (temp_len = 0;
		   temp_len < len && temp_len < print_max
		     && char_at (valaddr, temp_len, eltlen) != 0;
		   temp_len += 1);
	      len = temp_len;
	    }

	  printstr (stream, valaddr, len, 0, eltlen);
	}
      else
	{
	  len = 0;
	  fprintf_filtered (stream, "(");
	  print_optional_low_bound (stream, type);
	  if (TYPE_FIELD_BITSIZE (type, 0) > 0)
	    val_print_packed_array_elements (type, valaddr, 0, stream,
					     format, recurse, pretty);
	  else
	    val_print_array_elements (type, valaddr, address, stream,
				      format, deref_ref, recurse,
				      pretty, 0);
	  fprintf_filtered (stream, ")");
	}
      gdb_flush (stream);
      return len;

    case TYPE_CODE_REF:
      elttype = check_typedef (TYPE_TARGET_TYPE (type));
      /* De-reference the reference */
      if (deref_ref)
	{
	  if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
	    {
	      LONGEST deref_val_int = (LONGEST)
		unpack_pointer (lookup_pointer_type (builtin_type_void),
				valaddr);
	      if (deref_val_int != 0)
		{
		  struct value *deref_val =
		    ada_value_ind (value_from_longest
				   (lookup_pointer_type (elttype),
				    deref_val_int));
		  val_print (VALUE_TYPE (deref_val),
			     VALUE_CONTENTS (deref_val), 0,
			     VALUE_ADDRESS (deref_val), stream, format,
			     deref_ref, recurse + 1, pretty);
		}
	      else
		fputs_filtered ("(null)", stream);
	    }
	  else
	    fputs_filtered ("???", stream);
	}
      break;
    }
  gdb_flush (stream);
  return 0;
}
示例#4
0
static CORE_ADDR
mn10300_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
			int struct_return, CORE_ADDR struct_addr)
{
  int argnum = 0;
  int len = 0;
  int stack_offset = 0;
  int regsused = struct_return ? 1 : 0;

  /* This should be a nop, but align the stack just in case something
     went wrong.  Stacks are four byte aligned on the mn10300.  */
  sp &= ~3;

  /* Now make space on the stack for the args.

     XXX This doesn't appear to handle pass-by-invisible reference
     arguments.  */
  for (argnum = 0; argnum < nargs; argnum++)
    {
      int arg_length = (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 3) & ~3;

      while (regsused < 2 && arg_length > 0)
	{
	  regsused++;
	  arg_length -= 4;
	}
      len += arg_length;
    }

  /* Allocate stack space.  */
  sp -= len;

  regsused = struct_return ? 1 : 0;
  /* Push all arguments onto the stack. */
  for (argnum = 0; argnum < nargs; argnum++)
    {
      int len;
      char *val;

      /* XXX Check this.  What about UNIONS?  */
      if (TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_STRUCT
	  && TYPE_LENGTH (VALUE_TYPE (*args)) > 8)
	{
	  /* XXX Wrong, we want a pointer to this argument.  */
	  len = TYPE_LENGTH (VALUE_TYPE (*args));
	  val = (char *) VALUE_CONTENTS (*args);
	}
      else
	{
	  len = TYPE_LENGTH (VALUE_TYPE (*args));
	  val = (char *) VALUE_CONTENTS (*args);
	}

      while (regsused < 2 && len > 0)
	{
	  write_register (regsused, extract_unsigned_integer (val, 4));
	  val += 4;
	  len -= 4;
	  regsused++;
	}

      while (len > 0)
	{
	  write_memory (sp + stack_offset, val, 4);
	  len -= 4;
	  val += 4;
	  stack_offset += 4;
	}

      args++;
    }

  /* Make space for the flushback area.  */
  sp -= 8;
  return sp;
}
示例#5
0
CORE_ADDR
ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                                struct regcache *regcache, CORE_ADDR bp_addr,
                                int nargs, struct value **args, CORE_ADDR sp,
                                int struct_return, CORE_ADDR struct_addr)
{
    CORE_ADDR func_addr = find_function_addr (function, NULL);
    struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
    /* By this stage in the proceedings, SP has been decremented by "red
       zone size" + "struct return size".  Fetch the stack-pointer from
       before this and use that as the BACK_CHAIN.  */
    const CORE_ADDR back_chain = read_sp ();
    /* See for-loop comment below.  */
    int write_pass;
    /* Size of the Altivec's vector parameter region, the final value is
       computed in the for-loop below.  */
    LONGEST vparam_size = 0;
    /* Size of the general parameter region, the final value is computed
       in the for-loop below.  */
    LONGEST gparam_size = 0;
    /* Kevin writes ... I don't mind seeing tdep->wordsize used in the
       calls to align_up(), align_down(), etc.  because this makes it
       easier to reuse this code (in a copy/paste sense) in the future,
       but it is a 64-bit ABI and asserting that the wordsize is 8 bytes
       at some point makes it easier to verify that this function is
       correct without having to do a non-local analysis to figure out
       the possible values of tdep->wordsize.  */
    gdb_assert (tdep->wordsize == 8);

    /* Go through the argument list twice.

       Pass 1: Compute the function call's stack space and register
       requirements.

       Pass 2: Replay the same computation but this time also write the
       values out to the target.  */

    for (write_pass = 0; write_pass < 2; write_pass++)
    {
        int argno;
        /* Next available floating point register for float and double
           arguments.  */
        int freg = 1;
        /* Next available general register for non-vector (but possibly
           float) arguments.  */
        int greg = 3;
        /* Next available vector register for vector arguments.  */
        int vreg = 2;
        /* The address, at which the next general purpose parameter
           (integer, struct, float, ...) should be saved.  */
        CORE_ADDR gparam;
        /* Address, at which the next Altivec vector parameter should be
           saved.  */
        CORE_ADDR vparam;

        if (!write_pass)
        {
            /* During the first pass, GPARAM and VPARAM are more like
               offsets (start address zero) than addresses.  That way
               the accumulate the total stack space each region
               requires.  */
            gparam = 0;
            vparam = 0;
        }
        else
        {
            /* Decrement the stack pointer making space for the Altivec
               and general on-stack parameters.  Set vparam and gparam
               to their corresponding regions.  */
            vparam = align_down (sp - vparam_size, 16);
            gparam = align_down (vparam - gparam_size, 16);
            /* Add in space for the TOC, link editor double word,
               compiler double word, LR save area, CR save area.  */
            sp = align_down (gparam - 48, 16);
        }

        /* If the function is returning a `struct', then there is an
           extra hidden parameter (which will be passed in r3)
           containing the address of that struct..  In that case we
           should advance one word and start from r4 register to copy
           parameters.  This also consumes one on-stack parameter slot.  */
        if (struct_return)
        {
            if (write_pass)
                regcache_cooked_write_signed (regcache,
                                              tdep->ppc_gp0_regnum + greg,
                                              struct_addr);
            greg++;
            gparam = align_up (gparam + tdep->wordsize, tdep->wordsize);
        }

        for (argno = 0; argno < nargs; argno++)
        {
            struct value *arg = args[argno];
            struct type *type = check_typedef (VALUE_TYPE (arg));
            char *val = VALUE_CONTENTS (arg);
            if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8)
            {
                /* Floats and Doubles go in f1 .. f13.  They also
                   consume a left aligned GREG,, and can end up in
                   memory.  */
                if (write_pass)
                {
                    if (ppc_floating_point_unit_p (current_gdbarch)
                            && freg <= 13)
                    {
                        char regval[MAX_REGISTER_SIZE];
                        struct type *regtype
                            = register_type (gdbarch, tdep->ppc_fp0_regnum);
                        convert_typed_floating (val, type, regval, regtype);
                        regcache_cooked_write (regcache,
                                               tdep->ppc_fp0_regnum + freg,
                                               regval);
                    }
                    if (greg <= 10)
                    {
                        /* The ABI states "Single precision floating
                           point values are mapped to the first word in
                           a single doubleword" and "... floating point
                           values mapped to the first eight doublewords
                           of the parameter save area are also passed in
                           general registers").

                           This code interprets that to mean: store it,
                           left aligned, in the general register.  */
                        char regval[MAX_REGISTER_SIZE];
                        memset (regval, 0, sizeof regval);
                        memcpy (regval, val, TYPE_LENGTH (type));
                        regcache_cooked_write (regcache,
                                               tdep->ppc_gp0_regnum + greg,
                                               regval);
                    }
                    write_memory (gparam, val, TYPE_LENGTH (type));
                }
                /* Always consume parameter stack space.  */
                freg++;
                greg++;
                gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
            }
            else if (TYPE_LENGTH (type) == 16 && TYPE_VECTOR (type)
                     && TYPE_CODE (type) == TYPE_CODE_ARRAY
                     && tdep->ppc_vr0_regnum >= 0)
            {
                /* In the Altivec ABI, vectors go in the vector
                   registers v2 .. v13, or when that runs out, a vector
                   annex which goes above all the normal parameters.
                   NOTE: cagney/2003-09-21: This is a guess based on the
                   PowerOpen Altivec ABI.  */
                if (vreg <= 13)
                {
                    if (write_pass)
                        regcache_cooked_write (regcache,
                                               tdep->ppc_vr0_regnum + vreg, val);
                    vreg++;
                }
                else
                {
                    if (write_pass)
                        write_memory (vparam, val, TYPE_LENGTH (type));
                    vparam = align_up (vparam + TYPE_LENGTH (type), 16);
                }
            }
            else if ((TYPE_CODE (type) == TYPE_CODE_INT
                      || TYPE_CODE (type) == TYPE_CODE_ENUM)
                     && TYPE_LENGTH (type) <= 8)
            {
                /* Scalars get sign[un]extended and go in gpr3 .. gpr10.
                   They can also end up in memory.  */
                if (write_pass)
                {
                    /* Sign extend the value, then store it unsigned.  */
                    ULONGEST word = unpack_long (type, val);
                    if (greg <= 10)
                        regcache_cooked_write_unsigned (regcache,
                                                        tdep->ppc_gp0_regnum +
                                                        greg, word);
                    write_memory_unsigned_integer (gparam, tdep->wordsize,
                                                   word);
                }
                greg++;
                gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
            }
            else
            {
                int byte;
                for (byte = 0; byte < TYPE_LENGTH (type);
                        byte += tdep->wordsize)
                {
                    if (write_pass && greg <= 10)
                    {
                        char regval[MAX_REGISTER_SIZE];
                        int len = TYPE_LENGTH (type) - byte;
                        if (len > tdep->wordsize)
                            len = tdep->wordsize;
                        memset (regval, 0, sizeof regval);
                        /* WARNING: cagney/2003-09-21: As best I can
                           tell, the ABI specifies that the value should
                           be left aligned.  Unfortunately, GCC doesn't
                           do this - it instead right aligns even sized
                           values and puts odd sized values on the
                           stack.  Work around that by putting both a
                           left and right aligned value into the
                           register (hopefully no one notices :-^).
                           Arrrgh!  */
                        /* Left aligned (8 byte values such as pointers
                           fill the buffer).  */
                        memcpy (regval, val + byte, len);
                        /* Right aligned (but only if even).  */
                        if (len == 1 || len == 2 || len == 4)
                            memcpy (regval + tdep->wordsize - len,
                                    val + byte, len);
                        regcache_cooked_write (regcache, greg, regval);
                    }
                    greg++;
                }
                if (write_pass)
                    /* WARNING: cagney/2003-09-21: Strictly speaking, this
                       isn't necessary, unfortunately, GCC appears to get
                       "struct convention" parameter passing wrong putting
                       odd sized structures in memory instead of in a
                       register.  Work around this by always writing the
                       value to memory.  Fortunately, doing this
                       simplifies the code.  */
                    write_memory (gparam, val, TYPE_LENGTH (type));
                /* Always consume parameter stack space.  */
                gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize);
            }
        }

        if (!write_pass)
        {
            /* Save the true region sizes ready for the second pass.  */
            vparam_size = vparam;
            /* Make certain that the general parameter save area is at
               least the minimum 8 registers (or doublewords) in size.  */
            if (greg < 8)
                gparam_size = 8 * tdep->wordsize;
            else
                gparam_size = gparam;
        }
    }

    /* Update %sp.   */
    regcache_cooked_write_signed (regcache, SP_REGNUM, sp);

    /* Write the backchain (it occupies WORDSIZED bytes).  */
    write_memory_signed_integer (sp, tdep->wordsize, back_chain);

    /* Point the inferior function call's return address at the dummy's
       breakpoint.  */
    regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);

    /* Find a value for the TOC register.  Every symbol should have both
       ".FN" and "FN" in the minimal symbol table.  "FN" points at the
       FN's descriptor, while ".FN" points at the entry point (which
       matches FUNC_ADDR).  Need to reverse from FUNC_ADDR back to the
       FN's descriptor address (while at the same time being careful to
       find "FN" in the same object file as ".FN").  */
    {
        /* Find the minimal symbol that corresponds to FUNC_ADDR (should
           have the name ".FN").  */
        struct minimal_symbol *dot_fn = lookup_minimal_symbol_by_pc (func_addr);
        if (dot_fn != NULL && SYMBOL_LINKAGE_NAME (dot_fn)[0] == '.')
        {
            /* Get the section that contains FUNC_ADR.  Need this for the
                   "objfile" that it contains.  */
            struct obj_section *dot_fn_section = find_pc_section (func_addr);
            if (dot_fn_section != NULL && dot_fn_section->objfile != NULL)
            {
                /* Now find the corresponding "FN" (dropping ".") minimal
                   symbol's address.  Only look for the minimal symbol in
                   ".FN"'s object file - avoids problems when two object
                   files (i.e., shared libraries) contain a minimal symbol
                   with the same name.  */
                struct minimal_symbol *fn =
                    lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL,
                                           dot_fn_section->objfile);
                if (fn != NULL)
                {
                    /* Got the address of that descriptor.  The TOC is the
                       second double word.  */
                    CORE_ADDR toc =
                        read_memory_unsigned_integer (SYMBOL_VALUE_ADDRESS (fn)
                                                      + tdep->wordsize,
                                                      tdep->wordsize);
                    regcache_cooked_write_unsigned (regcache,
                                                    tdep->ppc_gp0_regnum + 2, toc);
                }
            }
        }
    }

    return sp;
}
示例#6
0
CORE_ADDR
ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                              struct regcache *regcache, CORE_ADDR bp_addr,
                              int nargs, struct value **args, CORE_ADDR sp,
                              int struct_return, CORE_ADDR struct_addr)
{
    struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
    const CORE_ADDR saved_sp = read_sp ();
    int argspace = 0;		/* 0 is an initial wrong guess.  */
    int write_pass;

    /* Go through the argument list twice.

       Pass 1: Figure out how much new stack space is required for
       arguments and pushed values.  Unlike the PowerOpen ABI, the SysV
       ABI doesn't reserve any extra space for parameters which are put
       in registers, but does always push structures and then pass their
       address.

       Pass 2: Replay the same computation but this time also write the
       values out to the target.  */

    for (write_pass = 0; write_pass < 2; write_pass++)
    {
        int argno;
        /* Next available floating point register for float and double
           arguments.  */
        int freg = 1;
        /* Next available general register for non-float, non-vector
           arguments.  */
        int greg = 3;
        /* Next available vector register for vector arguments.  */
        int vreg = 2;
        /* Arguments start above the "LR save word" and "Back chain".  */
        int argoffset = 2 * tdep->wordsize;
        /* Structures start after the arguments.  */
        int structoffset = argoffset + argspace;

        /* If the function is returning a `struct', then the first word
           (which will be passed in r3) is used for struct return
           address.  In that case we should advance one word and start
           from r4 register to copy parameters.  */
        if (struct_return)
        {
            if (write_pass)
                regcache_cooked_write_signed (regcache,
                                              tdep->ppc_gp0_regnum + greg,
                                              struct_addr);
            greg++;
        }

        for (argno = 0; argno < nargs; argno++)
        {
            struct value *arg = args[argno];
            struct type *type = check_typedef (VALUE_TYPE (arg));
            int len = TYPE_LENGTH (type);
            char *val = VALUE_CONTENTS (arg);

            if (TYPE_CODE (type) == TYPE_CODE_FLT
                    && ppc_floating_point_unit_p (current_gdbarch) && len <= 8)
            {
                /* Floating point value converted to "double" then
                   passed in an FP register, when the registers run out,
                   8 byte aligned stack is used.  */
                if (freg <= 8)
                {
                    if (write_pass)
                    {
                        /* Always store the floating point value using
                           the register's floating-point format.  */
                        char regval[MAX_REGISTER_SIZE];
                        struct type *regtype
                            = register_type (gdbarch, tdep->ppc_fp0_regnum + freg);
                        convert_typed_floating (val, type, regval, regtype);
                        regcache_cooked_write (regcache,
                                               tdep->ppc_fp0_regnum + freg,
                                               regval);
                    }
                    freg++;
                }
                else
                {
                    /* SysV ABI converts floats to doubles before
                       writing them to an 8 byte aligned stack location.  */
                    argoffset = align_up (argoffset, 8);
                    if (write_pass)
                    {
                        char memval[8];
                        struct type *memtype;
                        switch (TARGET_BYTE_ORDER)
                        {
                        case BFD_ENDIAN_BIG:
                            memtype = builtin_type_ieee_double_big;
                            break;
                        case BFD_ENDIAN_LITTLE:
                            memtype = builtin_type_ieee_double_little;
                            break;
                        default:
                            internal_error (__FILE__, __LINE__, "bad switch");
                        }
                        convert_typed_floating (val, type, memval, memtype);
                        write_memory (sp + argoffset, val, len);
                    }
                    argoffset += 8;
                }
            }
            else if (len == 8 && (TYPE_CODE (type) == TYPE_CODE_INT	/* long long */
                                  || (!ppc_floating_point_unit_p (current_gdbarch) && TYPE_CODE (type) == TYPE_CODE_FLT)))	/* double */
            {
                /* "long long" or "double" passed in an odd/even
                   register pair with the low addressed word in the odd
                   register and the high addressed word in the even
                   register, or when the registers run out an 8 byte
                   aligned stack location.  */
                if (greg > 9)
                {
                    /* Just in case GREG was 10.  */
                    greg = 11;
                    argoffset = align_up (argoffset, 8);
                    if (write_pass)
                        write_memory (sp + argoffset, val, len);
                    argoffset += 8;
                }
                else if (tdep->wordsize == 8)
                {
                    if (write_pass)
                        regcache_cooked_write (regcache,
                                               tdep->ppc_gp0_regnum + greg, val);
                    greg += 1;
                }
                else
                {
                    /* Must start on an odd register - r3/r4 etc.  */
                    if ((greg & 1) == 0)
                        greg++;
                    if (write_pass)
                    {
                        regcache_cooked_write (regcache,
                                               tdep->ppc_gp0_regnum + greg + 0,
                                               val + 0);
                        regcache_cooked_write (regcache,
                                               tdep->ppc_gp0_regnum + greg + 1,
                                               val + 4);
                    }
                    greg += 2;
                }
            }
            else if (len == 16
                     && TYPE_CODE (type) == TYPE_CODE_ARRAY
                     && TYPE_VECTOR (type) && tdep->ppc_vr0_regnum >= 0)
            {
                /* Vector parameter passed in an Altivec register, or
                   when that runs out, 16 byte aligned stack location.  */
                if (vreg <= 13)
                {
                    if (write_pass)
                        regcache_cooked_write (current_regcache,
                                               tdep->ppc_vr0_regnum + vreg, val);
                    vreg++;
                }
                else
                {
                    argoffset = align_up (argoffset, 16);
                    if (write_pass)
                        write_memory (sp + argoffset, val, 16);
                    argoffset += 16;
                }
            }
            else if (len == 8
                     && TYPE_CODE (type) == TYPE_CODE_ARRAY
                     && TYPE_VECTOR (type) && tdep->ppc_ev0_regnum >= 0)
            {
                /* Vector parameter passed in an e500 register, or when
                   that runs out, 8 byte aligned stack location.  Note
                   that since e500 vector and general purpose registers
                   both map onto the same underlying register set, a
                   "greg" and not a "vreg" is consumed here.  A cooked
                   write stores the value in the correct locations
                   within the raw register cache.  */
                if (greg <= 10)
                {
                    if (write_pass)
                        regcache_cooked_write (current_regcache,
                                               tdep->ppc_ev0_regnum + greg, val);
                    greg++;
                }
                else
                {
                    argoffset = align_up (argoffset, 8);
                    if (write_pass)
                        write_memory (sp + argoffset, val, 8);
                    argoffset += 8;
                }
            }
            else
            {
                /* Reduce the parameter down to something that fits in a
                   "word".  */
                char word[MAX_REGISTER_SIZE];
                memset (word, 0, MAX_REGISTER_SIZE);
                if (len > tdep->wordsize
                        || TYPE_CODE (type) == TYPE_CODE_STRUCT
                        || TYPE_CODE (type) == TYPE_CODE_UNION)
                {
                    /* Structs and large values are put on an 8 byte
                       aligned stack ... */
                    structoffset = align_up (structoffset, 8);
                    if (write_pass)
                        write_memory (sp + structoffset, val, len);
                    /* ... and then a "word" pointing to that address is
                       passed as the parameter.  */
                    store_unsigned_integer (word, tdep->wordsize,
                                            sp + structoffset);
                    structoffset += len;
                }
                else if (TYPE_CODE (type) == TYPE_CODE_INT)
                    /* Sign or zero extend the "int" into a "word".  */
                    store_unsigned_integer (word, tdep->wordsize,
                                            unpack_long (type, val));
                else
                    /* Always goes in the low address.  */
                    memcpy (word, val, len);
                /* Store that "word" in a register, or on the stack.
                   The words have "4" byte alignment.  */
                if (greg <= 10)
                {
                    if (write_pass)
                        regcache_cooked_write (regcache,
                                               tdep->ppc_gp0_regnum + greg, word);
                    greg++;
                }
                else
                {
                    argoffset = align_up (argoffset, tdep->wordsize);
                    if (write_pass)
                        write_memory (sp + argoffset, word, tdep->wordsize);
                    argoffset += tdep->wordsize;
                }
            }
        }

        /* Compute the actual stack space requirements.  */
        if (!write_pass)
        {
            /* Remember the amount of space needed by the arguments.  */
            argspace = argoffset;
            /* Allocate space for both the arguments and the structures.  */
            sp -= (argoffset + structoffset);
            /* Ensure that the stack is still 16 byte aligned.  */
            sp = align_down (sp, 16);
        }
    }

    /* Update %sp.   */
    regcache_cooked_write_signed (regcache, SP_REGNUM, sp);

    /* Write the backchain (it occupies WORDSIZED bytes).  */
    write_memory_signed_integer (sp, tdep->wordsize, saved_sp);

    /* Point the inferior function call's return address at the dummy's
       breakpoint.  */
    regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);

    return sp;
}
示例#7
0
文件: sparc-tdep.c 项目: DonCN/haiku
static CORE_ADDR
sparc32_store_arguments (struct regcache *regcache, int nargs,
			 struct value **args, CORE_ADDR sp,
			 int struct_return, CORE_ADDR struct_addr)
{
  /* Number of words in the "parameter array".  */
  int num_elements = 0;
  int element = 0;
  int i;

  for (i = 0; i < nargs; i++)
    {
      struct type *type = VALUE_TYPE (args[i]);
      int len = TYPE_LENGTH (type);

      if (sparc_structure_or_union_p (type)
	  || (sparc_floating_p (type) && len == 16))
	{
	  /* Structure, Union and Quad-Precision Arguments.  */
	  sp -= len;

	  /* Use doubleword alignment for these values.  That's always
             correct, and wasting a few bytes shouldn't be a problem.  */
	  sp &= ~0x7;

	  write_memory (sp, VALUE_CONTENTS (args[i]), len);
	  args[i] = value_from_pointer (lookup_pointer_type (type), sp);
	  num_elements++;
	}
      else if (sparc_floating_p (type))
	{
	  /* Floating arguments.  */
	  gdb_assert (len == 4 || len == 8);
	  num_elements += (len / 4);
	}
      else
	{
	  /* Integral and pointer arguments.  */
	  gdb_assert (sparc_integral_or_pointer_p (type));

	  if (len < 4)
	    args[i] = value_cast (builtin_type_int32, args[i]);
	  num_elements += ((len + 3) / 4);
	}
    }

  /* Always allocate at least six words.  */
  sp -= max (6, num_elements) * 4;

  /* The psABI says that "Software convention requires space for the
     struct/union return value pointer, even if the word is unused."  */
  sp -= 4;

  /* The psABI says that "Although software convention and the
     operating system require every stack frame to be doubleword
     aligned."  */
  sp &= ~0x7;

  for (i = 0; i < nargs; i++)
    {
      char *valbuf = VALUE_CONTENTS (args[i]);
      struct type *type = VALUE_TYPE (args[i]);
      int len = TYPE_LENGTH (type);

      gdb_assert (len == 4 || len == 8);

      if (element < 6)
	{
	  int regnum = SPARC_O0_REGNUM + element;

	  regcache_cooked_write (regcache, regnum, valbuf);
	  if (len > 4 && element < 5)
	    regcache_cooked_write (regcache, regnum + 1, valbuf + 4);
	}

      /* Always store the argument in memory.  */
      write_memory (sp + 4 + element * 4, valbuf, len);
      element += len / 4;
    }

  gdb_assert (element == num_elements);

  if (struct_return)
    {
      char buf[4];

      store_unsigned_integer (buf, 4, struct_addr);
      write_memory (sp, buf, 4);
    }

  return sp;
}
示例#8
0
int
c_val_print (struct type *type, char *valaddr, int embedded_offset,
	     CORE_ADDR address, struct ui_file *stream, int format,
	     int deref_ref, int recurse, enum val_prettyprint pretty)
{
  register unsigned int i = 0;	/* Number of characters printed */
  unsigned len;
  struct type *elttype;
  unsigned eltlen;
  LONGEST val;
  CORE_ADDR addr;

  CHECK_TYPEDEF (type);
  switch (TYPE_CODE (type))
    {
    case TYPE_CODE_ARRAY:
      elttype = check_typedef (TYPE_TARGET_TYPE (type));
      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
	{
	  eltlen = TYPE_LENGTH (elttype);
	  len = TYPE_LENGTH (type) / eltlen;
	  if (prettyprint_arrays)
	    {
	      print_spaces_filtered (2 + 2 * recurse, stream);
	    }
	  /* For an array of chars, print with string syntax.  */
	  if (eltlen == 1 &&
	      ((TYPE_CODE (elttype) == TYPE_CODE_INT)
	       || ((current_language->la_language == language_m2)
		   && (TYPE_CODE (elttype) == TYPE_CODE_CHAR)))
	      && (format == 0 || format == 's'))
	    {
	      /* If requested, look for the first null char and only print
	         elements up to it.  */
	      if (stop_print_at_null)
		{
		  unsigned int temp_len;

		  /* Look for a NULL char. */
		  for (temp_len = 0;
		       (valaddr + embedded_offset)[temp_len]
		       && temp_len < len && temp_len < print_max;
		       temp_len++);
		  len = temp_len;
		}

	      LA_PRINT_STRING (stream, valaddr + embedded_offset, len, eltlen, 0);
	      i = len;
	    }
	  else
	    {
	      fprintf_filtered (stream, "{");
	      /* If this is a virtual function table, print the 0th
	         entry specially, and the rest of the members normally.  */
	      if (cp_is_vtbl_ptr_type (elttype))
		{
		  i = 1;
		  fprintf_filtered (stream, "%d vtable entries", len - 1);
		}
	      else
		{
		  i = 0;
		}
	      val_print_array_elements (type, valaddr + embedded_offset, address, stream,
				     format, deref_ref, recurse, pretty, i);
	      fprintf_filtered (stream, "}");
	    }
	  break;
	}
      /* Array of unspecified length: treat like pointer to first elt.  */
      addr = address;
      goto print_unpacked_pointer;

    case TYPE_CODE_PTR:
      if (format && format != 's')
	{
	  print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
	  break;
	}
      if (vtblprint && cp_is_vtbl_ptr_type (type))
	{
	  /* Print the unmangled name if desired.  */
	  /* Print vtable entry - we only get here if we ARE using
	     -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.) */
	  CORE_ADDR addr
	    = extract_typed_address (valaddr + embedded_offset, type);
	  print_function_pointer_address (addr, stream);
	  break;
	}
      elttype = check_typedef (TYPE_TARGET_TYPE (type));
      if (TYPE_CODE (elttype) == TYPE_CODE_METHOD)
	{
	  cp_print_class_method (valaddr + embedded_offset, type, stream);
	}
      else if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER)
	{
	  cp_print_class_member (valaddr + embedded_offset,
				 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
				 stream, "&");
	}
      else
	{
	  addr = unpack_pointer (type, valaddr + embedded_offset);
	print_unpacked_pointer:
	  elttype = check_typedef (TYPE_TARGET_TYPE (type));

	  if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
	    {
	      /* Try to print what function it points to.  */
	      print_function_pointer_address (addr, stream);
	      /* Return value is irrelevant except for string pointers.  */
	      return (0);
	    }

	  if (addressprint && format != 's')
	    {
	      print_address_numeric (addr, 1, stream);
	    }

	  /* For a pointer to char or unsigned char, also print the string
	     pointed to, unless pointer is null.  */
	  /* FIXME: need to handle wchar_t here... */

	  if (TYPE_LENGTH (elttype) == 1
	      && TYPE_CODE (elttype) == TYPE_CODE_INT
	      && (format == 0 || format == 's')
	      && addr != 0)
	    {
	      i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream);
	    }
	  else if (cp_is_vtbl_member (type))
	    {
	      /* print vtbl's nicely */
	      CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);

	      struct minimal_symbol *msymbol =
	      lookup_minimal_symbol_by_pc (vt_address);
	      if ((msymbol != NULL) &&
		  (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
		{
		  fputs_filtered (" <", stream);
		  fputs_filtered (SYMBOL_SOURCE_NAME (msymbol), stream);
		  fputs_filtered (">", stream);
		}
	      if (vt_address && vtblprint)
		{
		  value_ptr vt_val;
		  struct symbol *wsym = (struct symbol *) NULL;
		  struct type *wtype;
		  struct symtab *s;
		  struct block *block = (struct block *) NULL;
		  int is_this_fld;

		  if (msymbol != NULL)
		    wsym = lookup_symbol (SYMBOL_NAME (msymbol), block,
					  VAR_NAMESPACE, &is_this_fld, &s);

		  if (wsym)
		    {
		      wtype = SYMBOL_TYPE (wsym);
		    }
		  else
		    {
		      wtype = TYPE_TARGET_TYPE (type);
		    }
		  vt_val = value_at (wtype, vt_address, NULL);
		  val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val), 0,
			     VALUE_ADDRESS (vt_val), stream, format,
			     deref_ref, recurse + 1, pretty);
		  if (pretty)
		    {
		      fprintf_filtered (stream, "\n");
		      print_spaces_filtered (2 + 2 * recurse, stream);
		    }
		}
	    }

	  /* Return number of characters printed, including the terminating
	     '\0' if we reached the end.  val_print_string takes care including
	     the terminating '\0' if necessary.  */
	  return i;
	}
      break;

    case TYPE_CODE_MEMBER:
      error ("not implemented: member type in c_val_print");
      break;

    case TYPE_CODE_REF:
      elttype = check_typedef (TYPE_TARGET_TYPE (type));
      if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER)
	{
	  cp_print_class_member (valaddr + embedded_offset,
				 TYPE_DOMAIN_TYPE (elttype),
				 stream, "");
	  break;
	}
      if (addressprint)
	{
	  CORE_ADDR addr
	    = extract_typed_address (valaddr + embedded_offset, type);
	  fprintf_filtered (stream, "@");
	  print_address_numeric (addr, 1, stream);
	  if (deref_ref)
	    fputs_filtered (": ", stream);
	}
      /* De-reference the reference.  */
      if (deref_ref)
	{
	  if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
	    {
	      value_ptr deref_val =
	      value_at
	      (TYPE_TARGET_TYPE (type),
	       unpack_pointer (lookup_pointer_type (builtin_type_void),
			       valaddr + embedded_offset),
	       NULL);
	      val_print (VALUE_TYPE (deref_val),
			 VALUE_CONTENTS (deref_val),
			 0,
			 VALUE_ADDRESS (deref_val),
			 stream,
			 format,
			 deref_ref,
			 recurse,
			 pretty);
	    }
	  else
	    fputs_filtered ("???", stream);
	}
      break;

    case TYPE_CODE_UNION:
      if (recurse && !unionprint)
	{
	  fprintf_filtered (stream, "{...}");
	  break;
	}
      /* Fall through.  */
    case TYPE_CODE_STRUCT:
      /*FIXME: Abstract this away */
      if (vtblprint && cp_is_vtbl_ptr_type (type))
	{
	  /* Print the unmangled name if desired.  */
	  /* Print vtable entry - we only get here if NOT using
	     -fvtable_thunks.  (Otherwise, look under TYPE_CODE_PTR.) */
	  int offset = (embedded_offset +
			TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8);
	  struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
	  CORE_ADDR addr
	    = extract_typed_address (valaddr + offset, field_type);

	  print_function_pointer_address (addr, stream);
	}
      else
	cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, format,
			       recurse, pretty, NULL, 0);
      break;

    case TYPE_CODE_ENUM:
      if (format)
	{
	  print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
	  break;
	}
      len = TYPE_NFIELDS (type);
      val = unpack_long (type, valaddr + embedded_offset);
      for (i = 0; i < len; i++)
	{
	  QUIT;
	  if (val == TYPE_FIELD_BITPOS (type, i))
	    {
	      break;
	    }
	}
      if (i < len)
	{
	  fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
	}
      else
	{
	  print_longest (stream, 'd', 0, val);
	}
      break;

    case TYPE_CODE_FUNC:
      if (format)
	{
	  print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
	  break;
	}
      /* FIXME, we should consider, at least for ANSI C language, eliminating
         the distinction made between FUNCs and POINTERs to FUNCs.  */
      fprintf_filtered (stream, "{");
      type_print (type, "", stream, -1);
      fprintf_filtered (stream, "} ");
      /* Try to print what function it points to, and its address.  */
      print_address_demangle (address, stream, demangle);
      break;

    case TYPE_CODE_BOOL:
      format = format ? format : output_format;
      if (format)
	print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
      else
	{
	  val = unpack_long (type, valaddr + embedded_offset);
	  if (val == 0)
	    fputs_filtered ("false", stream);
	  else if (val == 1)
	    fputs_filtered ("true", stream);
	  else
	    print_longest (stream, 'd', 0, val);
	}
      break;

    case TYPE_CODE_RANGE:
      /* FIXME: create_range_type does not set the unsigned bit in a
         range type (I think it probably should copy it from the target
         type), so we won't print values which are too large to
         fit in a signed integer correctly.  */
      /* FIXME: Doesn't handle ranges of enums correctly.  (Can't just
         print with the target type, though, because the size of our type
         and the target type might differ).  */
      /* FALLTHROUGH */

    case TYPE_CODE_INT:
      format = format ? format : output_format;
      if (format)
	{
	  print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
	}
      else
	{
	  val_print_type_code_int (type, valaddr + embedded_offset, stream);
	  /* C and C++ has no single byte int type, char is used instead.
	     Since we don't know whether the value is really intended to
	     be used as an integer or a character, print the character
	     equivalent as well. */
	  if (TYPE_LENGTH (type) == 1)
	    {
	      fputs_filtered (" ", stream);
	      LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset),
			     stream);
	    }
	}
      break;

    case TYPE_CODE_CHAR:
      format = format ? format : output_format;
      if (format)
	{
	  print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
	}
      else
	{
	  val = unpack_long (type, valaddr + embedded_offset);
	  if (TYPE_UNSIGNED (type))
	    fprintf_filtered (stream, "%u", (unsigned int) val);
	  else
	    fprintf_filtered (stream, "%d", (int) val);
	  fputs_filtered (" ", stream);
	  LA_PRINT_CHAR ((unsigned char) val, stream);
	}
      break;

    case TYPE_CODE_FLT:
      if (format)
	{
	  print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
	}
      else
	{
	  print_floating (valaddr + embedded_offset, type, stream);
	}
      break;

    case TYPE_CODE_METHOD:
      cp_print_class_method (valaddr + embedded_offset, lookup_pointer_type (type), stream);
      break;

    case TYPE_CODE_VOID:
      fprintf_filtered (stream, "void");
      break;

    case TYPE_CODE_ERROR:
      fprintf_filtered (stream, "<error type>");
      break;

    case TYPE_CODE_UNDEF:
      /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
         dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
         and no complete type for struct foo in that file.  */
      fprintf_filtered (stream, "<incomplete type>");
      break;

    default:
      error ("Invalid C/C++ type code %d in symbol table.", TYPE_CODE (type));
    }
  gdb_flush (stream);
  return (0);
}