1 /* Low level packing and unpacking of values for GDB, the GNU Debugger.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
37 /* Prototypes for exported functions. */
39 void _initialize_values (void);
41 /* Prototypes for local functions. */
43 static value_ptr
value_headof (value_ptr
, struct type
*, struct type
*);
45 static void show_values (char *, int);
47 static void show_convenience (char *, int);
49 static int vb_match (struct type
*, int, struct type
*);
51 /* The value-history records all the values printed
52 by print commands during this session. Each chunk
53 records 60 consecutive values. The first chunk on
54 the chain records the most recent values.
55 The total number of values is in value_history_count. */
57 #define VALUE_HISTORY_CHUNK 60
59 struct value_history_chunk
61 struct value_history_chunk
*next
;
62 value_ptr values
[VALUE_HISTORY_CHUNK
];
65 /* Chain of chunks now in use. */
67 static struct value_history_chunk
*value_history_chain
;
69 static int value_history_count
; /* Abs number of last entry stored */
71 /* List of all value objects currently allocated
72 (except for those released by calls to release_value)
73 This is so they can be freed after each command. */
75 static value_ptr all_values
;
77 /* Allocate a value that has the correct length for type TYPE. */
80 allocate_value (struct type
*type
)
82 register value_ptr val
;
83 struct type
*atype
= check_typedef (type
);
85 val
= (struct value
*) xmalloc (sizeof (struct value
) + TYPE_LENGTH (atype
));
86 VALUE_NEXT (val
) = all_values
;
88 VALUE_TYPE (val
) = type
;
89 VALUE_ENCLOSING_TYPE (val
) = type
;
90 VALUE_LVAL (val
) = not_lval
;
91 VALUE_ADDRESS (val
) = 0;
92 VALUE_FRAME (val
) = 0;
93 VALUE_OFFSET (val
) = 0;
94 VALUE_BITPOS (val
) = 0;
95 VALUE_BITSIZE (val
) = 0;
96 VALUE_REGNO (val
) = -1;
98 VALUE_OPTIMIZED_OUT (val
) = 0;
99 VALUE_BFD_SECTION (val
) = NULL
;
100 VALUE_EMBEDDED_OFFSET (val
) = 0;
101 VALUE_POINTED_TO_OFFSET (val
) = 0;
106 /* Allocate a value that has the correct length
107 for COUNT repetitions type TYPE. */
110 allocate_repeat_value (struct type
*type
, int count
)
112 int low_bound
= current_language
->string_lower_bound
; /* ??? */
113 /* FIXME-type-allocation: need a way to free this type when we are
115 struct type
*range_type
116 = create_range_type ((struct type
*) NULL
, builtin_type_int
,
117 low_bound
, count
+ low_bound
- 1);
118 /* FIXME-type-allocation: need a way to free this type when we are
120 return allocate_value (create_array_type ((struct type
*) NULL
,
124 /* Return a mark in the value chain. All values allocated after the
125 mark is obtained (except for those released) are subject to being freed
126 if a subsequent value_free_to_mark is passed the mark. */
133 /* Free all values allocated since MARK was obtained by value_mark
134 (except for those released). */
136 value_free_to_mark (value_ptr mark
)
140 for (val
= all_values
; val
&& val
!= mark
; val
= next
)
142 next
= VALUE_NEXT (val
);
148 /* Free all the values that have been allocated (except for those released).
149 Called after each command, successful or not. */
152 free_all_values (void)
154 register value_ptr val
, next
;
156 for (val
= all_values
; val
; val
= next
)
158 next
= VALUE_NEXT (val
);
165 /* Remove VAL from the chain all_values
166 so it will not be freed automatically. */
169 release_value (register value_ptr val
)
171 register value_ptr v
;
173 if (all_values
== val
)
175 all_values
= val
->next
;
179 for (v
= all_values
; v
; v
= v
->next
)
189 /* Release all values up to mark */
191 value_release_to_mark (value_ptr mark
)
195 for (val
= next
= all_values
; next
; next
= VALUE_NEXT (next
))
196 if (VALUE_NEXT (next
) == mark
)
198 all_values
= VALUE_NEXT (next
);
199 VALUE_NEXT (next
) = 0;
206 /* Return a copy of the value ARG.
207 It contains the same contents, for same memory address,
208 but it's a different block of storage. */
211 value_copy (value_ptr arg
)
213 register struct type
*encl_type
= VALUE_ENCLOSING_TYPE (arg
);
214 register value_ptr val
= allocate_value (encl_type
);
215 VALUE_TYPE (val
) = VALUE_TYPE (arg
);
216 VALUE_LVAL (val
) = VALUE_LVAL (arg
);
217 VALUE_ADDRESS (val
) = VALUE_ADDRESS (arg
);
218 VALUE_OFFSET (val
) = VALUE_OFFSET (arg
);
219 VALUE_BITPOS (val
) = VALUE_BITPOS (arg
);
220 VALUE_BITSIZE (val
) = VALUE_BITSIZE (arg
);
221 VALUE_FRAME (val
) = VALUE_FRAME (arg
);
222 VALUE_REGNO (val
) = VALUE_REGNO (arg
);
223 VALUE_LAZY (val
) = VALUE_LAZY (arg
);
224 VALUE_OPTIMIZED_OUT (val
) = VALUE_OPTIMIZED_OUT (arg
);
225 VALUE_EMBEDDED_OFFSET (val
) = VALUE_EMBEDDED_OFFSET (arg
);
226 VALUE_POINTED_TO_OFFSET (val
) = VALUE_POINTED_TO_OFFSET (arg
);
227 VALUE_BFD_SECTION (val
) = VALUE_BFD_SECTION (arg
);
228 val
->modifiable
= arg
->modifiable
;
229 if (!VALUE_LAZY (val
))
231 memcpy (VALUE_CONTENTS_ALL_RAW (val
), VALUE_CONTENTS_ALL_RAW (arg
),
232 TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg
)));
238 /* Access to the value history. */
240 /* Record a new value in the value history.
241 Returns the absolute history index of the entry.
242 Result of -1 indicates the value was not saved; otherwise it is the
243 value history index of this new item. */
246 record_latest_value (value_ptr val
)
250 /* We don't want this value to have anything to do with the inferior anymore.
251 In particular, "set $1 = 50" should not affect the variable from which
252 the value was taken, and fast watchpoints should be able to assume that
253 a value on the value history never changes. */
254 if (VALUE_LAZY (val
))
255 value_fetch_lazy (val
);
256 /* We preserve VALUE_LVAL so that the user can find out where it was fetched
257 from. This is a bit dubious, because then *&$1 does not just return $1
258 but the current contents of that location. c'est la vie... */
262 /* Here we treat value_history_count as origin-zero
263 and applying to the value being stored now. */
265 i
= value_history_count
% VALUE_HISTORY_CHUNK
;
268 register struct value_history_chunk
*new
269 = (struct value_history_chunk
*)
270 xmalloc (sizeof (struct value_history_chunk
));
271 memset (new->values
, 0, sizeof new->values
);
272 new->next
= value_history_chain
;
273 value_history_chain
= new;
276 value_history_chain
->values
[i
] = val
;
278 /* Now we regard value_history_count as origin-one
279 and applying to the value just stored. */
281 return ++value_history_count
;
284 /* Return a copy of the value in the history with sequence number NUM. */
287 access_value_history (int num
)
289 register struct value_history_chunk
*chunk
;
291 register int absnum
= num
;
294 absnum
+= value_history_count
;
299 error ("The history is empty.");
301 error ("There is only one value in the history.");
303 error ("History does not go back to $$%d.", -num
);
305 if (absnum
> value_history_count
)
306 error ("History has not yet reached $%d.", absnum
);
310 /* Now absnum is always absolute and origin zero. */
312 chunk
= value_history_chain
;
313 for (i
= (value_history_count
- 1) / VALUE_HISTORY_CHUNK
- absnum
/ VALUE_HISTORY_CHUNK
;
317 return value_copy (chunk
->values
[absnum
% VALUE_HISTORY_CHUNK
]);
320 /* Clear the value history entirely.
321 Must be done when new symbol tables are loaded,
322 because the type pointers become invalid. */
325 clear_value_history (void)
327 register struct value_history_chunk
*next
;
329 register value_ptr val
;
331 while (value_history_chain
)
333 for (i
= 0; i
< VALUE_HISTORY_CHUNK
; i
++)
334 if ((val
= value_history_chain
->values
[i
]) != NULL
)
336 next
= value_history_chain
->next
;
337 xfree (value_history_chain
);
338 value_history_chain
= next
;
340 value_history_count
= 0;
344 show_values (char *num_exp
, int from_tty
)
347 register value_ptr val
;
352 /* "info history +" should print from the stored position.
353 "info history <exp>" should print around value number <exp>. */
354 if (num_exp
[0] != '+' || num_exp
[1] != '\0')
355 num
= parse_and_eval_long (num_exp
) - 5;
359 /* "info history" means print the last 10 values. */
360 num
= value_history_count
- 9;
366 for (i
= num
; i
< num
+ 10 && i
<= value_history_count
; i
++)
368 val
= access_value_history (i
);
369 printf_filtered ("$%d = ", i
);
370 value_print (val
, gdb_stdout
, 0, Val_pretty_default
);
371 printf_filtered ("\n");
374 /* The next "info history +" should start after what we just printed. */
377 /* Hitting just return after this command should do the same thing as
378 "info history +". If num_exp is null, this is unnecessary, since
379 "info history +" is not useful after "info history". */
380 if (from_tty
&& num_exp
)
387 /* Internal variables. These are variables within the debugger
388 that hold values assigned by debugger commands.
389 The user refers to them with a '$' prefix
390 that does not appear in the variable names stored internally. */
392 static struct internalvar
*internalvars
;
394 /* Look up an internal variable with name NAME. NAME should not
395 normally include a dollar sign.
397 If the specified internal variable does not exist,
398 one is created, with a void value. */
401 lookup_internalvar (char *name
)
403 register struct internalvar
*var
;
405 for (var
= internalvars
; var
; var
= var
->next
)
406 if (STREQ (var
->name
, name
))
409 var
= (struct internalvar
*) xmalloc (sizeof (struct internalvar
));
410 var
->name
= concat (name
, NULL
);
411 var
->value
= allocate_value (builtin_type_void
);
412 release_value (var
->value
);
413 var
->next
= internalvars
;
419 value_of_internalvar (struct internalvar
*var
)
421 register value_ptr val
;
423 #ifdef IS_TRAPPED_INTERNALVAR
424 if (IS_TRAPPED_INTERNALVAR (var
->name
))
425 return VALUE_OF_TRAPPED_INTERNALVAR (var
);
428 val
= value_copy (var
->value
);
429 if (VALUE_LAZY (val
))
430 value_fetch_lazy (val
);
431 VALUE_LVAL (val
) = lval_internalvar
;
432 VALUE_INTERNALVAR (val
) = var
;
437 set_internalvar_component (struct internalvar
*var
, int offset
, int bitpos
,
438 int bitsize
, value_ptr newval
)
440 register char *addr
= VALUE_CONTENTS (var
->value
) + offset
;
442 #ifdef IS_TRAPPED_INTERNALVAR
443 if (IS_TRAPPED_INTERNALVAR (var
->name
))
444 SET_TRAPPED_INTERNALVAR (var
, newval
, bitpos
, bitsize
, offset
);
448 modify_field (addr
, value_as_long (newval
),
451 memcpy (addr
, VALUE_CONTENTS (newval
), TYPE_LENGTH (VALUE_TYPE (newval
)));
455 set_internalvar (struct internalvar
*var
, value_ptr val
)
459 #ifdef IS_TRAPPED_INTERNALVAR
460 if (IS_TRAPPED_INTERNALVAR (var
->name
))
461 SET_TRAPPED_INTERNALVAR (var
, val
, 0, 0, 0);
464 newval
= value_copy (val
);
465 newval
->modifiable
= 1;
467 /* Force the value to be fetched from the target now, to avoid problems
468 later when this internalvar is referenced and the target is gone or
470 if (VALUE_LAZY (newval
))
471 value_fetch_lazy (newval
);
473 /* Begin code which must not call error(). If var->value points to
474 something free'd, an error() obviously leaves a dangling pointer.
475 But we also get a danling pointer if var->value points to
476 something in the value chain (i.e., before release_value is
477 called), because after the error free_all_values will get called before
481 release_value (newval
);
482 /* End code which must not call error(). */
486 internalvar_name (struct internalvar
*var
)
491 /* Free all internalvars. Done when new symtabs are loaded,
492 because that makes the values invalid. */
495 clear_internalvars (void)
497 register struct internalvar
*var
;
502 internalvars
= var
->next
;
510 show_convenience (char *ignore
, int from_tty
)
512 register struct internalvar
*var
;
515 for (var
= internalvars
; var
; var
= var
->next
)
517 #ifdef IS_TRAPPED_INTERNALVAR
518 if (IS_TRAPPED_INTERNALVAR (var
->name
))
525 printf_filtered ("$%s = ", var
->name
);
526 value_print (var
->value
, gdb_stdout
, 0, Val_pretty_default
);
527 printf_filtered ("\n");
530 printf_unfiltered ("No debugger convenience variables now defined.\n\
531 Convenience variables have names starting with \"$\";\n\
532 use \"set\" as in \"set $foo = 5\" to define them.\n");
535 /* Extract a value as a C number (either long or double).
536 Knows how to convert fixed values to double, or
537 floating values to long.
538 Does not deallocate the value. */
541 value_as_long (register value_ptr val
)
543 /* This coerces arrays and functions, which is necessary (e.g.
544 in disassemble_command). It also dereferences references, which
545 I suspect is the most logical thing to do. */
547 return unpack_long (VALUE_TYPE (val
), VALUE_CONTENTS (val
));
551 value_as_double (register value_ptr val
)
556 foo
= unpack_double (VALUE_TYPE (val
), VALUE_CONTENTS (val
), &inv
);
558 error ("Invalid floating value found in program.");
561 /* Extract a value as a C pointer. Does not deallocate the value.
562 Note that val's type may not actually be a pointer; value_as_long
563 handles all the cases. */
565 value_as_pointer (value_ptr val
)
567 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
568 whether we want this to be true eventually. */
570 /* ADDR_BITS_REMOVE is wrong if we are being called for a
571 non-address (e.g. argument to "signal", "info break", etc.), or
572 for pointers to char, in which the low bits *are* significant. */
573 return ADDR_BITS_REMOVE (value_as_long (val
));
576 /* In converting VAL to an address (CORE_ADDR), any small integers
577 are first cast to a generic pointer. The function unpack_long
578 will then correctly convert that pointer into a canonical address
579 (using POINTER_TO_ADDRESS).
581 Without the cast, the MIPS gets: 0xa0000000 -> (unsigned int)
582 0xa0000000 -> (LONGEST) 0x00000000a0000000
584 With the cast, the MIPS gets: 0xa0000000 -> (unsigned int)
585 0xa0000000 -> (void*) 0xa0000000 -> (LONGEST) 0xffffffffa0000000.
587 If the user specifies an integer that is larger than the target
588 pointer type, it is assumed that it was intentional and the value
589 is converted directly into an ADDRESS. This ensures that no
590 information is discarded.
592 NOTE: The cast operation may eventualy be converted into a TARGET
593 method (see POINTER_TO_ADDRESS() and ADDRESS_TO_POINTER()) so
594 that the TARGET ISA/ABI can apply an arbitrary conversion.
596 NOTE: In pure harvard architectures function and data pointers
597 can be different and may require different integer to pointer
599 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
600 && TYPE_LENGTH (VALUE_TYPE (val
)) <= TYPE_LENGTH (builtin_type_ptr
))
602 val
= value_cast (builtin_type_ptr
, val
);
604 return unpack_long (VALUE_TYPE (val
), VALUE_CONTENTS (val
));
608 /* Unpack raw data (copied from debugee, target byte order) at VALADDR
609 as a long, or as a double, assuming the raw data is described
610 by type TYPE. Knows how to convert different sizes of values
611 and can convert between fixed and floating point. We don't assume
612 any alignment for the raw data. Return value is in host byte order.
614 If you want functions and arrays to be coerced to pointers, and
615 references to be dereferenced, call value_as_long() instead.
617 C++: It is assumed that the front-end has taken care of
618 all matters concerning pointers to members. A pointer
619 to member which reaches here is considered to be equivalent
620 to an INT (or some size). After all, it is only an offset. */
623 unpack_long (struct type
*type
, char *valaddr
)
625 register enum type_code code
= TYPE_CODE (type
);
626 register int len
= TYPE_LENGTH (type
);
627 register int nosign
= TYPE_UNSIGNED (type
);
629 if (current_language
->la_language
== language_scm
630 && is_scmvalue_type (type
))
631 return scm_unpack (type
, valaddr
, TYPE_CODE_INT
);
635 case TYPE_CODE_TYPEDEF
:
636 return unpack_long (check_typedef (type
), valaddr
);
641 case TYPE_CODE_RANGE
:
643 return extract_unsigned_integer (valaddr
, len
);
645 return extract_signed_integer (valaddr
, len
);
648 return extract_floating (valaddr
, len
);
652 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
653 whether we want this to be true eventually. */
654 if (GDB_TARGET_IS_D10V
656 return D10V_MAKE_DADDR (extract_address (valaddr
, len
));
657 return extract_typed_address (valaddr
, type
);
659 case TYPE_CODE_MEMBER
:
660 error ("not implemented: member types in unpack_long");
663 error ("Value can't be converted to integer.");
665 return 0; /* Placate lint. */
668 /* Return a double value from the specified type and address.
669 INVP points to an int which is set to 0 for valid value,
670 1 for invalid value (bad float format). In either case,
671 the returned double is OK to use. Argument is in target
672 format, result is in host format. */
675 unpack_double (struct type
*type
, char *valaddr
, int *invp
)
681 *invp
= 0; /* Assume valid. */
682 CHECK_TYPEDEF (type
);
683 code
= TYPE_CODE (type
);
684 len
= TYPE_LENGTH (type
);
685 nosign
= TYPE_UNSIGNED (type
);
686 if (code
== TYPE_CODE_FLT
)
689 if (INVALID_FLOAT (valaddr
, len
))
692 return 1.234567891011121314;
695 return extract_floating (valaddr
, len
);
699 /* Unsigned -- be sure we compensate for signed LONGEST. */
700 #if !defined (_MSC_VER) || (_MSC_VER > 900)
701 return (ULONGEST
) unpack_long (type
, valaddr
);
703 /* FIXME!!! msvc22 doesn't support unsigned __int64 -> double */
704 return (LONGEST
) unpack_long (type
, valaddr
);
705 #endif /* _MSC_VER */
709 /* Signed -- we are OK with unpack_long. */
710 return unpack_long (type
, valaddr
);
714 /* Unpack raw data (copied from debugee, target byte order) at VALADDR
715 as a CORE_ADDR, assuming the raw data is described by type TYPE.
716 We don't assume any alignment for the raw data. Return value is in
719 If you want functions and arrays to be coerced to pointers, and
720 references to be dereferenced, call value_as_pointer() instead.
722 C++: It is assumed that the front-end has taken care of
723 all matters concerning pointers to members. A pointer
724 to member which reaches here is considered to be equivalent
725 to an INT (or some size). After all, it is only an offset. */
728 unpack_pointer (struct type
*type
, char *valaddr
)
730 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
731 whether we want this to be true eventually. */
732 return unpack_long (type
, valaddr
);
736 /* Get the value of the FIELDN'th field (which must be static) of TYPE. */
739 value_static_field (struct type
*type
, int fieldno
)
743 if (TYPE_FIELD_STATIC_HAS_ADDR (type
, fieldno
))
745 addr
= TYPE_FIELD_STATIC_PHYSADDR (type
, fieldno
);
750 char *phys_name
= TYPE_FIELD_STATIC_PHYSNAME (type
, fieldno
);
751 struct symbol
*sym
= lookup_symbol (phys_name
, 0, VAR_NAMESPACE
, 0, NULL
);
754 /* With some compilers, e.g. HP aCC, static data members are reported
755 as non-debuggable symbols */
756 struct minimal_symbol
*msym
= lookup_minimal_symbol (phys_name
, NULL
, NULL
);
761 addr
= SYMBOL_VALUE_ADDRESS (msym
);
762 sect
= SYMBOL_BFD_SECTION (msym
);
767 addr
= SYMBOL_VALUE_ADDRESS (sym
);
768 sect
= SYMBOL_BFD_SECTION (sym
);
770 SET_FIELD_PHYSADDR (TYPE_FIELD (type
, fieldno
), addr
);
772 return value_at (TYPE_FIELD_TYPE (type
, fieldno
), addr
, sect
);
775 /* Given a value ARG1 (offset by OFFSET bytes)
776 of a struct or union type ARG_TYPE,
777 extract and return the value of one of its (non-static) fields.
778 FIELDNO says which field. */
781 value_primitive_field (register value_ptr arg1
, int offset
,
782 register int fieldno
, register struct type
*arg_type
)
784 register value_ptr v
;
785 register struct type
*type
;
787 CHECK_TYPEDEF (arg_type
);
788 type
= TYPE_FIELD_TYPE (arg_type
, fieldno
);
790 /* Handle packed fields */
792 if (TYPE_FIELD_BITSIZE (arg_type
, fieldno
))
794 v
= value_from_longest (type
,
795 unpack_field_as_long (arg_type
,
796 VALUE_CONTENTS (arg1
)
799 VALUE_BITPOS (v
) = TYPE_FIELD_BITPOS (arg_type
, fieldno
) % 8;
800 VALUE_BITSIZE (v
) = TYPE_FIELD_BITSIZE (arg_type
, fieldno
);
801 VALUE_OFFSET (v
) = VALUE_OFFSET (arg1
) + offset
802 + TYPE_FIELD_BITPOS (arg_type
, fieldno
) / 8;
804 else if (fieldno
< TYPE_N_BASECLASSES (arg_type
))
806 /* This field is actually a base subobject, so preserve the
807 entire object's contents for later references to virtual
809 v
= allocate_value (VALUE_ENCLOSING_TYPE (arg1
));
810 VALUE_TYPE (v
) = arg_type
;
811 if (VALUE_LAZY (arg1
))
814 memcpy (VALUE_CONTENTS_ALL_RAW (v
), VALUE_CONTENTS_ALL_RAW (arg1
),
815 TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg1
)));
816 VALUE_OFFSET (v
) = VALUE_OFFSET (arg1
);
817 VALUE_EMBEDDED_OFFSET (v
)
819 VALUE_EMBEDDED_OFFSET (arg1
) +
820 TYPE_FIELD_BITPOS (arg_type
, fieldno
) / 8;
824 /* Plain old data member */
825 offset
+= TYPE_FIELD_BITPOS (arg_type
, fieldno
) / 8;
826 v
= allocate_value (type
);
827 if (VALUE_LAZY (arg1
))
830 memcpy (VALUE_CONTENTS_RAW (v
),
831 VALUE_CONTENTS_RAW (arg1
) + offset
,
833 VALUE_OFFSET (v
) = VALUE_OFFSET (arg1
) + offset
;
835 VALUE_LVAL (v
) = VALUE_LVAL (arg1
);
836 if (VALUE_LVAL (arg1
) == lval_internalvar
)
837 VALUE_LVAL (v
) = lval_internalvar_component
;
838 VALUE_ADDRESS (v
) = VALUE_ADDRESS (arg1
);
839 VALUE_REGNO (v
) = VALUE_REGNO (arg1
);
840 /* VALUE_OFFSET (v) = VALUE_OFFSET (arg1) + offset
841 + TYPE_FIELD_BITPOS (arg_type, fieldno) / 8; */
845 /* Given a value ARG1 of a struct or union type,
846 extract and return the value of one of its (non-static) fields.
847 FIELDNO says which field. */
850 value_field (register value_ptr arg1
, register int fieldno
)
852 return value_primitive_field (arg1
, 0, fieldno
, VALUE_TYPE (arg1
));
855 /* Return a non-virtual function as a value.
856 F is the list of member functions which contains the desired method.
857 J is an index into F which provides the desired method. */
860 value_fn_field (value_ptr
*arg1p
, struct fn_field
*f
, int j
, struct type
*type
,
863 register value_ptr v
;
864 register struct type
*ftype
= TYPE_FN_FIELD_TYPE (f
, j
);
867 sym
= lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, j
),
868 0, VAR_NAMESPACE
, 0, NULL
);
872 error ("Internal error: could not find physical method named %s",
873 TYPE_FN_FIELD_PHYSNAME (f, j));
876 v
= allocate_value (ftype
);
877 VALUE_ADDRESS (v
) = BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
878 VALUE_TYPE (v
) = ftype
;
882 if (type
!= VALUE_TYPE (*arg1p
))
883 *arg1p
= value_ind (value_cast (lookup_pointer_type (type
),
884 value_addr (*arg1p
)));
886 /* Move the `this' pointer according to the offset.
887 VALUE_OFFSET (*arg1p) += offset;
894 /* Return a virtual function as a value.
895 ARG1 is the object which provides the virtual function
896 table pointer. *ARG1P is side-effected in calling this function.
897 F is the list of member functions which contains the desired virtual
899 J is an index into F which provides the desired virtual function.
901 TYPE is the type in which F is located. */
903 value_virtual_fn_field (value_ptr
*arg1p
, struct fn_field
*f
, int j
,
904 struct type
*type
, int offset
)
906 value_ptr arg1
= *arg1p
;
907 struct type
*type1
= check_typedef (VALUE_TYPE (arg1
));
909 if (TYPE_HAS_VTABLE (type
))
911 /* Deal with HP/Taligent runtime model for virtual functions */
913 value_ptr argp
; /* arg1 cast to base */
914 CORE_ADDR coreptr
; /* pointer to target address */
915 int class_index
; /* which class segment pointer to use */
916 struct type
*ftype
= TYPE_FN_FIELD_TYPE (f
, j
); /* method type */
918 argp
= value_cast (type
, *arg1p
);
920 if (VALUE_ADDRESS (argp
) == 0)
921 error ("Address of object is null; object may not have been created.");
923 /* pai: FIXME -- 32x64 possible problem? */
924 /* First word (4 bytes) in object layout is the vtable pointer */
925 coreptr
= *(CORE_ADDR
*) (VALUE_CONTENTS (argp
)); /* pai: (temp) */
926 /* + offset + VALUE_EMBEDDED_OFFSET (argp)); */
929 error ("Virtual table pointer is null for object; object may not have been created.");
932 * FIXME: The code here currently handles only
933 * the non-RRBC case of the Taligent/HP runtime spec; when RRBC
934 * is introduced, the condition for the "if" below will have to
935 * be changed to be a test for the RRBC case. */
939 /* Non-RRBC case; the virtual function pointers are stored at fixed
940 * offsets in the virtual table. */
942 /* Retrieve the offset in the virtual table from the debug
943 * info. The offset of the vfunc's entry is in words from
944 * the beginning of the vtable; but first we have to adjust
945 * by HP_ACC_VFUNC_START to account for other entries */
947 /* pai: FIXME: 32x64 problem here, a word may be 8 bytes in
948 * which case the multiplier should be 8 and values should be long */
949 vp
= value_at (builtin_type_int
,
950 coreptr
+ 4 * (TYPE_FN_FIELD_VOFFSET (f
, j
) + HP_ACC_VFUNC_START
), NULL
);
952 coreptr
= *(CORE_ADDR
*) (VALUE_CONTENTS (vp
));
953 /* coreptr now contains the address of the virtual function */
954 /* (Actually, it contains the pointer to the plabel for the function. */
958 /* RRBC case; the virtual function pointers are found by double
959 * indirection through the class segment tables. */
961 /* Choose class segment depending on type we were passed */
962 class_index
= class_index_in_primary_list (type
);
964 /* Find class segment pointer. These are in the vtable slots after
965 * some other entries, so adjust by HP_ACC_VFUNC_START for that. */
966 /* pai: FIXME 32x64 problem here, if words are 8 bytes long
967 * the multiplier below has to be 8 and value should be long. */
968 vp
= value_at (builtin_type_int
,
969 coreptr
+ 4 * (HP_ACC_VFUNC_START
+ class_index
), NULL
);
970 /* Indirect once more, offset by function index */
971 /* pai: FIXME 32x64 problem here, again multiplier could be 8 and value long */
972 coreptr
= *(CORE_ADDR
*) (VALUE_CONTENTS (vp
) + 4 * TYPE_FN_FIELD_VOFFSET (f
, j
));
973 vp
= value_at (builtin_type_int
, coreptr
, NULL
);
974 coreptr
= *(CORE_ADDR
*) (VALUE_CONTENTS (vp
));
976 /* coreptr now contains the address of the virtual function */
977 /* (Actually, it contains the pointer to the plabel for the function.) */
982 error ("Address of virtual function is null; error in virtual table?");
984 /* Wrap this addr in a value and return pointer */
985 vp
= allocate_value (ftype
);
986 VALUE_TYPE (vp
) = ftype
;
987 VALUE_ADDRESS (vp
) = coreptr
;
989 /* pai: (temp) do we need the value_ind stuff in value_fn_field? */
993 { /* Not using HP/Taligent runtime conventions; so try to
994 * use g++ conventions for virtual table */
996 struct type
*entry_type
;
997 /* First, get the virtual function table pointer. That comes
998 with a strange type, so cast it to type `pointer to long' (which
999 should serve just fine as a function type). Then, index into
1000 the table, and convert final value to appropriate function type. */
1001 value_ptr entry
, vfn
, vtbl
;
1002 value_ptr vi
= value_from_longest (builtin_type_int
,
1003 (LONGEST
) TYPE_FN_FIELD_VOFFSET (f
, j
));
1004 struct type
*fcontext
= TYPE_FN_FIELD_FCONTEXT (f
, j
);
1005 struct type
*context
;
1006 if (fcontext
== NULL
)
1007 /* We don't have an fcontext (e.g. the program was compiled with
1008 g++ version 1). Try to get the vtbl from the TYPE_VPTR_BASETYPE.
1009 This won't work right for multiple inheritance, but at least we
1010 should do as well as GDB 3.x did. */
1011 fcontext
= TYPE_VPTR_BASETYPE (type
);
1012 context
= lookup_pointer_type (fcontext
);
1013 /* Now context is a pointer to the basetype containing the vtbl. */
1014 if (TYPE_TARGET_TYPE (context
) != type1
)
1016 value_ptr tmp
= value_cast (context
, value_addr (arg1
));
1017 VALUE_POINTED_TO_OFFSET (tmp
) = 0;
1018 arg1
= value_ind (tmp
);
1019 type1
= check_typedef (VALUE_TYPE (arg1
));
1023 /* Now context is the basetype containing the vtbl. */
1025 /* This type may have been defined before its virtual function table
1026 was. If so, fill in the virtual function table entry for the
1028 if (TYPE_VPTR_FIELDNO (context
) < 0)
1029 fill_in_vptr_fieldno (context
);
1031 /* The virtual function table is now an array of structures
1032 which have the form { int16 offset, delta; void *pfn; }. */
1033 vtbl
= value_primitive_field (arg1
, 0, TYPE_VPTR_FIELDNO (context
),
1034 TYPE_VPTR_BASETYPE (context
));
1036 /* With older versions of g++, the vtbl field pointed to an array
1037 of structures. Nowadays it points directly to the structure. */
1038 if (TYPE_CODE (VALUE_TYPE (vtbl
)) == TYPE_CODE_PTR
1039 && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (vtbl
))) == TYPE_CODE_ARRAY
)
1041 /* Handle the case where the vtbl field points to an
1042 array of structures. */
1043 vtbl
= value_ind (vtbl
);
1045 /* Index into the virtual function table. This is hard-coded because
1046 looking up a field is not cheap, and it may be important to save
1047 time, e.g. if the user has set a conditional breakpoint calling
1048 a virtual function. */
1049 entry
= value_subscript (vtbl
, vi
);
1053 /* Handle the case where the vtbl field points directly to a structure. */
1054 vtbl
= value_add (vtbl
, vi
);
1055 entry
= value_ind (vtbl
);
1058 entry_type
= check_typedef (VALUE_TYPE (entry
));
1060 if (TYPE_CODE (entry_type
) == TYPE_CODE_STRUCT
)
1062 /* Move the `this' pointer according to the virtual function table. */
1063 VALUE_OFFSET (arg1
) += value_as_long (value_field (entry
, 0));
1065 if (!VALUE_LAZY (arg1
))
1067 VALUE_LAZY (arg1
) = 1;
1068 value_fetch_lazy (arg1
);
1071 vfn
= value_field (entry
, 2);
1073 else if (TYPE_CODE (entry_type
) == TYPE_CODE_PTR
)
1076 error ("I'm confused: virtual function table has bad type");
1077 /* Reinstantiate the function pointer with the correct type. */
1078 VALUE_TYPE (vfn
) = lookup_pointer_type (TYPE_FN_FIELD_TYPE (f
, j
));
1085 /* ARG is a pointer to an object we know to be at least
1086 a DTYPE. BTYPE is the most derived basetype that has
1087 already been searched (and need not be searched again).
1088 After looking at the vtables between BTYPE and DTYPE,
1089 return the most derived type we find. The caller must
1090 be satisfied when the return value == DTYPE.
1092 FIXME-tiemann: should work with dossier entries as well.
1093 NOTICE - djb: I see no good reason at all to keep this function now that
1094 we have RTTI support. It's used in literally one place, and it's
1095 hard to keep this function up to date when it's purpose is served
1096 by value_rtti_type efficiently.
1097 Consider it gone for 5.1. */
1100 value_headof (value_ptr in_arg
, struct type
*btype
, struct type
*dtype
)
1102 /* First collect the vtables we must look at for this object. */
1103 value_ptr arg
, vtbl
;
1105 char *demangled_name
;
1106 struct minimal_symbol
*msymbol
;
1108 btype
= TYPE_VPTR_BASETYPE (dtype
);
1109 CHECK_TYPEDEF (btype
);
1112 arg
= value_cast (lookup_pointer_type (btype
), arg
);
1113 if (TYPE_CODE (VALUE_TYPE (arg
)) == TYPE_CODE_REF
)
1116 * Copy the value, but change the type from (T&) to (T*).
1117 * We keep the same location information, which is efficient,
1118 * and allows &(&X) to get the location containing the reference.
1120 arg
= value_copy (arg
);
1121 VALUE_TYPE (arg
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg
)));
1123 if (VALUE_ADDRESS(value_field (value_ind(arg
), TYPE_VPTR_FIELDNO (btype
)))==0)
1126 vtbl
= value_ind (value_field (value_ind (arg
), TYPE_VPTR_FIELDNO (btype
)));
1127 /* Turn vtable into typeinfo function */
1128 VALUE_OFFSET(vtbl
)+=4;
1130 msymbol
= lookup_minimal_symbol_by_pc ( value_as_pointer(value_ind(vtbl
)) );
1132 || (demangled_name
= SYMBOL_NAME (msymbol
)) == NULL
)
1134 /* If we expected to find a vtable, but did not, let the user
1135 know that we aren't happy, but don't throw an error.
1136 FIXME: there has to be a better way to do this. */
1137 struct type
*error_type
= (struct type
*) xmalloc (sizeof (struct type
));
1138 memcpy (error_type
, VALUE_TYPE (in_arg
), sizeof (struct type
));
1139 TYPE_NAME (error_type
) = savestring ("suspicious *", sizeof ("suspicious *"));
1140 VALUE_TYPE (in_arg
) = error_type
;
1143 demangled_name
= cplus_demangle(demangled_name
,DMGL_ANSI
);
1144 *(strchr (demangled_name
, ' ')) = '\0';
1146 sym
= lookup_symbol (demangled_name
, 0, VAR_NAMESPACE
, 0, 0);
1148 error ("could not find type declaration for `%s'", demangled_name
);
1151 VALUE_TYPE (arg
) = lookup_pointer_type (SYMBOL_TYPE (sym
));
1155 /* ARG is a pointer object of type TYPE. If TYPE has virtual
1156 function tables, probe ARG's tables (including the vtables
1157 of its baseclasses) to figure out the most derived type that ARG
1158 could actually be a pointer to. */
1161 value_from_vtable_info (value_ptr arg
, struct type
*type
)
1163 /* Take care of preliminaries. */
1164 if (TYPE_VPTR_FIELDNO (type
) < 0)
1165 fill_in_vptr_fieldno (type
);
1166 if (TYPE_VPTR_FIELDNO (type
) < 0)
1169 return value_headof (arg
, 0, type
);
1172 /* Return true if the INDEXth field of TYPE is a virtual baseclass
1173 pointer which is for the base class whose type is BASECLASS. */
1176 vb_match (struct type
*type
, int index
, struct type
*basetype
)
1178 struct type
*fieldtype
;
1179 char *name
= TYPE_FIELD_NAME (type
, index
);
1180 char *field_class_name
= NULL
;
1184 /* gcc 2.4 uses _vb$. */
1185 if (name
[1] == 'v' && name
[2] == 'b' && is_cplus_marker (name
[3]))
1186 field_class_name
= name
+ 4;
1187 /* gcc 2.5 will use __vb_. */
1188 if (name
[1] == '_' && name
[2] == 'v' && name
[3] == 'b' && name
[4] == '_')
1189 field_class_name
= name
+ 5;
1191 if (field_class_name
== NULL
)
1192 /* This field is not a virtual base class pointer. */
1195 /* It's a virtual baseclass pointer, now we just need to find out whether
1196 it is for this baseclass. */
1197 fieldtype
= TYPE_FIELD_TYPE (type
, index
);
1198 if (fieldtype
== NULL
1199 || TYPE_CODE (fieldtype
) != TYPE_CODE_PTR
)
1200 /* "Can't happen". */
1203 /* What we check for is that either the types are equal (needed for
1204 nameless types) or have the same name. This is ugly, and a more
1205 elegant solution should be devised (which would probably just push
1206 the ugliness into symbol reading unless we change the stabs format). */
1207 if (TYPE_TARGET_TYPE (fieldtype
) == basetype
)
1210 if (TYPE_NAME (basetype
) != NULL
1211 && TYPE_NAME (TYPE_TARGET_TYPE (fieldtype
)) != NULL
1212 && STREQ (TYPE_NAME (basetype
),
1213 TYPE_NAME (TYPE_TARGET_TYPE (fieldtype
))))
1218 /* Compute the offset of the baseclass which is
1219 the INDEXth baseclass of class TYPE,
1220 for value at VALADDR (in host) at ADDRESS (in target).
1221 The result is the offset of the baseclass value relative
1222 to (the address of)(ARG) + OFFSET.
1224 -1 is returned on error. */
1227 baseclass_offset (struct type
*type
, int index
, char *valaddr
,
1230 struct type
*basetype
= TYPE_BASECLASS (type
, index
);
1232 if (BASETYPE_VIA_VIRTUAL (type
, index
))
1234 /* Must hunt for the pointer to this virtual baseclass. */
1235 register int i
, len
= TYPE_NFIELDS (type
);
1236 register int n_baseclasses
= TYPE_N_BASECLASSES (type
);
1238 /* First look for the virtual baseclass pointer
1240 for (i
= n_baseclasses
; i
< len
; i
++)
1242 if (vb_match (type
, i
, basetype
))
1245 = unpack_pointer (TYPE_FIELD_TYPE (type
, i
),
1246 valaddr
+ (TYPE_FIELD_BITPOS (type
, i
) / 8));
1248 return addr
- (LONGEST
) address
;
1251 /* Not in the fields, so try looking through the baseclasses. */
1252 for (i
= index
+ 1; i
< n_baseclasses
; i
++)
1255 baseclass_offset (type
, i
, valaddr
, address
);
1263 /* Baseclass is easily computed. */
1264 return TYPE_BASECLASS_BITPOS (type
, index
) / 8;
1267 /* Unpack a field FIELDNO of the specified TYPE, from the anonymous object at
1270 Extracting bits depends on endianness of the machine. Compute the
1271 number of least significant bits to discard. For big endian machines,
1272 we compute the total number of bits in the anonymous object, subtract
1273 off the bit count from the MSB of the object to the MSB of the
1274 bitfield, then the size of the bitfield, which leaves the LSB discard
1275 count. For little endian machines, the discard count is simply the
1276 number of bits from the LSB of the anonymous object to the LSB of the
1279 If the field is signed, we also do sign extension. */
1282 unpack_field_as_long (struct type
*type
, char *valaddr
, int fieldno
)
1286 int bitpos
= TYPE_FIELD_BITPOS (type
, fieldno
);
1287 int bitsize
= TYPE_FIELD_BITSIZE (type
, fieldno
);
1289 struct type
*field_type
;
1291 val
= extract_unsigned_integer (valaddr
+ bitpos
/ 8, sizeof (val
));
1292 field_type
= TYPE_FIELD_TYPE (type
, fieldno
);
1293 CHECK_TYPEDEF (field_type
);
1295 /* Extract bits. See comment above. */
1297 if (BITS_BIG_ENDIAN
)
1298 lsbcount
= (sizeof val
* 8 - bitpos
% 8 - bitsize
);
1300 lsbcount
= (bitpos
% 8);
1303 /* If the field does not entirely fill a LONGEST, then zero the sign bits.
1304 If the field is signed, and is negative, then sign extend. */
1306 if ((bitsize
> 0) && (bitsize
< 8 * (int) sizeof (val
)))
1308 valmask
= (((ULONGEST
) 1) << bitsize
) - 1;
1310 if (!TYPE_UNSIGNED (field_type
))
1312 if (val
& (valmask
^ (valmask
>> 1)))
1321 /* Modify the value of a bitfield. ADDR points to a block of memory in
1322 target byte order; the bitfield starts in the byte pointed to. FIELDVAL
1323 is the desired value of the field, in host byte order. BITPOS and BITSIZE
1324 indicate which bits (in target bit order) comprise the bitfield. */
1327 modify_field (char *addr
, LONGEST fieldval
, int bitpos
, int bitsize
)
1331 /* If a negative fieldval fits in the field in question, chop
1332 off the sign extension bits. */
1333 if (bitsize
< (8 * (int) sizeof (fieldval
))
1334 && (~fieldval
& ~((1 << (bitsize
- 1)) - 1)) == 0)
1335 fieldval
= fieldval
& ((1 << bitsize
) - 1);
1337 /* Warn if value is too big to fit in the field in question. */
1338 if (bitsize
< (8 * (int) sizeof (fieldval
))
1339 && 0 != (fieldval
& ~((1 << bitsize
) - 1)))
1341 /* FIXME: would like to include fieldval in the message, but
1342 we don't have a sprintf_longest. */
1343 warning ("Value does not fit in %d bits.", bitsize
);
1345 /* Truncate it, otherwise adjoining fields may be corrupted. */
1346 fieldval
= fieldval
& ((1 << bitsize
) - 1);
1349 oword
= extract_signed_integer (addr
, sizeof oword
);
1351 /* Shifting for bit field depends on endianness of the target machine. */
1352 if (BITS_BIG_ENDIAN
)
1353 bitpos
= sizeof (oword
) * 8 - bitpos
- bitsize
;
1355 /* Mask out old value, while avoiding shifts >= size of oword */
1356 if (bitsize
< 8 * (int) sizeof (oword
))
1357 oword
&= ~(((((ULONGEST
) 1) << bitsize
) - 1) << bitpos
);
1359 oword
&= ~((~(ULONGEST
) 0) << bitpos
);
1360 oword
|= fieldval
<< bitpos
;
1362 store_signed_integer (addr
, sizeof oword
, oword
);
1365 /* Convert C numbers into newly allocated values */
1368 value_from_longest (struct type
*type
, register LONGEST num
)
1370 register value_ptr val
= allocate_value (type
);
1371 register enum type_code code
;
1374 code
= TYPE_CODE (type
);
1375 len
= TYPE_LENGTH (type
);
1379 case TYPE_CODE_TYPEDEF
:
1380 type
= check_typedef (type
);
1383 case TYPE_CODE_CHAR
:
1384 case TYPE_CODE_ENUM
:
1385 case TYPE_CODE_BOOL
:
1386 case TYPE_CODE_RANGE
:
1387 store_signed_integer (VALUE_CONTENTS_RAW (val
), len
, num
);
1392 store_typed_address (VALUE_CONTENTS_RAW (val
), type
, (CORE_ADDR
) num
);
1396 error ("Unexpected type (%d) encountered for integer constant.", code
);
1402 /* Create a value representing a pointer of type TYPE to the address
1405 value_from_pointer (struct type
*type
, CORE_ADDR addr
)
1407 value_ptr val
= allocate_value (type
);
1408 store_typed_address (VALUE_CONTENTS_RAW (val
), type
, addr
);
1413 /* Create a value for a string constant to be stored locally
1414 (not in the inferior's memory space, but in GDB memory).
1415 This is analogous to value_from_longest, which also does not
1416 use inferior memory. String shall NOT contain embedded nulls. */
1419 value_from_string (char *ptr
)
1422 int len
= strlen (ptr
);
1423 int lowbound
= current_language
->string_lower_bound
;
1424 struct type
*rangetype
=
1425 create_range_type ((struct type
*) NULL
,
1427 lowbound
, len
+ lowbound
- 1);
1428 struct type
*stringtype
=
1429 create_array_type ((struct type
*) NULL
,
1430 *current_language
->string_char_type
,
1433 val
= allocate_value (stringtype
);
1434 memcpy (VALUE_CONTENTS_RAW (val
), ptr
, len
);
1439 value_from_double (struct type
*type
, DOUBLEST num
)
1441 register value_ptr val
= allocate_value (type
);
1442 struct type
*base_type
= check_typedef (type
);
1443 register enum type_code code
= TYPE_CODE (base_type
);
1444 register int len
= TYPE_LENGTH (base_type
);
1446 if (code
== TYPE_CODE_FLT
)
1448 store_floating (VALUE_CONTENTS_RAW (val
), len
, num
);
1451 error ("Unexpected type encountered for floating constant.");
1456 /* Deal with the value that is "about to be returned". */
1458 /* Return the value that a function returning now
1459 would be returning to its caller, assuming its type is VALTYPE.
1460 RETBUF is where we look for what ought to be the contents
1461 of the registers (in raw form). This is because it is often
1462 desirable to restore old values to those registers
1463 after saving the contents of interest, and then call
1464 this function using the saved values.
1465 struct_return is non-zero when the function in question is
1466 using the structure return conventions on the machine in question;
1467 0 when it is using the value returning conventions (this often
1468 means returning pointer to where structure is vs. returning value). */
1472 value_being_returned (struct type
*valtype
, char *retbuf
, int struct_return
)
1474 register value_ptr val
;
1477 /* If this is not defined, just use EXTRACT_RETURN_VALUE instead. */
1478 if (EXTRACT_STRUCT_VALUE_ADDRESS_P
)
1481 addr
= EXTRACT_STRUCT_VALUE_ADDRESS (retbuf
);
1483 error ("Function return value unknown");
1484 return value_at (valtype
, addr
, NULL
);
1487 val
= allocate_value (valtype
);
1488 CHECK_TYPEDEF (valtype
);
1489 EXTRACT_RETURN_VALUE (valtype
, retbuf
, VALUE_CONTENTS_RAW (val
));
1494 /* Should we use EXTRACT_STRUCT_VALUE_ADDRESS instead of
1495 EXTRACT_RETURN_VALUE? GCC_P is true if compiled with gcc
1496 and TYPE is the type (which is known to be struct, union or array).
1498 On most machines, the struct convention is used unless we are
1499 using gcc and the type is of a special size. */
1500 /* As of about 31 Mar 93, GCC was changed to be compatible with the
1501 native compiler. GCC 2.3.3 was the last release that did it the
1502 old way. Since gcc2_compiled was not changed, we have no
1503 way to correctly win in all cases, so we just do the right thing
1504 for gcc1 and for gcc2 after this change. Thus it loses for gcc
1505 2.0-2.3.3. This is somewhat unfortunate, but changing gcc2_compiled
1506 would cause more chaos than dealing with some struct returns being
1510 generic_use_struct_convention (int gcc_p
, struct type
*value_type
)
1512 return !((gcc_p
== 1)
1513 && (TYPE_LENGTH (value_type
) == 1
1514 || TYPE_LENGTH (value_type
) == 2
1515 || TYPE_LENGTH (value_type
) == 4
1516 || TYPE_LENGTH (value_type
) == 8));
1519 #ifndef USE_STRUCT_CONVENTION
1520 #define USE_STRUCT_CONVENTION(gcc_p,type) generic_use_struct_convention (gcc_p, type)
1524 /* Return true if the function specified is using the structure returning
1525 convention on this machine to return arguments, or 0 if it is using
1526 the value returning convention. FUNCTION is the value representing
1527 the function, FUNCADDR is the address of the function, and VALUE_TYPE
1528 is the type returned by the function. GCC_P is nonzero if compiled
1533 using_struct_return (value_ptr function
, CORE_ADDR funcaddr
,
1534 struct type
*value_type
, int gcc_p
)
1536 register enum type_code code
= TYPE_CODE (value_type
);
1538 if (code
== TYPE_CODE_ERROR
)
1539 error ("Function return type unknown.");
1541 if (code
== TYPE_CODE_STRUCT
1542 || code
== TYPE_CODE_UNION
1543 || code
== TYPE_CODE_ARRAY
1544 || RETURN_VALUE_ON_STACK (value_type
))
1545 return USE_STRUCT_CONVENTION (gcc_p
, value_type
);
1550 /* Store VAL so it will be returned if a function returns now.
1551 Does not verify that VAL's type matches what the current
1552 function wants to return. */
1555 set_return_value (value_ptr val
)
1557 struct type
*type
= check_typedef (VALUE_TYPE (val
));
1558 register enum type_code code
= TYPE_CODE (type
);
1560 if (code
== TYPE_CODE_ERROR
)
1561 error ("Function return type unknown.");
1563 if (code
== TYPE_CODE_STRUCT
1564 || code
== TYPE_CODE_UNION
) /* FIXME, implement struct return. */
1565 error ("GDB does not support specifying a struct or union return value.");
1567 STORE_RETURN_VALUE (type
, VALUE_CONTENTS (val
));
1571 _initialize_values (void)
1573 add_cmd ("convenience", no_class
, show_convenience
,
1574 "Debugger convenience (\"$foo\") variables.\n\
1575 These variables are created when you assign them values;\n\
1576 thus, \"print $foo=1\" gives \"$foo\" the value 1. Values may be any type.\n\n\
1577 A few convenience variables are given values automatically:\n\
1578 \"$_\"holds the last address examined with \"x\" or \"info lines\",\n\
1579 \"$__\" holds the contents of the last address examined with \"x\".",
1582 add_cmd ("values", no_class
, show_values
,
1583 "Elements of value history around item number IDX (or last ten).",