* hppa-tdep.c (pc_in_linker_stub): New function.
[deliverable/binutils-gdb.git] / gdb / findvar.c
1 /* Find a variable's value in memory, for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "frame.h"
24 #include "value.h"
25 #include "gdbcore.h"
26 #include "inferior.h"
27 #include "target.h"
28
29 #if !defined (GET_SAVED_REGISTER)
30
31 /* Return the address in which frame FRAME's value of register REGNUM
32 has been saved in memory. Or return zero if it has not been saved.
33 If REGNUM specifies the SP, the value we return is actually
34 the SP value, not an address where it was saved. */
35
36 CORE_ADDR
37 find_saved_register (frame, regnum)
38 FRAME frame;
39 int regnum;
40 {
41 struct frame_info *fi;
42 struct frame_saved_regs saved_regs;
43
44 register FRAME frame1 = 0;
45 register CORE_ADDR addr = 0;
46
47 if (frame == 0) /* No regs saved if want current frame */
48 return 0;
49
50 #ifdef HAVE_REGISTER_WINDOWS
51 /* We assume that a register in a register window will only be saved
52 in one place (since the name changes and/or disappears as you go
53 towards inner frames), so we only call get_frame_saved_regs on
54 the current frame. This is directly in contradiction to the
55 usage below, which assumes that registers used in a frame must be
56 saved in a lower (more interior) frame. This change is a result
57 of working on a register window machine; get_frame_saved_regs
58 always returns the registers saved within a frame, within the
59 context (register namespace) of that frame. */
60
61 /* However, note that we don't want this to return anything if
62 nothing is saved (if there's a frame inside of this one). Also,
63 callers to this routine asking for the stack pointer want the
64 stack pointer saved for *this* frame; this is returned from the
65 next frame. */
66
67
68 if (REGISTER_IN_WINDOW_P(regnum))
69 {
70 frame1 = get_next_frame (frame);
71 if (!frame1) return 0; /* Registers of this frame are
72 active. */
73
74 /* Get the SP from the next frame in; it will be this
75 current frame. */
76 if (regnum != SP_REGNUM)
77 frame1 = frame;
78
79 fi = get_frame_info (frame1);
80 get_frame_saved_regs (fi, &saved_regs);
81 return saved_regs.regs[regnum]; /* ... which might be zero */
82 }
83 #endif /* HAVE_REGISTER_WINDOWS */
84
85 /* Note that this next routine assumes that registers used in
86 frame x will be saved only in the frame that x calls and
87 frames interior to it. This is not true on the sparc, but the
88 above macro takes care of it, so we should be all right. */
89 while (1)
90 {
91 QUIT;
92 frame1 = get_prev_frame (frame1);
93 if (frame1 == 0 || frame1 == frame)
94 break;
95 fi = get_frame_info (frame1);
96 get_frame_saved_regs (fi, &saved_regs);
97 if (saved_regs.regs[regnum])
98 addr = saved_regs.regs[regnum];
99 }
100
101 return addr;
102 }
103
104 /* Find register number REGNUM relative to FRAME and put its (raw,
105 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
106 variable was optimized out (and thus can't be fetched). Set *LVAL
107 to lval_memory, lval_register, or not_lval, depending on whether
108 the value was fetched from memory, from a register, or in a strange
109 and non-modifiable way (e.g. a frame pointer which was calculated
110 rather than fetched). Set *ADDRP to the address, either in memory
111 on as a REGISTER_BYTE offset into the registers array.
112
113 Note that this implementation never sets *LVAL to not_lval. But
114 it can be replaced by defining GET_SAVED_REGISTER and supplying
115 your own.
116
117 The argument RAW_BUFFER must point to aligned memory. */
118
119 void
120 get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
121 char *raw_buffer;
122 int *optimized;
123 CORE_ADDR *addrp;
124 FRAME frame;
125 int regnum;
126 enum lval_type *lval;
127 {
128 CORE_ADDR addr;
129 /* Normal systems don't optimize out things with register numbers. */
130 if (optimized != NULL)
131 *optimized = 0;
132 addr = find_saved_register (frame, regnum);
133 if (addr != 0)
134 {
135 if (lval != NULL)
136 *lval = lval_memory;
137 if (regnum == SP_REGNUM)
138 {
139 if (raw_buffer != NULL)
140 {
141 *(CORE_ADDR *)raw_buffer = addr;
142 /* Put it back in target byte order. */
143 SWAP_TARGET_AND_HOST (raw_buffer, sizeof (CORE_ADDR));
144 }
145 if (addrp != NULL)
146 *addrp = 0;
147 return;
148 }
149 if (raw_buffer != NULL)
150 read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
151 }
152 else
153 {
154 if (lval != NULL)
155 *lval = lval_register;
156 addr = REGISTER_BYTE (regnum);
157 if (raw_buffer != NULL)
158 read_register_gen (regnum, raw_buffer);
159 }
160 if (addrp != NULL)
161 *addrp = addr;
162 }
163 #endif /* GET_SAVED_REGISTER. */
164
165 /* Copy the bytes of register REGNUM, relative to the current stack frame,
166 into our memory at MYADDR, in target byte order.
167 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
168
169 Returns 1 if could not be read, 0 if could. */
170
171 int
172 read_relative_register_raw_bytes (regnum, myaddr)
173 int regnum;
174 char *myaddr;
175 {
176 int optim;
177 if (regnum == FP_REGNUM && selected_frame)
178 {
179 memcpy (myaddr, &FRAME_FP(selected_frame), REGISTER_RAW_SIZE(FP_REGNUM));
180 SWAP_TARGET_AND_HOST (myaddr, REGISTER_RAW_SIZE(FP_REGNUM)); /* in target order */
181 return 0;
182 }
183
184 get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, selected_frame,
185 regnum, (enum lval_type *)NULL);
186 return optim;
187 }
188
189 /* Return a `value' with the contents of register REGNUM
190 in its virtual format, with the type specified by
191 REGISTER_VIRTUAL_TYPE. */
192
193 value
194 value_of_register (regnum)
195 int regnum;
196 {
197 CORE_ADDR addr;
198 int optim;
199 register value val;
200 char raw_buffer[MAX_REGISTER_RAW_SIZE];
201 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
202 enum lval_type lval;
203
204 get_saved_register (raw_buffer, &optim, &addr,
205 selected_frame, regnum, &lval);
206
207 REGISTER_CONVERT_TO_VIRTUAL (regnum, raw_buffer, virtual_buffer);
208 val = allocate_value (REGISTER_VIRTUAL_TYPE (regnum));
209 memcpy (VALUE_CONTENTS_RAW (val), virtual_buffer,
210 REGISTER_VIRTUAL_SIZE (regnum));
211 VALUE_LVAL (val) = lval;
212 VALUE_ADDRESS (val) = addr;
213 VALUE_REGNO (val) = regnum;
214 VALUE_OPTIMIZED_OUT (val) = optim;
215 return val;
216 }
217 \f
218 /* Low level examining and depositing of registers.
219
220 The caller is responsible for making
221 sure that the inferior is stopped before calling the fetching routines,
222 or it will get garbage. (a change from GDB version 3, in which
223 the caller got the value from the last stop). */
224
225 /* Contents of the registers in target byte order.
226 We allocate some extra slop since we do a lot of bcopy's around `registers',
227 and failing-soft is better than failing hard. */
228 char registers[REGISTER_BYTES + /* SLOP */ 256];
229
230 /* Nonzero if that register has been fetched. */
231 char register_valid[NUM_REGS];
232
233 /* Indicate that registers may have changed, so invalidate the cache. */
234 void
235 registers_changed ()
236 {
237 int i;
238 for (i = 0; i < NUM_REGS; i++)
239 register_valid[i] = 0;
240 }
241
242 /* Indicate that all registers have been fetched, so mark them all valid. */
243 void
244 registers_fetched ()
245 {
246 int i;
247 for (i = 0; i < NUM_REGS; i++)
248 register_valid[i] = 1;
249 }
250
251 /* Copy LEN bytes of consecutive data from registers
252 starting with the REGBYTE'th byte of register data
253 into memory at MYADDR. */
254
255 void
256 read_register_bytes (regbyte, myaddr, len)
257 int regbyte;
258 char *myaddr;
259 int len;
260 {
261 /* Fetch all registers. */
262 int i;
263 for (i = 0; i < NUM_REGS; i++)
264 if (!register_valid[i])
265 {
266 target_fetch_registers (-1);
267 break;
268 }
269 if (myaddr != NULL)
270 memcpy (myaddr, &registers[regbyte], len);
271 }
272
273 /* Read register REGNO into memory at MYADDR, which must be large enough
274 for REGISTER_RAW_BYTES (REGNO). Target byte-order.
275 If the register is known to be the size of a CORE_ADDR or smaller,
276 read_register can be used instead. */
277 void
278 read_register_gen (regno, myaddr)
279 int regno;
280 char *myaddr;
281 {
282 if (!register_valid[regno])
283 target_fetch_registers (regno);
284 memcpy (myaddr, &registers[REGISTER_BYTE (regno)],
285 REGISTER_RAW_SIZE (regno));
286 }
287
288 /* Copy LEN bytes of consecutive data from memory at MYADDR
289 into registers starting with the REGBYTE'th byte of register data. */
290
291 void
292 write_register_bytes (regbyte, myaddr, len)
293 int regbyte;
294 char *myaddr;
295 int len;
296 {
297 /* Make sure the entire registers array is valid. */
298 read_register_bytes (0, (char *)NULL, REGISTER_BYTES);
299 memcpy (&registers[regbyte], myaddr, len);
300 target_store_registers (-1);
301 }
302
303 /* Return the contents of register REGNO, regarding it as an integer. */
304 /* FIXME, this loses when the REGISTER_VIRTUAL (REGNO) is true. Also,
305 why is the return type CORE_ADDR rather than some integer type? */
306
307 CORE_ADDR
308 read_register (regno)
309 int regno;
310 {
311 unsigned short sval;
312 unsigned int ival;
313 unsigned long lval;
314 LONGEST llval;
315
316 int size;
317
318 if (!register_valid[regno])
319 target_fetch_registers (regno);
320
321 size = REGISTER_RAW_SIZE(regno);
322
323 if (size == sizeof (unsigned char))
324 return registers[REGISTER_BYTE (regno)];
325 else if (size == sizeof (sval))
326 {
327 memcpy (&sval, &registers[REGISTER_BYTE (regno)], sizeof (sval));
328 SWAP_TARGET_AND_HOST (&sval, sizeof (sval));
329 return sval;
330 }
331 else if (size == sizeof (ival))
332 {
333 memcpy (&ival, &registers[REGISTER_BYTE (regno)], sizeof (ival));
334 SWAP_TARGET_AND_HOST (&ival, sizeof (ival));
335 return ival;
336 }
337 else if (size == sizeof (lval))
338 {
339 memcpy (&lval, &registers[REGISTER_BYTE (regno)], sizeof (lval));
340 SWAP_TARGET_AND_HOST (&lval, sizeof (lval));
341 return lval;
342 }
343 else if (size == sizeof (llval))
344 {
345 memcpy (&llval, &registers[REGISTER_BYTE (regno)], sizeof (llval));
346 SWAP_TARGET_AND_HOST (&llval, sizeof (llval));
347 return llval;
348 }
349 else
350 {
351 error ("GDB Internal Error in read_register() for register %d, size %d",
352 regno, REGISTER_RAW_SIZE(regno));
353 }
354 }
355
356 /* Registers we shouldn't try to store. */
357 #if !defined (CANNOT_STORE_REGISTER)
358 #define CANNOT_STORE_REGISTER(regno) 0
359 #endif
360
361 /* Store VALUE in the register number REGNO, regarded as an integer. */
362 /* FIXME, this loses when REGISTER_VIRTUAL (REGNO) is true. Also,
363 shouldn't the val arg be a LONGEST or something? */
364
365 void
366 write_register (regno, val)
367 int regno, val;
368 {
369 unsigned char cval;
370 unsigned short sval;
371 unsigned int ival;
372 unsigned long lval;
373 LONGEST llval;
374 int size;
375 PTR ptr;
376
377 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
378 the registers array if something writes to this register. */
379 if (CANNOT_STORE_REGISTER (regno))
380 return;
381
382 /* If we have a valid copy of the register, and new value == old value,
383 then don't bother doing the actual store. */
384
385 size = REGISTER_RAW_SIZE(regno);
386
387 if (size == sizeof(cval))
388 {
389 ptr = (PTR) &cval;
390 cval = val;
391 }
392 else if (size == sizeof(sval))
393 {
394 ptr = (PTR) &sval;
395 sval = val;
396 }
397 else if (size == sizeof(ival))
398 {
399 ptr = (PTR) &ival;
400 ival = val;
401 }
402 else if (size == sizeof(lval))
403 {
404 ptr = (PTR) &lval;
405 lval = val;
406 }
407 else if (size == sizeof(llval))
408 {
409 ptr = (PTR) &llval;
410 llval = val;
411 }
412 else
413 {
414 error ("GDB Internal Error in write_register() for register %d, size %d",
415 regno, size);
416 }
417
418 SWAP_TARGET_AND_HOST (ptr, size);
419 if (register_valid [regno])
420 {
421 if (memcmp (&registers[REGISTER_BYTE (regno)],
422 ptr, size) == 0)
423 return;
424 }
425
426 target_prepare_to_store ();
427
428 memcpy (&registers[REGISTER_BYTE (regno)], ptr, size);
429
430 register_valid [regno] = 1;
431
432 target_store_registers (regno);
433 }
434
435 /* Record that register REGNO contains VAL.
436 This is used when the value is obtained from the inferior or core dump,
437 so there is no need to store the value there. */
438
439 void
440 supply_register (regno, val)
441 int regno;
442 char *val;
443 {
444 register_valid[regno] = 1;
445 memcpy (&registers[REGISTER_BYTE (regno)], val, REGISTER_RAW_SIZE (regno));
446
447 /* On some architectures, e.g. HPPA, there are a few stray bits in some
448 registers, that the rest of the code would like to ignore. */
449 #ifdef CLEAN_UP_REGISTER_VALUE
450 CLEAN_UP_REGISTER_VALUE(regno, &registers[REGISTER_BYTE(regno)]);
451 #endif
452 }
453 \f
454 /* Given a struct symbol for a variable,
455 and a stack frame id, read the value of the variable
456 and return a (pointer to a) struct value containing the value.
457 If the variable cannot be found, return a zero pointer.
458 If FRAME is NULL, use the selected_frame. */
459
460 value
461 read_var_value (var, frame)
462 register struct symbol *var;
463 FRAME frame;
464 {
465 register value v;
466 struct frame_info *fi;
467 struct type *type = SYMBOL_TYPE (var);
468 CORE_ADDR addr;
469 register int len;
470
471 v = allocate_value (type);
472 VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
473 len = TYPE_LENGTH (type);
474
475 if (frame == 0) frame = selected_frame;
476
477 switch (SYMBOL_CLASS (var))
478 {
479 case LOC_CONST:
480 memcpy (VALUE_CONTENTS_RAW (v), &SYMBOL_VALUE (var), len);
481 SWAP_TARGET_AND_HOST (VALUE_CONTENTS_RAW (v), len);
482 VALUE_LVAL (v) = not_lval;
483 return v;
484
485 case LOC_LABEL:
486 addr = SYMBOL_VALUE_ADDRESS (var);
487 memcpy (VALUE_CONTENTS_RAW (v), &addr, len);
488 SWAP_TARGET_AND_HOST (VALUE_CONTENTS_RAW (v), len);
489 VALUE_LVAL (v) = not_lval;
490 return v;
491
492 case LOC_CONST_BYTES:
493 {
494 char *bytes_addr;
495 bytes_addr = SYMBOL_VALUE_BYTES (var);
496 memcpy (VALUE_CONTENTS_RAW (v), bytes_addr, len);
497 VALUE_LVAL (v) = not_lval;
498 return v;
499 }
500
501 case LOC_STATIC:
502 addr = SYMBOL_VALUE_ADDRESS (var);
503 break;
504
505 case LOC_ARG:
506 if (SYMBOL_BASEREG_VALID (var))
507 {
508 addr = FRAME_GET_BASEREG_VALUE (frame, SYMBOL_BASEREG (var));
509 }
510 else
511 {
512 fi = get_frame_info (frame);
513 if (fi == NULL)
514 return 0;
515 addr = FRAME_ARGS_ADDRESS (fi);
516 }
517 if (!addr)
518 {
519 return 0;
520 }
521 addr += SYMBOL_VALUE (var);
522 break;
523
524 case LOC_REF_ARG:
525 if (SYMBOL_BASEREG_VALID (var))
526 {
527 addr = FRAME_GET_BASEREG_VALUE (frame, SYMBOL_BASEREG (var));
528 }
529 else
530 {
531 fi = get_frame_info (frame);
532 if (fi == NULL)
533 return 0;
534 addr = FRAME_ARGS_ADDRESS (fi);
535 }
536 if (!addr)
537 {
538 return 0;
539 }
540 addr += SYMBOL_VALUE (var);
541 read_memory (addr, (char *) &addr, sizeof (CORE_ADDR));
542 break;
543
544 case LOC_LOCAL:
545 case LOC_LOCAL_ARG:
546 if (SYMBOL_BASEREG_VALID (var))
547 {
548 addr = FRAME_GET_BASEREG_VALUE (frame, SYMBOL_BASEREG (var));
549 }
550 else
551 {
552 fi = get_frame_info (frame);
553 if (fi == NULL)
554 return 0;
555 addr = FRAME_LOCALS_ADDRESS (fi);
556 }
557 addr += SYMBOL_VALUE (var);
558 break;
559
560 case LOC_TYPEDEF:
561 error ("Cannot look up value of a typedef");
562 break;
563
564 case LOC_BLOCK:
565 VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
566 return v;
567
568 case LOC_REGISTER:
569 case LOC_REGPARM:
570 case LOC_REGPARM_ADDR:
571 {
572 struct block *b;
573
574 if (frame == NULL)
575 return 0;
576 b = get_frame_block (frame);
577
578 v = value_from_register (type, SYMBOL_VALUE (var), frame);
579
580 if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
581 {
582 addr = *(CORE_ADDR *)VALUE_CONTENTS (v);
583 VALUE_LVAL (v) = lval_memory;
584 }
585 else
586 return v;
587 }
588 break;
589
590 case LOC_OPTIMIZED_OUT:
591 VALUE_LVAL (v) = not_lval;
592 VALUE_OPTIMIZED_OUT (v) = 1;
593 return v;
594
595 default:
596 error ("Cannot look up value of a botched symbol.");
597 break;
598 }
599
600 VALUE_ADDRESS (v) = addr;
601 VALUE_LAZY (v) = 1;
602 return v;
603 }
604
605 /* Return a value of type TYPE, stored in register REGNUM, in frame
606 FRAME. */
607
608 value
609 value_from_register (type, regnum, frame)
610 struct type *type;
611 int regnum;
612 FRAME frame;
613 {
614 char raw_buffer [MAX_REGISTER_RAW_SIZE];
615 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
616 CORE_ADDR addr;
617 int optim;
618 value v = allocate_value (type);
619 int len = TYPE_LENGTH (type);
620 char *value_bytes = 0;
621 int value_bytes_copied = 0;
622 int num_storage_locs;
623 enum lval_type lval;
624
625 VALUE_REGNO (v) = regnum;
626
627 num_storage_locs = (len > REGISTER_VIRTUAL_SIZE (regnum) ?
628 ((len - 1) / REGISTER_RAW_SIZE (regnum)) + 1 :
629 1);
630
631 if (num_storage_locs > 1
632 #ifdef GDB_TARGET_IS_H8500
633 || TYPE_CODE (type) == TYPE_CODE_PTR
634 #endif
635 )
636 {
637 /* Value spread across multiple storage locations. */
638
639 int local_regnum;
640 int mem_stor = 0, reg_stor = 0;
641 int mem_tracking = 1;
642 CORE_ADDR last_addr = 0;
643 CORE_ADDR first_addr;
644
645 value_bytes = (char *) alloca (len + MAX_REGISTER_RAW_SIZE);
646
647 /* Copy all of the data out, whereever it may be. */
648
649 #ifdef GDB_TARGET_IS_H8500
650 /* This piece of hideosity is required because the H8500 treats registers
651 differently depending upon whether they are used as pointers or not. As a
652 pointer, a register needs to have a page register tacked onto the front.
653 An alternate way to do this would be to have gcc output different register
654 numbers for the pointer & non-pointer form of the register. But, it
655 doesn't, so we're stuck with this. */
656
657 if (TYPE_CODE (type) == TYPE_CODE_PTR
658 && len > 2)
659 {
660 int page_regnum;
661
662 switch (regnum)
663 {
664 case R0_REGNUM: case R1_REGNUM: case R2_REGNUM: case R3_REGNUM:
665 page_regnum = SEG_D_REGNUM;
666 break;
667 case R4_REGNUM: case R5_REGNUM:
668 page_regnum = SEG_E_REGNUM;
669 break;
670 case R6_REGNUM: case R7_REGNUM:
671 page_regnum = SEG_T_REGNUM;
672 break;
673 }
674
675 value_bytes[0] = 0;
676 get_saved_register (value_bytes + 1,
677 &optim,
678 &addr,
679 frame,
680 page_regnum,
681 &lval);
682
683 if (lval == lval_register)
684 reg_stor++;
685 else
686 mem_stor++;
687 first_addr = addr;
688 last_addr = addr;
689
690 get_saved_register (value_bytes + 2,
691 &optim,
692 &addr,
693 frame,
694 regnum,
695 &lval);
696
697 if (lval == lval_register)
698 reg_stor++;
699 else
700 {
701 mem_stor++;
702 mem_tracking = mem_tracking && (addr == last_addr);
703 }
704 last_addr = addr;
705 }
706 else
707 #endif /* GDB_TARGET_IS_H8500 */
708 for (local_regnum = regnum;
709 value_bytes_copied < len;
710 (value_bytes_copied += REGISTER_RAW_SIZE (local_regnum),
711 ++local_regnum))
712 {
713 get_saved_register (value_bytes + value_bytes_copied,
714 &optim,
715 &addr,
716 frame,
717 local_regnum,
718 &lval);
719
720 if (regnum == local_regnum)
721 first_addr = addr;
722 if (lval == lval_register)
723 reg_stor++;
724 else
725 {
726 mem_stor++;
727
728 mem_tracking =
729 (mem_tracking
730 && (regnum == local_regnum
731 || addr == last_addr));
732 }
733 last_addr = addr;
734 }
735
736 if ((reg_stor && mem_stor)
737 || (mem_stor && !mem_tracking))
738 /* Mixed storage; all of the hassle we just went through was
739 for some good purpose. */
740 {
741 VALUE_LVAL (v) = lval_reg_frame_relative;
742 VALUE_FRAME (v) = FRAME_FP (frame);
743 VALUE_FRAME_REGNUM (v) = regnum;
744 }
745 else if (mem_stor)
746 {
747 VALUE_LVAL (v) = lval_memory;
748 VALUE_ADDRESS (v) = first_addr;
749 }
750 else if (reg_stor)
751 {
752 VALUE_LVAL (v) = lval_register;
753 VALUE_ADDRESS (v) = first_addr;
754 }
755 else
756 fatal ("value_from_register: Value not stored anywhere!");
757
758 VALUE_OPTIMIZED_OUT (v) = optim;
759
760 /* Any structure stored in more than one register will always be
761 an integral number of registers. Otherwise, you'd need to do
762 some fiddling with the last register copied here for little
763 endian machines. */
764
765 /* Copy into the contents section of the value. */
766 memcpy (VALUE_CONTENTS_RAW (v), value_bytes, len);
767
768 /* Finally do any conversion necessary when extracting this
769 type from more than one register. */
770 #ifdef REGISTER_CONVERT_TO_TYPE
771 REGISTER_CONVERT_TO_TYPE(regnum, type, VALUE_CONTENTS_RAW(v));
772 #endif
773 return v;
774 }
775
776 /* Data is completely contained within a single register. Locate the
777 register's contents in a real register or in core;
778 read the data in raw format. */
779
780 get_saved_register (raw_buffer, &optim, &addr, frame, regnum, &lval);
781 VALUE_OPTIMIZED_OUT (v) = optim;
782 VALUE_LVAL (v) = lval;
783 VALUE_ADDRESS (v) = addr;
784
785 /* Convert the raw contents to virtual contents.
786 (Just copy them if the formats are the same.) */
787
788 REGISTER_CONVERT_TO_VIRTUAL (regnum, raw_buffer, virtual_buffer);
789
790 if (REGISTER_CONVERTIBLE (regnum))
791 {
792 /* When the raw and virtual formats differ, the virtual format
793 corresponds to a specific data type. If we want that type,
794 copy the data into the value.
795 Otherwise, do a type-conversion. */
796
797 if (type != REGISTER_VIRTUAL_TYPE (regnum))
798 {
799 /* eg a variable of type `float' in a 68881 register
800 with raw type `extended' and virtual type `double'.
801 Fetch it as a `double' and then convert to `float'. */
802 v = allocate_value (REGISTER_VIRTUAL_TYPE (regnum));
803 memcpy (VALUE_CONTENTS_RAW (v), virtual_buffer, len);
804 v = value_cast (type, v);
805 }
806 else
807 memcpy (VALUE_CONTENTS_RAW (v), virtual_buffer, len);
808 }
809 else
810 {
811 /* Raw and virtual formats are the same for this register. */
812
813 #if TARGET_BYTE_ORDER == BIG_ENDIAN
814 if (len < REGISTER_RAW_SIZE (regnum))
815 {
816 /* Big-endian, and we want less than full size. */
817 VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len;
818 }
819 #endif
820
821 memcpy (VALUE_CONTENTS_RAW (v), virtual_buffer + VALUE_OFFSET (v), len);
822 }
823
824 return v;
825 }
826 \f
827 /* Given a struct symbol for a variable or function,
828 and a stack frame id,
829 return a (pointer to a) struct value containing the properly typed
830 address. */
831
832 value
833 locate_var_value (var, frame)
834 register struct symbol *var;
835 FRAME frame;
836 {
837 CORE_ADDR addr = 0;
838 struct type *type = SYMBOL_TYPE (var);
839 value lazy_value;
840
841 /* Evaluate it first; if the result is a memory address, we're fine.
842 Lazy evaluation pays off here. */
843
844 lazy_value = read_var_value (var, frame);
845 if (lazy_value == 0)
846 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
847
848 if (VALUE_LAZY (lazy_value)
849 || TYPE_CODE (type) == TYPE_CODE_FUNC)
850 {
851 addr = VALUE_ADDRESS (lazy_value);
852 return value_from_longest (lookup_pointer_type (type), (LONGEST) addr);
853 }
854
855 /* Not a memory address; check what the problem was. */
856 switch (VALUE_LVAL (lazy_value))
857 {
858 case lval_register:
859 case lval_reg_frame_relative:
860 error ("Address requested for identifier \"%s\" which is in a register.",
861 SYMBOL_SOURCE_NAME (var));
862 break;
863
864 default:
865 error ("Can't take address of \"%s\" which isn't an lvalue.",
866 SYMBOL_SOURCE_NAME (var));
867 break;
868 }
869 return 0; /* For lint -- never reached */
870 }
This page took 0.046625 seconds and 4 git commands to generate.