1 /* Find a variable's value in memory, for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991 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. */
29 /* Basic byte-swapping routines. GDB has needed these for a long time...
30 All extract a target-format integer at ADDR which is LEN bytes long. */
32 #if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8
33 /* 8 bit characters are a pretty safe assumption these days, so we
34 assume it throughout all these swapping routines. If we had to deal with
35 9 bit characters, we would need to make len be in bits and would have
36 to re-write these routines... */
41 extract_signed_integer (addr
, len
)
47 unsigned char *startaddr
= (unsigned char *)addr
;
48 unsigned char *endaddr
= startaddr
+ len
;
50 if (len
> sizeof (LONGEST
))
52 That operation is not available on integers of more than %d bytes.",
55 /* Start at the most significant end of the integer, and work towards
56 the least significant. */
57 #if TARGET_BYTE_ORDER == BIG_ENDIAN
62 /* Do the sign extension once at the start. */
63 retval
= ((LONGEST
)*p
^ 0x80) - 0x80;
64 #if TARGET_BYTE_ORDER == BIG_ENDIAN
65 for (++p
; p
< endaddr
; ++p
)
67 for (--p
; p
>= startaddr
; --p
)
70 retval
= (retval
<< 8) | *p
;
76 extract_unsigned_integer (addr
, len
)
80 unsigned LONGEST retval
;
82 unsigned char *startaddr
= (unsigned char *)addr
;
83 unsigned char *endaddr
= startaddr
+ len
;
85 if (len
> sizeof (unsigned LONGEST
))
87 That operation is not available on integers of more than %d bytes.",
88 sizeof (unsigned LONGEST
));
90 /* Start at the most significant end of the integer, and work towards
91 the least significant. */
93 #if TARGET_BYTE_ORDER == BIG_ENDIAN
94 for (p
= startaddr
; p
< endaddr
; ++p
)
96 for (p
= endaddr
- 1; p
>= startaddr
; --p
)
99 retval
= (retval
<< 8) | *p
;
105 extract_address (addr
, len
)
109 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
110 whether we want this to be true eventually. */
111 return extract_unsigned_integer (addr
, len
);
115 store_signed_integer (addr
, len
, val
)
121 unsigned char *startaddr
= (unsigned char *)addr
;
122 unsigned char *endaddr
= startaddr
+ len
;
124 /* Start at the least significant end of the integer, and work towards
125 the most significant. */
126 #if TARGET_BYTE_ORDER == BIG_ENDIAN
127 for (p
= endaddr
- 1; p
>= startaddr
; --p
)
129 for (p
= startaddr
; p
< endaddr
; ++p
)
138 store_unsigned_integer (addr
, len
, val
)
141 unsigned LONGEST val
;
144 unsigned char *startaddr
= (unsigned char *)addr
;
145 unsigned char *endaddr
= startaddr
+ len
;
147 /* Start at the least significant end of the integer, and work towards
148 the most significant. */
149 #if TARGET_BYTE_ORDER == BIG_ENDIAN
150 for (p
= endaddr
- 1; p
>= startaddr
; --p
)
152 for (p
= startaddr
; p
< endaddr
; ++p
)
161 store_address (addr
, len
, val
)
166 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
167 whether we want this to be true eventually. */
168 store_unsigned_integer (addr
, len
, (LONGEST
)val
);
171 /* Swap LEN bytes at BUFFER between target and host byte-order. This is
172 the wrong way to do byte-swapping because it assumes that you have a way
173 to have a host variable of exactly the right size. Once extract_floating
174 and store_floating have been fixed, this can go away. */
175 #if TARGET_BYTE_ORDER == HOST_BYTE_ORDER
176 #define SWAP_TARGET_AND_HOST(buffer,len)
177 #else /* Target and host byte order differ. */
178 #define SWAP_TARGET_AND_HOST(buffer,len) \
181 char *p = (char *)(buffer); \
182 char *q = ((char *)(buffer)) + len - 1; \
183 for (; p < q; p++, q--) \
190 #endif /* Target and host byte order differ. */
192 /* There are many problems with floating point cross-debugging.
194 1. These routines only handle byte-swapping, not conversion of
195 formats. So if host is IEEE floating and target is VAX floating,
196 or vice-versa, it loses. This means that we can't (yet) use these
197 routines for extendeds. Extendeds are handled by
198 REGISTER_CONVERTIBLE. What we want is to use floatformat.h, but that
199 doesn't yet handle VAX floating at all.
201 2. We can't deal with it if there is more than one floating point
202 format in use. This has to be fixed at the unpack_double level.
204 3. We probably should have a LONGEST_DOUBLE or DOUBLEST or whatever
205 we want to call it which is long double where available. */
208 extract_floating (addr
, len
)
212 if (len
== sizeof (float))
215 memcpy (&retval
, addr
, sizeof (retval
));
216 SWAP_TARGET_AND_HOST (&retval
, sizeof (retval
));
219 else if (len
== sizeof (double))
222 memcpy (&retval
, addr
, sizeof (retval
));
223 SWAP_TARGET_AND_HOST (&retval
, sizeof (retval
));
228 error ("Can't deal with a floating point number of %d bytes.", len
);
233 store_floating (addr
, len
, val
)
238 if (len
== sizeof (float))
240 float floatval
= val
;
241 SWAP_TARGET_AND_HOST (&floatval
, sizeof (floatval
));
242 memcpy (addr
, &floatval
, sizeof (floatval
));
244 else if (len
== sizeof (double))
246 SWAP_TARGET_AND_HOST (&val
, sizeof (val
));
247 memcpy (addr
, &val
, sizeof (val
));
251 error ("Can't deal with a floating point number of %d bytes.", len
);
255 #if !defined (GET_SAVED_REGISTER)
257 /* Return the address in which frame FRAME's value of register REGNUM
258 has been saved in memory. Or return zero if it has not been saved.
259 If REGNUM specifies the SP, the value we return is actually
260 the SP value, not an address where it was saved. */
263 find_saved_register (frame
, regnum
)
267 struct frame_info
*fi
;
268 struct frame_saved_regs saved_regs
;
270 register FRAME frame1
= 0;
271 register CORE_ADDR addr
= 0;
273 if (frame
== 0) /* No regs saved if want current frame */
276 #ifdef HAVE_REGISTER_WINDOWS
277 /* We assume that a register in a register window will only be saved
278 in one place (since the name changes and/or disappears as you go
279 towards inner frames), so we only call get_frame_saved_regs on
280 the current frame. This is directly in contradiction to the
281 usage below, which assumes that registers used in a frame must be
282 saved in a lower (more interior) frame. This change is a result
283 of working on a register window machine; get_frame_saved_regs
284 always returns the registers saved within a frame, within the
285 context (register namespace) of that frame. */
287 /* However, note that we don't want this to return anything if
288 nothing is saved (if there's a frame inside of this one). Also,
289 callers to this routine asking for the stack pointer want the
290 stack pointer saved for *this* frame; this is returned from the
294 if (REGISTER_IN_WINDOW_P(regnum
))
296 frame1
= get_next_frame (frame
);
297 if (!frame1
) return 0; /* Registers of this frame are
300 /* Get the SP from the next frame in; it will be this
302 if (regnum
!= SP_REGNUM
)
305 fi
= get_frame_info (frame1
);
306 get_frame_saved_regs (fi
, &saved_regs
);
307 return saved_regs
.regs
[regnum
]; /* ... which might be zero */
309 #endif /* HAVE_REGISTER_WINDOWS */
311 /* Note that this next routine assumes that registers used in
312 frame x will be saved only in the frame that x calls and
313 frames interior to it. This is not true on the sparc, but the
314 above macro takes care of it, so we should be all right. */
318 frame1
= get_prev_frame (frame1
);
319 if (frame1
== 0 || frame1
== frame
)
321 fi
= get_frame_info (frame1
);
322 get_frame_saved_regs (fi
, &saved_regs
);
323 if (saved_regs
.regs
[regnum
])
324 addr
= saved_regs
.regs
[regnum
];
330 /* Find register number REGNUM relative to FRAME and put its (raw,
331 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
332 variable was optimized out (and thus can't be fetched). Set *LVAL
333 to lval_memory, lval_register, or not_lval, depending on whether
334 the value was fetched from memory, from a register, or in a strange
335 and non-modifiable way (e.g. a frame pointer which was calculated
336 rather than fetched). Set *ADDRP to the address, either in memory
337 on as a REGISTER_BYTE offset into the registers array.
339 Note that this implementation never sets *LVAL to not_lval. But
340 it can be replaced by defining GET_SAVED_REGISTER and supplying
343 The argument RAW_BUFFER must point to aligned memory. */
346 get_saved_register (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
)
352 enum lval_type
*lval
;
355 /* Normal systems don't optimize out things with register numbers. */
356 if (optimized
!= NULL
)
358 addr
= find_saved_register (frame
, regnum
);
363 if (regnum
== SP_REGNUM
)
365 if (raw_buffer
!= NULL
)
367 /* Put it back in target format. */
368 store_address (raw_buffer
, REGISTER_RAW_SIZE (regnum
), addr
);
374 if (raw_buffer
!= NULL
)
375 read_memory (addr
, raw_buffer
, REGISTER_RAW_SIZE (regnum
));
380 *lval
= lval_register
;
381 addr
= REGISTER_BYTE (regnum
);
382 if (raw_buffer
!= NULL
)
383 read_register_gen (regnum
, raw_buffer
);
388 #endif /* GET_SAVED_REGISTER. */
390 /* Copy the bytes of register REGNUM, relative to the current stack frame,
391 into our memory at MYADDR, in target byte order.
392 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
394 Returns 1 if could not be read, 0 if could. */
397 read_relative_register_raw_bytes (regnum
, myaddr
)
402 if (regnum
== FP_REGNUM
&& selected_frame
)
404 /* Put it back in target format. */
405 store_address (myaddr
, REGISTER_RAW_SIZE(FP_REGNUM
),
406 FRAME_FP(selected_frame
));
410 get_saved_register (myaddr
, &optim
, (CORE_ADDR
*) NULL
, selected_frame
,
411 regnum
, (enum lval_type
*)NULL
);
415 /* Return a `value' with the contents of register REGNUM
416 in its virtual format, with the type specified by
417 REGISTER_VIRTUAL_TYPE. */
420 value_of_register (regnum
)
425 register value reg_val
;
426 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
429 get_saved_register (raw_buffer
, &optim
, &addr
,
430 selected_frame
, regnum
, &lval
);
432 reg_val
= allocate_value (REGISTER_VIRTUAL_TYPE (regnum
));
434 /* Convert raw data to virtual format if necessary. */
436 #ifdef REGISTER_CONVERTIBLE
437 if (REGISTER_CONVERTIBLE (regnum
))
439 REGISTER_CONVERT_TO_VIRTUAL (regnum
, REGISTER_VIRTUAL_TYPE (regnum
),
440 raw_buffer
, VALUE_CONTENTS_RAW (reg_val
));
444 memcpy (VALUE_CONTENTS_RAW (reg_val
), raw_buffer
,
445 REGISTER_RAW_SIZE (regnum
));
446 VALUE_LVAL (reg_val
) = lval
;
447 VALUE_ADDRESS (reg_val
) = addr
;
448 VALUE_REGNO (reg_val
) = regnum
;
449 VALUE_OPTIMIZED_OUT (reg_val
) = optim
;
453 /* Low level examining and depositing of registers.
455 The caller is responsible for making
456 sure that the inferior is stopped before calling the fetching routines,
457 or it will get garbage. (a change from GDB version 3, in which
458 the caller got the value from the last stop). */
460 /* Contents of the registers in target byte order.
461 We allocate some extra slop since we do a lot of memcpy's around `registers',
462 and failing-soft is better than failing hard. */
463 char registers
[REGISTER_BYTES
+ /* SLOP */ 256];
465 /* Nonzero if that register has been fetched. */
466 char register_valid
[NUM_REGS
];
468 /* Indicate that registers may have changed, so invalidate the cache. */
473 for (i
= 0; i
< NUM_REGS
; i
++)
474 register_valid
[i
] = 0;
477 /* Indicate that all registers have been fetched, so mark them all valid. */
482 for (i
= 0; i
< NUM_REGS
; i
++)
483 register_valid
[i
] = 1;
486 /* Copy LEN bytes of consecutive data from registers
487 starting with the REGBYTE'th byte of register data
488 into memory at MYADDR. */
491 read_register_bytes (regbyte
, myaddr
, len
)
496 /* Fetch all registers. */
498 for (i
= 0; i
< NUM_REGS
; i
++)
499 if (!register_valid
[i
])
501 target_fetch_registers (-1);
505 memcpy (myaddr
, ®isters
[regbyte
], len
);
508 /* Read register REGNO into memory at MYADDR, which must be large enough
509 for REGISTER_RAW_BYTES (REGNO). Target byte-order.
510 If the register is known to be the size of a CORE_ADDR or smaller,
511 read_register can be used instead. */
513 read_register_gen (regno
, myaddr
)
517 if (!register_valid
[regno
])
518 target_fetch_registers (regno
);
519 memcpy (myaddr
, ®isters
[REGISTER_BYTE (regno
)],
520 REGISTER_RAW_SIZE (regno
));
523 /* Copy LEN bytes of consecutive data from memory at MYADDR
524 into registers starting with the REGBYTE'th byte of register data. */
527 write_register_bytes (regbyte
, myaddr
, len
)
532 /* Make sure the entire registers array is valid. */
533 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
534 memcpy (®isters
[regbyte
], myaddr
, len
);
535 target_store_registers (-1);
538 /* Return the raw contents of register REGNO, regarding it as an integer. */
539 /* This probably should be returning LONGEST rather than CORE_ADDR. */
542 read_register (regno
)
545 if (!register_valid
[regno
])
546 target_fetch_registers (regno
);
548 return extract_address (®isters
[REGISTER_BYTE (regno
)],
549 REGISTER_RAW_SIZE(regno
));
552 /* Registers we shouldn't try to store. */
553 #if !defined (CANNOT_STORE_REGISTER)
554 #define CANNOT_STORE_REGISTER(regno) 0
557 /* Store VALUE, into the raw contents of register number REGNO. */
558 /* FIXME: The val arg should probably be a LONGEST. */
561 write_register (regno
, val
)
568 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
569 the registers array if something writes to this register. */
570 if (CANNOT_STORE_REGISTER (regno
))
573 size
= REGISTER_RAW_SIZE(regno
);
575 store_signed_integer (buf
, size
, (LONGEST
) val
);
577 /* If we have a valid copy of the register, and new value == old value,
578 then don't bother doing the actual store. */
580 if (register_valid
[regno
])
582 if (memcmp (®isters
[REGISTER_BYTE (regno
)], buf
, size
) == 0)
586 target_prepare_to_store ();
588 memcpy (®isters
[REGISTER_BYTE (regno
)], buf
, size
);
590 register_valid
[regno
] = 1;
592 target_store_registers (regno
);
595 /* Record that register REGNO contains VAL.
596 This is used when the value is obtained from the inferior or core dump,
597 so there is no need to store the value there. */
600 supply_register (regno
, val
)
604 register_valid
[regno
] = 1;
605 memcpy (®isters
[REGISTER_BYTE (regno
)], val
, REGISTER_RAW_SIZE (regno
));
607 /* On some architectures, e.g. HPPA, there are a few stray bits in some
608 registers, that the rest of the code would like to ignore. */
609 #ifdef CLEAN_UP_REGISTER_VALUE
610 CLEAN_UP_REGISTER_VALUE(regno
, ®isters
[REGISTER_BYTE(regno
)]);
614 /* Will calling read_var_value or locate_var_value on SYM end
615 up caring what frame it is being evaluated relative to? SYM must
618 symbol_read_needs_frame (sym
)
621 switch (SYMBOL_CLASS (sym
))
623 /* All cases listed explicitly so that gcc -Wall will detect it if
624 we failed to consider one. */
629 case LOC_REGPARM_ADDR
:
633 case LOC_BASEREG_ARG
:
642 /* Getting the address of a label can be done independently of the block,
643 even if some *uses* of that address wouldn't work so well without
647 case LOC_CONST_BYTES
:
648 case LOC_OPTIMIZED_OUT
:
654 /* Given a struct symbol for a variable,
655 and a stack frame id, read the value of the variable
656 and return a (pointer to a) struct value containing the value.
657 If the variable cannot be found, return a zero pointer.
658 If FRAME is NULL, use the selected_frame. */
661 read_var_value (var
, frame
)
662 register struct symbol
*var
;
666 struct frame_info
*fi
;
667 struct type
*type
= SYMBOL_TYPE (var
);
671 v
= allocate_value (type
);
672 VALUE_LVAL (v
) = lval_memory
; /* The most likely possibility. */
673 len
= TYPE_LENGTH (type
);
675 if (frame
== 0) frame
= selected_frame
;
677 switch (SYMBOL_CLASS (var
))
680 /* Put the constant back in target format. */
681 store_signed_integer (VALUE_CONTENTS_RAW (v
), len
,
682 (LONGEST
) SYMBOL_VALUE (var
));
683 VALUE_LVAL (v
) = not_lval
;
687 /* Put the constant back in target format. */
688 store_address (VALUE_CONTENTS_RAW (v
), len
, SYMBOL_VALUE_ADDRESS (var
));
689 VALUE_LVAL (v
) = not_lval
;
692 case LOC_CONST_BYTES
:
695 bytes_addr
= SYMBOL_VALUE_BYTES (var
);
696 memcpy (VALUE_CONTENTS_RAW (v
), bytes_addr
, len
);
697 VALUE_LVAL (v
) = not_lval
;
702 addr
= SYMBOL_VALUE_ADDRESS (var
);
706 fi
= get_frame_info (frame
);
709 addr
= FRAME_ARGS_ADDRESS (fi
);
714 addr
+= SYMBOL_VALUE (var
);
718 fi
= get_frame_info (frame
);
721 addr
= FRAME_ARGS_ADDRESS (fi
);
726 addr
+= SYMBOL_VALUE (var
);
727 addr
= read_memory_unsigned_integer
728 (addr
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
733 fi
= get_frame_info (frame
);
736 addr
= FRAME_LOCALS_ADDRESS (fi
);
737 addr
+= SYMBOL_VALUE (var
);
741 case LOC_BASEREG_ARG
:
743 char buf
[MAX_REGISTER_RAW_SIZE
];
744 get_saved_register (buf
, NULL
, NULL
, frame
, SYMBOL_BASEREG (var
),
746 addr
= extract_address (buf
, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var
)));
747 addr
+= SYMBOL_VALUE (var
);
752 error ("Cannot look up value of a typedef");
756 VALUE_ADDRESS (v
) = BLOCK_START (SYMBOL_BLOCK_VALUE (var
));
761 case LOC_REGPARM_ADDR
:
767 b
= get_frame_block (frame
);
769 v
= value_from_register (type
, SYMBOL_VALUE (var
), frame
);
771 if (SYMBOL_CLASS (var
) == LOC_REGPARM_ADDR
)
773 addr
= *(CORE_ADDR
*)VALUE_CONTENTS (v
);
774 VALUE_LVAL (v
) = lval_memory
;
781 case LOC_OPTIMIZED_OUT
:
782 VALUE_LVAL (v
) = not_lval
;
783 VALUE_OPTIMIZED_OUT (v
) = 1;
787 error ("Cannot look up value of a botched symbol.");
791 VALUE_ADDRESS (v
) = addr
;
796 /* Return a value of type TYPE, stored in register REGNUM, in frame
800 value_from_register (type
, regnum
, frame
)
805 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
808 value v
= allocate_value (type
);
809 int len
= TYPE_LENGTH (type
);
810 char *value_bytes
= 0;
811 int value_bytes_copied
= 0;
812 int num_storage_locs
;
815 VALUE_REGNO (v
) = regnum
;
817 num_storage_locs
= (len
> REGISTER_VIRTUAL_SIZE (regnum
) ?
818 ((len
- 1) / REGISTER_RAW_SIZE (regnum
)) + 1 :
821 if (num_storage_locs
> 1
822 #ifdef GDB_TARGET_IS_H8500
823 || TYPE_CODE (type
) == TYPE_CODE_PTR
827 /* Value spread across multiple storage locations. */
830 int mem_stor
= 0, reg_stor
= 0;
831 int mem_tracking
= 1;
832 CORE_ADDR last_addr
= 0;
833 CORE_ADDR first_addr
= 0;
835 value_bytes
= (char *) alloca (len
+ MAX_REGISTER_RAW_SIZE
);
837 /* Copy all of the data out, whereever it may be. */
839 #ifdef GDB_TARGET_IS_H8500
840 /* This piece of hideosity is required because the H8500 treats registers
841 differently depending upon whether they are used as pointers or not. As a
842 pointer, a register needs to have a page register tacked onto the front.
843 An alternate way to do this would be to have gcc output different register
844 numbers for the pointer & non-pointer form of the register. But, it
845 doesn't, so we're stuck with this. */
847 if (TYPE_CODE (type
) == TYPE_CODE_PTR
854 case R0_REGNUM
: case R1_REGNUM
: case R2_REGNUM
: case R3_REGNUM
:
855 page_regnum
= SEG_D_REGNUM
;
857 case R4_REGNUM
: case R5_REGNUM
:
858 page_regnum
= SEG_E_REGNUM
;
860 case R6_REGNUM
: case R7_REGNUM
:
861 page_regnum
= SEG_T_REGNUM
;
866 get_saved_register (value_bytes
+ 1,
873 if (lval
== lval_register
)
880 get_saved_register (value_bytes
+ 2,
887 if (lval
== lval_register
)
892 mem_tracking
= mem_tracking
&& (addr
== last_addr
);
897 #endif /* GDB_TARGET_IS_H8500 */
898 for (local_regnum
= regnum
;
899 value_bytes_copied
< len
;
900 (value_bytes_copied
+= REGISTER_RAW_SIZE (local_regnum
),
903 get_saved_register (value_bytes
+ value_bytes_copied
,
910 if (regnum
== local_regnum
)
912 if (lval
== lval_register
)
920 && (regnum
== local_regnum
921 || addr
== last_addr
));
926 if ((reg_stor
&& mem_stor
)
927 || (mem_stor
&& !mem_tracking
))
928 /* Mixed storage; all of the hassle we just went through was
929 for some good purpose. */
931 VALUE_LVAL (v
) = lval_reg_frame_relative
;
932 VALUE_FRAME (v
) = FRAME_FP (frame
);
933 VALUE_FRAME_REGNUM (v
) = regnum
;
937 VALUE_LVAL (v
) = lval_memory
;
938 VALUE_ADDRESS (v
) = first_addr
;
942 VALUE_LVAL (v
) = lval_register
;
943 VALUE_ADDRESS (v
) = first_addr
;
946 fatal ("value_from_register: Value not stored anywhere!");
948 VALUE_OPTIMIZED_OUT (v
) = optim
;
950 /* Any structure stored in more than one register will always be
951 an integral number of registers. Otherwise, you'd need to do
952 some fiddling with the last register copied here for little
955 /* Copy into the contents section of the value. */
956 memcpy (VALUE_CONTENTS_RAW (v
), value_bytes
, len
);
958 /* Finally do any conversion necessary when extracting this
959 type from more than one register. */
960 #ifdef REGISTER_CONVERT_TO_TYPE
961 REGISTER_CONVERT_TO_TYPE(regnum
, type
, VALUE_CONTENTS_RAW(v
));
966 /* Data is completely contained within a single register. Locate the
967 register's contents in a real register or in core;
968 read the data in raw format. */
970 get_saved_register (raw_buffer
, &optim
, &addr
, frame
, regnum
, &lval
);
971 VALUE_OPTIMIZED_OUT (v
) = optim
;
972 VALUE_LVAL (v
) = lval
;
973 VALUE_ADDRESS (v
) = addr
;
975 /* Convert raw data to virtual format if necessary. */
977 #ifdef REGISTER_CONVERTIBLE
978 if (REGISTER_CONVERTIBLE (regnum
))
980 REGISTER_CONVERT_TO_VIRTUAL (regnum
, type
,
981 raw_buffer
, VALUE_CONTENTS_RAW (v
));
986 /* Raw and virtual formats are the same for this register. */
988 #if TARGET_BYTE_ORDER == BIG_ENDIAN
989 if (len
< REGISTER_RAW_SIZE (regnum
))
991 /* Big-endian, and we want less than full size. */
992 VALUE_OFFSET (v
) = REGISTER_RAW_SIZE (regnum
) - len
;
996 memcpy (VALUE_CONTENTS_RAW (v
), raw_buffer
+ VALUE_OFFSET (v
), len
);
1002 /* Given a struct symbol for a variable or function,
1003 and a stack frame id,
1004 return a (pointer to a) struct value containing the properly typed
1008 locate_var_value (var
, frame
)
1009 register struct symbol
*var
;
1013 struct type
*type
= SYMBOL_TYPE (var
);
1016 /* Evaluate it first; if the result is a memory address, we're fine.
1017 Lazy evaluation pays off here. */
1019 lazy_value
= read_var_value (var
, frame
);
1020 if (lazy_value
== 0)
1021 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var
));
1023 if (VALUE_LAZY (lazy_value
)
1024 || TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1026 addr
= VALUE_ADDRESS (lazy_value
);
1027 return value_from_longest (lookup_pointer_type (type
), (LONGEST
) addr
);
1030 /* Not a memory address; check what the problem was. */
1031 switch (VALUE_LVAL (lazy_value
))
1034 case lval_reg_frame_relative
:
1035 error ("Address requested for identifier \"%s\" which is in a register.",
1036 SYMBOL_SOURCE_NAME (var
));
1040 error ("Can't take address of \"%s\" which isn't an lvalue.",
1041 SYMBOL_SOURCE_NAME (var
));
1044 return 0; /* For lint -- never reached */