1 /* Find a variable's value in memory, for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1994, 1995 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program 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 2 of the License, or
9 (at your option) any later version.
11 This program 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 this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
30 static void write_register_pid
PARAMS ((int regno
, LONGEST val
, int pid
));
32 /* Basic byte-swapping routines. GDB has needed these for a long time...
33 All extract a target-format integer at ADDR which is LEN bytes long. */
35 #if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8
36 /* 8 bit characters are a pretty safe assumption these days, so we
37 assume it throughout all these swapping routines. If we had to deal with
38 9 bit characters, we would need to make len be in bits and would have
39 to re-write these routines... */
44 extract_signed_integer (addr
, len
)
50 unsigned char *startaddr
= (unsigned char *)addr
;
51 unsigned char *endaddr
= startaddr
+ len
;
53 if (len
> sizeof (LONGEST
))
55 That operation is not available on integers of more than %d bytes.",
58 /* Start at the most significant end of the integer, and work towards
59 the least significant. */
60 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
63 /* Do the sign extension once at the start. */
64 retval
= ((LONGEST
)*p
^ 0x80) - 0x80;
65 for (++p
; p
< endaddr
; ++p
)
66 retval
= (retval
<< 8) | *p
;
71 /* Do the sign extension once at the start. */
72 retval
= ((LONGEST
)*p
^ 0x80) - 0x80;
73 for (--p
; p
>= startaddr
; --p
)
74 retval
= (retval
<< 8) | *p
;
80 extract_unsigned_integer (addr
, len
)
84 unsigned LONGEST retval
;
86 unsigned char *startaddr
= (unsigned char *)addr
;
87 unsigned char *endaddr
= startaddr
+ len
;
89 if (len
> sizeof (unsigned LONGEST
))
91 That operation is not available on integers of more than %d bytes.",
92 sizeof (unsigned LONGEST
));
94 /* Start at the most significant end of the integer, and work towards
95 the least significant. */
97 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
99 for (p
= startaddr
; p
< endaddr
; ++p
)
100 retval
= (retval
<< 8) | *p
;
104 for (p
= endaddr
- 1; p
>= startaddr
; --p
)
105 retval
= (retval
<< 8) | *p
;
111 extract_address (addr
, len
)
115 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
116 whether we want this to be true eventually. */
117 return extract_unsigned_integer (addr
, len
);
121 store_signed_integer (addr
, len
, val
)
127 unsigned char *startaddr
= (unsigned char *)addr
;
128 unsigned char *endaddr
= startaddr
+ len
;
130 /* Start at the least significant end of the integer, and work towards
131 the most significant. */
132 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
134 for (p
= endaddr
- 1; p
>= startaddr
; --p
)
142 for (p
= startaddr
; p
< endaddr
; ++p
)
151 store_unsigned_integer (addr
, len
, val
)
154 unsigned LONGEST val
;
157 unsigned char *startaddr
= (unsigned char *)addr
;
158 unsigned char *endaddr
= startaddr
+ len
;
160 /* Start at the least significant end of the integer, and work towards
161 the most significant. */
162 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
164 for (p
= endaddr
- 1; p
>= startaddr
; --p
)
172 for (p
= startaddr
; p
< endaddr
; ++p
)
181 store_address (addr
, len
, val
)
186 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
187 whether we want this to be true eventually. */
188 store_unsigned_integer (addr
, len
, (LONGEST
)val
);
191 /* Swap LEN bytes at BUFFER between target and host byte-order. */
192 #define SWAP_FLOATING(buffer,len) \
195 if (TARGET_BYTE_ORDER != HOST_BYTE_ORDER) \
198 char *p = (char *)(buffer); \
199 char *q = ((char *)(buffer)) + len - 1; \
200 for (; p < q; p++, q--) \
210 /* There are various problems with the extract_floating and store_floating
213 1. These routines only handle byte-swapping, not conversion of
214 formats. So if host is IEEE floating and target is VAX floating,
215 or vice-versa, it loses. This means that we can't (yet) use these
216 routines for extendeds. Extendeds are handled by
217 REGISTER_CONVERTIBLE. What we want is to use floatformat.h, but that
218 doesn't yet handle VAX floating at all.
220 2. We can't deal with it if there is more than one floating point
221 format in use. This has to be fixed at the unpack_double level.
223 3. We probably should have a LONGEST_DOUBLE or DOUBLEST or whatever
224 we want to call it which is long double where available. */
227 extract_floating (addr
, len
)
231 if (len
== sizeof (float))
234 memcpy (&retval
, addr
, sizeof (retval
));
235 SWAP_FLOATING (&retval
, sizeof (retval
));
238 else if (len
== sizeof (double))
241 memcpy (&retval
, addr
, sizeof (retval
));
242 SWAP_FLOATING (&retval
, sizeof (retval
));
247 error ("Can't deal with a floating point number of %d bytes.", len
);
252 store_floating (addr
, len
, val
)
257 if (len
== sizeof (float))
259 float floatval
= val
;
260 SWAP_FLOATING (&floatval
, sizeof (floatval
));
261 memcpy (addr
, &floatval
, sizeof (floatval
));
263 else if (len
== sizeof (double))
265 SWAP_FLOATING (&val
, sizeof (val
));
266 memcpy (addr
, &val
, sizeof (val
));
270 error ("Can't deal with a floating point number of %d bytes.", len
);
274 #if !defined (GET_SAVED_REGISTER)
276 /* Return the address in which frame FRAME's value of register REGNUM
277 has been saved in memory. Or return zero if it has not been saved.
278 If REGNUM specifies the SP, the value we return is actually
279 the SP value, not an address where it was saved. */
282 find_saved_register (frame
, regnum
)
283 struct frame_info
*frame
;
286 struct frame_saved_regs saved_regs
;
288 register struct frame_info
*frame1
= NULL
;
289 register CORE_ADDR addr
= 0;
291 if (frame
== NULL
) /* No regs saved if want current frame */
294 #ifdef HAVE_REGISTER_WINDOWS
295 /* We assume that a register in a register window will only be saved
296 in one place (since the name changes and/or disappears as you go
297 towards inner frames), so we only call get_frame_saved_regs on
298 the current frame. This is directly in contradiction to the
299 usage below, which assumes that registers used in a frame must be
300 saved in a lower (more interior) frame. This change is a result
301 of working on a register window machine; get_frame_saved_regs
302 always returns the registers saved within a frame, within the
303 context (register namespace) of that frame. */
305 /* However, note that we don't want this to return anything if
306 nothing is saved (if there's a frame inside of this one). Also,
307 callers to this routine asking for the stack pointer want the
308 stack pointer saved for *this* frame; this is returned from the
311 if (REGISTER_IN_WINDOW_P(regnum
))
313 frame1
= get_next_frame (frame
);
314 if (!frame1
) return 0; /* Registers of this frame are active. */
316 /* Get the SP from the next frame in; it will be this
318 if (regnum
!= SP_REGNUM
)
321 get_frame_saved_regs (frame1
, &saved_regs
);
322 return saved_regs
.regs
[regnum
]; /* ... which might be zero */
324 #endif /* HAVE_REGISTER_WINDOWS */
326 /* Note that this next routine assumes that registers used in
327 frame x will be saved only in the frame that x calls and
328 frames interior to it. This is not true on the sparc, but the
329 above macro takes care of it, so we should be all right. */
333 frame1
= get_prev_frame (frame1
);
334 if (frame1
== 0 || frame1
== frame
)
336 get_frame_saved_regs (frame1
, &saved_regs
);
337 if (saved_regs
.regs
[regnum
])
338 addr
= saved_regs
.regs
[regnum
];
344 /* Find register number REGNUM relative to FRAME and put its (raw,
345 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
346 variable was optimized out (and thus can't be fetched). Set *LVAL
347 to lval_memory, lval_register, or not_lval, depending on whether
348 the value was fetched from memory, from a register, or in a strange
349 and non-modifiable way (e.g. a frame pointer which was calculated
350 rather than fetched). Set *ADDRP to the address, either in memory
351 on as a REGISTER_BYTE offset into the registers array.
353 Note that this implementation never sets *LVAL to not_lval. But
354 it can be replaced by defining GET_SAVED_REGISTER and supplying
357 The argument RAW_BUFFER must point to aligned memory. */
360 get_saved_register (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
)
364 struct frame_info
*frame
;
366 enum lval_type
*lval
;
370 if (!target_has_registers
)
371 error ("No registers.");
373 /* Normal systems don't optimize out things with register numbers. */
374 if (optimized
!= NULL
)
376 addr
= find_saved_register (frame
, regnum
);
381 if (regnum
== SP_REGNUM
)
383 if (raw_buffer
!= NULL
)
385 /* Put it back in target format. */
386 store_address (raw_buffer
, REGISTER_RAW_SIZE (regnum
), addr
);
392 if (raw_buffer
!= NULL
)
393 read_memory (addr
, raw_buffer
, REGISTER_RAW_SIZE (regnum
));
398 *lval
= lval_register
;
399 addr
= REGISTER_BYTE (regnum
);
400 if (raw_buffer
!= NULL
)
401 read_register_gen (regnum
, raw_buffer
);
406 #endif /* GET_SAVED_REGISTER. */
408 /* Copy the bytes of register REGNUM, relative to the current stack frame,
409 into our memory at MYADDR, in target byte order.
410 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
412 Returns 1 if could not be read, 0 if could. */
415 read_relative_register_raw_bytes (regnum
, myaddr
)
420 if (regnum
== FP_REGNUM
&& selected_frame
)
422 /* Put it back in target format. */
423 store_address (myaddr
, REGISTER_RAW_SIZE(FP_REGNUM
),
424 FRAME_FP(selected_frame
));
428 get_saved_register (myaddr
, &optim
, (CORE_ADDR
*) NULL
, selected_frame
,
429 regnum
, (enum lval_type
*)NULL
);
433 /* Return a `value' with the contents of register REGNUM
434 in its virtual format, with the type specified by
435 REGISTER_VIRTUAL_TYPE. */
438 value_of_register (regnum
)
443 register value_ptr reg_val
;
444 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
447 get_saved_register (raw_buffer
, &optim
, &addr
,
448 selected_frame
, regnum
, &lval
);
450 reg_val
= allocate_value (REGISTER_VIRTUAL_TYPE (regnum
));
452 /* Convert raw data to virtual format if necessary. */
454 #ifdef REGISTER_CONVERTIBLE
455 if (REGISTER_CONVERTIBLE (regnum
))
457 REGISTER_CONVERT_TO_VIRTUAL (regnum
, REGISTER_VIRTUAL_TYPE (regnum
),
458 raw_buffer
, VALUE_CONTENTS_RAW (reg_val
));
462 memcpy (VALUE_CONTENTS_RAW (reg_val
), raw_buffer
,
463 REGISTER_RAW_SIZE (regnum
));
464 VALUE_LVAL (reg_val
) = lval
;
465 VALUE_ADDRESS (reg_val
) = addr
;
466 VALUE_REGNO (reg_val
) = regnum
;
467 VALUE_OPTIMIZED_OUT (reg_val
) = optim
;
471 /* Low level examining and depositing of registers.
473 The caller is responsible for making
474 sure that the inferior is stopped before calling the fetching routines,
475 or it will get garbage. (a change from GDB version 3, in which
476 the caller got the value from the last stop). */
478 /* Contents of the registers in target byte order.
479 We allocate some extra slop since we do a lot of memcpy's around `registers',
480 and failing-soft is better than failing hard. */
481 char registers
[REGISTER_BYTES
+ /* SLOP */ 256];
483 /* Nonzero if that register has been fetched. */
484 char register_valid
[NUM_REGS
];
486 /* The thread/process associated with the current set of registers. For now,
487 -1 is special, and means `no current process'. */
488 int registers_pid
= -1;
490 /* Indicate that registers may have changed, so invalidate the cache. */
496 int numregs
= ARCH_NUM_REGS
;
500 for (i
= 0; i
< numregs
; i
++)
501 register_valid
[i
] = 0;
504 /* Indicate that all registers have been fetched, so mark them all valid. */
509 int numregs
= ARCH_NUM_REGS
;
510 for (i
= 0; i
< numregs
; i
++)
511 register_valid
[i
] = 1;
514 /* Copy LEN bytes of consecutive data from registers
515 starting with the REGBYTE'th byte of register data
516 into memory at MYADDR. */
519 read_register_bytes (regbyte
, myaddr
, len
)
524 /* Fetch all registers. */
527 if (registers_pid
!= inferior_pid
)
529 registers_changed ();
530 registers_pid
= inferior_pid
;
533 numregs
= ARCH_NUM_REGS
;
534 for (i
= 0; i
< numregs
; i
++)
535 if (!register_valid
[i
])
537 target_fetch_registers (-1);
541 memcpy (myaddr
, ®isters
[regbyte
], len
);
544 /* Read register REGNO into memory at MYADDR, which must be large enough
545 for REGISTER_RAW_BYTES (REGNO). Target byte-order.
546 If the register is known to be the size of a CORE_ADDR or smaller,
547 read_register can be used instead. */
549 read_register_gen (regno
, myaddr
)
553 if (registers_pid
!= inferior_pid
)
555 registers_changed ();
556 registers_pid
= inferior_pid
;
559 if (!register_valid
[regno
])
560 target_fetch_registers (regno
);
561 memcpy (myaddr
, ®isters
[REGISTER_BYTE (regno
)],
562 REGISTER_RAW_SIZE (regno
));
565 /* Copy LEN bytes of consecutive data from memory at MYADDR
566 into registers starting with the REGBYTE'th byte of register data. */
569 write_register_bytes (regbyte
, myaddr
, len
)
574 if (registers_pid
!= inferior_pid
)
576 registers_changed ();
577 registers_pid
= inferior_pid
;
580 /* Make sure the entire registers array is valid. */
581 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
582 memcpy (®isters
[regbyte
], myaddr
, len
);
583 target_store_registers (-1);
586 /* Return the raw contents of register REGNO, regarding it as an integer. */
587 /* This probably should be returning LONGEST rather than CORE_ADDR. */
590 read_register (regno
)
593 if (registers_pid
!= inferior_pid
)
595 registers_changed ();
596 registers_pid
= inferior_pid
;
599 if (!register_valid
[regno
])
600 target_fetch_registers (regno
);
602 return extract_address (®isters
[REGISTER_BYTE (regno
)],
603 REGISTER_RAW_SIZE(regno
));
607 read_register_pid (regno
, pid
)
613 if (pid
== inferior_pid
)
614 return read_register (regno
);
616 save_pid
= inferior_pid
;
620 retval
= read_register (regno
);
622 inferior_pid
= save_pid
;
627 /* Registers we shouldn't try to store. */
628 #if !defined (CANNOT_STORE_REGISTER)
629 #define CANNOT_STORE_REGISTER(regno) 0
632 /* Store VALUE, into the raw contents of register number REGNO. */
635 write_register (regno
, val
)
642 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
643 the registers array if something writes to this register. */
644 if (CANNOT_STORE_REGISTER (regno
))
647 if (registers_pid
!= inferior_pid
)
649 registers_changed ();
650 registers_pid
= inferior_pid
;
653 size
= REGISTER_RAW_SIZE(regno
);
655 store_signed_integer (buf
, size
, (LONGEST
) val
);
657 /* If we have a valid copy of the register, and new value == old value,
658 then don't bother doing the actual store. */
660 if (register_valid
[regno
]
661 && memcmp (®isters
[REGISTER_BYTE (regno
)], buf
, size
) == 0)
664 target_prepare_to_store ();
666 memcpy (®isters
[REGISTER_BYTE (regno
)], buf
, size
);
668 register_valid
[regno
] = 1;
670 target_store_registers (regno
);
674 write_register_pid (regno
, val
, pid
)
681 if (pid
== inferior_pid
)
683 write_register (regno
, val
);
687 save_pid
= inferior_pid
;
691 write_register (regno
, val
);
693 inferior_pid
= save_pid
;
696 /* Record that register REGNO contains VAL.
697 This is used when the value is obtained from the inferior or core dump,
698 so there is no need to store the value there. */
701 supply_register (regno
, val
)
705 if (registers_pid
!= inferior_pid
)
707 registers_changed ();
708 registers_pid
= inferior_pid
;
711 register_valid
[regno
] = 1;
712 memcpy (®isters
[REGISTER_BYTE (regno
)], val
, REGISTER_RAW_SIZE (regno
));
714 /* On some architectures, e.g. HPPA, there are a few stray bits in some
715 registers, that the rest of the code would like to ignore. */
716 #ifdef CLEAN_UP_REGISTER_VALUE
717 CLEAN_UP_REGISTER_VALUE(regno
, ®isters
[REGISTER_BYTE(regno
)]);
722 /* This routine is getting awfully cluttered with #if's. It's probably
723 time to turn this into READ_PC and define it in the tm.h file.
724 Ditto for write_pc. */
729 #ifdef TARGET_READ_PC
730 return TARGET_READ_PC (inferior_pid
);
732 return ADDR_BITS_REMOVE ((CORE_ADDR
) read_register_pid (PC_REGNUM
, inferior_pid
));
740 #ifdef TARGET_READ_PC
741 return TARGET_READ_PC (pid
);
743 return ADDR_BITS_REMOVE ((CORE_ADDR
) read_register_pid (PC_REGNUM
, pid
));
751 #ifdef TARGET_WRITE_PC
752 TARGET_WRITE_PC (val
, inferior_pid
);
754 write_register_pid (PC_REGNUM
, val
, inferior_pid
);
756 write_register_pid (NPC_REGNUM
, val
+ 4, inferior_pid
);
758 write_register_pid (NNPC_REGNUM
, val
+ 8, inferior_pid
);
765 write_pc_pid (val
, pid
)
769 #ifdef TARGET_WRITE_PC
770 TARGET_WRITE_PC (val
, pid
);
772 write_register_pid (PC_REGNUM
, val
, pid
);
774 write_register_pid (NPC_REGNUM
, val
+ 4, pid
);
776 write_register_pid (NNPC_REGNUM
, val
+ 8, pid
);
782 /* Cope with strage ways of getting to the stack and frame pointers */
787 #ifdef TARGET_READ_SP
788 return TARGET_READ_SP ();
790 return read_register (SP_REGNUM
);
798 #ifdef TARGET_WRITE_SP
799 TARGET_WRITE_SP (val
);
801 write_register (SP_REGNUM
, val
);
808 #ifdef TARGET_READ_FP
809 return TARGET_READ_FP ();
811 return read_register (FP_REGNUM
);
819 #ifdef TARGET_WRITE_FP
820 TARGET_WRITE_FP (val
);
822 write_register (FP_REGNUM
, val
);
826 /* Will calling read_var_value or locate_var_value on SYM end
827 up caring what frame it is being evaluated relative to? SYM must
830 symbol_read_needs_frame (sym
)
833 switch (SYMBOL_CLASS (sym
))
835 /* All cases listed explicitly so that gcc -Wall will detect it if
836 we failed to consider one. */
841 case LOC_REGPARM_ADDR
:
845 case LOC_BASEREG_ARG
:
854 /* Getting the address of a label can be done independently of the block,
855 even if some *uses* of that address wouldn't work so well without
859 case LOC_CONST_BYTES
:
860 case LOC_OPTIMIZED_OUT
:
866 /* Given a struct symbol for a variable,
867 and a stack frame id, read the value of the variable
868 and return a (pointer to a) struct value containing the value.
869 If the variable cannot be found, return a zero pointer.
870 If FRAME is NULL, use the selected_frame. */
873 read_var_value (var
, frame
)
874 register struct symbol
*var
;
875 struct frame_info
*frame
;
877 register value_ptr v
;
878 struct type
*type
= SYMBOL_TYPE (var
);
882 v
= allocate_value (type
);
883 VALUE_LVAL (v
) = lval_memory
; /* The most likely possibility. */
884 len
= TYPE_LENGTH (type
);
886 if (frame
== NULL
) frame
= selected_frame
;
888 switch (SYMBOL_CLASS (var
))
891 /* Put the constant back in target format. */
892 store_signed_integer (VALUE_CONTENTS_RAW (v
), len
,
893 (LONGEST
) SYMBOL_VALUE (var
));
894 VALUE_LVAL (v
) = not_lval
;
898 /* Put the constant back in target format. */
899 store_address (VALUE_CONTENTS_RAW (v
), len
, SYMBOL_VALUE_ADDRESS (var
));
900 VALUE_LVAL (v
) = not_lval
;
903 case LOC_CONST_BYTES
:
906 bytes_addr
= SYMBOL_VALUE_BYTES (var
);
907 memcpy (VALUE_CONTENTS_RAW (v
), bytes_addr
, len
);
908 VALUE_LVAL (v
) = not_lval
;
913 addr
= SYMBOL_VALUE_ADDRESS (var
);
919 addr
= FRAME_ARGS_ADDRESS (frame
);
922 addr
+= SYMBOL_VALUE (var
);
928 addr
= FRAME_ARGS_ADDRESS (frame
);
931 addr
+= SYMBOL_VALUE (var
);
932 addr
= read_memory_unsigned_integer
933 (addr
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
940 addr
= FRAME_LOCALS_ADDRESS (frame
);
941 addr
+= SYMBOL_VALUE (var
);
945 case LOC_BASEREG_ARG
:
947 char buf
[MAX_REGISTER_RAW_SIZE
];
948 get_saved_register (buf
, NULL
, NULL
, frame
, SYMBOL_BASEREG (var
),
950 addr
= extract_address (buf
, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var
)));
951 addr
+= SYMBOL_VALUE (var
);
956 error ("Cannot look up value of a typedef");
960 VALUE_ADDRESS (v
) = BLOCK_START (SYMBOL_BLOCK_VALUE (var
));
965 case LOC_REGPARM_ADDR
:
971 b
= get_frame_block (frame
);
974 if (SYMBOL_CLASS (var
) == LOC_REGPARM_ADDR
)
977 value_as_pointer (value_from_register (lookup_pointer_type (type
),
980 VALUE_LVAL (v
) = lval_memory
;
983 return value_from_register (type
, SYMBOL_VALUE (var
), frame
);
987 case LOC_OPTIMIZED_OUT
:
988 VALUE_LVAL (v
) = not_lval
;
989 VALUE_OPTIMIZED_OUT (v
) = 1;
993 error ("Cannot look up value of a botched symbol.");
997 VALUE_ADDRESS (v
) = addr
;
1002 /* Return a value of type TYPE, stored in register REGNUM, in frame
1006 value_from_register (type
, regnum
, frame
)
1009 struct frame_info
*frame
;
1011 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1014 value_ptr v
= allocate_value (type
);
1015 int len
= TYPE_LENGTH (type
);
1016 char *value_bytes
= 0;
1017 int value_bytes_copied
= 0;
1018 int num_storage_locs
;
1019 enum lval_type lval
;
1021 VALUE_REGNO (v
) = regnum
;
1023 num_storage_locs
= (len
> REGISTER_VIRTUAL_SIZE (regnum
) ?
1024 ((len
- 1) / REGISTER_RAW_SIZE (regnum
)) + 1 :
1027 if (num_storage_locs
> 1
1028 #ifdef GDB_TARGET_IS_H8500
1029 || TYPE_CODE (type
) == TYPE_CODE_PTR
1033 /* Value spread across multiple storage locations. */
1036 int mem_stor
= 0, reg_stor
= 0;
1037 int mem_tracking
= 1;
1038 CORE_ADDR last_addr
= 0;
1039 CORE_ADDR first_addr
= 0;
1041 value_bytes
= (char *) alloca (len
+ MAX_REGISTER_RAW_SIZE
);
1043 /* Copy all of the data out, whereever it may be. */
1045 #ifdef GDB_TARGET_IS_H8500
1046 /* This piece of hideosity is required because the H8500 treats registers
1047 differently depending upon whether they are used as pointers or not. As a
1048 pointer, a register needs to have a page register tacked onto the front.
1049 An alternate way to do this would be to have gcc output different register
1050 numbers for the pointer & non-pointer form of the register. But, it
1051 doesn't, so we're stuck with this. */
1053 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1060 case R0_REGNUM
: case R1_REGNUM
: case R2_REGNUM
: case R3_REGNUM
:
1061 page_regnum
= SEG_D_REGNUM
;
1063 case R4_REGNUM
: case R5_REGNUM
:
1064 page_regnum
= SEG_E_REGNUM
;
1066 case R6_REGNUM
: case R7_REGNUM
:
1067 page_regnum
= SEG_T_REGNUM
;
1072 get_saved_register (value_bytes
+ 1,
1079 if (lval
== lval_register
)
1086 get_saved_register (value_bytes
+ 2,
1093 if (lval
== lval_register
)
1098 mem_tracking
= mem_tracking
&& (addr
== last_addr
);
1103 #endif /* GDB_TARGET_IS_H8500 */
1104 for (local_regnum
= regnum
;
1105 value_bytes_copied
< len
;
1106 (value_bytes_copied
+= REGISTER_RAW_SIZE (local_regnum
),
1109 get_saved_register (value_bytes
+ value_bytes_copied
,
1116 if (regnum
== local_regnum
)
1118 if (lval
== lval_register
)
1126 && (regnum
== local_regnum
1127 || addr
== last_addr
));
1132 if ((reg_stor
&& mem_stor
)
1133 || (mem_stor
&& !mem_tracking
))
1134 /* Mixed storage; all of the hassle we just went through was
1135 for some good purpose. */
1137 VALUE_LVAL (v
) = lval_reg_frame_relative
;
1138 VALUE_FRAME (v
) = FRAME_FP (frame
);
1139 VALUE_FRAME_REGNUM (v
) = regnum
;
1143 VALUE_LVAL (v
) = lval_memory
;
1144 VALUE_ADDRESS (v
) = first_addr
;
1148 VALUE_LVAL (v
) = lval_register
;
1149 VALUE_ADDRESS (v
) = first_addr
;
1152 fatal ("value_from_register: Value not stored anywhere!");
1154 VALUE_OPTIMIZED_OUT (v
) = optim
;
1156 /* Any structure stored in more than one register will always be
1157 an integral number of registers. Otherwise, you'd need to do
1158 some fiddling with the last register copied here for little
1161 /* Copy into the contents section of the value. */
1162 memcpy (VALUE_CONTENTS_RAW (v
), value_bytes
, len
);
1164 /* Finally do any conversion necessary when extracting this
1165 type from more than one register. */
1166 #ifdef REGISTER_CONVERT_TO_TYPE
1167 REGISTER_CONVERT_TO_TYPE(regnum
, type
, VALUE_CONTENTS_RAW(v
));
1172 /* Data is completely contained within a single register. Locate the
1173 register's contents in a real register or in core;
1174 read the data in raw format. */
1176 get_saved_register (raw_buffer
, &optim
, &addr
, frame
, regnum
, &lval
);
1177 VALUE_OPTIMIZED_OUT (v
) = optim
;
1178 VALUE_LVAL (v
) = lval
;
1179 VALUE_ADDRESS (v
) = addr
;
1181 /* Convert raw data to virtual format if necessary. */
1183 #ifdef REGISTER_CONVERTIBLE
1184 if (REGISTER_CONVERTIBLE (regnum
))
1186 REGISTER_CONVERT_TO_VIRTUAL (regnum
, type
,
1187 raw_buffer
, VALUE_CONTENTS_RAW (v
));
1192 /* Raw and virtual formats are the same for this register. */
1194 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
&& len
< REGISTER_RAW_SIZE (regnum
))
1196 /* Big-endian, and we want less than full size. */
1197 VALUE_OFFSET (v
) = REGISTER_RAW_SIZE (regnum
) - len
;
1200 memcpy (VALUE_CONTENTS_RAW (v
), raw_buffer
+ VALUE_OFFSET (v
), len
);
1206 /* Given a struct symbol for a variable or function,
1207 and a stack frame id,
1208 return a (pointer to a) struct value containing the properly typed
1212 locate_var_value (var
, frame
)
1213 register struct symbol
*var
;
1214 struct frame_info
*frame
;
1217 struct type
*type
= SYMBOL_TYPE (var
);
1218 value_ptr lazy_value
;
1220 /* Evaluate it first; if the result is a memory address, we're fine.
1221 Lazy evaluation pays off here. */
1223 lazy_value
= read_var_value (var
, frame
);
1224 if (lazy_value
== 0)
1225 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var
));
1227 if (VALUE_LAZY (lazy_value
)
1228 || TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1230 addr
= VALUE_ADDRESS (lazy_value
);
1231 return value_from_longest (lookup_pointer_type (type
), (LONGEST
) addr
);
1234 /* Not a memory address; check what the problem was. */
1235 switch (VALUE_LVAL (lazy_value
))
1238 case lval_reg_frame_relative
:
1239 error ("Address requested for identifier \"%s\" which is in a register.",
1240 SYMBOL_SOURCE_NAME (var
));
1244 error ("Can't take address of \"%s\" which isn't an lvalue.",
1245 SYMBOL_SOURCE_NAME (var
));
1248 return 0; /* For lint -- never reached */