1 /* Find a variable's value in memory, for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "gdb_string.h"
29 #include "floatformat.h"
31 /* This is used to indicate that we don't know the format of the floating point
32 number. Typically, this is useful for native ports, where the actual format
33 is irrelevant, since no conversions will be taking place. */
35 const struct floatformat floatformat_unknown;
37 /* Registers we shouldn't try to store. */
38 #if !defined (CANNOT_STORE_REGISTER)
39 #define CANNOT_STORE_REGISTER(regno) 0
42 static void write_register_pid PARAMS ((int regno, LONGEST val, int pid));
44 /* Basic byte-swapping routines. GDB has needed these for a long time...
45 All extract a target-format integer at ADDR which is LEN bytes long. */
47 #if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8
48 /* 8 bit characters are a pretty safe assumption these days, so we
49 assume it throughout all these swapping routines. If we had to deal with
50 9 bit characters, we would need to make len be in bits and would have
51 to re-write these routines... */
56 extract_signed_integer (addr, len)
62 unsigned char *startaddr = (unsigned char *)addr;
63 unsigned char *endaddr = startaddr + len;
65 if (len > (int) sizeof (LONGEST))
67 That operation is not available on integers of more than %d bytes.",
70 /* Start at the most significant end of the integer, and work towards
71 the least significant. */
72 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
75 /* Do the sign extension once at the start. */
76 retval = ((LONGEST)*p ^ 0x80) - 0x80;
77 for (++p; p < endaddr; ++p)
78 retval = (retval << 8) | *p;
83 /* Do the sign extension once at the start. */
84 retval = ((LONGEST)*p ^ 0x80) - 0x80;
85 for (--p; p >= startaddr; --p)
86 retval = (retval << 8) | *p;
92 extract_unsigned_integer (addr, len)
96 unsigned LONGEST retval;
98 unsigned char *startaddr = (unsigned char *)addr;
99 unsigned char *endaddr = startaddr + len;
101 if (len > (int) sizeof (unsigned LONGEST))
103 That operation is not available on integers of more than %d bytes.",
104 sizeof (unsigned LONGEST));
106 /* Start at the most significant end of the integer, and work towards
107 the least significant. */
109 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
111 for (p = startaddr; p < endaddr; ++p)
112 retval = (retval << 8) | *p;
116 for (p = endaddr - 1; p >= startaddr; --p)
117 retval = (retval << 8) | *p;
122 /* Sometimes a long long unsigned integer can be extracted as a
123 LONGEST value. This is done so that we can print these values
124 better. If this integer can be converted to a LONGEST, this
125 function returns 1 and sets *PVAL. Otherwise it returns 0. */
128 extract_long_unsigned_integer (addr, orig_len, pval)
133 char *p, *first_addr;
137 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
139 for (p = (char *) addr;
140 len > (int) sizeof (LONGEST) && p < (char *) addr + orig_len;
152 first_addr = (char *) addr;
153 for (p = (char *) addr + orig_len - 1;
154 len > (int) sizeof (LONGEST) && p >= (char *) addr;
164 if (len <= (int) sizeof (LONGEST))
166 *pval = (LONGEST) extract_unsigned_integer (first_addr,
175 extract_address (addr, len)
179 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
180 whether we want this to be true eventually. */
181 return extract_unsigned_integer (addr, len);
185 store_signed_integer (addr, len, val)
191 unsigned char *startaddr = (unsigned char *)addr;
192 unsigned char *endaddr = startaddr + len;
194 /* Start at the least significant end of the integer, and work towards
195 the most significant. */
196 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
198 for (p = endaddr - 1; p >= startaddr; --p)
206 for (p = startaddr; p < endaddr; ++p)
215 store_unsigned_integer (addr, len, val)
218 unsigned LONGEST val;
221 unsigned char *startaddr = (unsigned char *)addr;
222 unsigned char *endaddr = startaddr + len;
224 /* Start at the least significant end of the integer, and work towards
225 the most significant. */
226 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
228 for (p = endaddr - 1; p >= startaddr; --p)
236 for (p = startaddr; p < endaddr; ++p)
245 store_address (addr, len, val)
250 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
251 whether we want this to be true eventually. */
252 store_unsigned_integer (addr, len, (LONGEST)val);
255 /* Swap LEN bytes at BUFFER between target and host byte-order. */
256 #define SWAP_FLOATING(buffer,len) \
259 if (TARGET_BYTE_ORDER != HOST_BYTE_ORDER) \
262 char *p = (char *)(buffer); \
263 char *q = ((char *)(buffer)) + len - 1; \
264 for (; p < q; p++, q--) \
274 /* There are various problems with the extract_floating and store_floating
277 1. These routines only handle byte-swapping, not conversion of
278 formats. So if host is IEEE floating and target is VAX floating,
279 or vice-versa, it loses. This means that we can't (yet) use these
280 routines for extendeds. Extendeds are handled by
281 REGISTER_CONVERTIBLE. What we want is to use floatformat.h, but that
282 doesn't yet handle VAX floating at all.
284 2. We can't deal with it if there is more than one floating point
285 format in use. This has to be fixed at the unpack_double level.
287 3. We probably should have a LONGEST_DOUBLE or DOUBLEST or whatever
288 we want to call it which is long double where available. */
291 extract_floating (addr, len)
297 if (len == sizeof (float))
299 if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
303 memcpy (&retval, addr, sizeof (retval));
307 FLOATFORMAT_TO_DOUBLEST (TARGET_FLOAT_FORMAT, addr, &dretval);
309 else if (len == sizeof (double))
311 if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
315 memcpy (&retval, addr, sizeof (retval));
319 FLOATFORMAT_TO_DOUBLEST (TARGET_DOUBLE_FORMAT, addr, &dretval);
321 else if (len == sizeof (DOUBLEST))
323 if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
327 memcpy (&retval, addr, sizeof (retval));
331 FLOATFORMAT_TO_DOUBLEST (TARGET_LONG_DOUBLE_FORMAT, addr, &dretval);
335 error ("Can't deal with a floating point number of %d bytes.", len);
342 store_floating (addr, len, val)
347 if (len == sizeof (float))
349 if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
351 float floatval = val;
353 memcpy (addr, &floatval, sizeof (floatval));
356 FLOATFORMAT_FROM_DOUBLEST (TARGET_FLOAT_FORMAT, &val, addr);
358 else if (len == sizeof (double))
360 if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
362 double doubleval = val;
364 memcpy (addr, &doubleval, sizeof (doubleval));
367 FLOATFORMAT_FROM_DOUBLEST (TARGET_DOUBLE_FORMAT, &val, addr);
369 else if (len == sizeof (DOUBLEST))
371 if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
372 memcpy (addr, &val, sizeof (val));
374 FLOATFORMAT_FROM_DOUBLEST (TARGET_LONG_DOUBLE_FORMAT, &val, addr);
378 error ("Can't deal with a floating point number of %d bytes.", len);
382 #if !defined (GET_SAVED_REGISTER)
384 /* Return the address in which frame FRAME's value of register REGNUM
385 has been saved in memory. Or return zero if it has not been saved.
386 If REGNUM specifies the SP, the value we return is actually
387 the SP value, not an address where it was saved. */
390 find_saved_register (frame, regnum)
391 struct frame_info *frame;
394 struct frame_saved_regs saved_regs;
396 register struct frame_info *frame1 = NULL;
397 register CORE_ADDR addr = 0;
399 if (frame == NULL) /* No regs saved if want current frame */
402 #ifdef HAVE_REGISTER_WINDOWS
403 /* We assume that a register in a register window will only be saved
404 in one place (since the name changes and/or disappears as you go
405 towards inner frames), so we only call get_frame_saved_regs on
406 the current frame. This is directly in contradiction to the
407 usage below, which assumes that registers used in a frame must be
408 saved in a lower (more interior) frame. This change is a result
409 of working on a register window machine; get_frame_saved_regs
410 always returns the registers saved within a frame, within the
411 context (register namespace) of that frame. */
413 /* However, note that we don't want this to return anything if
414 nothing is saved (if there's a frame inside of this one). Also,
415 callers to this routine asking for the stack pointer want the
416 stack pointer saved for *this* frame; this is returned from the
419 if (REGISTER_IN_WINDOW_P(regnum))
421 frame1 = get_next_frame (frame);
422 if (!frame1) return 0; /* Registers of this frame are active. */
424 /* Get the SP from the next frame in; it will be this
426 if (regnum != SP_REGNUM)
429 get_frame_saved_regs (frame1, &saved_regs);
430 return saved_regs.regs[regnum]; /* ... which might be zero */
432 #endif /* HAVE_REGISTER_WINDOWS */
434 /* Note that this next routine assumes that registers used in
435 frame x will be saved only in the frame that x calls and
436 frames interior to it. This is not true on the sparc, but the
437 above macro takes care of it, so we should be all right. */
441 frame1 = get_prev_frame (frame1);
442 if (frame1 == 0 || frame1 == frame)
444 get_frame_saved_regs (frame1, &saved_regs);
445 if (saved_regs.regs[regnum])
446 addr = saved_regs.regs[regnum];
452 /* Find register number REGNUM relative to FRAME and put its (raw,
453 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
454 variable was optimized out (and thus can't be fetched). Set *LVAL
455 to lval_memory, lval_register, or not_lval, depending on whether
456 the value was fetched from memory, from a register, or in a strange
457 and non-modifiable way (e.g. a frame pointer which was calculated
458 rather than fetched). Set *ADDRP to the address, either in memory
459 on as a REGISTER_BYTE offset into the registers array.
461 Note that this implementation never sets *LVAL to not_lval. But
462 it can be replaced by defining GET_SAVED_REGISTER and supplying
465 The argument RAW_BUFFER must point to aligned memory. */
468 get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
472 struct frame_info *frame;
474 enum lval_type *lval;
478 if (!target_has_registers)
479 error ("No registers.");
481 /* Normal systems don't optimize out things with register numbers. */
482 if (optimized != NULL)
484 addr = find_saved_register (frame, regnum);
489 if (regnum == SP_REGNUM)
491 if (raw_buffer != NULL)
493 /* Put it back in target format. */
494 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), addr);
500 if (raw_buffer != NULL)
501 read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
506 *lval = lval_register;
507 addr = REGISTER_BYTE (regnum);
508 if (raw_buffer != NULL)
509 read_register_gen (regnum, raw_buffer);
514 #endif /* GET_SAVED_REGISTER. */
516 /* Copy the bytes of register REGNUM, relative to the current stack frame,
517 into our memory at MYADDR, in target byte order.
518 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
520 Returns 1 if could not be read, 0 if could. */
523 read_relative_register_raw_bytes (regnum, myaddr)
528 if (regnum == FP_REGNUM && selected_frame)
530 /* Put it back in target format. */
531 store_address (myaddr, REGISTER_RAW_SIZE(FP_REGNUM),
532 FRAME_FP(selected_frame));
536 get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, selected_frame,
537 regnum, (enum lval_type *)NULL);
541 /* Return a `value' with the contents of register REGNUM
542 in its virtual format, with the type specified by
543 REGISTER_VIRTUAL_TYPE. */
546 value_of_register (regnum)
551 register value_ptr reg_val;
552 char raw_buffer[MAX_REGISTER_RAW_SIZE];
555 get_saved_register (raw_buffer, &optim, &addr,
556 selected_frame, regnum, &lval);
558 reg_val = allocate_value (REGISTER_VIRTUAL_TYPE (regnum));
560 /* Convert raw data to virtual format if necessary. */
562 #ifdef REGISTER_CONVERTIBLE
563 if (REGISTER_CONVERTIBLE (regnum))
565 REGISTER_CONVERT_TO_VIRTUAL (regnum, REGISTER_VIRTUAL_TYPE (regnum),
566 raw_buffer, VALUE_CONTENTS_RAW (reg_val));
570 memcpy (VALUE_CONTENTS_RAW (reg_val), raw_buffer,
571 REGISTER_RAW_SIZE (regnum));
572 VALUE_LVAL (reg_val) = lval;
573 VALUE_ADDRESS (reg_val) = addr;
574 VALUE_REGNO (reg_val) = regnum;
575 VALUE_OPTIMIZED_OUT (reg_val) = optim;
579 /* Low level examining and depositing of registers.
581 The caller is responsible for making
582 sure that the inferior is stopped before calling the fetching routines,
583 or it will get garbage. (a change from GDB version 3, in which
584 the caller got the value from the last stop). */
586 /* Contents of the registers in target byte order.
587 We allocate some extra slop since we do a lot of memcpy's around `registers',
588 and failing-soft is better than failing hard. */
589 char registers[REGISTER_BYTES + /* SLOP */ 256];
591 /* Nonzero if that register has been fetched. */
592 char register_valid[NUM_REGS];
594 /* The thread/process associated with the current set of registers. For now,
595 -1 is special, and means `no current process'. */
596 int registers_pid = -1;
598 /* Indicate that registers may have changed, so invalidate the cache. */
604 int numregs = ARCH_NUM_REGS;
608 for (i = 0; i < numregs; i++)
609 register_valid[i] = 0;
611 if (registers_changed_hook)
612 registers_changed_hook ();
615 /* Indicate that all registers have been fetched, so mark them all valid. */
620 int numregs = ARCH_NUM_REGS;
621 for (i = 0; i < numregs; i++)
622 register_valid[i] = 1;
625 /* read_register_bytes and write_register_bytes are generally a *BAD* idea.
626 They are inefficient because they need to check for partial updates, which
627 can only be done by scanning through all of the registers and seeing if the
628 bytes that are being read/written fall inside of an invalid register. [The
629 main reason this is necessary is that register sizes can vary, so a simple
630 index won't suffice.] It is far better to call read_register_gen if you
631 want to get at the raw register contents, as it only takes a regno as an
632 argument, and therefore can't do a partial register update. It would also
633 be good to have a write_register_gen for similar reasons.
635 Prior to the recent fixes to check for partial updates, both read and
636 write_register_bytes always checked to see if any registers were stale, and
637 then called target_fetch_registers (-1) to update the whole set. This
638 caused really slowed things down for remote targets. */
640 /* Copy INLEN bytes of consecutive data from registers
641 starting with the INREGBYTE'th byte of register data
642 into memory at MYADDR. */
645 read_register_bytes (inregbyte, myaddr, inlen)
650 int inregend = inregbyte + inlen;
653 if (registers_pid != inferior_pid)
655 registers_changed ();
656 registers_pid = inferior_pid;
659 /* See if we are trying to read bytes from out-of-date registers. If so,
660 update just those registers. */
662 for (regno = 0; regno < NUM_REGS; regno++)
664 int regstart, regend;
667 if (register_valid[regno])
670 regstart = REGISTER_BYTE (regno);
671 regend = regstart + REGISTER_RAW_SIZE (regno);
673 startin = regstart >= inregbyte && regstart < inregend;
674 endin = regend > inregbyte && regend <= inregend;
676 if (!startin && !endin)
679 /* We've found an invalid register where at least one byte will be read.
680 Update it from the target. */
682 target_fetch_registers (regno);
684 if (!register_valid[regno])
685 error ("read_register_bytes: Couldn't update register %d.", regno);
689 memcpy (myaddr, ®isters[inregbyte], inlen);
692 /* Read register REGNO into memory at MYADDR, which must be large enough
693 for REGISTER_RAW_BYTES (REGNO). Target byte-order.
694 If the register is known to be the size of a CORE_ADDR or smaller,
695 read_register can be used instead. */
697 read_register_gen (regno, myaddr)
701 if (registers_pid != inferior_pid)
703 registers_changed ();
704 registers_pid = inferior_pid;
707 if (!register_valid[regno])
708 target_fetch_registers (regno);
709 memcpy (myaddr, ®isters[REGISTER_BYTE (regno)],
710 REGISTER_RAW_SIZE (regno));
713 /* Write register REGNO at MYADDR to the target. MYADDR points at
714 REGISTER_RAW_BYTES(REGNO), which must be in target byte-order. */
717 write_register_gen (regno, myaddr)
723 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
724 the registers array if something writes to this register. */
725 if (CANNOT_STORE_REGISTER (regno))
728 if (registers_pid != inferior_pid)
730 registers_changed ();
731 registers_pid = inferior_pid;
734 size = REGISTER_RAW_SIZE(regno);
736 /* If we have a valid copy of the register, and new value == old value,
737 then don't bother doing the actual store. */
739 if (register_valid [regno]
740 && memcmp (®isters[REGISTER_BYTE (regno)], myaddr, size) == 0)
743 target_prepare_to_store ();
745 memcpy (®isters[REGISTER_BYTE (regno)], myaddr, size);
747 register_valid [regno] = 1;
749 target_store_registers (regno);
752 /* Copy INLEN bytes of consecutive data from memory at MYADDR
753 into registers starting with the MYREGSTART'th byte of register data. */
756 write_register_bytes (myregstart, myaddr, inlen)
761 int myregend = myregstart + inlen;
764 target_prepare_to_store ();
766 /* Scan through the registers updating any that are covered by the range
767 myregstart<=>myregend using write_register_gen, which does nice things
768 like handling threads, and avoiding updates when the new and old contents
771 for (regno = 0; regno < NUM_REGS; regno++)
773 int regstart, regend;
775 char regbuf[MAX_REGISTER_RAW_SIZE];
777 regstart = REGISTER_BYTE (regno);
778 regend = regstart + REGISTER_RAW_SIZE (regno);
780 startin = regstart >= myregstart && regstart < myregend;
781 endin = regend > myregstart && regend <= myregend;
783 if (!startin && !endin)
784 continue; /* Register is completely out of range */
786 if (startin && endin) /* register is completely in range */
788 write_register_gen (regno, myaddr + (regstart - myregstart));
792 /* We may be doing a partial update of an invalid register. Update it
793 from the target before scribbling on it. */
794 read_register_gen (regno, regbuf);
797 memcpy (registers + regstart,
798 myaddr + regstart - myregstart,
799 myregend - regstart);
801 memcpy (registers + myregstart,
803 regend - myregstart);
804 target_store_registers (regno);
808 /* Return the raw contents of register REGNO, regarding it as an integer. */
809 /* This probably should be returning LONGEST rather than CORE_ADDR. */
812 read_register (regno)
815 if (registers_pid != inferior_pid)
817 registers_changed ();
818 registers_pid = inferior_pid;
821 if (!register_valid[regno])
822 target_fetch_registers (regno);
824 return extract_address (®isters[REGISTER_BYTE (regno)],
825 REGISTER_RAW_SIZE(regno));
829 read_register_pid (regno, pid)
835 if (pid == inferior_pid)
836 return read_register (regno);
838 save_pid = inferior_pid;
842 retval = read_register (regno);
844 inferior_pid = save_pid;
849 /* Store VALUE, into the raw contents of register number REGNO. */
852 write_register (regno, val)
859 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
860 the registers array if something writes to this register. */
861 if (CANNOT_STORE_REGISTER (regno))
864 if (registers_pid != inferior_pid)
866 registers_changed ();
867 registers_pid = inferior_pid;
870 size = REGISTER_RAW_SIZE(regno);
872 store_signed_integer (buf, size, (LONGEST) val);
874 /* If we have a valid copy of the register, and new value == old value,
875 then don't bother doing the actual store. */
877 if (register_valid [regno]
878 && memcmp (®isters[REGISTER_BYTE (regno)], buf, size) == 0)
881 target_prepare_to_store ();
883 memcpy (®isters[REGISTER_BYTE (regno)], buf, size);
885 register_valid [regno] = 1;
887 target_store_registers (regno);
891 write_register_pid (regno, val, pid)
898 if (pid == inferior_pid)
900 write_register (regno, val);
904 save_pid = inferior_pid;
908 write_register (regno, val);
910 inferior_pid = save_pid;
913 /* Record that register REGNO contains VAL.
914 This is used when the value is obtained from the inferior or core dump,
915 so there is no need to store the value there. */
918 supply_register (regno, val)
922 if (registers_pid != inferior_pid)
924 registers_changed ();
925 registers_pid = inferior_pid;
928 register_valid[regno] = 1;
929 memcpy (®isters[REGISTER_BYTE (regno)], val, REGISTER_RAW_SIZE (regno));
931 /* On some architectures, e.g. HPPA, there are a few stray bits in some
932 registers, that the rest of the code would like to ignore. */
933 #ifdef CLEAN_UP_REGISTER_VALUE
934 CLEAN_UP_REGISTER_VALUE(regno, ®isters[REGISTER_BYTE(regno)]);
939 /* This routine is getting awfully cluttered with #if's. It's probably
940 time to turn this into READ_PC and define it in the tm.h file.
941 Ditto for write_pc. */
946 #ifdef TARGET_READ_PC
947 return TARGET_READ_PC (inferior_pid);
949 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, inferior_pid));
957 #ifdef TARGET_READ_PC
958 return TARGET_READ_PC (pid);
960 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, pid));
968 #ifdef TARGET_WRITE_PC
969 TARGET_WRITE_PC (val, inferior_pid);
971 write_register_pid (PC_REGNUM, val, inferior_pid);
973 write_register_pid (NPC_REGNUM, val + 4, inferior_pid);
975 write_register_pid (NNPC_REGNUM, val + 8, inferior_pid);
982 write_pc_pid (val, pid)
986 #ifdef TARGET_WRITE_PC
987 TARGET_WRITE_PC (val, pid);
989 write_register_pid (PC_REGNUM, val, pid);
991 write_register_pid (NPC_REGNUM, val + 4, pid);
993 write_register_pid (NNPC_REGNUM, val + 8, pid);
999 /* Cope with strage ways of getting to the stack and frame pointers */
1004 #ifdef TARGET_READ_SP
1005 return TARGET_READ_SP ();
1007 return read_register (SP_REGNUM);
1015 #ifdef TARGET_WRITE_SP
1016 TARGET_WRITE_SP (val);
1018 write_register (SP_REGNUM, val);
1025 #ifdef TARGET_READ_FP
1026 return TARGET_READ_FP ();
1028 return read_register (FP_REGNUM);
1036 #ifdef TARGET_WRITE_FP
1037 TARGET_WRITE_FP (val);
1039 write_register (FP_REGNUM, val);
1043 /* Will calling read_var_value or locate_var_value on SYM end
1044 up caring what frame it is being evaluated relative to? SYM must
1047 symbol_read_needs_frame (sym)
1050 switch (SYMBOL_CLASS (sym))
1052 /* All cases listed explicitly so that gcc -Wall will detect it if
1053 we failed to consider one. */
1058 case LOC_REGPARM_ADDR:
1062 case LOC_BASEREG_ARG:
1071 /* Getting the address of a label can be done independently of the block,
1072 even if some *uses* of that address wouldn't work so well without
1076 case LOC_CONST_BYTES:
1077 case LOC_UNRESOLVED:
1078 case LOC_OPTIMIZED_OUT:
1084 /* Given a struct symbol for a variable,
1085 and a stack frame id, read the value of the variable
1086 and return a (pointer to a) struct value containing the value.
1087 If the variable cannot be found, return a zero pointer.
1088 If FRAME is NULL, use the selected_frame. */
1091 read_var_value (var, frame)
1092 register struct symbol *var;
1093 struct frame_info *frame;
1095 register value_ptr v;
1096 struct type *type = SYMBOL_TYPE (var);
1100 v = allocate_value (type);
1101 VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
1102 len = TYPE_LENGTH (type);
1104 if (frame == NULL) frame = selected_frame;
1106 switch (SYMBOL_CLASS (var))
1109 /* Put the constant back in target format. */
1110 store_signed_integer (VALUE_CONTENTS_RAW (v), len,
1111 (LONGEST) SYMBOL_VALUE (var));
1112 VALUE_LVAL (v) = not_lval;
1116 /* Put the constant back in target format. */
1117 store_address (VALUE_CONTENTS_RAW (v), len, SYMBOL_VALUE_ADDRESS (var));
1118 VALUE_LVAL (v) = not_lval;
1121 case LOC_CONST_BYTES:
1124 bytes_addr = SYMBOL_VALUE_BYTES (var);
1125 memcpy (VALUE_CONTENTS_RAW (v), bytes_addr, len);
1126 VALUE_LVAL (v) = not_lval;
1131 addr = SYMBOL_VALUE_ADDRESS (var);
1137 addr = FRAME_ARGS_ADDRESS (frame);
1140 addr += SYMBOL_VALUE (var);
1146 addr = FRAME_ARGS_ADDRESS (frame);
1149 addr += SYMBOL_VALUE (var);
1150 addr = read_memory_unsigned_integer
1151 (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1158 addr = FRAME_LOCALS_ADDRESS (frame);
1159 addr += SYMBOL_VALUE (var);
1163 case LOC_BASEREG_ARG:
1165 char buf[MAX_REGISTER_RAW_SIZE];
1166 get_saved_register (buf, NULL, NULL, frame, SYMBOL_BASEREG (var),
1168 addr = extract_address (buf, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var)));
1169 addr += SYMBOL_VALUE (var);
1174 error ("Cannot look up value of a typedef");
1178 VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
1183 case LOC_REGPARM_ADDR:
1189 b = get_frame_block (frame);
1192 if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
1195 value_as_pointer (value_from_register (lookup_pointer_type (type),
1198 VALUE_LVAL (v) = lval_memory;
1201 return value_from_register (type, SYMBOL_VALUE (var), frame);
1205 case LOC_UNRESOLVED:
1207 struct minimal_symbol *msym;
1209 msym = lookup_minimal_symbol (SYMBOL_NAME (var), NULL, NULL);
1212 addr = SYMBOL_VALUE_ADDRESS (msym);
1216 case LOC_OPTIMIZED_OUT:
1217 VALUE_LVAL (v) = not_lval;
1218 VALUE_OPTIMIZED_OUT (v) = 1;
1222 error ("Cannot look up value of a botched symbol.");
1226 VALUE_ADDRESS (v) = addr;
1231 /* Return a value of type TYPE, stored in register REGNUM, in frame
1235 value_from_register (type, regnum, frame)
1238 struct frame_info *frame;
1240 char raw_buffer [MAX_REGISTER_RAW_SIZE];
1243 value_ptr v = allocate_value (type);
1244 char *value_bytes = 0;
1245 int value_bytes_copied = 0;
1246 int num_storage_locs;
1247 enum lval_type lval;
1250 CHECK_TYPEDEF (type);
1251 len = TYPE_LENGTH (type);
1253 VALUE_REGNO (v) = regnum;
1255 num_storage_locs = (len > REGISTER_VIRTUAL_SIZE (regnum) ?
1256 ((len - 1) / REGISTER_RAW_SIZE (regnum)) + 1 :
1259 if (num_storage_locs > 1
1260 #ifdef GDB_TARGET_IS_H8500
1261 || TYPE_CODE (type) == TYPE_CODE_PTR
1265 /* Value spread across multiple storage locations. */
1268 int mem_stor = 0, reg_stor = 0;
1269 int mem_tracking = 1;
1270 CORE_ADDR last_addr = 0;
1271 CORE_ADDR first_addr = 0;
1273 value_bytes = (char *) alloca (len + MAX_REGISTER_RAW_SIZE);
1275 /* Copy all of the data out, whereever it may be. */
1277 #ifdef GDB_TARGET_IS_H8500
1278 /* This piece of hideosity is required because the H8500 treats registers
1279 differently depending upon whether they are used as pointers or not. As a
1280 pointer, a register needs to have a page register tacked onto the front.
1281 An alternate way to do this would be to have gcc output different register
1282 numbers for the pointer & non-pointer form of the register. But, it
1283 doesn't, so we're stuck with this. */
1285 if (TYPE_CODE (type) == TYPE_CODE_PTR
1292 case R0_REGNUM: case R1_REGNUM: case R2_REGNUM: case R3_REGNUM:
1293 page_regnum = SEG_D_REGNUM;
1295 case R4_REGNUM: case R5_REGNUM:
1296 page_regnum = SEG_E_REGNUM;
1298 case R6_REGNUM: case R7_REGNUM:
1299 page_regnum = SEG_T_REGNUM;
1304 get_saved_register (value_bytes + 1,
1311 if (lval == lval_register)
1318 get_saved_register (value_bytes + 2,
1325 if (lval == lval_register)
1330 mem_tracking = mem_tracking && (addr == last_addr);
1335 #endif /* GDB_TARGET_IS_H8500 */
1336 for (local_regnum = regnum;
1337 value_bytes_copied < len;
1338 (value_bytes_copied += REGISTER_RAW_SIZE (local_regnum),
1341 get_saved_register (value_bytes + value_bytes_copied,
1348 if (regnum == local_regnum)
1350 if (lval == lval_register)
1358 && (regnum == local_regnum
1359 || addr == last_addr));
1364 if ((reg_stor && mem_stor)
1365 || (mem_stor && !mem_tracking))
1366 /* Mixed storage; all of the hassle we just went through was
1367 for some good purpose. */
1369 VALUE_LVAL (v) = lval_reg_frame_relative;
1370 VALUE_FRAME (v) = FRAME_FP (frame);
1371 VALUE_FRAME_REGNUM (v) = regnum;
1375 VALUE_LVAL (v) = lval_memory;
1376 VALUE_ADDRESS (v) = first_addr;
1380 VALUE_LVAL (v) = lval_register;
1381 VALUE_ADDRESS (v) = first_addr;
1384 fatal ("value_from_register: Value not stored anywhere!");
1386 VALUE_OPTIMIZED_OUT (v) = optim;
1388 /* Any structure stored in more than one register will always be
1389 an integral number of registers. Otherwise, you'd need to do
1390 some fiddling with the last register copied here for little
1393 /* Copy into the contents section of the value. */
1394 memcpy (VALUE_CONTENTS_RAW (v), value_bytes, len);
1396 /* Finally do any conversion necessary when extracting this
1397 type from more than one register. */
1398 #ifdef REGISTER_CONVERT_TO_TYPE
1399 REGISTER_CONVERT_TO_TYPE(regnum, type, VALUE_CONTENTS_RAW(v));
1404 /* Data is completely contained within a single register. Locate the
1405 register's contents in a real register or in core;
1406 read the data in raw format. */
1408 get_saved_register (raw_buffer, &optim, &addr, frame, regnum, &lval);
1409 VALUE_OPTIMIZED_OUT (v) = optim;
1410 VALUE_LVAL (v) = lval;
1411 VALUE_ADDRESS (v) = addr;
1413 /* Convert raw data to virtual format if necessary. */
1415 #ifdef REGISTER_CONVERTIBLE
1416 if (REGISTER_CONVERTIBLE (regnum))
1418 REGISTER_CONVERT_TO_VIRTUAL (regnum, type,
1419 raw_buffer, VALUE_CONTENTS_RAW (v));
1424 /* Raw and virtual formats are the same for this register. */
1426 if (TARGET_BYTE_ORDER == BIG_ENDIAN && len < REGISTER_RAW_SIZE (regnum))
1428 /* Big-endian, and we want less than full size. */
1429 VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len;
1432 memcpy (VALUE_CONTENTS_RAW (v), raw_buffer + VALUE_OFFSET (v), len);
1438 /* Given a struct symbol for a variable or function,
1439 and a stack frame id,
1440 return a (pointer to a) struct value containing the properly typed
1444 locate_var_value (var, frame)
1445 register struct symbol *var;
1446 struct frame_info *frame;
1449 struct type *type = SYMBOL_TYPE (var);
1450 value_ptr lazy_value;
1452 /* Evaluate it first; if the result is a memory address, we're fine.
1453 Lazy evaluation pays off here. */
1455 lazy_value = read_var_value (var, frame);
1456 if (lazy_value == 0)
1457 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
1459 if (VALUE_LAZY (lazy_value)
1460 || TYPE_CODE (type) == TYPE_CODE_FUNC)
1462 addr = VALUE_ADDRESS (lazy_value);
1463 return value_from_longest (lookup_pointer_type (type), (LONGEST) addr);
1466 /* Not a memory address; check what the problem was. */
1467 switch (VALUE_LVAL (lazy_value))
1470 case lval_reg_frame_relative:
1471 error ("Address requested for identifier \"%s\" which is in a register.",
1472 SYMBOL_SOURCE_NAME (var));
1476 error ("Can't take address of \"%s\" which isn't an lvalue.",
1477 SYMBOL_SOURCE_NAME (var));
1480 return 0; /* For lint -- never reached */