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. */
28 #include "gdb_string.h"
30 /* Registers we shouldn't try to store. */
31 #if !defined (CANNOT_STORE_REGISTER)
32 #define CANNOT_STORE_REGISTER(regno) 0
35 static void write_register_pid PARAMS ((int regno, LONGEST val, int pid));
37 /* Basic byte-swapping routines. GDB has needed these for a long time...
38 All extract a target-format integer at ADDR which is LEN bytes long. */
40 #if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8
41 /* 8 bit characters are a pretty safe assumption these days, so we
42 assume it throughout all these swapping routines. If we had to deal with
43 9 bit characters, we would need to make len be in bits and would have
44 to re-write these routines... */
49 extract_signed_integer (addr, len)
55 unsigned char *startaddr = (unsigned char *)addr;
56 unsigned char *endaddr = startaddr + len;
58 if (len > sizeof (LONGEST))
60 That operation is not available on integers of more than %d bytes.",
63 /* Start at the most significant end of the integer, and work towards
64 the least significant. */
65 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
68 /* Do the sign extension once at the start. */
69 retval = ((LONGEST)*p ^ 0x80) - 0x80;
70 for (++p; p < endaddr; ++p)
71 retval = (retval << 8) | *p;
76 /* Do the sign extension once at the start. */
77 retval = ((LONGEST)*p ^ 0x80) - 0x80;
78 for (--p; p >= startaddr; --p)
79 retval = (retval << 8) | *p;
85 extract_unsigned_integer (addr, len)
89 unsigned LONGEST retval;
91 unsigned char *startaddr = (unsigned char *)addr;
92 unsigned char *endaddr = startaddr + len;
94 if (len > sizeof (unsigned LONGEST))
96 That operation is not available on integers of more than %d bytes.",
97 sizeof (unsigned LONGEST));
99 /* Start at the most significant end of the integer, and work towards
100 the least significant. */
102 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
104 for (p = startaddr; p < endaddr; ++p)
105 retval = (retval << 8) | *p;
109 for (p = endaddr - 1; p >= startaddr; --p)
110 retval = (retval << 8) | *p;
116 extract_address (addr, len)
120 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
121 whether we want this to be true eventually. */
122 return extract_unsigned_integer (addr, len);
126 store_signed_integer (addr, len, val)
132 unsigned char *startaddr = (unsigned char *)addr;
133 unsigned char *endaddr = startaddr + len;
135 /* Start at the least significant end of the integer, and work towards
136 the most significant. */
137 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
139 for (p = endaddr - 1; p >= startaddr; --p)
147 for (p = startaddr; p < endaddr; ++p)
156 store_unsigned_integer (addr, len, val)
159 unsigned LONGEST val;
162 unsigned char *startaddr = (unsigned char *)addr;
163 unsigned char *endaddr = startaddr + len;
165 /* Start at the least significant end of the integer, and work towards
166 the most significant. */
167 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
169 for (p = endaddr - 1; p >= startaddr; --p)
177 for (p = startaddr; p < endaddr; ++p)
186 store_address (addr, len, val)
191 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
192 whether we want this to be true eventually. */
193 store_unsigned_integer (addr, len, (LONGEST)val);
196 /* Swap LEN bytes at BUFFER between target and host byte-order. */
197 #define SWAP_FLOATING(buffer,len) \
200 if (TARGET_BYTE_ORDER != HOST_BYTE_ORDER) \
203 char *p = (char *)(buffer); \
204 char *q = ((char *)(buffer)) + len - 1; \
205 for (; p < q; p++, q--) \
215 /* There are various problems with the extract_floating and store_floating
218 1. These routines only handle byte-swapping, not conversion of
219 formats. So if host is IEEE floating and target is VAX floating,
220 or vice-versa, it loses. This means that we can't (yet) use these
221 routines for extendeds. Extendeds are handled by
222 REGISTER_CONVERTIBLE. What we want is to use floatformat.h, but that
223 doesn't yet handle VAX floating at all.
225 2. We can't deal with it if there is more than one floating point
226 format in use. This has to be fixed at the unpack_double level.
228 3. We probably should have a LONGEST_DOUBLE or DOUBLEST or whatever
229 we want to call it which is long double where available. */
232 extract_floating (addr, len)
236 if (len == sizeof (float))
239 memcpy (&retval, addr, sizeof (retval));
240 SWAP_FLOATING (&retval, sizeof (retval));
243 else if (len == sizeof (double))
246 memcpy (&retval, addr, sizeof (retval));
247 SWAP_FLOATING (&retval, sizeof (retval));
252 error ("Can't deal with a floating point number of %d bytes.", len);
257 store_floating (addr, len, val)
262 if (len == sizeof (float))
264 float floatval = val;
265 SWAP_FLOATING (&floatval, sizeof (floatval));
266 memcpy (addr, &floatval, sizeof (floatval));
268 else if (len == sizeof (double))
270 SWAP_FLOATING (&val, sizeof (val));
271 memcpy (addr, &val, sizeof (val));
275 error ("Can't deal with a floating point number of %d bytes.", len);
279 #if !defined (GET_SAVED_REGISTER)
281 /* Return the address in which frame FRAME's value of register REGNUM
282 has been saved in memory. Or return zero if it has not been saved.
283 If REGNUM specifies the SP, the value we return is actually
284 the SP value, not an address where it was saved. */
287 find_saved_register (frame, regnum)
288 struct frame_info *frame;
291 struct frame_saved_regs saved_regs;
293 register struct frame_info *frame1 = NULL;
294 register CORE_ADDR addr = 0;
296 if (frame == NULL) /* No regs saved if want current frame */
299 #ifdef HAVE_REGISTER_WINDOWS
300 /* We assume that a register in a register window will only be saved
301 in one place (since the name changes and/or disappears as you go
302 towards inner frames), so we only call get_frame_saved_regs on
303 the current frame. This is directly in contradiction to the
304 usage below, which assumes that registers used in a frame must be
305 saved in a lower (more interior) frame. This change is a result
306 of working on a register window machine; get_frame_saved_regs
307 always returns the registers saved within a frame, within the
308 context (register namespace) of that frame. */
310 /* However, note that we don't want this to return anything if
311 nothing is saved (if there's a frame inside of this one). Also,
312 callers to this routine asking for the stack pointer want the
313 stack pointer saved for *this* frame; this is returned from the
316 if (REGISTER_IN_WINDOW_P(regnum))
318 frame1 = get_next_frame (frame);
319 if (!frame1) return 0; /* Registers of this frame are active. */
321 /* Get the SP from the next frame in; it will be this
323 if (regnum != SP_REGNUM)
326 get_frame_saved_regs (frame1, &saved_regs);
327 return saved_regs.regs[regnum]; /* ... which might be zero */
329 #endif /* HAVE_REGISTER_WINDOWS */
331 /* Note that this next routine assumes that registers used in
332 frame x will be saved only in the frame that x calls and
333 frames interior to it. This is not true on the sparc, but the
334 above macro takes care of it, so we should be all right. */
338 frame1 = get_prev_frame (frame1);
339 if (frame1 == 0 || frame1 == frame)
341 get_frame_saved_regs (frame1, &saved_regs);
342 if (saved_regs.regs[regnum])
343 addr = saved_regs.regs[regnum];
349 /* Find register number REGNUM relative to FRAME and put its (raw,
350 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
351 variable was optimized out (and thus can't be fetched). Set *LVAL
352 to lval_memory, lval_register, or not_lval, depending on whether
353 the value was fetched from memory, from a register, or in a strange
354 and non-modifiable way (e.g. a frame pointer which was calculated
355 rather than fetched). Set *ADDRP to the address, either in memory
356 on as a REGISTER_BYTE offset into the registers array.
358 Note that this implementation never sets *LVAL to not_lval. But
359 it can be replaced by defining GET_SAVED_REGISTER and supplying
362 The argument RAW_BUFFER must point to aligned memory. */
365 get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
369 struct frame_info *frame;
371 enum lval_type *lval;
375 if (!target_has_registers)
376 error ("No registers.");
378 /* Normal systems don't optimize out things with register numbers. */
379 if (optimized != NULL)
381 addr = find_saved_register (frame, regnum);
386 if (regnum == SP_REGNUM)
388 if (raw_buffer != NULL)
390 /* Put it back in target format. */
391 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), addr);
397 if (raw_buffer != NULL)
398 read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
403 *lval = lval_register;
404 addr = REGISTER_BYTE (regnum);
405 if (raw_buffer != NULL)
406 read_register_gen (regnum, raw_buffer);
411 #endif /* GET_SAVED_REGISTER. */
413 /* Copy the bytes of register REGNUM, relative to the current stack frame,
414 into our memory at MYADDR, in target byte order.
415 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
417 Returns 1 if could not be read, 0 if could. */
420 read_relative_register_raw_bytes (regnum, myaddr)
425 if (regnum == FP_REGNUM && selected_frame)
427 /* Put it back in target format. */
428 store_address (myaddr, REGISTER_RAW_SIZE(FP_REGNUM),
429 FRAME_FP(selected_frame));
433 get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, selected_frame,
434 regnum, (enum lval_type *)NULL);
438 /* Return a `value' with the contents of register REGNUM
439 in its virtual format, with the type specified by
440 REGISTER_VIRTUAL_TYPE. */
443 value_of_register (regnum)
448 register value_ptr reg_val;
449 char raw_buffer[MAX_REGISTER_RAW_SIZE];
452 get_saved_register (raw_buffer, &optim, &addr,
453 selected_frame, regnum, &lval);
455 reg_val = allocate_value (REGISTER_VIRTUAL_TYPE (regnum));
457 /* Convert raw data to virtual format if necessary. */
459 #ifdef REGISTER_CONVERTIBLE
460 if (REGISTER_CONVERTIBLE (regnum))
462 REGISTER_CONVERT_TO_VIRTUAL (regnum, REGISTER_VIRTUAL_TYPE (regnum),
463 raw_buffer, VALUE_CONTENTS_RAW (reg_val));
467 memcpy (VALUE_CONTENTS_RAW (reg_val), raw_buffer,
468 REGISTER_RAW_SIZE (regnum));
469 VALUE_LVAL (reg_val) = lval;
470 VALUE_ADDRESS (reg_val) = addr;
471 VALUE_REGNO (reg_val) = regnum;
472 VALUE_OPTIMIZED_OUT (reg_val) = optim;
476 /* Low level examining and depositing of registers.
478 The caller is responsible for making
479 sure that the inferior is stopped before calling the fetching routines,
480 or it will get garbage. (a change from GDB version 3, in which
481 the caller got the value from the last stop). */
483 /* Contents of the registers in target byte order.
484 We allocate some extra slop since we do a lot of memcpy's around `registers',
485 and failing-soft is better than failing hard. */
486 char registers[REGISTER_BYTES + /* SLOP */ 256];
488 /* Nonzero if that register has been fetched. */
489 char register_valid[NUM_REGS];
491 /* The thread/process associated with the current set of registers. For now,
492 -1 is special, and means `no current process'. */
493 int registers_pid = -1;
495 /* Indicate that registers may have changed, so invalidate the cache. */
501 int numregs = ARCH_NUM_REGS;
505 for (i = 0; i < numregs; i++)
506 register_valid[i] = 0;
508 if (registers_changed_hook)
509 registers_changed_hook ();
512 /* Indicate that all registers have been fetched, so mark them all valid. */
517 int numregs = ARCH_NUM_REGS;
518 for (i = 0; i < numregs; i++)
519 register_valid[i] = 1;
522 /* read_register_bytes and write_register_bytes are generally a *BAD* idea.
523 They are inefficient because they need to check for partial updates, which
524 can only be done by scanning through all of the registers and seeing if the
525 bytes that are being read/written fall inside of an invalid register. [The
526 main reason this is necessary is that register sizes can vary, so a simple
527 index won't suffice.] It is far better to call read_register_gen if you
528 want to get at the raw register contents, as it only takes a regno as an
529 argument, and therefore can't do a partial register update. It would also
530 be good to have a write_register_gen for similar reasons.
532 Prior to the recent fixes to check for partial updates, both read and
533 write_register_bytes always checked to see if any registers were stale, and
534 then called target_fetch_registers (-1) to update the whole set. This
535 caused really slowed things down for remote targets. */
537 /* Copy INLEN bytes of consecutive data from registers
538 starting with the INREGBYTE'th byte of register data
539 into memory at MYADDR. */
542 read_register_bytes (inregbyte, myaddr, inlen)
547 int inregend = inregbyte + inlen;
550 if (registers_pid != inferior_pid)
552 registers_changed ();
553 registers_pid = inferior_pid;
556 /* See if we are trying to read bytes from out-of-date registers. If so,
557 update just those registers. */
559 for (regno = 0; regno < NUM_REGS; regno++)
561 int regstart, regend;
564 if (register_valid[regno])
567 regstart = REGISTER_BYTE (regno);
568 regend = regstart + REGISTER_RAW_SIZE (regno);
570 startin = regstart >= inregbyte && regstart < inregend;
571 endin = regend > inregbyte && regend <= inregend;
573 if (!startin && !endin)
576 /* We've found an invalid register where at least one byte will be read.
577 Update it from the target. */
579 target_fetch_registers (regno);
581 if (!register_valid[regno])
582 error ("read_register_bytes: Couldn't update register %d.", regno);
586 memcpy (myaddr, ®isters[inregbyte], inlen);
589 /* Read register REGNO into memory at MYADDR, which must be large enough
590 for REGISTER_RAW_BYTES (REGNO). Target byte-order.
591 If the register is known to be the size of a CORE_ADDR or smaller,
592 read_register can be used instead. */
594 read_register_gen (regno, myaddr)
598 if (registers_pid != inferior_pid)
600 registers_changed ();
601 registers_pid = inferior_pid;
604 if (!register_valid[regno])
605 target_fetch_registers (regno);
606 memcpy (myaddr, ®isters[REGISTER_BYTE (regno)],
607 REGISTER_RAW_SIZE (regno));
610 /* Write register REGNO at MYADDR to the target. MYADDR points at
611 REGISTER_RAW_BYTES(REGNO), which must be in target byte-order. */
614 write_register_gen (regno, myaddr)
620 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
621 the registers array if something writes to this register. */
622 if (CANNOT_STORE_REGISTER (regno))
625 if (registers_pid != inferior_pid)
627 registers_changed ();
628 registers_pid = inferior_pid;
631 size = REGISTER_RAW_SIZE(regno);
633 /* If we have a valid copy of the register, and new value == old value,
634 then don't bother doing the actual store. */
636 if (register_valid [regno]
637 && memcmp (®isters[REGISTER_BYTE (regno)], myaddr, size) == 0)
640 target_prepare_to_store ();
642 memcpy (®isters[REGISTER_BYTE (regno)], myaddr, size);
644 register_valid [regno] = 1;
646 target_store_registers (regno);
649 /* Copy INLEN bytes of consecutive data from memory at MYADDR
650 into registers starting with the MYREGSTART'th byte of register data. */
653 write_register_bytes (myregstart, myaddr, inlen)
658 int myregend = myregstart + inlen;
661 target_prepare_to_store ();
663 /* Scan through the registers updating any that are covered by the range
664 myregstart<=>myregend using write_register_gen, which does nice things
665 like handling threads, and avoiding updates when the new and old contents
668 for (regno = 0; regno < NUM_REGS; regno++)
670 int regstart, regend;
672 char regbuf[MAX_REGISTER_RAW_SIZE];
674 regstart = REGISTER_BYTE (regno);
675 regend = regstart + REGISTER_RAW_SIZE (regno);
677 startin = regstart >= myregstart && regstart < myregend;
678 endin = regend > myregstart && regend <= myregend;
680 if (!startin && !endin)
681 continue; /* Register is completely out of range */
683 if (startin && endin) /* register is completely in range */
685 write_register_gen (regno, myaddr + (regstart - myregstart));
689 /* We may be doing a partial update of an invalid register. Update it
690 from the target before scribbling on it. */
691 read_register_gen (regno, regbuf);
694 memcpy (registers + regstart,
695 myaddr + regstart - myregstart,
696 myregend - regstart);
698 memcpy (registers + myregstart,
700 regend - myregstart);
701 target_store_registers (regno);
705 /* Return the raw contents of register REGNO, regarding it as an integer. */
706 /* This probably should be returning LONGEST rather than CORE_ADDR. */
709 read_register (regno)
712 if (registers_pid != inferior_pid)
714 registers_changed ();
715 registers_pid = inferior_pid;
718 if (!register_valid[regno])
719 target_fetch_registers (regno);
721 return extract_address (®isters[REGISTER_BYTE (regno)],
722 REGISTER_RAW_SIZE(regno));
726 read_register_pid (regno, pid)
732 if (pid == inferior_pid)
733 return read_register (regno);
735 save_pid = inferior_pid;
739 retval = read_register (regno);
741 inferior_pid = save_pid;
746 /* Store VALUE, into the raw contents of register number REGNO. */
749 write_register (regno, val)
756 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
757 the registers array if something writes to this register. */
758 if (CANNOT_STORE_REGISTER (regno))
761 if (registers_pid != inferior_pid)
763 registers_changed ();
764 registers_pid = inferior_pid;
767 size = REGISTER_RAW_SIZE(regno);
769 store_signed_integer (buf, size, (LONGEST) val);
771 /* If we have a valid copy of the register, and new value == old value,
772 then don't bother doing the actual store. */
774 if (register_valid [regno]
775 && memcmp (®isters[REGISTER_BYTE (regno)], buf, size) == 0)
778 target_prepare_to_store ();
780 memcpy (®isters[REGISTER_BYTE (regno)], buf, size);
782 register_valid [regno] = 1;
784 target_store_registers (regno);
788 write_register_pid (regno, val, pid)
795 if (pid == inferior_pid)
797 write_register (regno, val);
801 save_pid = inferior_pid;
805 write_register (regno, val);
807 inferior_pid = save_pid;
810 /* Record that register REGNO contains VAL.
811 This is used when the value is obtained from the inferior or core dump,
812 so there is no need to store the value there. */
815 supply_register (regno, val)
819 if (registers_pid != inferior_pid)
821 registers_changed ();
822 registers_pid = inferior_pid;
825 register_valid[regno] = 1;
826 memcpy (®isters[REGISTER_BYTE (regno)], val, REGISTER_RAW_SIZE (regno));
828 /* On some architectures, e.g. HPPA, there are a few stray bits in some
829 registers, that the rest of the code would like to ignore. */
830 #ifdef CLEAN_UP_REGISTER_VALUE
831 CLEAN_UP_REGISTER_VALUE(regno, ®isters[REGISTER_BYTE(regno)]);
836 /* This routine is getting awfully cluttered with #if's. It's probably
837 time to turn this into READ_PC and define it in the tm.h file.
838 Ditto for write_pc. */
843 #ifdef TARGET_READ_PC
844 return TARGET_READ_PC (inferior_pid);
846 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, inferior_pid));
854 #ifdef TARGET_READ_PC
855 return TARGET_READ_PC (pid);
857 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, pid));
865 #ifdef TARGET_WRITE_PC
866 TARGET_WRITE_PC (val, inferior_pid);
868 write_register_pid (PC_REGNUM, val, inferior_pid);
870 write_register_pid (NPC_REGNUM, val + 4, inferior_pid);
872 write_register_pid (NNPC_REGNUM, val + 8, inferior_pid);
879 write_pc_pid (val, pid)
883 #ifdef TARGET_WRITE_PC
884 TARGET_WRITE_PC (val, pid);
886 write_register_pid (PC_REGNUM, val, pid);
888 write_register_pid (NPC_REGNUM, val + 4, pid);
890 write_register_pid (NNPC_REGNUM, val + 8, pid);
896 /* Cope with strage ways of getting to the stack and frame pointers */
901 #ifdef TARGET_READ_SP
902 return TARGET_READ_SP ();
904 return read_register (SP_REGNUM);
912 #ifdef TARGET_WRITE_SP
913 TARGET_WRITE_SP (val);
915 write_register (SP_REGNUM, val);
922 #ifdef TARGET_READ_FP
923 return TARGET_READ_FP ();
925 return read_register (FP_REGNUM);
933 #ifdef TARGET_WRITE_FP
934 TARGET_WRITE_FP (val);
936 write_register (FP_REGNUM, val);
940 /* Will calling read_var_value or locate_var_value on SYM end
941 up caring what frame it is being evaluated relative to? SYM must
944 symbol_read_needs_frame (sym)
947 switch (SYMBOL_CLASS (sym))
949 /* All cases listed explicitly so that gcc -Wall will detect it if
950 we failed to consider one. */
955 case LOC_REGPARM_ADDR:
959 case LOC_BASEREG_ARG:
968 /* Getting the address of a label can be done independently of the block,
969 even if some *uses* of that address wouldn't work so well without
973 case LOC_CONST_BYTES:
974 case LOC_OPTIMIZED_OUT:
980 /* Given a struct symbol for a variable,
981 and a stack frame id, read the value of the variable
982 and return a (pointer to a) struct value containing the value.
983 If the variable cannot be found, return a zero pointer.
984 If FRAME is NULL, use the selected_frame. */
987 read_var_value (var, frame)
988 register struct symbol *var;
989 struct frame_info *frame;
991 register value_ptr v;
992 struct type *type = SYMBOL_TYPE (var);
996 v = allocate_value (type);
997 VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
998 len = TYPE_LENGTH (type);
1000 if (frame == NULL) frame = selected_frame;
1002 switch (SYMBOL_CLASS (var))
1005 /* Put the constant back in target format. */
1006 store_signed_integer (VALUE_CONTENTS_RAW (v), len,
1007 (LONGEST) SYMBOL_VALUE (var));
1008 VALUE_LVAL (v) = not_lval;
1012 /* Put the constant back in target format. */
1013 store_address (VALUE_CONTENTS_RAW (v), len, SYMBOL_VALUE_ADDRESS (var));
1014 VALUE_LVAL (v) = not_lval;
1017 case LOC_CONST_BYTES:
1020 bytes_addr = SYMBOL_VALUE_BYTES (var);
1021 memcpy (VALUE_CONTENTS_RAW (v), bytes_addr, len);
1022 VALUE_LVAL (v) = not_lval;
1027 addr = SYMBOL_VALUE_ADDRESS (var);
1033 addr = FRAME_ARGS_ADDRESS (frame);
1036 addr += SYMBOL_VALUE (var);
1042 addr = FRAME_ARGS_ADDRESS (frame);
1045 addr += SYMBOL_VALUE (var);
1046 addr = read_memory_unsigned_integer
1047 (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1054 addr = FRAME_LOCALS_ADDRESS (frame);
1055 addr += SYMBOL_VALUE (var);
1059 case LOC_BASEREG_ARG:
1061 char buf[MAX_REGISTER_RAW_SIZE];
1062 get_saved_register (buf, NULL, NULL, frame, SYMBOL_BASEREG (var),
1064 addr = extract_address (buf, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var)));
1065 addr += SYMBOL_VALUE (var);
1070 error ("Cannot look up value of a typedef");
1074 VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
1079 case LOC_REGPARM_ADDR:
1085 b = get_frame_block (frame);
1088 if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
1091 value_as_pointer (value_from_register (lookup_pointer_type (type),
1094 VALUE_LVAL (v) = lval_memory;
1097 return value_from_register (type, SYMBOL_VALUE (var), frame);
1101 case LOC_OPTIMIZED_OUT:
1102 VALUE_LVAL (v) = not_lval;
1103 VALUE_OPTIMIZED_OUT (v) = 1;
1107 error ("Cannot look up value of a botched symbol.");
1111 VALUE_ADDRESS (v) = addr;
1116 /* Return a value of type TYPE, stored in register REGNUM, in frame
1120 value_from_register (type, regnum, frame)
1123 struct frame_info *frame;
1125 char raw_buffer [MAX_REGISTER_RAW_SIZE];
1128 value_ptr v = allocate_value (type);
1129 int len = TYPE_LENGTH (type);
1130 char *value_bytes = 0;
1131 int value_bytes_copied = 0;
1132 int num_storage_locs;
1133 enum lval_type lval;
1135 VALUE_REGNO (v) = regnum;
1137 num_storage_locs = (len > REGISTER_VIRTUAL_SIZE (regnum) ?
1138 ((len - 1) / REGISTER_RAW_SIZE (regnum)) + 1 :
1141 if (num_storage_locs > 1
1142 #ifdef GDB_TARGET_IS_H8500
1143 || TYPE_CODE (type) == TYPE_CODE_PTR
1147 /* Value spread across multiple storage locations. */
1150 int mem_stor = 0, reg_stor = 0;
1151 int mem_tracking = 1;
1152 CORE_ADDR last_addr = 0;
1153 CORE_ADDR first_addr = 0;
1155 value_bytes = (char *) alloca (len + MAX_REGISTER_RAW_SIZE);
1157 /* Copy all of the data out, whereever it may be. */
1159 #ifdef GDB_TARGET_IS_H8500
1160 /* This piece of hideosity is required because the H8500 treats registers
1161 differently depending upon whether they are used as pointers or not. As a
1162 pointer, a register needs to have a page register tacked onto the front.
1163 An alternate way to do this would be to have gcc output different register
1164 numbers for the pointer & non-pointer form of the register. But, it
1165 doesn't, so we're stuck with this. */
1167 if (TYPE_CODE (type) == TYPE_CODE_PTR
1174 case R0_REGNUM: case R1_REGNUM: case R2_REGNUM: case R3_REGNUM:
1175 page_regnum = SEG_D_REGNUM;
1177 case R4_REGNUM: case R5_REGNUM:
1178 page_regnum = SEG_E_REGNUM;
1180 case R6_REGNUM: case R7_REGNUM:
1181 page_regnum = SEG_T_REGNUM;
1186 get_saved_register (value_bytes + 1,
1193 if (lval == lval_register)
1200 get_saved_register (value_bytes + 2,
1207 if (lval == lval_register)
1212 mem_tracking = mem_tracking && (addr == last_addr);
1217 #endif /* GDB_TARGET_IS_H8500 */
1218 for (local_regnum = regnum;
1219 value_bytes_copied < len;
1220 (value_bytes_copied += REGISTER_RAW_SIZE (local_regnum),
1223 get_saved_register (value_bytes + value_bytes_copied,
1230 if (regnum == local_regnum)
1232 if (lval == lval_register)
1240 && (regnum == local_regnum
1241 || addr == last_addr));
1246 if ((reg_stor && mem_stor)
1247 || (mem_stor && !mem_tracking))
1248 /* Mixed storage; all of the hassle we just went through was
1249 for some good purpose. */
1251 VALUE_LVAL (v) = lval_reg_frame_relative;
1252 VALUE_FRAME (v) = FRAME_FP (frame);
1253 VALUE_FRAME_REGNUM (v) = regnum;
1257 VALUE_LVAL (v) = lval_memory;
1258 VALUE_ADDRESS (v) = first_addr;
1262 VALUE_LVAL (v) = lval_register;
1263 VALUE_ADDRESS (v) = first_addr;
1266 fatal ("value_from_register: Value not stored anywhere!");
1268 VALUE_OPTIMIZED_OUT (v) = optim;
1270 /* Any structure stored in more than one register will always be
1271 an integral number of registers. Otherwise, you'd need to do
1272 some fiddling with the last register copied here for little
1275 /* Copy into the contents section of the value. */
1276 memcpy (VALUE_CONTENTS_RAW (v), value_bytes, len);
1278 /* Finally do any conversion necessary when extracting this
1279 type from more than one register. */
1280 #ifdef REGISTER_CONVERT_TO_TYPE
1281 REGISTER_CONVERT_TO_TYPE(regnum, type, VALUE_CONTENTS_RAW(v));
1286 /* Data is completely contained within a single register. Locate the
1287 register's contents in a real register or in core;
1288 read the data in raw format. */
1290 get_saved_register (raw_buffer, &optim, &addr, frame, regnum, &lval);
1291 VALUE_OPTIMIZED_OUT (v) = optim;
1292 VALUE_LVAL (v) = lval;
1293 VALUE_ADDRESS (v) = addr;
1295 /* Convert raw data to virtual format if necessary. */
1297 #ifdef REGISTER_CONVERTIBLE
1298 if (REGISTER_CONVERTIBLE (regnum))
1300 REGISTER_CONVERT_TO_VIRTUAL (regnum, type,
1301 raw_buffer, VALUE_CONTENTS_RAW (v));
1306 /* Raw and virtual formats are the same for this register. */
1308 if (TARGET_BYTE_ORDER == BIG_ENDIAN && len < REGISTER_RAW_SIZE (regnum))
1310 /* Big-endian, and we want less than full size. */
1311 VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len;
1314 memcpy (VALUE_CONTENTS_RAW (v), raw_buffer + VALUE_OFFSET (v), len);
1320 /* Given a struct symbol for a variable or function,
1321 and a stack frame id,
1322 return a (pointer to a) struct value containing the properly typed
1326 locate_var_value (var, frame)
1327 register struct symbol *var;
1328 struct frame_info *frame;
1331 struct type *type = SYMBOL_TYPE (var);
1332 value_ptr lazy_value;
1334 /* Evaluate it first; if the result is a memory address, we're fine.
1335 Lazy evaluation pays off here. */
1337 lazy_value = read_var_value (var, frame);
1338 if (lazy_value == 0)
1339 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
1341 if (VALUE_LAZY (lazy_value)
1342 || TYPE_CODE (type) == TYPE_CODE_FUNC)
1344 addr = VALUE_ADDRESS (lazy_value);
1345 return value_from_longest (lookup_pointer_type (type), (LONGEST) addr);
1348 /* Not a memory address; check what the problem was. */
1349 switch (VALUE_LVAL (lazy_value))
1352 case lval_reg_frame_relative:
1353 error ("Address requested for identifier \"%s\" which is in a register.",
1354 SYMBOL_SOURCE_NAME (var));
1358 error ("Can't take address of \"%s\" which isn't an lvalue.",
1359 SYMBOL_SOURCE_NAME (var));
1362 return 0; /* For lint -- never reached */