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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
));
250 else if (len
== sizeof (long double))
253 memcpy (&retval
, addr
, sizeof (retval
));
254 SWAP_FLOATING (&retval
, sizeof (retval
));
259 error ("Can't deal with a floating point number of %d bytes.", len
);
264 store_floating (addr
, len
, val
)
269 if (len
== sizeof (float))
271 float floatval
= val
;
272 SWAP_FLOATING (&floatval
, sizeof (floatval
));
273 memcpy (addr
, &floatval
, sizeof (floatval
));
275 else if (len
== sizeof (double))
277 double doubleval
= val
;
279 SWAP_FLOATING (&doubleval
, sizeof (doubleval
));
280 memcpy (addr
, &doubleval
, sizeof (doubleval
));
282 else if (len
== sizeof (long double))
284 SWAP_FLOATING (&val
, sizeof (val
));
285 memcpy (addr
, &val
, sizeof (val
));
289 error ("Can't deal with a floating point number of %d bytes.", len
);
293 #if !defined (GET_SAVED_REGISTER)
295 /* Return the address in which frame FRAME's value of register REGNUM
296 has been saved in memory. Or return zero if it has not been saved.
297 If REGNUM specifies the SP, the value we return is actually
298 the SP value, not an address where it was saved. */
301 find_saved_register (frame
, regnum
)
302 struct frame_info
*frame
;
305 struct frame_saved_regs saved_regs
;
307 register struct frame_info
*frame1
= NULL
;
308 register CORE_ADDR addr
= 0;
310 if (frame
== NULL
) /* No regs saved if want current frame */
313 #ifdef HAVE_REGISTER_WINDOWS
314 /* We assume that a register in a register window will only be saved
315 in one place (since the name changes and/or disappears as you go
316 towards inner frames), so we only call get_frame_saved_regs on
317 the current frame. This is directly in contradiction to the
318 usage below, which assumes that registers used in a frame must be
319 saved in a lower (more interior) frame. This change is a result
320 of working on a register window machine; get_frame_saved_regs
321 always returns the registers saved within a frame, within the
322 context (register namespace) of that frame. */
324 /* However, note that we don't want this to return anything if
325 nothing is saved (if there's a frame inside of this one). Also,
326 callers to this routine asking for the stack pointer want the
327 stack pointer saved for *this* frame; this is returned from the
330 if (REGISTER_IN_WINDOW_P(regnum
))
332 frame1
= get_next_frame (frame
);
333 if (!frame1
) return 0; /* Registers of this frame are active. */
335 /* Get the SP from the next frame in; it will be this
337 if (regnum
!= SP_REGNUM
)
340 get_frame_saved_regs (frame1
, &saved_regs
);
341 return saved_regs
.regs
[regnum
]; /* ... which might be zero */
343 #endif /* HAVE_REGISTER_WINDOWS */
345 /* Note that this next routine assumes that registers used in
346 frame x will be saved only in the frame that x calls and
347 frames interior to it. This is not true on the sparc, but the
348 above macro takes care of it, so we should be all right. */
352 frame1
= get_prev_frame (frame1
);
353 if (frame1
== 0 || frame1
== frame
)
355 get_frame_saved_regs (frame1
, &saved_regs
);
356 if (saved_regs
.regs
[regnum
])
357 addr
= saved_regs
.regs
[regnum
];
363 /* Find register number REGNUM relative to FRAME and put its (raw,
364 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
365 variable was optimized out (and thus can't be fetched). Set *LVAL
366 to lval_memory, lval_register, or not_lval, depending on whether
367 the value was fetched from memory, from a register, or in a strange
368 and non-modifiable way (e.g. a frame pointer which was calculated
369 rather than fetched). Set *ADDRP to the address, either in memory
370 on as a REGISTER_BYTE offset into the registers array.
372 Note that this implementation never sets *LVAL to not_lval. But
373 it can be replaced by defining GET_SAVED_REGISTER and supplying
376 The argument RAW_BUFFER must point to aligned memory. */
379 get_saved_register (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
)
383 struct frame_info
*frame
;
385 enum lval_type
*lval
;
389 if (!target_has_registers
)
390 error ("No registers.");
392 /* Normal systems don't optimize out things with register numbers. */
393 if (optimized
!= NULL
)
395 addr
= find_saved_register (frame
, regnum
);
400 if (regnum
== SP_REGNUM
)
402 if (raw_buffer
!= NULL
)
404 /* Put it back in target format. */
405 store_address (raw_buffer
, REGISTER_RAW_SIZE (regnum
), addr
);
411 if (raw_buffer
!= NULL
)
412 read_memory (addr
, raw_buffer
, REGISTER_RAW_SIZE (regnum
));
417 *lval
= lval_register
;
418 addr
= REGISTER_BYTE (regnum
);
419 if (raw_buffer
!= NULL
)
420 read_register_gen (regnum
, raw_buffer
);
425 #endif /* GET_SAVED_REGISTER. */
427 /* Copy the bytes of register REGNUM, relative to the current stack frame,
428 into our memory at MYADDR, in target byte order.
429 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
431 Returns 1 if could not be read, 0 if could. */
434 read_relative_register_raw_bytes (regnum
, myaddr
)
439 if (regnum
== FP_REGNUM
&& selected_frame
)
441 /* Put it back in target format. */
442 store_address (myaddr
, REGISTER_RAW_SIZE(FP_REGNUM
),
443 FRAME_FP(selected_frame
));
447 get_saved_register (myaddr
, &optim
, (CORE_ADDR
*) NULL
, selected_frame
,
448 regnum
, (enum lval_type
*)NULL
);
452 /* Return a `value' with the contents of register REGNUM
453 in its virtual format, with the type specified by
454 REGISTER_VIRTUAL_TYPE. */
457 value_of_register (regnum
)
462 register value_ptr reg_val
;
463 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
466 get_saved_register (raw_buffer
, &optim
, &addr
,
467 selected_frame
, regnum
, &lval
);
469 reg_val
= allocate_value (REGISTER_VIRTUAL_TYPE (regnum
));
471 /* Convert raw data to virtual format if necessary. */
473 #ifdef REGISTER_CONVERTIBLE
474 if (REGISTER_CONVERTIBLE (regnum
))
476 REGISTER_CONVERT_TO_VIRTUAL (regnum
, REGISTER_VIRTUAL_TYPE (regnum
),
477 raw_buffer
, VALUE_CONTENTS_RAW (reg_val
));
481 memcpy (VALUE_CONTENTS_RAW (reg_val
), raw_buffer
,
482 REGISTER_RAW_SIZE (regnum
));
483 VALUE_LVAL (reg_val
) = lval
;
484 VALUE_ADDRESS (reg_val
) = addr
;
485 VALUE_REGNO (reg_val
) = regnum
;
486 VALUE_OPTIMIZED_OUT (reg_val
) = optim
;
490 /* Low level examining and depositing of registers.
492 The caller is responsible for making
493 sure that the inferior is stopped before calling the fetching routines,
494 or it will get garbage. (a change from GDB version 3, in which
495 the caller got the value from the last stop). */
497 /* Contents of the registers in target byte order.
498 We allocate some extra slop since we do a lot of memcpy's around `registers',
499 and failing-soft is better than failing hard. */
500 char registers
[REGISTER_BYTES
+ /* SLOP */ 256];
502 /* Nonzero if that register has been fetched. */
503 char register_valid
[NUM_REGS
];
505 /* The thread/process associated with the current set of registers. For now,
506 -1 is special, and means `no current process'. */
507 int registers_pid
= -1;
509 /* Indicate that registers may have changed, so invalidate the cache. */
515 int numregs
= ARCH_NUM_REGS
;
519 for (i
= 0; i
< numregs
; i
++)
520 register_valid
[i
] = 0;
522 if (registers_changed_hook
)
523 registers_changed_hook ();
526 /* Indicate that all registers have been fetched, so mark them all valid. */
531 int numregs
= ARCH_NUM_REGS
;
532 for (i
= 0; i
< numregs
; i
++)
533 register_valid
[i
] = 1;
536 /* read_register_bytes and write_register_bytes are generally a *BAD* idea.
537 They are inefficient because they need to check for partial updates, which
538 can only be done by scanning through all of the registers and seeing if the
539 bytes that are being read/written fall inside of an invalid register. [The
540 main reason this is necessary is that register sizes can vary, so a simple
541 index won't suffice.] It is far better to call read_register_gen if you
542 want to get at the raw register contents, as it only takes a regno as an
543 argument, and therefore can't do a partial register update. It would also
544 be good to have a write_register_gen for similar reasons.
546 Prior to the recent fixes to check for partial updates, both read and
547 write_register_bytes always checked to see if any registers were stale, and
548 then called target_fetch_registers (-1) to update the whole set. This
549 caused really slowed things down for remote targets. */
551 /* Copy INLEN bytes of consecutive data from registers
552 starting with the INREGBYTE'th byte of register data
553 into memory at MYADDR. */
556 read_register_bytes (inregbyte
, myaddr
, inlen
)
561 int inregend
= inregbyte
+ inlen
;
564 if (registers_pid
!= inferior_pid
)
566 registers_changed ();
567 registers_pid
= inferior_pid
;
570 /* See if we are trying to read bytes from out-of-date registers. If so,
571 update just those registers. */
573 for (regno
= 0; regno
< NUM_REGS
; regno
++)
575 int regstart
, regend
;
578 if (register_valid
[regno
])
581 regstart
= REGISTER_BYTE (regno
);
582 regend
= regstart
+ REGISTER_RAW_SIZE (regno
);
584 startin
= regstart
>= inregbyte
&& regstart
< inregend
;
585 endin
= regend
> inregbyte
&& regend
<= inregend
;
587 if (!startin
&& !endin
)
590 /* We've found an invalid register where at least one byte will be read.
591 Update it from the target. */
593 target_fetch_registers (regno
);
595 if (!register_valid
[regno
])
596 error ("read_register_bytes: Couldn't update register %d.", regno
);
600 memcpy (myaddr
, ®isters
[inregbyte
], inlen
);
603 /* Read register REGNO into memory at MYADDR, which must be large enough
604 for REGISTER_RAW_BYTES (REGNO). Target byte-order.
605 If the register is known to be the size of a CORE_ADDR or smaller,
606 read_register can be used instead. */
608 read_register_gen (regno
, myaddr
)
612 if (registers_pid
!= inferior_pid
)
614 registers_changed ();
615 registers_pid
= inferior_pid
;
618 if (!register_valid
[regno
])
619 target_fetch_registers (regno
);
620 memcpy (myaddr
, ®isters
[REGISTER_BYTE (regno
)],
621 REGISTER_RAW_SIZE (regno
));
624 /* Write register REGNO at MYADDR to the target. MYADDR points at
625 REGISTER_RAW_BYTES(REGNO), which must be in target byte-order. */
628 write_register_gen (regno
, myaddr
)
634 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
635 the registers array if something writes to this register. */
636 if (CANNOT_STORE_REGISTER (regno
))
639 if (registers_pid
!= inferior_pid
)
641 registers_changed ();
642 registers_pid
= inferior_pid
;
645 size
= REGISTER_RAW_SIZE(regno
);
647 /* If we have a valid copy of the register, and new value == old value,
648 then don't bother doing the actual store. */
650 if (register_valid
[regno
]
651 && memcmp (®isters
[REGISTER_BYTE (regno
)], myaddr
, size
) == 0)
654 target_prepare_to_store ();
656 memcpy (®isters
[REGISTER_BYTE (regno
)], myaddr
, size
);
658 register_valid
[regno
] = 1;
660 target_store_registers (regno
);
663 /* Copy INLEN bytes of consecutive data from memory at MYADDR
664 into registers starting with the MYREGSTART'th byte of register data. */
667 write_register_bytes (myregstart
, myaddr
, inlen
)
672 int myregend
= myregstart
+ inlen
;
675 target_prepare_to_store ();
677 /* Scan through the registers updating any that are covered by the range
678 myregstart<=>myregend using write_register_gen, which does nice things
679 like handling threads, and avoiding updates when the new and old contents
682 for (regno
= 0; regno
< NUM_REGS
; regno
++)
684 int regstart
, regend
;
686 char regbuf
[MAX_REGISTER_RAW_SIZE
];
688 regstart
= REGISTER_BYTE (regno
);
689 regend
= regstart
+ REGISTER_RAW_SIZE (regno
);
691 startin
= regstart
>= myregstart
&& regstart
< myregend
;
692 endin
= regend
> myregstart
&& regend
<= myregend
;
694 if (!startin
&& !endin
)
695 continue; /* Register is completely out of range */
697 if (startin
&& endin
) /* register is completely in range */
699 write_register_gen (regno
, myaddr
+ (regstart
- myregstart
));
703 /* We may be doing a partial update of an invalid register. Update it
704 from the target before scribbling on it. */
705 read_register_gen (regno
, regbuf
);
708 memcpy (registers
+ regstart
,
709 myaddr
+ regstart
- myregstart
,
710 myregend
- regstart
);
712 memcpy (registers
+ myregstart
,
714 regend
- myregstart
);
715 target_store_registers (regno
);
719 /* Return the raw contents of register REGNO, regarding it as an integer. */
720 /* This probably should be returning LONGEST rather than CORE_ADDR. */
723 read_register (regno
)
726 if (registers_pid
!= inferior_pid
)
728 registers_changed ();
729 registers_pid
= inferior_pid
;
732 if (!register_valid
[regno
])
733 target_fetch_registers (regno
);
735 return extract_address (®isters
[REGISTER_BYTE (regno
)],
736 REGISTER_RAW_SIZE(regno
));
740 read_register_pid (regno
, pid
)
746 if (pid
== inferior_pid
)
747 return read_register (regno
);
749 save_pid
= inferior_pid
;
753 retval
= read_register (regno
);
755 inferior_pid
= save_pid
;
760 /* Store VALUE, into the raw contents of register number REGNO. */
763 write_register (regno
, val
)
770 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
771 the registers array if something writes to this register. */
772 if (CANNOT_STORE_REGISTER (regno
))
775 if (registers_pid
!= inferior_pid
)
777 registers_changed ();
778 registers_pid
= inferior_pid
;
781 size
= REGISTER_RAW_SIZE(regno
);
783 store_signed_integer (buf
, size
, (LONGEST
) val
);
785 /* If we have a valid copy of the register, and new value == old value,
786 then don't bother doing the actual store. */
788 if (register_valid
[regno
]
789 && memcmp (®isters
[REGISTER_BYTE (regno
)], buf
, size
) == 0)
792 target_prepare_to_store ();
794 memcpy (®isters
[REGISTER_BYTE (regno
)], buf
, size
);
796 register_valid
[regno
] = 1;
798 target_store_registers (regno
);
802 write_register_pid (regno
, val
, pid
)
809 if (pid
== inferior_pid
)
811 write_register (regno
, val
);
815 save_pid
= inferior_pid
;
819 write_register (regno
, val
);
821 inferior_pid
= save_pid
;
824 /* Record that register REGNO contains VAL.
825 This is used when the value is obtained from the inferior or core dump,
826 so there is no need to store the value there. */
829 supply_register (regno
, val
)
833 if (registers_pid
!= inferior_pid
)
835 registers_changed ();
836 registers_pid
= inferior_pid
;
839 register_valid
[regno
] = 1;
840 memcpy (®isters
[REGISTER_BYTE (regno
)], val
, REGISTER_RAW_SIZE (regno
));
842 /* On some architectures, e.g. HPPA, there are a few stray bits in some
843 registers, that the rest of the code would like to ignore. */
844 #ifdef CLEAN_UP_REGISTER_VALUE
845 CLEAN_UP_REGISTER_VALUE(regno
, ®isters
[REGISTER_BYTE(regno
)]);
850 /* This routine is getting awfully cluttered with #if's. It's probably
851 time to turn this into READ_PC and define it in the tm.h file.
852 Ditto for write_pc. */
857 #ifdef TARGET_READ_PC
858 return TARGET_READ_PC (inferior_pid
);
860 return ADDR_BITS_REMOVE ((CORE_ADDR
) read_register_pid (PC_REGNUM
, inferior_pid
));
868 #ifdef TARGET_READ_PC
869 return TARGET_READ_PC (pid
);
871 return ADDR_BITS_REMOVE ((CORE_ADDR
) read_register_pid (PC_REGNUM
, pid
));
879 #ifdef TARGET_WRITE_PC
880 TARGET_WRITE_PC (val
, inferior_pid
);
882 write_register_pid (PC_REGNUM
, val
, inferior_pid
);
884 write_register_pid (NPC_REGNUM
, val
+ 4, inferior_pid
);
886 write_register_pid (NNPC_REGNUM
, val
+ 8, inferior_pid
);
893 write_pc_pid (val
, pid
)
897 #ifdef TARGET_WRITE_PC
898 TARGET_WRITE_PC (val
, pid
);
900 write_register_pid (PC_REGNUM
, val
, pid
);
902 write_register_pid (NPC_REGNUM
, val
+ 4, pid
);
904 write_register_pid (NNPC_REGNUM
, val
+ 8, pid
);
910 /* Cope with strage ways of getting to the stack and frame pointers */
915 #ifdef TARGET_READ_SP
916 return TARGET_READ_SP ();
918 return read_register (SP_REGNUM
);
926 #ifdef TARGET_WRITE_SP
927 TARGET_WRITE_SP (val
);
929 write_register (SP_REGNUM
, val
);
936 #ifdef TARGET_READ_FP
937 return TARGET_READ_FP ();
939 return read_register (FP_REGNUM
);
947 #ifdef TARGET_WRITE_FP
948 TARGET_WRITE_FP (val
);
950 write_register (FP_REGNUM
, val
);
954 /* Will calling read_var_value or locate_var_value on SYM end
955 up caring what frame it is being evaluated relative to? SYM must
958 symbol_read_needs_frame (sym
)
961 switch (SYMBOL_CLASS (sym
))
963 /* All cases listed explicitly so that gcc -Wall will detect it if
964 we failed to consider one. */
969 case LOC_REGPARM_ADDR
:
973 case LOC_BASEREG_ARG
:
982 /* Getting the address of a label can be done independently of the block,
983 even if some *uses* of that address wouldn't work so well without
987 case LOC_CONST_BYTES
:
989 case LOC_OPTIMIZED_OUT
:
995 /* Given a struct symbol for a variable,
996 and a stack frame id, read the value of the variable
997 and return a (pointer to a) struct value containing the value.
998 If the variable cannot be found, return a zero pointer.
999 If FRAME is NULL, use the selected_frame. */
1002 read_var_value (var
, frame
)
1003 register struct symbol
*var
;
1004 struct frame_info
*frame
;
1006 register value_ptr v
;
1007 struct type
*type
= SYMBOL_TYPE (var
);
1011 v
= allocate_value (type
);
1012 VALUE_LVAL (v
) = lval_memory
; /* The most likely possibility. */
1013 len
= TYPE_LENGTH (type
);
1015 if (frame
== NULL
) frame
= selected_frame
;
1017 switch (SYMBOL_CLASS (var
))
1020 /* Put the constant back in target format. */
1021 store_signed_integer (VALUE_CONTENTS_RAW (v
), len
,
1022 (LONGEST
) SYMBOL_VALUE (var
));
1023 VALUE_LVAL (v
) = not_lval
;
1027 /* Put the constant back in target format. */
1028 store_address (VALUE_CONTENTS_RAW (v
), len
, SYMBOL_VALUE_ADDRESS (var
));
1029 VALUE_LVAL (v
) = not_lval
;
1032 case LOC_CONST_BYTES
:
1035 bytes_addr
= SYMBOL_VALUE_BYTES (var
);
1036 memcpy (VALUE_CONTENTS_RAW (v
), bytes_addr
, len
);
1037 VALUE_LVAL (v
) = not_lval
;
1042 addr
= SYMBOL_VALUE_ADDRESS (var
);
1048 addr
= FRAME_ARGS_ADDRESS (frame
);
1051 addr
+= SYMBOL_VALUE (var
);
1057 addr
= FRAME_ARGS_ADDRESS (frame
);
1060 addr
+= SYMBOL_VALUE (var
);
1061 addr
= read_memory_unsigned_integer
1062 (addr
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
1069 addr
= FRAME_LOCALS_ADDRESS (frame
);
1070 addr
+= SYMBOL_VALUE (var
);
1074 case LOC_BASEREG_ARG
:
1076 char buf
[MAX_REGISTER_RAW_SIZE
];
1077 get_saved_register (buf
, NULL
, NULL
, frame
, SYMBOL_BASEREG (var
),
1079 addr
= extract_address (buf
, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var
)));
1080 addr
+= SYMBOL_VALUE (var
);
1085 error ("Cannot look up value of a typedef");
1089 VALUE_ADDRESS (v
) = BLOCK_START (SYMBOL_BLOCK_VALUE (var
));
1094 case LOC_REGPARM_ADDR
:
1100 b
= get_frame_block (frame
);
1103 if (SYMBOL_CLASS (var
) == LOC_REGPARM_ADDR
)
1106 value_as_pointer (value_from_register (lookup_pointer_type (type
),
1109 VALUE_LVAL (v
) = lval_memory
;
1112 return value_from_register (type
, SYMBOL_VALUE (var
), frame
);
1116 case LOC_UNRESOLVED
:
1118 struct minimal_symbol
*msym
;
1120 msym
= lookup_minimal_symbol (SYMBOL_NAME (var
), NULL
, NULL
);
1123 addr
= SYMBOL_VALUE_ADDRESS (msym
);
1127 case LOC_OPTIMIZED_OUT
:
1128 VALUE_LVAL (v
) = not_lval
;
1129 VALUE_OPTIMIZED_OUT (v
) = 1;
1133 error ("Cannot look up value of a botched symbol.");
1137 VALUE_ADDRESS (v
) = addr
;
1142 /* Return a value of type TYPE, stored in register REGNUM, in frame
1146 value_from_register (type
, regnum
, frame
)
1149 struct frame_info
*frame
;
1151 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1154 value_ptr v
= allocate_value (type
);
1155 char *value_bytes
= 0;
1156 int value_bytes_copied
= 0;
1157 int num_storage_locs
;
1158 enum lval_type lval
;
1161 CHECK_TYPEDEF (type
);
1162 len
= TYPE_LENGTH (type
);
1164 VALUE_REGNO (v
) = regnum
;
1166 num_storage_locs
= (len
> REGISTER_VIRTUAL_SIZE (regnum
) ?
1167 ((len
- 1) / REGISTER_RAW_SIZE (regnum
)) + 1 :
1170 if (num_storage_locs
> 1
1171 #ifdef GDB_TARGET_IS_H8500
1172 || TYPE_CODE (type
) == TYPE_CODE_PTR
1176 /* Value spread across multiple storage locations. */
1179 int mem_stor
= 0, reg_stor
= 0;
1180 int mem_tracking
= 1;
1181 CORE_ADDR last_addr
= 0;
1182 CORE_ADDR first_addr
= 0;
1184 value_bytes
= (char *) alloca (len
+ MAX_REGISTER_RAW_SIZE
);
1186 /* Copy all of the data out, whereever it may be. */
1188 #ifdef GDB_TARGET_IS_H8500
1189 /* This piece of hideosity is required because the H8500 treats registers
1190 differently depending upon whether they are used as pointers or not. As a
1191 pointer, a register needs to have a page register tacked onto the front.
1192 An alternate way to do this would be to have gcc output different register
1193 numbers for the pointer & non-pointer form of the register. But, it
1194 doesn't, so we're stuck with this. */
1196 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1203 case R0_REGNUM
: case R1_REGNUM
: case R2_REGNUM
: case R3_REGNUM
:
1204 page_regnum
= SEG_D_REGNUM
;
1206 case R4_REGNUM
: case R5_REGNUM
:
1207 page_regnum
= SEG_E_REGNUM
;
1209 case R6_REGNUM
: case R7_REGNUM
:
1210 page_regnum
= SEG_T_REGNUM
;
1215 get_saved_register (value_bytes
+ 1,
1222 if (lval
== lval_register
)
1229 get_saved_register (value_bytes
+ 2,
1236 if (lval
== lval_register
)
1241 mem_tracking
= mem_tracking
&& (addr
== last_addr
);
1246 #endif /* GDB_TARGET_IS_H8500 */
1247 for (local_regnum
= regnum
;
1248 value_bytes_copied
< len
;
1249 (value_bytes_copied
+= REGISTER_RAW_SIZE (local_regnum
),
1252 get_saved_register (value_bytes
+ value_bytes_copied
,
1259 if (regnum
== local_regnum
)
1261 if (lval
== lval_register
)
1269 && (regnum
== local_regnum
1270 || addr
== last_addr
));
1275 if ((reg_stor
&& mem_stor
)
1276 || (mem_stor
&& !mem_tracking
))
1277 /* Mixed storage; all of the hassle we just went through was
1278 for some good purpose. */
1280 VALUE_LVAL (v
) = lval_reg_frame_relative
;
1281 VALUE_FRAME (v
) = FRAME_FP (frame
);
1282 VALUE_FRAME_REGNUM (v
) = regnum
;
1286 VALUE_LVAL (v
) = lval_memory
;
1287 VALUE_ADDRESS (v
) = first_addr
;
1291 VALUE_LVAL (v
) = lval_register
;
1292 VALUE_ADDRESS (v
) = first_addr
;
1295 fatal ("value_from_register: Value not stored anywhere!");
1297 VALUE_OPTIMIZED_OUT (v
) = optim
;
1299 /* Any structure stored in more than one register will always be
1300 an integral number of registers. Otherwise, you'd need to do
1301 some fiddling with the last register copied here for little
1304 /* Copy into the contents section of the value. */
1305 memcpy (VALUE_CONTENTS_RAW (v
), value_bytes
, len
);
1307 /* Finally do any conversion necessary when extracting this
1308 type from more than one register. */
1309 #ifdef REGISTER_CONVERT_TO_TYPE
1310 REGISTER_CONVERT_TO_TYPE(regnum
, type
, VALUE_CONTENTS_RAW(v
));
1315 /* Data is completely contained within a single register. Locate the
1316 register's contents in a real register or in core;
1317 read the data in raw format. */
1319 get_saved_register (raw_buffer
, &optim
, &addr
, frame
, regnum
, &lval
);
1320 VALUE_OPTIMIZED_OUT (v
) = optim
;
1321 VALUE_LVAL (v
) = lval
;
1322 VALUE_ADDRESS (v
) = addr
;
1324 /* Convert raw data to virtual format if necessary. */
1326 #ifdef REGISTER_CONVERTIBLE
1327 if (REGISTER_CONVERTIBLE (regnum
))
1329 REGISTER_CONVERT_TO_VIRTUAL (regnum
, type
,
1330 raw_buffer
, VALUE_CONTENTS_RAW (v
));
1335 /* Raw and virtual formats are the same for this register. */
1337 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
&& len
< REGISTER_RAW_SIZE (regnum
))
1339 /* Big-endian, and we want less than full size. */
1340 VALUE_OFFSET (v
) = REGISTER_RAW_SIZE (regnum
) - len
;
1343 memcpy (VALUE_CONTENTS_RAW (v
), raw_buffer
+ VALUE_OFFSET (v
), len
);
1349 /* Given a struct symbol for a variable or function,
1350 and a stack frame id,
1351 return a (pointer to a) struct value containing the properly typed
1355 locate_var_value (var
, frame
)
1356 register struct symbol
*var
;
1357 struct frame_info
*frame
;
1360 struct type
*type
= SYMBOL_TYPE (var
);
1361 value_ptr lazy_value
;
1363 /* Evaluate it first; if the result is a memory address, we're fine.
1364 Lazy evaluation pays off here. */
1366 lazy_value
= read_var_value (var
, frame
);
1367 if (lazy_value
== 0)
1368 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var
));
1370 if (VALUE_LAZY (lazy_value
)
1371 || TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1373 addr
= VALUE_ADDRESS (lazy_value
);
1374 return value_from_longest (lookup_pointer_type (type
), (LONGEST
) addr
);
1377 /* Not a memory address; check what the problem was. */
1378 switch (VALUE_LVAL (lazy_value
))
1381 case lval_reg_frame_relative
:
1382 error ("Address requested for identifier \"%s\" which is in a register.",
1383 SYMBOL_SOURCE_NAME (var
));
1387 error ("Can't take address of \"%s\" which isn't an lvalue.",
1388 SYMBOL_SOURCE_NAME (var
));
1391 return 0; /* For lint -- never reached */