1 /* Low level packing and unpacking of values for GDB.
2 Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
4 This file is part of GDB.
6 GDB is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GDB is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 /* The value-history records all the values printed
27 by print commands during this session. Each chunk
28 records 60 consecutive values. The first chunk on
29 the chain records the most recent values.
30 The total number of values is in value_history_count. */
32 #define VALUE_HISTORY_CHUNK 60
34 struct value_history_chunk
36 struct value_history_chunk
*next
;
37 value values
[VALUE_HISTORY_CHUNK
];
40 /* Chain of chunks now in use. */
42 static struct value_history_chunk
*value_history_chain
;
44 static int value_history_count
; /* Abs number of last entry stored */
47 /* List of all value objects currently allocated
48 (except for those released by calls to release_value)
49 This is so they can be freed after each command. */
51 static value all_values
;
53 /* Allocate a value that has the correct length for type TYPE. */
61 val
= (value
) xmalloc (sizeof (struct value
) + TYPE_LENGTH (type
));
62 VALUE_NEXT (val
) = all_values
;
64 VALUE_TYPE (val
) = type
;
65 VALUE_LVAL (val
) = not_lval
;
66 VALUE_ADDRESS (val
) = 0;
67 VALUE_FRAME (val
) = 0;
68 VALUE_OFFSET (val
) = 0;
69 VALUE_BITPOS (val
) = 0;
70 VALUE_BITSIZE (val
) = 0;
71 VALUE_REPEATED (val
) = 0;
72 VALUE_REPETITIONS (val
) = 0;
73 VALUE_REGNO (val
) = -1;
77 /* Allocate a value that has the correct length
78 for COUNT repetitions type TYPE. */
81 allocate_repeat_value (type
, count
)
87 val
= (value
) xmalloc (sizeof (struct value
) + TYPE_LENGTH (type
) * count
);
88 VALUE_NEXT (val
) = all_values
;
90 VALUE_TYPE (val
) = type
;
91 VALUE_LVAL (val
) = not_lval
;
92 VALUE_ADDRESS (val
) = 0;
93 VALUE_FRAME (val
) = 0;
94 VALUE_OFFSET (val
) = 0;
95 VALUE_BITPOS (val
) = 0;
96 VALUE_BITSIZE (val
) = 0;
97 VALUE_REPEATED (val
) = 1;
98 VALUE_REPETITIONS (val
) = count
;
99 VALUE_REGNO (val
) = -1;
103 /* Free all the values that have been allocated (except for those released).
104 Called after each command, successful or not. */
109 register value val
, next
;
111 for (val
= all_values
; val
; val
= next
)
113 next
= VALUE_NEXT (val
);
120 /* Remove VAL from the chain all_values
121 so it will not be freed automatically. */
129 if (all_values
== val
)
131 all_values
= val
->next
;
135 for (v
= all_values
; v
; v
= v
->next
)
145 /* Return a copy of the value ARG.
146 It contains the same contents, for same memory address,
147 but it's a different block of storage. */
154 register struct type
*type
= VALUE_TYPE (arg
);
155 if (VALUE_REPEATED (arg
))
156 val
= allocate_repeat_value (type
, VALUE_REPETITIONS (arg
));
158 val
= allocate_value (type
);
159 VALUE_LVAL (val
) = VALUE_LVAL (arg
);
160 VALUE_ADDRESS (val
) = VALUE_ADDRESS (arg
);
161 VALUE_OFFSET (val
) = VALUE_OFFSET (arg
);
162 VALUE_BITPOS (val
) = VALUE_BITPOS (arg
);
163 VALUE_BITSIZE (val
) = VALUE_BITSIZE (arg
);
164 VALUE_REGNO (val
) = VALUE_REGNO (arg
);
165 bcopy (VALUE_CONTENTS (arg
), VALUE_CONTENTS (val
),
166 TYPE_LENGTH (VALUE_TYPE (arg
))
167 * (VALUE_REPEATED (arg
) ? VALUE_REPETITIONS (arg
) : 1));
171 /* Access to the value history. */
173 /* Record a new value in the value history.
174 Returns the absolute history index of the entry. */
177 record_latest_value (val
)
183 /* Check error now if about to store an invalid float. We return -1
184 to the caller, but allow them to continue, e.g. to print it as "Nan". */
185 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_FLT
) {
186 foo
= unpack_double (VALUE_TYPE (val
), VALUE_CONTENTS (val
), &i
);
187 if (i
) return -1; /* Indicate value not saved in history */
190 /* Here we treat value_history_count as origin-zero
191 and applying to the value being stored now. */
193 i
= value_history_count
% VALUE_HISTORY_CHUNK
;
196 register struct value_history_chunk
*new
197 = (struct value_history_chunk
*)
198 xmalloc (sizeof (struct value_history_chunk
));
199 bzero (new->values
, sizeof new->values
);
200 new->next
= value_history_chain
;
201 value_history_chain
= new;
204 value_history_chain
->values
[i
] = val
;
207 /* Now we regard value_history_count as origin-one
208 and applying to the value just stored. */
210 return ++value_history_count
;
213 /* Return a copy of the value in the history with sequence number NUM. */
216 access_value_history (num
)
219 register struct value_history_chunk
*chunk
;
221 register int absnum
= num
;
224 absnum
+= value_history_count
;
229 error ("The history is empty.");
231 error ("There is only one value in the history.");
233 error ("History does not go back to $$%d.", -num
);
235 if (absnum
> value_history_count
)
236 error ("History has not yet reached $%d.", absnum
);
240 /* Now absnum is always absolute and origin zero. */
242 chunk
= value_history_chain
;
243 for (i
= (value_history_count
- 1) / VALUE_HISTORY_CHUNK
- absnum
/ VALUE_HISTORY_CHUNK
;
247 return value_copy (chunk
->values
[absnum
% VALUE_HISTORY_CHUNK
]);
250 /* Clear the value history entirely.
251 Must be done when new symbol tables are loaded,
252 because the type pointers become invalid. */
255 clear_value_history ()
257 register struct value_history_chunk
*next
;
261 while (value_history_chain
)
263 for (i
= 0; i
< VALUE_HISTORY_CHUNK
; i
++)
264 if (val
= value_history_chain
->values
[i
])
266 next
= value_history_chain
->next
;
267 free (value_history_chain
);
268 value_history_chain
= next
;
270 value_history_count
= 0;
274 value_history_info (num_exp
, from_tty
)
284 if (num_exp
[0] == '+' && num_exp
[1] == '\0')
285 /* "info history +" should print from the stored position. */
288 /* "info history <exp>" should print around value number <exp>. */
289 num
= parse_and_eval_address (num_exp
) - 5;
293 /* "info history" means print the last 10 values. */
294 num
= value_history_count
- 9;
300 for (i
= num
; i
< num
+ 10 && i
<= value_history_count
; i
++)
302 val
= access_value_history (i
);
303 printf_filtered ("$%d = ", i
);
304 value_print (val
, stdout
, 0, Val_pretty_default
);
305 printf_filtered ("\n");
308 /* The next "info history +" should start after what we just printed. */
311 /* Hitting just return after this command should do the same thing as
312 "info history +". If num_exp is null, this is unnecessary, since
313 "info history +" is not useful after "info history". */
314 if (from_tty
&& num_exp
)
321 /* Internal variables. These are variables within the debugger
322 that hold values assigned by debugger commands.
323 The user refers to them with a '$' prefix
324 that does not appear in the variable names stored internally. */
326 static struct internalvar
*internalvars
;
328 /* Look up an internal variable with name NAME. NAME should not
329 normally include a dollar sign.
331 If the specified internal variable does not exist,
332 one is created, with a void value. */
335 lookup_internalvar (name
)
338 register struct internalvar
*var
;
340 for (var
= internalvars
; var
; var
= var
->next
)
341 if (!strcmp (var
->name
, name
))
344 var
= (struct internalvar
*) xmalloc (sizeof (struct internalvar
));
345 var
->name
= concat (name
, "", "");
346 var
->value
= allocate_value (builtin_type_void
);
347 release_value (var
->value
);
348 var
->next
= internalvars
;
354 value_of_internalvar (var
)
355 struct internalvar
*var
;
359 #ifdef IS_TRAPPED_INTERNALVAR
360 if (IS_TRAPPED_INTERNALVAR (var
->name
))
361 return VALUE_OF_TRAPPED_INTERNALVAR (var
);
364 val
= value_copy (var
->value
);
365 VALUE_LVAL (val
) = lval_internalvar
;
366 VALUE_INTERNALVAR (val
) = var
;
371 set_internalvar_component (var
, offset
, bitpos
, bitsize
, newval
)
372 struct internalvar
*var
;
373 int offset
, bitpos
, bitsize
;
376 register char *addr
= VALUE_CONTENTS (var
->value
) + offset
;
378 #ifdef IS_TRAPPED_INTERNALVAR
379 if (IS_TRAPPED_INTERNALVAR (var
->name
))
380 SET_TRAPPED_INTERNALVAR (var
, newval
, bitpos
, bitsize
, offset
);
384 modify_field (addr
, (int) value_as_long (newval
),
387 bcopy (VALUE_CONTENTS (newval
), addr
,
388 TYPE_LENGTH (VALUE_TYPE (newval
)));
392 set_internalvar (var
, val
)
393 struct internalvar
*var
;
396 #ifdef IS_TRAPPED_INTERNALVAR
397 if (IS_TRAPPED_INTERNALVAR (var
->name
))
398 SET_TRAPPED_INTERNALVAR (var
, val
, 0, 0, 0);
402 var
->value
= value_copy (val
);
403 release_value (var
->value
);
407 internalvar_name (var
)
408 struct internalvar
*var
;
413 /* Free all internalvars. Done when new symtabs are loaded,
414 because that makes the values invalid. */
417 clear_internalvars ()
419 register struct internalvar
*var
;
424 internalvars
= var
->next
;
434 register struct internalvar
*var
;
437 for (var
= internalvars
; var
; var
= var
->next
)
439 #ifdef IS_TRAPPED_INTERNALVAR
440 if (IS_TRAPPED_INTERNALVAR (var
->name
))
445 printf ("Debugger convenience variables:\n\n");
448 printf ("$%s: ", var
->name
);
449 value_print (var
->value
, stdout
, 0, Val_pretty_default
);
453 printf ("No debugger convenience variables now defined.\n\
454 Convenience variables have names starting with \"$\";\n\
455 use \"set\" as in \"set $foo = 5\" to define them.\n");
458 /* Extract a value as a C number (either long or double).
459 Knows how to convert fixed values to double, or
460 floating values to long.
461 Does not deallocate the value. */
467 return unpack_long (VALUE_TYPE (val
), VALUE_CONTENTS (val
));
471 value_as_double (val
)
477 foo
= unpack_double (VALUE_TYPE (val
), VALUE_CONTENTS (val
), &inv
);
479 error ("Invalid floating value found in program.");
483 /* Unpack raw data (copied from debugee) at VALADDR
484 as a long, or as a double, assuming the raw data is described
485 by type TYPE. Knows how to convert different sizes of values
486 and can convert between fixed and floating point.
488 C++: It is assumed that the front-end has taken care of
489 all matters concerning pointers to members. A pointer
490 to member which reaches here is considered to be equivalent
491 to an INT (or some size). After all, it is only an offset. */
494 unpack_long (type
, valaddr
)
498 register enum type_code code
= TYPE_CODE (type
);
499 register int len
= TYPE_LENGTH (type
);
500 register int nosign
= TYPE_UNSIGNED (type
);
502 if (code
== TYPE_CODE_ENUM
)
503 code
= TYPE_CODE_INT
;
504 if (code
== TYPE_CODE_FLT
)
506 if (len
== sizeof (float))
507 return * (float *) valaddr
;
509 if (len
== sizeof (double))
510 return * (double *) valaddr
;
512 else if (code
== TYPE_CODE_INT
&& nosign
)
514 if (len
== sizeof (char))
515 return * (unsigned char *) valaddr
;
517 if (len
== sizeof (short))
518 return * (unsigned short *) valaddr
;
520 if (len
== sizeof (int))
521 return * (unsigned int *) valaddr
;
523 if (len
== sizeof (long))
524 return * (unsigned long *) valaddr
;
526 if (len
== sizeof (long long))
527 return * (unsigned long long *) valaddr
;
530 else if (code
== TYPE_CODE_INT
)
532 if (len
== sizeof (char))
533 return * (char *) valaddr
;
535 if (len
== sizeof (short))
536 return * (short *) valaddr
;
538 if (len
== sizeof (int))
539 return * (int *) valaddr
;
541 if (len
== sizeof (long))
542 return * (long *) valaddr
;
545 if (len
== sizeof (long long))
546 return * (long long *) valaddr
;
549 else if (code
== TYPE_CODE_PTR
550 || code
== TYPE_CODE_REF
)
552 if (len
== sizeof (char *))
553 return (CORE_ADDR
) * (char **) valaddr
;
555 else if (code
== TYPE_CODE_MEMBER
)
556 error ("not implemented: member types in unpack_long");
558 error ("Value not integer or pointer.");
561 /* Return a double value from the specified type and address.
562 INVP points to an int which is set to 0 for valid value,
563 1 for invalid value (bad float format). In either case,
564 the returned double is OK to use. */
567 unpack_double (type
, valaddr
, invp
)
572 register enum type_code code
= TYPE_CODE (type
);
573 register int len
= TYPE_LENGTH (type
);
574 register int nosign
= TYPE_UNSIGNED (type
);
576 *invp
= 0; /* Assume valid. */
577 if (code
== TYPE_CODE_FLT
)
579 if (INVALID_FLOAT (valaddr
, len
))
582 return 1.234567891011121314;
585 if (len
== sizeof (float))
586 return * (float *) valaddr
;
588 if (len
== sizeof (double))
590 /* Some machines require doubleword alignment for doubles.
591 This code works on them, and on other machines. */
593 bcopy ((char *) valaddr
, (char *) &temp
, sizeof (double));
597 else if (code
== TYPE_CODE_INT
&& nosign
)
599 if (len
== sizeof (char))
600 return * (unsigned char *) valaddr
;
602 if (len
== sizeof (short))
603 return * (unsigned short *) valaddr
;
605 if (len
== sizeof (int))
606 return * (unsigned int *) valaddr
;
608 if (len
== sizeof (long))
609 return * (unsigned long *) valaddr
;
612 if (len
== sizeof (long long))
613 return * (unsigned long long *) valaddr
;
616 else if (code
== TYPE_CODE_INT
)
618 if (len
== sizeof (char))
619 return * (char *) valaddr
;
621 if (len
== sizeof (short))
622 return * (short *) valaddr
;
624 if (len
== sizeof (int))
625 return * (int *) valaddr
;
627 if (len
== sizeof (long))
628 return * (long *) valaddr
;
631 if (len
== sizeof (long long))
632 return * (long long *) valaddr
;
636 error ("Value not floating number.");
638 return (double) 0; /* To silence compiler warning. */
641 /* Given a value ARG1 of a struct or union type,
642 extract and return the value of one of its fields.
643 FIELDNO says which field.
645 For C++, must also be able to return values from static fields */
648 value_field (arg1
, fieldno
)
650 register int fieldno
;
653 register struct type
*type
= TYPE_FIELD_TYPE (VALUE_TYPE (arg1
), fieldno
);
656 /* Handle packed fields */
658 offset
= TYPE_FIELD_BITPOS (VALUE_TYPE (arg1
), fieldno
) / 8;
659 if (TYPE_FIELD_BITSIZE (VALUE_TYPE (arg1
), fieldno
))
661 v
= value_from_long (type
,
662 unpack_field_as_long (VALUE_TYPE (arg1
),
663 VALUE_CONTENTS (arg1
),
665 VALUE_BITPOS (v
) = TYPE_FIELD_BITPOS (VALUE_TYPE (arg1
), fieldno
) % 8;
666 VALUE_BITSIZE (v
) = TYPE_FIELD_BITSIZE (VALUE_TYPE (arg1
), fieldno
);
670 v
= allocate_value (type
);
671 bcopy (VALUE_CONTENTS (arg1
) + offset
,
675 VALUE_LVAL (v
) = VALUE_LVAL (arg1
);
676 if (VALUE_LVAL (arg1
) == lval_internalvar
)
677 VALUE_LVAL (v
) = lval_internalvar_component
;
678 VALUE_ADDRESS (v
) = VALUE_ADDRESS (arg1
);
679 VALUE_OFFSET (v
) = offset
+ VALUE_OFFSET (arg1
);
684 value_fn_field (arg1
, fieldno
, subfieldno
)
686 register int fieldno
;
689 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (VALUE_TYPE (arg1
), fieldno
);
690 register struct type
*type
= TYPE_FN_FIELD_TYPE (f
, subfieldno
);
693 sym
= lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, subfieldno
),
694 0, VAR_NAMESPACE
, 0);
695 if (! sym
) error ("Internal error: could not find physical method named %s",
696 TYPE_FN_FIELD_PHYSNAME (f
, subfieldno
));
698 v
= allocate_value (type
);
699 VALUE_ADDRESS (v
) = BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
700 VALUE_TYPE (v
) = type
;
704 /* Return a virtual function as a value.
705 ARG1 is the object which provides the virtual function
707 F is the list of member functions which contains the desired virtual
709 J is an index into F which provides the desired virtual function.
710 TYPE is the basetype which first provides the virtual function table. */
712 value_virtual_fn_field (arg1
, f
, j
, type
)
718 /* First, get the virtual function table pointer. That comes
719 with a strange type, so cast it to type `pointer to long' (which
720 should serve just fine as a function type). Then, index into
721 the table, and convert final value to appropriate function type. */
723 value vi
= value_from_long (builtin_type_int
,
724 (LONGEST
) TYPE_FN_FIELD_VOFFSET (f
, j
));
725 VALUE_TYPE (arg1
) = TYPE_VPTR_BASETYPE (type
);
727 /* This type may have been defined before its virtual function table
728 was. If so, fill in the virtual function table entry for the
730 if (TYPE_VPTR_FIELDNO (type
) < 0)
731 TYPE_VPTR_FIELDNO (type
)
732 = fill_in_vptr_fieldno (type
);
734 /* The virtual function table is now an array of structures
735 which have the form { int16 offset, delta; void *pfn; }. */
736 vtbl
= value_ind (value_field (arg1
, TYPE_VPTR_FIELDNO (type
)));
738 /* Index into the virtual function table. This is hard-coded because
739 looking up a field is not cheap, and it may be important to save
740 time, e.g. if the user has set a conditional breakpoint calling
741 a virtual function. */
742 vfn
= value_field (value_subscript (vtbl
, vi
), 2);
744 /* Reinstantiate the function pointer with the correct type. */
745 VALUE_TYPE (vfn
) = lookup_pointer_type (TYPE_FN_FIELD_TYPE (f
, j
));
749 /* The value of a static class member does not depend
750 on its instance, only on its type. If FIELDNO >= 0,
751 then fieldno is a valid field number and is used directly.
752 Otherwise, FIELDNAME is the name of the field we are
753 searching for. If it is not a static field name, an
754 error is signaled. TYPE is the type in which we look for the
755 static field member. */
757 value_static_field (type
, fieldname
, fieldno
)
758 register struct type
*type
;
760 register int fieldno
;
767 register struct type
*t
= type
;
768 /* Look for static field. */
772 for (i
= TYPE_NFIELDS (t
) - 1; i
>= 0; i
--)
773 if (! strcmp (TYPE_FIELD_NAME (t
, i
), fieldname
))
775 if (TYPE_FIELD_STATIC (t
, i
))
781 error ("field `%s' is not static");
783 t
= TYPE_BASECLASSES (t
) ? TYPE_BASECLASS (t
, 1) : 0;
788 if (destructor_name_p (fieldname
, t
))
789 error ("use `info method' command to print out value of destructor");
795 for (i
= TYPE_NFN_FIELDS (t
) - 1; i
>= 0; i
--)
797 if (! strcmp (TYPE_FN_FIELDLIST_NAME (t
, i
), fieldname
))
799 error ("use `info method' command to print value of method \"%s\"", fieldname
);
802 t
= TYPE_BASECLASSES (t
) ? TYPE_BASECLASS (t
, 1) : 0;
804 error("there is no field named %s", fieldname
);
809 sym
= lookup_symbol (TYPE_FIELD_STATIC_PHYSNAME (type
, fieldno
),
810 0, VAR_NAMESPACE
, 0);
811 if (! sym
) error ("Internal error: could not find physical static variable named %s", TYPE_FIELD_BITSIZE (type
, fieldno
));
813 type
= TYPE_FIELD_TYPE (type
, fieldno
);
814 v
= value_at (type
, (CORE_ADDR
)SYMBOL_BLOCK_VALUE (sym
));
819 unpack_field_as_long (type
, valaddr
, fieldno
)
825 int bitpos
= TYPE_FIELD_BITPOS (type
, fieldno
);
826 int bitsize
= TYPE_FIELD_BITSIZE (type
, fieldno
);
828 bcopy (valaddr
+ bitpos
/ 8, &val
, sizeof val
);
830 /* Extracting bits depends on endianness of the machine. */
831 #ifdef BITS_BIG_ENDIAN
832 val
= val
>> (sizeof val
* 8 - bitpos
% 8 - bitsize
);
834 val
= val
>> (bitpos
% 8);
837 val
&= (1 << bitsize
) - 1;
842 modify_field (addr
, fieldval
, bitpos
, bitsize
)
849 /* Reject values too big to fit in the field in question.
850 Otherwise adjoining fields may be corrupted. */
851 if (fieldval
& ~((1<<bitsize
)-1))
852 error ("Value %d does not fit in %d bits.", fieldval
, bitsize
);
854 bcopy (addr
, &oword
, sizeof oword
);
856 /* Shifting for bit field depends on endianness of the machine. */
857 #ifdef BITS_BIG_ENDIAN
858 bitpos
= sizeof (oword
) * 8 - bitpos
- bitsize
;
861 oword
&= ~(((1 << bitsize
) - 1) << bitpos
);
862 oword
|= fieldval
<< bitpos
;
863 bcopy (&oword
, addr
, sizeof oword
);
866 /* Convert C numbers into newly allocated values */
869 value_from_long (type
, num
)
871 register LONGEST num
;
873 register value val
= allocate_value (type
);
874 register enum type_code code
= TYPE_CODE (type
);
875 register int len
= TYPE_LENGTH (type
);
877 if (code
== TYPE_CODE_INT
|| code
== TYPE_CODE_ENUM
)
879 if (len
== sizeof (char))
880 * (char *) VALUE_CONTENTS (val
) = num
;
881 else if (len
== sizeof (short))
882 * (short *) VALUE_CONTENTS (val
) = num
;
883 else if (len
== sizeof (int))
884 * (int *) VALUE_CONTENTS (val
) = num
;
885 else if (len
== sizeof (long))
886 * (long *) VALUE_CONTENTS (val
) = num
;
888 else if (len
== sizeof (long long))
889 * (long long *) VALUE_CONTENTS (val
) = num
;
892 error ("Integer type encountered with unexpected data length.");
895 error ("Unexpected type encountered for integer constant.");
901 value_from_double (type
, num
)
905 register value val
= allocate_value (type
);
906 register enum type_code code
= TYPE_CODE (type
);
907 register int len
= TYPE_LENGTH (type
);
909 if (code
== TYPE_CODE_FLT
)
911 if (len
== sizeof (float))
912 * (float *) VALUE_CONTENTS (val
) = num
;
913 else if (len
== sizeof (double))
914 * (double *) VALUE_CONTENTS (val
) = num
;
916 error ("Floating type encountered with unexpected data length.");
919 error ("Unexpected type encountered for floating constant.");
924 /* Deal with the value that is "about to be returned". */
926 /* Return the value that a function returning now
927 would be returning to its caller, assuming its type is VALTYPE.
928 RETBUF is where we look for what ought to be the contents
929 of the registers (in raw form). This is because it is often
930 desirable to restore old values to those registers
931 after saving the contents of interest, and then call
932 this function using the saved values.
933 struct_return is non-zero when the function in question is
934 using the structure return conventions on the machine in question;
935 0 when it is using the value returning conventions (this often
936 means returning pointer to where structure is vs. returning value). */
939 value_being_returned (valtype
, retbuf
, struct_return
)
940 register struct type
*valtype
;
941 char retbuf
[REGISTER_BYTES
];
947 return value_at (valtype
, EXTRACT_STRUCT_VALUE_ADDRESS (retbuf
));
949 val
= allocate_value (valtype
);
950 EXTRACT_RETURN_VALUE (valtype
, retbuf
, VALUE_CONTENTS (val
));
955 /* Return true if the function specified is using the structure returning
956 convention on this machine to return arguments, or 0 if it is using
957 the value returning convention. FUNCTION is the value representing
958 the function, FUNCADDR is the address of the function, and VALUE_TYPE
959 is the type returned by the function */
961 struct block
*block_for_pc ();
964 using_struct_return (function
, funcaddr
, value_type
)
967 struct type
*value_type
;
969 register enum type_code code
= TYPE_CODE (value_type
);
971 if (code
== TYPE_CODE_STRUCT
||
972 code
== TYPE_CODE_UNION
||
973 code
== TYPE_CODE_ARRAY
)
975 struct block
*b
= block_for_pc (funcaddr
);
977 if (!(BLOCK_GCC_COMPILED (b
) && TYPE_LENGTH (value_type
) < 8))
984 /* Store VAL so it will be returned if a function returns now.
985 Does not verify that VAL's type matches what the current
986 function wants to return. */
989 set_return_value (val
)
992 register enum type_code code
= TYPE_CODE (VALUE_TYPE (val
));
993 char regbuf
[REGISTER_BYTES
];
997 if (code
== TYPE_CODE_STRUCT
998 || code
== TYPE_CODE_UNION
)
999 error ("Specifying a struct or union return value is not supported.");
1001 if (code
== TYPE_CODE_FLT
)
1003 dbuf
= value_as_double (val
);
1005 STORE_RETURN_VALUE (VALUE_TYPE (val
), &dbuf
);
1009 lbuf
= value_as_long (val
);
1010 STORE_RETURN_VALUE (VALUE_TYPE (val
), &lbuf
);
1015 _initialize_values ()
1017 add_info ("convenience", convenience_info
,
1018 "Debugger convenience (\"$foo\") variables.\n\
1019 These variables are created when you assign them values;\n\
1020 thus, \"print $foo=1\" gives \"$foo\" the value 1. Values may be any type.\n\n\
1021 A few convenience variables are given values automatically GDB:\n\
1022 \"$_\"holds the last address examined with \"x\" or \"info lines\",\n\
1023 \"$__\" holds the contents of the last address examined with \"x\".");
1025 add_info ("values", value_history_info
,
1026 "Elements of value history (around item number IDX, or last ten).");
1027 add_info_alias ("history", value_history_info
, 0);