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 a fixed version of
199 ieee-float.c (the current version can't deal with single or double,
200 and I suspect it is probably broken for some extendeds too).
202 2. We can't deal with it if there is more than one floating point
203 format in use. This has to be fixed at the unpack_double level.
205 3. We probably should have a LONGEST_DOUBLE or DOUBLEST or whatever
206 we want to call it which is long double where available. */
209 extract_floating (addr, len)
213 if (len == sizeof (float))
216 memcpy (&retval, addr, sizeof (retval));
217 SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
220 else if (len == sizeof (double))
223 memcpy (&retval, addr, sizeof (retval));
224 SWAP_TARGET_AND_HOST (&retval, sizeof (retval));
229 error ("Can't deal with a floating point number of %d bytes.", len);
234 store_floating (addr, len, val)
239 if (len == sizeof (float))
241 float floatval = val;
242 SWAP_TARGET_AND_HOST (&floatval, sizeof (floatval));
243 memcpy (addr, &floatval, sizeof (floatval));
245 else if (len == sizeof (double))
247 SWAP_TARGET_AND_HOST (&val, sizeof (val));
248 memcpy (addr, &val, sizeof (val));
252 error ("Can't deal with a floating point number of %d bytes.", len);
256 #if !defined (GET_SAVED_REGISTER)
258 /* Return the address in which frame FRAME's value of register REGNUM
259 has been saved in memory. Or return zero if it has not been saved.
260 If REGNUM specifies the SP, the value we return is actually
261 the SP value, not an address where it was saved. */
264 find_saved_register (frame, regnum)
268 struct frame_info *fi;
269 struct frame_saved_regs saved_regs;
271 register FRAME frame1 = 0;
272 register CORE_ADDR addr = 0;
274 if (frame == 0) /* No regs saved if want current frame */
277 #ifdef HAVE_REGISTER_WINDOWS
278 /* We assume that a register in a register window will only be saved
279 in one place (since the name changes and/or disappears as you go
280 towards inner frames), so we only call get_frame_saved_regs on
281 the current frame. This is directly in contradiction to the
282 usage below, which assumes that registers used in a frame must be
283 saved in a lower (more interior) frame. This change is a result
284 of working on a register window machine; get_frame_saved_regs
285 always returns the registers saved within a frame, within the
286 context (register namespace) of that frame. */
288 /* However, note that we don't want this to return anything if
289 nothing is saved (if there's a frame inside of this one). Also,
290 callers to this routine asking for the stack pointer want the
291 stack pointer saved for *this* frame; this is returned from the
295 if (REGISTER_IN_WINDOW_P(regnum))
297 frame1 = get_next_frame (frame);
298 if (!frame1) return 0; /* Registers of this frame are
301 /* Get the SP from the next frame in; it will be this
303 if (regnum != SP_REGNUM)
306 fi = get_frame_info (frame1);
307 get_frame_saved_regs (fi, &saved_regs);
308 return saved_regs.regs[regnum]; /* ... which might be zero */
310 #endif /* HAVE_REGISTER_WINDOWS */
312 /* Note that this next routine assumes that registers used in
313 frame x will be saved only in the frame that x calls and
314 frames interior to it. This is not true on the sparc, but the
315 above macro takes care of it, so we should be all right. */
319 frame1 = get_prev_frame (frame1);
320 if (frame1 == 0 || frame1 == frame)
322 fi = get_frame_info (frame1);
323 get_frame_saved_regs (fi, &saved_regs);
324 if (saved_regs.regs[regnum])
325 addr = saved_regs.regs[regnum];
331 /* Find register number REGNUM relative to FRAME and put its (raw,
332 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
333 variable was optimized out (and thus can't be fetched). Set *LVAL
334 to lval_memory, lval_register, or not_lval, depending on whether
335 the value was fetched from memory, from a register, or in a strange
336 and non-modifiable way (e.g. a frame pointer which was calculated
337 rather than fetched). Set *ADDRP to the address, either in memory
338 on as a REGISTER_BYTE offset into the registers array.
340 Note that this implementation never sets *LVAL to not_lval. But
341 it can be replaced by defining GET_SAVED_REGISTER and supplying
344 The argument RAW_BUFFER must point to aligned memory. */
347 get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
353 enum lval_type *lval;
356 /* Normal systems don't optimize out things with register numbers. */
357 if (optimized != NULL)
359 addr = find_saved_register (frame, regnum);
364 if (regnum == SP_REGNUM)
366 if (raw_buffer != NULL)
368 /* Put it back in target format. */
369 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), addr);
375 if (raw_buffer != NULL)
376 read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
381 *lval = lval_register;
382 addr = REGISTER_BYTE (regnum);
383 if (raw_buffer != NULL)
384 read_register_gen (regnum, raw_buffer);
389 #endif /* GET_SAVED_REGISTER. */
391 /* Copy the bytes of register REGNUM, relative to the current stack frame,
392 into our memory at MYADDR, in target byte order.
393 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
395 Returns 1 if could not be read, 0 if could. */
398 read_relative_register_raw_bytes (regnum, myaddr)
403 if (regnum == FP_REGNUM && selected_frame)
405 /* Put it back in target format. */
406 store_address (myaddr, REGISTER_RAW_SIZE(FP_REGNUM),
407 FRAME_FP(selected_frame));
411 get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, selected_frame,
412 regnum, (enum lval_type *)NULL);
416 /* Return a `value' with the contents of register REGNUM
417 in its virtual format, with the type specified by
418 REGISTER_VIRTUAL_TYPE. */
421 value_of_register (regnum)
427 char raw_buffer[MAX_REGISTER_RAW_SIZE];
430 get_saved_register (raw_buffer, &optim, &addr,
431 selected_frame, regnum, &lval);
433 val = allocate_value (REGISTER_VIRTUAL_TYPE (regnum));
435 /* Convert raw data to virtual format if necessary. */
437 #ifdef REGISTER_CONVERTIBLE
438 if (REGISTER_CONVERTIBLE (regnum))
440 REGISTER_CONVERT_TO_VIRTUAL (regnum, REGISTER_VIRTUAL_TYPE (regnum),
441 raw_buffer, VALUE_CONTENTS_RAW (val));
445 memcpy (VALUE_CONTENTS_RAW (val), raw_buffer,
446 REGISTER_RAW_SIZE (regnum));
447 VALUE_LVAL (val) = lval;
448 VALUE_ADDRESS (val) = addr;
449 VALUE_REGNO (val) = regnum;
450 VALUE_OPTIMIZED_OUT (val) = optim;
454 /* Low level examining and depositing of registers.
456 The caller is responsible for making
457 sure that the inferior is stopped before calling the fetching routines,
458 or it will get garbage. (a change from GDB version 3, in which
459 the caller got the value from the last stop). */
461 /* Contents of the registers in target byte order.
462 We allocate some extra slop since we do a lot of memcpy's around `registers',
463 and failing-soft is better than failing hard. */
464 char registers[REGISTER_BYTES + /* SLOP */ 256];
466 /* Nonzero if that register has been fetched. */
467 char register_valid[NUM_REGS];
469 /* Indicate that registers may have changed, so invalidate the cache. */
474 for (i = 0; i < NUM_REGS; i++)
475 register_valid[i] = 0;
478 /* Indicate that all registers have been fetched, so mark them all valid. */
483 for (i = 0; i < NUM_REGS; i++)
484 register_valid[i] = 1;
487 /* Copy LEN bytes of consecutive data from registers
488 starting with the REGBYTE'th byte of register data
489 into memory at MYADDR. */
492 read_register_bytes (regbyte, myaddr, len)
497 /* Fetch all registers. */
499 for (i = 0; i < NUM_REGS; i++)
500 if (!register_valid[i])
502 target_fetch_registers (-1);
506 memcpy (myaddr, ®isters[regbyte], len);
509 /* Read register REGNO into memory at MYADDR, which must be large enough
510 for REGISTER_RAW_BYTES (REGNO). Target byte-order.
511 If the register is known to be the size of a CORE_ADDR or smaller,
512 read_register can be used instead. */
514 read_register_gen (regno, myaddr)
518 if (!register_valid[regno])
519 target_fetch_registers (regno);
520 memcpy (myaddr, ®isters[REGISTER_BYTE (regno)],
521 REGISTER_RAW_SIZE (regno));
524 /* Copy LEN bytes of consecutive data from memory at MYADDR
525 into registers starting with the REGBYTE'th byte of register data. */
528 write_register_bytes (regbyte, myaddr, len)
533 /* Make sure the entire registers array is valid. */
534 read_register_bytes (0, (char *)NULL, REGISTER_BYTES);
535 memcpy (®isters[regbyte], myaddr, len);
536 target_store_registers (-1);
539 /* Return the raw contents of register REGNO, regarding it as an integer. */
540 /* This probably should be returning LONGEST rather than CORE_ADDR. */
543 read_register (regno)
546 if (!register_valid[regno])
547 target_fetch_registers (regno);
549 return extract_address (®isters[REGISTER_BYTE (regno)],
550 REGISTER_RAW_SIZE(regno));
553 /* Registers we shouldn't try to store. */
554 #if !defined (CANNOT_STORE_REGISTER)
555 #define CANNOT_STORE_REGISTER(regno) 0
558 /* Store VALUE, into the raw contents of register number REGNO. */
559 /* FIXME: The val arg should probably be a LONGEST. */
562 write_register (regno, val)
569 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
570 the registers array if something writes to this register. */
571 if (CANNOT_STORE_REGISTER (regno))
574 size = REGISTER_RAW_SIZE(regno);
576 store_signed_integer (buf, size, (LONGEST) val);
578 /* If we have a valid copy of the register, and new value == old value,
579 then don't bother doing the actual store. */
581 if (register_valid [regno])
583 if (memcmp (®isters[REGISTER_BYTE (regno)], buf, size) == 0)
587 target_prepare_to_store ();
589 memcpy (®isters[REGISTER_BYTE (regno)], buf, size);
591 register_valid [regno] = 1;
593 target_store_registers (regno);
596 /* Record that register REGNO contains VAL.
597 This is used when the value is obtained from the inferior or core dump,
598 so there is no need to store the value there. */
601 supply_register (regno, val)
605 register_valid[regno] = 1;
606 memcpy (®isters[REGISTER_BYTE (regno)], val, REGISTER_RAW_SIZE (regno));
608 /* On some architectures, e.g. HPPA, there are a few stray bits in some
609 registers, that the rest of the code would like to ignore. */
610 #ifdef CLEAN_UP_REGISTER_VALUE
611 CLEAN_UP_REGISTER_VALUE(regno, ®isters[REGISTER_BYTE(regno)]);
615 /* Will calling read_var_value or locate_var_value on SYM end
616 up caring what frame it is being evaluated relative to? SYM must
619 symbol_read_needs_frame (sym)
622 switch (SYMBOL_CLASS (sym))
624 /* All cases listed explicitly so that gcc -Wall will detect it if
625 we failed to consider one. */
630 case LOC_REGPARM_ADDR:
634 case LOC_BASEREG_ARG:
643 /* Getting the address of a label can be done independently of the block,
644 even if some *uses* of that address wouldn't work so well without
648 case LOC_CONST_BYTES:
649 case LOC_OPTIMIZED_OUT:
655 /* Given a struct symbol for a variable,
656 and a stack frame id, read the value of the variable
657 and return a (pointer to a) struct value containing the value.
658 If the variable cannot be found, return a zero pointer.
659 If FRAME is NULL, use the selected_frame. */
662 read_var_value (var, frame)
663 register struct symbol *var;
667 struct frame_info *fi;
668 struct type *type = SYMBOL_TYPE (var);
672 v = allocate_value (type);
673 VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
674 len = TYPE_LENGTH (type);
676 if (frame == 0) frame = selected_frame;
678 switch (SYMBOL_CLASS (var))
681 /* Put the constant back in target format. */
682 store_signed_integer (VALUE_CONTENTS_RAW (v), len,
683 (LONGEST) SYMBOL_VALUE (var));
684 VALUE_LVAL (v) = not_lval;
688 /* Put the constant back in target format. */
689 store_address (VALUE_CONTENTS_RAW (v), len, SYMBOL_VALUE_ADDRESS (var));
690 VALUE_LVAL (v) = not_lval;
693 case LOC_CONST_BYTES:
696 bytes_addr = SYMBOL_VALUE_BYTES (var);
697 memcpy (VALUE_CONTENTS_RAW (v), bytes_addr, len);
698 VALUE_LVAL (v) = not_lval;
703 addr = SYMBOL_VALUE_ADDRESS (var);
707 fi = get_frame_info (frame);
710 addr = FRAME_ARGS_ADDRESS (fi);
715 addr += SYMBOL_VALUE (var);
719 fi = get_frame_info (frame);
722 addr = FRAME_ARGS_ADDRESS (fi);
727 addr += SYMBOL_VALUE (var);
728 addr = read_memory_unsigned_integer
729 (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
734 fi = get_frame_info (frame);
737 addr = FRAME_LOCALS_ADDRESS (fi);
738 addr += SYMBOL_VALUE (var);
742 case LOC_BASEREG_ARG:
744 char buf[MAX_REGISTER_RAW_SIZE];
745 get_saved_register (buf, NULL, NULL, frame, SYMBOL_BASEREG (var),
747 addr = extract_address (buf, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var)));
748 addr += SYMBOL_VALUE (var);
753 error ("Cannot look up value of a typedef");
757 VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
762 case LOC_REGPARM_ADDR:
768 b = get_frame_block (frame);
770 v = value_from_register (type, SYMBOL_VALUE (var), frame);
772 if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
774 addr = *(CORE_ADDR *)VALUE_CONTENTS (v);
775 VALUE_LVAL (v) = lval_memory;
782 case LOC_OPTIMIZED_OUT:
783 VALUE_LVAL (v) = not_lval;
784 VALUE_OPTIMIZED_OUT (v) = 1;
788 error ("Cannot look up value of a botched symbol.");
792 VALUE_ADDRESS (v) = addr;
797 /* Return a value of type TYPE, stored in register REGNUM, in frame
801 value_from_register (type, regnum, frame)
806 char raw_buffer [MAX_REGISTER_RAW_SIZE];
809 value v = allocate_value (type);
810 int len = TYPE_LENGTH (type);
811 char *value_bytes = 0;
812 int value_bytes_copied = 0;
813 int num_storage_locs;
816 VALUE_REGNO (v) = regnum;
818 num_storage_locs = (len > REGISTER_VIRTUAL_SIZE (regnum) ?
819 ((len - 1) / REGISTER_RAW_SIZE (regnum)) + 1 :
822 if (num_storage_locs > 1
823 #ifdef GDB_TARGET_IS_H8500
824 || TYPE_CODE (type) == TYPE_CODE_PTR
828 /* Value spread across multiple storage locations. */
831 int mem_stor = 0, reg_stor = 0;
832 int mem_tracking = 1;
833 CORE_ADDR last_addr = 0;
834 CORE_ADDR first_addr = 0;
836 value_bytes = (char *) alloca (len + MAX_REGISTER_RAW_SIZE);
838 /* Copy all of the data out, whereever it may be. */
840 #ifdef GDB_TARGET_IS_H8500
841 /* This piece of hideosity is required because the H8500 treats registers
842 differently depending upon whether they are used as pointers or not. As a
843 pointer, a register needs to have a page register tacked onto the front.
844 An alternate way to do this would be to have gcc output different register
845 numbers for the pointer & non-pointer form of the register. But, it
846 doesn't, so we're stuck with this. */
848 if (TYPE_CODE (type) == TYPE_CODE_PTR
855 case R0_REGNUM: case R1_REGNUM: case R2_REGNUM: case R3_REGNUM:
856 page_regnum = SEG_D_REGNUM;
858 case R4_REGNUM: case R5_REGNUM:
859 page_regnum = SEG_E_REGNUM;
861 case R6_REGNUM: case R7_REGNUM:
862 page_regnum = SEG_T_REGNUM;
867 get_saved_register (value_bytes + 1,
874 if (lval == lval_register)
881 get_saved_register (value_bytes + 2,
888 if (lval == lval_register)
893 mem_tracking = mem_tracking && (addr == last_addr);
898 #endif /* GDB_TARGET_IS_H8500 */
899 for (local_regnum = regnum;
900 value_bytes_copied < len;
901 (value_bytes_copied += REGISTER_RAW_SIZE (local_regnum),
904 get_saved_register (value_bytes + value_bytes_copied,
911 if (regnum == local_regnum)
913 if (lval == lval_register)
921 && (regnum == local_regnum
922 || addr == last_addr));
927 if ((reg_stor && mem_stor)
928 || (mem_stor && !mem_tracking))
929 /* Mixed storage; all of the hassle we just went through was
930 for some good purpose. */
932 VALUE_LVAL (v) = lval_reg_frame_relative;
933 VALUE_FRAME (v) = FRAME_FP (frame);
934 VALUE_FRAME_REGNUM (v) = regnum;
938 VALUE_LVAL (v) = lval_memory;
939 VALUE_ADDRESS (v) = first_addr;
943 VALUE_LVAL (v) = lval_register;
944 VALUE_ADDRESS (v) = first_addr;
947 fatal ("value_from_register: Value not stored anywhere!");
949 VALUE_OPTIMIZED_OUT (v) = optim;
951 /* Any structure stored in more than one register will always be
952 an integral number of registers. Otherwise, you'd need to do
953 some fiddling with the last register copied here for little
956 /* Copy into the contents section of the value. */
957 memcpy (VALUE_CONTENTS_RAW (v), value_bytes, len);
959 /* Finally do any conversion necessary when extracting this
960 type from more than one register. */
961 #ifdef REGISTER_CONVERT_TO_TYPE
962 REGISTER_CONVERT_TO_TYPE(regnum, type, VALUE_CONTENTS_RAW(v));
967 /* Data is completely contained within a single register. Locate the
968 register's contents in a real register or in core;
969 read the data in raw format. */
971 get_saved_register (raw_buffer, &optim, &addr, frame, regnum, &lval);
972 VALUE_OPTIMIZED_OUT (v) = optim;
973 VALUE_LVAL (v) = lval;
974 VALUE_ADDRESS (v) = addr;
976 /* Convert raw data to virtual format if necessary. */
978 #ifdef REGISTER_CONVERTIBLE
979 if (REGISTER_CONVERTIBLE (regnum))
981 REGISTER_CONVERT_TO_VIRTUAL (regnum, type,
982 raw_buffer, VALUE_CONTENTS_RAW (v));
987 /* Raw and virtual formats are the same for this register. */
989 #if TARGET_BYTE_ORDER == BIG_ENDIAN
990 if (len < REGISTER_RAW_SIZE (regnum))
992 /* Big-endian, and we want less than full size. */
993 VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len;
997 memcpy (VALUE_CONTENTS_RAW (v), raw_buffer + VALUE_OFFSET (v), len);
1003 /* Given a struct symbol for a variable or function,
1004 and a stack frame id,
1005 return a (pointer to a) struct value containing the properly typed
1009 locate_var_value (var, frame)
1010 register struct symbol *var;
1014 struct type *type = SYMBOL_TYPE (var);
1017 /* Evaluate it first; if the result is a memory address, we're fine.
1018 Lazy evaluation pays off here. */
1020 lazy_value = read_var_value (var, frame);
1021 if (lazy_value == 0)
1022 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
1024 if (VALUE_LAZY (lazy_value)
1025 || TYPE_CODE (type) == TYPE_CODE_FUNC)
1027 addr = VALUE_ADDRESS (lazy_value);
1028 return value_from_longest (lookup_pointer_type (type), (LONGEST) addr);
1031 /* Not a memory address; check what the problem was. */
1032 switch (VALUE_LVAL (lazy_value))
1035 case lval_reg_frame_relative:
1036 error ("Address requested for identifier \"%s\" which is in a register.",
1037 SYMBOL_SOURCE_NAME (var));
1041 error ("Can't take address of \"%s\" which isn't an lvalue.",
1042 SYMBOL_SOURCE_NAME (var));
1045 return 0; /* For lint -- never reached */