1 /* Find a variable's value in memory, for GDB, the GNU debugger.
2 Copyright 1986, 87, 89, 91, 94, 95, 96, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 #include "gdb_string.h"
31 #include "floatformat.h"
32 #include "symfile.h" /* for overlay functions */
34 /* This is used to indicate that we don't know the format of the floating point
35 number. Typically, this is useful for native ports, where the actual format
36 is irrelevant, since no conversions will be taking place. */
38 const struct floatformat floatformat_unknown
;
40 /* Basic byte-swapping routines. GDB has needed these for a long time...
41 All extract a target-format integer at ADDR which is LEN bytes long. */
43 #if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8
44 /* 8 bit characters are a pretty safe assumption these days, so we
45 assume it throughout all these swapping routines. If we had to deal with
46 9 bit characters, we would need to make len be in bits and would have
47 to re-write these routines... */
52 extract_signed_integer (void *addr
, int len
)
56 unsigned char *startaddr
= (unsigned char *) addr
;
57 unsigned char *endaddr
= startaddr
+ len
;
59 if (len
> (int) sizeof (LONGEST
))
61 That operation is not available on integers of more than %d bytes.",
64 /* Start at the most significant end of the integer, and work towards
65 the least significant. */
66 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
69 /* Do the sign extension once at the start. */
70 retval
= ((LONGEST
) * p
^ 0x80) - 0x80;
71 for (++p
; p
< endaddr
; ++p
)
72 retval
= (retval
<< 8) | *p
;
77 /* Do the sign extension once at the start. */
78 retval
= ((LONGEST
) * p
^ 0x80) - 0x80;
79 for (--p
; p
>= startaddr
; --p
)
80 retval
= (retval
<< 8) | *p
;
86 extract_unsigned_integer (void *addr
, int len
)
90 unsigned char *startaddr
= (unsigned char *) addr
;
91 unsigned char *endaddr
= startaddr
+ len
;
93 if (len
> (int) sizeof (ULONGEST
))
95 That operation is not available on integers of more than %d bytes.",
98 /* Start at the most significant end of the integer, and work towards
99 the least significant. */
101 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
103 for (p
= startaddr
; p
< endaddr
; ++p
)
104 retval
= (retval
<< 8) | *p
;
108 for (p
= endaddr
- 1; p
>= startaddr
; --p
)
109 retval
= (retval
<< 8) | *p
;
114 /* Sometimes a long long unsigned integer can be extracted as a
115 LONGEST value. This is done so that we can print these values
116 better. If this integer can be converted to a LONGEST, this
117 function returns 1 and sets *PVAL. Otherwise it returns 0. */
120 extract_long_unsigned_integer (void *addr
, int orig_len
, LONGEST
*pval
)
122 char *p
, *first_addr
;
126 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
128 for (p
= (char *) addr
;
129 len
> (int) sizeof (LONGEST
) && p
< (char *) addr
+ orig_len
;
141 first_addr
= (char *) addr
;
142 for (p
= (char *) addr
+ orig_len
- 1;
143 len
> (int) sizeof (LONGEST
) && p
>= (char *) addr
;
153 if (len
<= (int) sizeof (LONGEST
))
155 *pval
= (LONGEST
) extract_unsigned_integer (first_addr
,
164 /* Treat the LEN bytes at ADDR as a target-format address, and return
165 that address. ADDR is a buffer in the GDB process, not in the
168 This function should only be used by target-specific code. It
169 assumes that a pointer has the same representation as that thing's
170 address represented as an integer. Some machines use word
171 addresses, or similarly munged things, for certain types of
172 pointers, so that assumption doesn't hold everywhere.
174 Common code should use extract_typed_address instead, or something
175 else based on POINTER_TO_ADDRESS. */
178 extract_address (void *addr
, int len
)
180 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
181 whether we want this to be true eventually. */
182 return (CORE_ADDR
) extract_unsigned_integer (addr
, len
);
186 /* Treat the bytes at BUF as a pointer of type TYPE, and return the
187 address it represents. */
189 extract_typed_address (void *buf
, struct type
*type
)
191 if (TYPE_CODE (type
) != TYPE_CODE_PTR
192 && TYPE_CODE (type
) != TYPE_CODE_REF
)
193 internal_error ("findvar.c (extract_typed_address): "
194 "type is not a pointer or reference");
196 return POINTER_TO_ADDRESS (type
, buf
);
201 store_signed_integer (void *addr
, int len
, LONGEST val
)
204 unsigned char *startaddr
= (unsigned char *) addr
;
205 unsigned char *endaddr
= startaddr
+ len
;
207 /* Start at the least significant end of the integer, and work towards
208 the most significant. */
209 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
211 for (p
= endaddr
- 1; p
>= startaddr
; --p
)
219 for (p
= startaddr
; p
< endaddr
; ++p
)
228 store_unsigned_integer (void *addr
, int len
, ULONGEST val
)
231 unsigned char *startaddr
= (unsigned char *) addr
;
232 unsigned char *endaddr
= startaddr
+ len
;
234 /* Start at the least significant end of the integer, and work towards
235 the most significant. */
236 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
238 for (p
= endaddr
- 1; p
>= startaddr
; --p
)
246 for (p
= startaddr
; p
< endaddr
; ++p
)
254 /* Store the address VAL as a LEN-byte value in target byte order at
255 ADDR. ADDR is a buffer in the GDB process, not in the inferior.
257 This function should only be used by target-specific code. It
258 assumes that a pointer has the same representation as that thing's
259 address represented as an integer. Some machines use word
260 addresses, or similarly munged things, for certain types of
261 pointers, so that assumption doesn't hold everywhere.
263 Common code should use store_typed_address instead, or something else
264 based on ADDRESS_TO_POINTER. */
266 store_address (void *addr
, int len
, LONGEST val
)
268 store_unsigned_integer (addr
, len
, val
);
272 /* Store the address ADDR as a pointer of type TYPE at BUF, in target
275 store_typed_address (void *buf
, struct type
*type
, CORE_ADDR addr
)
277 if (TYPE_CODE (type
) != TYPE_CODE_PTR
278 && TYPE_CODE (type
) != TYPE_CODE_REF
)
279 internal_error ("findvar.c (store_typed_address): "
280 "type is not a pointer or reference");
282 ADDRESS_TO_POINTER (type
, buf
, addr
);
288 /* Extract a floating-point number from a target-order byte-stream at ADDR.
289 Returns the value as type DOUBLEST.
291 If the host and target formats agree, we just copy the raw data into the
292 appropriate type of variable and return, letting the host increase precision
293 as necessary. Otherwise, we call the conversion routine and let it do the
297 extract_floating (void *addr
, int len
)
301 if (len
* TARGET_CHAR_BIT
== TARGET_FLOAT_BIT
)
303 if (HOST_FLOAT_FORMAT
== TARGET_FLOAT_FORMAT
)
307 memcpy (&retval
, addr
, sizeof (retval
));
311 floatformat_to_doublest (TARGET_FLOAT_FORMAT
, addr
, &dretval
);
313 else if (len
* TARGET_CHAR_BIT
== TARGET_DOUBLE_BIT
)
315 if (HOST_DOUBLE_FORMAT
== TARGET_DOUBLE_FORMAT
)
319 memcpy (&retval
, addr
, sizeof (retval
));
323 floatformat_to_doublest (TARGET_DOUBLE_FORMAT
, addr
, &dretval
);
325 else if (len
* TARGET_CHAR_BIT
== TARGET_LONG_DOUBLE_BIT
)
327 if (HOST_LONG_DOUBLE_FORMAT
== TARGET_LONG_DOUBLE_FORMAT
)
331 memcpy (&retval
, addr
, sizeof (retval
));
335 floatformat_to_doublest (TARGET_LONG_DOUBLE_FORMAT
, addr
, &dretval
);
339 error ("Can't deal with a floating point number of %d bytes.", len
);
346 store_floating (void *addr
, int len
, DOUBLEST val
)
348 if (len
* TARGET_CHAR_BIT
== TARGET_FLOAT_BIT
)
350 if (HOST_FLOAT_FORMAT
== TARGET_FLOAT_FORMAT
)
352 float floatval
= val
;
354 memcpy (addr
, &floatval
, sizeof (floatval
));
357 floatformat_from_doublest (TARGET_FLOAT_FORMAT
, &val
, addr
);
359 else if (len
* TARGET_CHAR_BIT
== TARGET_DOUBLE_BIT
)
361 if (HOST_DOUBLE_FORMAT
== TARGET_DOUBLE_FORMAT
)
363 double doubleval
= val
;
365 memcpy (addr
, &doubleval
, sizeof (doubleval
));
368 floatformat_from_doublest (TARGET_DOUBLE_FORMAT
, &val
, addr
);
370 else if (len
* TARGET_CHAR_BIT
== TARGET_LONG_DOUBLE_BIT
)
372 if (HOST_LONG_DOUBLE_FORMAT
== TARGET_LONG_DOUBLE_FORMAT
)
373 memcpy (addr
, &val
, sizeof (val
));
375 floatformat_from_doublest (TARGET_LONG_DOUBLE_FORMAT
, &val
, addr
);
379 error ("Can't deal with a floating point number of %d bytes.", len
);
383 /* Return a `value' with the contents of register REGNUM
384 in its virtual format, with the type specified by
385 REGISTER_VIRTUAL_TYPE.
387 NOTE: returns NULL if register value is not available.
388 Caller will check return value or die! */
391 value_of_register (int regnum
)
395 register value_ptr reg_val
;
396 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
399 get_saved_register (raw_buffer
, &optim
, &addr
,
400 selected_frame
, regnum
, &lval
);
402 if (register_cached (regnum
) < 0)
403 return NULL
; /* register value not available */
405 reg_val
= allocate_value (REGISTER_VIRTUAL_TYPE (regnum
));
407 /* Convert raw data to virtual format if necessary. */
409 if (REGISTER_CONVERTIBLE (regnum
))
411 REGISTER_CONVERT_TO_VIRTUAL (regnum
, REGISTER_VIRTUAL_TYPE (regnum
),
412 raw_buffer
, VALUE_CONTENTS_RAW (reg_val
));
414 else if (REGISTER_RAW_SIZE (regnum
) == REGISTER_VIRTUAL_SIZE (regnum
))
415 memcpy (VALUE_CONTENTS_RAW (reg_val
), raw_buffer
,
416 REGISTER_RAW_SIZE (regnum
));
418 internal_error ("Register \"%s\" (%d) has conflicting raw (%d) and virtual (%d) size",
419 REGISTER_NAME (regnum
),
421 REGISTER_RAW_SIZE (regnum
),
422 REGISTER_VIRTUAL_SIZE (regnum
));
423 VALUE_LVAL (reg_val
) = lval
;
424 VALUE_ADDRESS (reg_val
) = addr
;
425 VALUE_REGNO (reg_val
) = regnum
;
426 VALUE_OPTIMIZED_OUT (reg_val
) = optim
;
430 /* Given a pointer of type TYPE in target form in BUF, return the
431 address it represents. */
433 unsigned_pointer_to_address (struct type
*type
, void *buf
)
435 return extract_address (buf
, TYPE_LENGTH (type
));
439 signed_pointer_to_address (struct type
*type
, void *buf
)
441 return extract_signed_integer (buf
, TYPE_LENGTH (type
));
444 /* Given an address, store it as a pointer of type TYPE in target
447 unsigned_address_to_pointer (struct type
*type
, void *buf
, CORE_ADDR addr
)
449 store_address (buf
, TYPE_LENGTH (type
), addr
);
453 address_to_signed_pointer (struct type
*type
, void *buf
, CORE_ADDR addr
)
455 store_signed_integer (buf
, TYPE_LENGTH (type
), addr
);
458 /* Will calling read_var_value or locate_var_value on SYM end
459 up caring what frame it is being evaluated relative to? SYM must
462 symbol_read_needs_frame (struct symbol
*sym
)
464 switch (SYMBOL_CLASS (sym
))
466 /* All cases listed explicitly so that gcc -Wall will detect it if
467 we failed to consider one. */
472 case LOC_REGPARM_ADDR
:
476 case LOC_BASEREG_ARG
:
477 case LOC_THREAD_LOCAL_STATIC
:
487 /* Getting the address of a label can be done independently of the block,
488 even if some *uses* of that address wouldn't work so well without
492 case LOC_CONST_BYTES
:
494 case LOC_OPTIMIZED_OUT
:
500 /* Given a struct symbol for a variable,
501 and a stack frame id, read the value of the variable
502 and return a (pointer to a) struct value containing the value.
503 If the variable cannot be found, return a zero pointer.
504 If FRAME is NULL, use the selected_frame. */
507 read_var_value (register struct symbol
*var
, struct frame_info
*frame
)
509 register value_ptr v
;
510 struct type
*type
= SYMBOL_TYPE (var
);
514 v
= allocate_value (type
);
515 VALUE_LVAL (v
) = lval_memory
; /* The most likely possibility. */
516 VALUE_BFD_SECTION (v
) = SYMBOL_BFD_SECTION (var
);
518 len
= TYPE_LENGTH (type
);
521 frame
= selected_frame
;
523 switch (SYMBOL_CLASS (var
))
526 /* Put the constant back in target format. */
527 store_signed_integer (VALUE_CONTENTS_RAW (v
), len
,
528 (LONGEST
) SYMBOL_VALUE (var
));
529 VALUE_LVAL (v
) = not_lval
;
533 /* Put the constant back in target format. */
534 if (overlay_debugging
)
537 = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var
),
538 SYMBOL_BFD_SECTION (var
));
539 store_typed_address (VALUE_CONTENTS_RAW (v
), type
, addr
);
542 store_typed_address (VALUE_CONTENTS_RAW (v
), type
,
543 SYMBOL_VALUE_ADDRESS (var
));
544 VALUE_LVAL (v
) = not_lval
;
547 case LOC_CONST_BYTES
:
550 bytes_addr
= SYMBOL_VALUE_BYTES (var
);
551 memcpy (VALUE_CONTENTS_RAW (v
), bytes_addr
, len
);
552 VALUE_LVAL (v
) = not_lval
;
557 if (overlay_debugging
)
558 addr
= symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var
),
559 SYMBOL_BFD_SECTION (var
));
561 addr
= SYMBOL_VALUE_ADDRESS (var
);
565 /* The import slot does not have a real address in it from the
566 dynamic loader (dld.sl on HP-UX), if the target hasn't begun
567 execution yet, so check for that. */
568 if (!target_has_execution
)
570 Attempt to access variable defined in different shared object or load module when\n\
571 addresses have not been bound by the dynamic loader. Try again when executable is running.");
573 addr
= SYMBOL_VALUE_ADDRESS (var
);
574 addr
= read_memory_unsigned_integer
575 (addr
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
581 addr
= FRAME_ARGS_ADDRESS (frame
);
584 addr
+= SYMBOL_VALUE (var
);
590 addr
= FRAME_ARGS_ADDRESS (frame
);
593 addr
+= SYMBOL_VALUE (var
);
594 addr
= read_memory_unsigned_integer
595 (addr
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
602 addr
= FRAME_LOCALS_ADDRESS (frame
);
603 addr
+= SYMBOL_VALUE (var
);
607 case LOC_BASEREG_ARG
:
609 char buf
[MAX_REGISTER_RAW_SIZE
];
610 get_saved_register (buf
, NULL
, NULL
, frame
, SYMBOL_BASEREG (var
),
612 addr
= extract_address (buf
, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var
)));
613 addr
+= SYMBOL_VALUE (var
);
617 case LOC_THREAD_LOCAL_STATIC
:
619 char buf
[MAX_REGISTER_RAW_SIZE
];
621 get_saved_register (buf
, NULL
, NULL
, frame
, SYMBOL_BASEREG (var
),
623 addr
= extract_address (buf
, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var
)));
624 addr
+= SYMBOL_VALUE (var
);
629 error ("Cannot look up value of a typedef");
633 if (overlay_debugging
)
634 VALUE_ADDRESS (v
) = symbol_overlayed_address
635 (BLOCK_START (SYMBOL_BLOCK_VALUE (var
)), SYMBOL_BFD_SECTION (var
));
637 VALUE_ADDRESS (v
) = BLOCK_START (SYMBOL_BLOCK_VALUE (var
));
642 case LOC_REGPARM_ADDR
:
645 int regno
= SYMBOL_VALUE (var
);
650 b
= get_frame_block (frame
);
652 if (SYMBOL_CLASS (var
) == LOC_REGPARM_ADDR
)
654 regval
= value_from_register (lookup_pointer_type (type
),
659 error ("Value of register variable not available.");
661 addr
= value_as_pointer (regval
);
662 VALUE_LVAL (v
) = lval_memory
;
666 regval
= value_from_register (type
, regno
, frame
);
669 error ("Value of register variable not available.");
677 struct minimal_symbol
*msym
;
679 msym
= lookup_minimal_symbol (SYMBOL_NAME (var
), NULL
, NULL
);
682 if (overlay_debugging
)
683 addr
= symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (msym
),
684 SYMBOL_BFD_SECTION (msym
));
686 addr
= SYMBOL_VALUE_ADDRESS (msym
);
690 case LOC_OPTIMIZED_OUT
:
691 VALUE_LVAL (v
) = not_lval
;
692 VALUE_OPTIMIZED_OUT (v
) = 1;
696 error ("Cannot look up value of a botched symbol.");
700 VALUE_ADDRESS (v
) = addr
;
705 /* Return a value of type TYPE, stored in register REGNUM, in frame
708 NOTE: returns NULL if register value is not available.
709 Caller will check return value or die! */
712 value_from_register (struct type
*type
, int regnum
, struct frame_info
*frame
)
714 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
717 value_ptr v
= allocate_value (type
);
718 char *value_bytes
= 0;
719 int value_bytes_copied
= 0;
720 int num_storage_locs
;
724 CHECK_TYPEDEF (type
);
725 len
= TYPE_LENGTH (type
);
727 /* Pointers on D10V are really only 16 bits,
728 but we lie to gdb elsewhere... */
729 if (GDB_TARGET_IS_D10V
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
732 VALUE_REGNO (v
) = regnum
;
734 num_storage_locs
= (len
> REGISTER_VIRTUAL_SIZE (regnum
) ?
735 ((len
- 1) / REGISTER_RAW_SIZE (regnum
)) + 1 :
738 if (num_storage_locs
> 1
739 #ifdef GDB_TARGET_IS_H8500
740 || TYPE_CODE (type
) == TYPE_CODE_PTR
744 /* Value spread across multiple storage locations. */
747 int mem_stor
= 0, reg_stor
= 0;
748 int mem_tracking
= 1;
749 CORE_ADDR last_addr
= 0;
750 CORE_ADDR first_addr
= 0;
752 value_bytes
= (char *) alloca (len
+ MAX_REGISTER_RAW_SIZE
);
754 /* Copy all of the data out, whereever it may be. */
756 #ifdef GDB_TARGET_IS_H8500
757 /* This piece of hideosity is required because the H8500 treats registers
758 differently depending upon whether they are used as pointers or not. As a
759 pointer, a register needs to have a page register tacked onto the front.
760 An alternate way to do this would be to have gcc output different register
761 numbers for the pointer & non-pointer form of the register. But, it
762 doesn't, so we're stuck with this. */
764 if (TYPE_CODE (type
) == TYPE_CODE_PTR
775 page_regnum
= SEG_D_REGNUM
;
779 page_regnum
= SEG_E_REGNUM
;
783 page_regnum
= SEG_T_REGNUM
;
788 get_saved_register (value_bytes
+ 1,
795 if (register_cached (page_regnum
) == -1)
796 return NULL
; /* register value not available */
798 if (lval
== lval_register
)
805 get_saved_register (value_bytes
+ 2,
812 if (register_cached (regnum
) == -1)
813 return NULL
; /* register value not available */
815 if (lval
== lval_register
)
820 mem_tracking
= mem_tracking
&& (addr
== last_addr
);
825 #endif /* GDB_TARGET_IS_H8500 */
826 for (local_regnum
= regnum
;
827 value_bytes_copied
< len
;
828 (value_bytes_copied
+= REGISTER_RAW_SIZE (local_regnum
),
831 get_saved_register (value_bytes
+ value_bytes_copied
,
838 if (register_cached (local_regnum
) == -1)
839 return NULL
; /* register value not available */
841 if (regnum
== local_regnum
)
843 if (lval
== lval_register
)
851 && (regnum
== local_regnum
852 || addr
== last_addr
));
857 if ((reg_stor
&& mem_stor
)
858 || (mem_stor
&& !mem_tracking
))
859 /* Mixed storage; all of the hassle we just went through was
860 for some good purpose. */
862 VALUE_LVAL (v
) = lval_reg_frame_relative
;
863 VALUE_FRAME (v
) = FRAME_FP (frame
);
864 VALUE_FRAME_REGNUM (v
) = regnum
;
868 VALUE_LVAL (v
) = lval_memory
;
869 VALUE_ADDRESS (v
) = first_addr
;
873 VALUE_LVAL (v
) = lval_register
;
874 VALUE_ADDRESS (v
) = first_addr
;
877 internal_error ("value_from_register: Value not stored anywhere!");
879 VALUE_OPTIMIZED_OUT (v
) = optim
;
881 /* Any structure stored in more than one register will always be
882 an integral number of registers. Otherwise, you'd need to do
883 some fiddling with the last register copied here for little
886 /* Copy into the contents section of the value. */
887 memcpy (VALUE_CONTENTS_RAW (v
), value_bytes
, len
);
889 /* Finally do any conversion necessary when extracting this
890 type from more than one register. */
891 #ifdef REGISTER_CONVERT_TO_TYPE
892 REGISTER_CONVERT_TO_TYPE (regnum
, type
, VALUE_CONTENTS_RAW (v
));
897 /* Data is completely contained within a single register. Locate the
898 register's contents in a real register or in core;
899 read the data in raw format. */
901 get_saved_register (raw_buffer
, &optim
, &addr
, frame
, regnum
, &lval
);
903 if (register_cached (regnum
) == -1)
904 return NULL
; /* register value not available */
906 VALUE_OPTIMIZED_OUT (v
) = optim
;
907 VALUE_LVAL (v
) = lval
;
908 VALUE_ADDRESS (v
) = addr
;
910 /* Convert raw data to virtual format if necessary. */
912 if (REGISTER_CONVERTIBLE (regnum
))
914 REGISTER_CONVERT_TO_VIRTUAL (regnum
, type
,
915 raw_buffer
, VALUE_CONTENTS_RAW (v
));
919 /* Raw and virtual formats are the same for this register. */
921 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
&& len
< REGISTER_RAW_SIZE (regnum
))
923 /* Big-endian, and we want less than full size. */
924 VALUE_OFFSET (v
) = REGISTER_RAW_SIZE (regnum
) - len
;
927 memcpy (VALUE_CONTENTS_RAW (v
), raw_buffer
+ VALUE_OFFSET (v
), len
);
930 if (GDB_TARGET_IS_D10V
931 && TYPE_CODE (type
) == TYPE_CODE_PTR
)
936 snum
= (unsigned short)
937 extract_unsigned_integer (VALUE_CONTENTS_RAW (v
), 2);
939 if (TYPE_TARGET_TYPE (type
) /* pointer to function */
940 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_FUNC
))
941 num
= D10V_MAKE_IADDR (snum
);
942 else /* pointer to data */
943 num
= D10V_MAKE_DADDR (snum
);
945 store_address (VALUE_CONTENTS_RAW (v
), 4, num
);
951 /* Given a struct symbol for a variable or function,
952 and a stack frame id,
953 return a (pointer to a) struct value containing the properly typed
957 locate_var_value (register struct symbol
*var
, struct frame_info
*frame
)
960 struct type
*type
= SYMBOL_TYPE (var
);
961 value_ptr lazy_value
;
963 /* Evaluate it first; if the result is a memory address, we're fine.
964 Lazy evaluation pays off here. */
966 lazy_value
= read_var_value (var
, frame
);
968 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var
));
970 if (VALUE_LAZY (lazy_value
)
971 || TYPE_CODE (type
) == TYPE_CODE_FUNC
)
975 addr
= VALUE_ADDRESS (lazy_value
);
976 val
= value_from_pointer (lookup_pointer_type (type
), addr
);
977 VALUE_BFD_SECTION (val
) = VALUE_BFD_SECTION (lazy_value
);
981 /* Not a memory address; check what the problem was. */
982 switch (VALUE_LVAL (lazy_value
))
985 case lval_reg_frame_relative
:
986 error ("Address requested for identifier \"%s\" which is in a register.",
987 SYMBOL_SOURCE_NAME (var
));
991 error ("Can't take address of \"%s\" which isn't an lvalue.",
992 SYMBOL_SOURCE_NAME (var
));
995 return 0; /* For lint -- never reached */