* gch981.{ch,exp}, gch1041.{ch,exp}: New test cases.
[deliverable/binutils-gdb.git] / gdb / findvar.c
CommitLineData
bd5635a1 1/* Find a variable's value in memory, for GDB, the GNU debugger.
b52cac6b 2 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996 Free Software Foundation, Inc.
bd5635a1
RP
3
4This file is part of GDB.
5
36b9d39c 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
36b9d39c
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
36b9d39c 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
36b9d39c 17along with this program; if not, write to the Free Software
aa220473 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
bd5635a1 19
bd5635a1 20#include "defs.h"
bd5635a1 21#include "symtab.h"
51b57ded 22#include "gdbtypes.h"
bd5635a1
RP
23#include "frame.h"
24#include "value.h"
25#include "gdbcore.h"
26#include "inferior.h"
27#include "target.h"
2b576293
C
28#include "gdb_string.h"
29
30/* Registers we shouldn't try to store. */
31#if !defined (CANNOT_STORE_REGISTER)
32#define CANNOT_STORE_REGISTER(regno) 0
33#endif
bd5635a1 34
326ae3e2
KH
35static void write_register_pid PARAMS ((int regno, LONGEST val, int pid));
36
ade40d31
RP
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. */
39
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... */
45 you lose
46#endif
47
48LONGEST
49extract_signed_integer (addr, len)
50 PTR addr;
51 int len;
52{
53 LONGEST retval;
54 unsigned char *p;
55 unsigned char *startaddr = (unsigned char *)addr;
56 unsigned char *endaddr = startaddr + len;
57
b52cac6b 58 if (len > (int) sizeof (LONGEST))
ade40d31
RP
59 error ("\
60That operation is not available on integers of more than %d bytes.",
61 sizeof (LONGEST));
62
63 /* Start at the most significant end of the integer, and work towards
64 the least significant. */
326ae3e2 65 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
ade40d31 66 {
326ae3e2
KH
67 p = startaddr;
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;
72 }
73 else
74 {
75 p = endaddr - 1;
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;
ade40d31
RP
80 }
81 return retval;
82}
83
84unsigned LONGEST
85extract_unsigned_integer (addr, len)
86 PTR addr;
87 int len;
88{
89 unsigned LONGEST retval;
90 unsigned char *p;
91 unsigned char *startaddr = (unsigned char *)addr;
92 unsigned char *endaddr = startaddr + len;
93
b52cac6b 94 if (len > (int) sizeof (unsigned LONGEST))
ade40d31
RP
95 error ("\
96That operation is not available on integers of more than %d bytes.",
97 sizeof (unsigned LONGEST));
98
99 /* Start at the most significant end of the integer, and work towards
100 the least significant. */
101 retval = 0;
326ae3e2 102 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
ade40d31 103 {
326ae3e2
KH
104 for (p = startaddr; p < endaddr; ++p)
105 retval = (retval << 8) | *p;
106 }
107 else
108 {
109 for (p = endaddr - 1; p >= startaddr; --p)
110 retval = (retval << 8) | *p;
ade40d31
RP
111 }
112 return retval;
113}
114
b52cac6b
FF
115/* Sometimes a long long unsigned integer can be extracted as a
116 LONGEST value. This is done so that we can print these values
117 better. If this integer can be converted to a LONGEST, this
118 function returns 1 and sets *PVAL. Otherwise it returns 0. */
119
120int
121extract_long_unsigned_integer (addr, orig_len, pval)
122 PTR addr;
123 int orig_len;
124 LONGEST *pval;
125{
126 char *p, *first_addr;
127 int len;
128
129 len = orig_len;
130 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
131 {
132 for (p = (char *) addr;
133 len > (int) sizeof (LONGEST) && p < (char *) addr + orig_len;
134 p++)
135 {
136 if (*p == 0)
137 len--;
138 else
139 break;
140 }
141 first_addr = p;
142 }
143 else
144 {
145 first_addr = (char *) addr;
146 for (p = (char *) addr + orig_len - 1;
147 len > (int) sizeof (LONGEST) && p >= (char *) addr;
148 p--)
149 {
150 if (*p == 0)
151 len--;
152 else
153 break;
154 }
155 }
156
157 if (len <= (int) sizeof (LONGEST))
158 {
159 *pval = (LONGEST) extract_unsigned_integer (first_addr,
160 sizeof (LONGEST));
161 return 1;
162 }
163
164 return 0;
165}
166
ade40d31
RP
167CORE_ADDR
168extract_address (addr, len)
169 PTR addr;
170 int len;
171{
172 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
173 whether we want this to be true eventually. */
174 return extract_unsigned_integer (addr, len);
175}
176
177void
178store_signed_integer (addr, len, val)
179 PTR addr;
180 int len;
181 LONGEST val;
182{
183 unsigned char *p;
184 unsigned char *startaddr = (unsigned char *)addr;
185 unsigned char *endaddr = startaddr + len;
186
187 /* Start at the least significant end of the integer, and work towards
188 the most significant. */
326ae3e2 189 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
ade40d31 190 {
326ae3e2
KH
191 for (p = endaddr - 1; p >= startaddr; --p)
192 {
193 *p = val & 0xff;
194 val >>= 8;
195 }
196 }
197 else
198 {
199 for (p = startaddr; p < endaddr; ++p)
200 {
201 *p = val & 0xff;
202 val >>= 8;
203 }
ade40d31
RP
204 }
205}
206
207void
208store_unsigned_integer (addr, len, val)
209 PTR addr;
210 int len;
211 unsigned LONGEST val;
212{
213 unsigned char *p;
214 unsigned char *startaddr = (unsigned char *)addr;
215 unsigned char *endaddr = startaddr + len;
216
217 /* Start at the least significant end of the integer, and work towards
218 the most significant. */
326ae3e2 219 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
ade40d31 220 {
326ae3e2
KH
221 for (p = endaddr - 1; p >= startaddr; --p)
222 {
223 *p = val & 0xff;
224 val >>= 8;
225 }
226 }
227 else
228 {
229 for (p = startaddr; p < endaddr; ++p)
230 {
231 *p = val & 0xff;
232 val >>= 8;
233 }
ade40d31
RP
234 }
235}
236
237void
238store_address (addr, len, val)
239 PTR addr;
240 int len;
241 CORE_ADDR val;
242{
243 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
244 whether we want this to be true eventually. */
245 store_unsigned_integer (addr, len, (LONGEST)val);
246}
247\f
bc28e68d
JK
248/* Swap LEN bytes at BUFFER between target and host byte-order. */
249#define SWAP_FLOATING(buffer,len) \
250 do \
251 { \
252 if (TARGET_BYTE_ORDER != HOST_BYTE_ORDER) \
253 { \
254 char tmp; \
255 char *p = (char *)(buffer); \
256 char *q = ((char *)(buffer)) + len - 1; \
257 for (; p < q; p++, q--) \
258 { \
259 tmp = *q; \
260 *q = *p; \
261 *p = tmp; \
262 } \
263 } \
264 } \
265 while (0)
326ae3e2 266
bc28e68d
JK
267/* There are various problems with the extract_floating and store_floating
268 routines.
ad09cb2b
PS
269
270 1. These routines only handle byte-swapping, not conversion of
271 formats. So if host is IEEE floating and target is VAX floating,
272 or vice-versa, it loses. This means that we can't (yet) use these
273 routines for extendeds. Extendeds are handled by
48792545
JK
274 REGISTER_CONVERTIBLE. What we want is to use floatformat.h, but that
275 doesn't yet handle VAX floating at all.
ad09cb2b
PS
276
277 2. We can't deal with it if there is more than one floating point
278 format in use. This has to be fixed at the unpack_double level.
279
280 3. We probably should have a LONGEST_DOUBLE or DOUBLEST or whatever
281 we want to call it which is long double where available. */
282
aa220473 283DOUBLEST
ad09cb2b
PS
284extract_floating (addr, len)
285 PTR addr;
286 int len;
287{
288 if (len == sizeof (float))
289 {
290 float retval;
291 memcpy (&retval, addr, sizeof (retval));
bc28e68d 292 SWAP_FLOATING (&retval, sizeof (retval));
ad09cb2b
PS
293 return retval;
294 }
295 else if (len == sizeof (double))
296 {
297 double retval;
298 memcpy (&retval, addr, sizeof (retval));
bc28e68d 299 SWAP_FLOATING (&retval, sizeof (retval));
ad09cb2b
PS
300 return retval;
301 }
b52cac6b 302 else if (len == sizeof (DOUBLEST))
aa220473 303 {
b52cac6b 304 DOUBLEST retval;
aa220473
SG
305 memcpy (&retval, addr, sizeof (retval));
306 SWAP_FLOATING (&retval, sizeof (retval));
307 return retval;
308 }
ad09cb2b
PS
309 else
310 {
311 error ("Can't deal with a floating point number of %d bytes.", len);
312 }
313}
314
315void
316store_floating (addr, len, val)
317 PTR addr;
318 int len;
aa220473 319 DOUBLEST val;
ad09cb2b
PS
320{
321 if (len == sizeof (float))
322 {
323 float floatval = val;
bc28e68d 324 SWAP_FLOATING (&floatval, sizeof (floatval));
ad09cb2b
PS
325 memcpy (addr, &floatval, sizeof (floatval));
326 }
327 else if (len == sizeof (double))
aa220473
SG
328 {
329 double doubleval = val;
330
331 SWAP_FLOATING (&doubleval, sizeof (doubleval));
332 memcpy (addr, &doubleval, sizeof (doubleval));
333 }
b52cac6b 334 else if (len == sizeof (DOUBLEST))
ad09cb2b 335 {
bc28e68d 336 SWAP_FLOATING (&val, sizeof (val));
ad09cb2b
PS
337 memcpy (addr, &val, sizeof (val));
338 }
339 else
340 {
341 error ("Can't deal with a floating point number of %d bytes.", len);
342 }
343}
344\f
bd5635a1
RP
345#if !defined (GET_SAVED_REGISTER)
346
347/* Return the address in which frame FRAME's value of register REGNUM
348 has been saved in memory. Or return zero if it has not been saved.
349 If REGNUM specifies the SP, the value we return is actually
350 the SP value, not an address where it was saved. */
351
352CORE_ADDR
353find_saved_register (frame, regnum)
326ae3e2 354 struct frame_info *frame;
bd5635a1
RP
355 int regnum;
356{
bd5635a1
RP
357 struct frame_saved_regs saved_regs;
358
326ae3e2 359 register struct frame_info *frame1 = NULL;
bd5635a1
RP
360 register CORE_ADDR addr = 0;
361
326ae3e2 362 if (frame == NULL) /* No regs saved if want current frame */
bd5635a1
RP
363 return 0;
364
365#ifdef HAVE_REGISTER_WINDOWS
366 /* We assume that a register in a register window will only be saved
367 in one place (since the name changes and/or disappears as you go
368 towards inner frames), so we only call get_frame_saved_regs on
369 the current frame. This is directly in contradiction to the
370 usage below, which assumes that registers used in a frame must be
371 saved in a lower (more interior) frame. This change is a result
372 of working on a register window machine; get_frame_saved_regs
373 always returns the registers saved within a frame, within the
374 context (register namespace) of that frame. */
375
376 /* However, note that we don't want this to return anything if
377 nothing is saved (if there's a frame inside of this one). Also,
378 callers to this routine asking for the stack pointer want the
379 stack pointer saved for *this* frame; this is returned from the
380 next frame. */
381
bd5635a1
RP
382 if (REGISTER_IN_WINDOW_P(regnum))
383 {
384 frame1 = get_next_frame (frame);
326ae3e2 385 if (!frame1) return 0; /* Registers of this frame are active. */
bd5635a1
RP
386
387 /* Get the SP from the next frame in; it will be this
388 current frame. */
389 if (regnum != SP_REGNUM)
390 frame1 = frame;
391
326ae3e2 392 get_frame_saved_regs (frame1, &saved_regs);
bd5635a1
RP
393 return saved_regs.regs[regnum]; /* ... which might be zero */
394 }
395#endif /* HAVE_REGISTER_WINDOWS */
396
397 /* Note that this next routine assumes that registers used in
398 frame x will be saved only in the frame that x calls and
399 frames interior to it. This is not true on the sparc, but the
400 above macro takes care of it, so we should be all right. */
401 while (1)
402 {
403 QUIT;
404 frame1 = get_prev_frame (frame1);
405 if (frame1 == 0 || frame1 == frame)
406 break;
326ae3e2 407 get_frame_saved_regs (frame1, &saved_regs);
bd5635a1
RP
408 if (saved_regs.regs[regnum])
409 addr = saved_regs.regs[regnum];
410 }
411
412 return addr;
413}
414
4d50f90a
JK
415/* Find register number REGNUM relative to FRAME and put its (raw,
416 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
417 variable was optimized out (and thus can't be fetched). Set *LVAL
418 to lval_memory, lval_register, or not_lval, depending on whether
419 the value was fetched from memory, from a register, or in a strange
bd5635a1
RP
420 and non-modifiable way (e.g. a frame pointer which was calculated
421 rather than fetched). Set *ADDRP to the address, either in memory
422 on as a REGISTER_BYTE offset into the registers array.
423
424 Note that this implementation never sets *LVAL to not_lval. But
425 it can be replaced by defining GET_SAVED_REGISTER and supplying
426 your own.
427
428 The argument RAW_BUFFER must point to aligned memory. */
4d50f90a 429
bd5635a1
RP
430void
431get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
432 char *raw_buffer;
433 int *optimized;
434 CORE_ADDR *addrp;
326ae3e2 435 struct frame_info *frame;
bd5635a1
RP
436 int regnum;
437 enum lval_type *lval;
438{
439 CORE_ADDR addr;
326ae3e2
KH
440
441 if (!target_has_registers)
442 error ("No registers.");
443
bd5635a1
RP
444 /* Normal systems don't optimize out things with register numbers. */
445 if (optimized != NULL)
446 *optimized = 0;
447 addr = find_saved_register (frame, regnum);
51b57ded 448 if (addr != 0)
bd5635a1
RP
449 {
450 if (lval != NULL)
451 *lval = lval_memory;
452 if (regnum == SP_REGNUM)
453 {
454 if (raw_buffer != NULL)
4d50f90a 455 {
ade40d31
RP
456 /* Put it back in target format. */
457 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), addr);
4d50f90a 458 }
bd5635a1
RP
459 if (addrp != NULL)
460 *addrp = 0;
461 return;
462 }
463 if (raw_buffer != NULL)
464 read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
465 }
466 else
467 {
468 if (lval != NULL)
469 *lval = lval_register;
470 addr = REGISTER_BYTE (regnum);
471 if (raw_buffer != NULL)
472 read_register_gen (regnum, raw_buffer);
473 }
474 if (addrp != NULL)
475 *addrp = addr;
476}
477#endif /* GET_SAVED_REGISTER. */
478
479/* Copy the bytes of register REGNUM, relative to the current stack frame,
480 into our memory at MYADDR, in target byte order.
481 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
482
483 Returns 1 if could not be read, 0 if could. */
484
485int
486read_relative_register_raw_bytes (regnum, myaddr)
487 int regnum;
488 char *myaddr;
489{
490 int optim;
491 if (regnum == FP_REGNUM && selected_frame)
492 {
ade40d31
RP
493 /* Put it back in target format. */
494 store_address (myaddr, REGISTER_RAW_SIZE(FP_REGNUM),
495 FRAME_FP(selected_frame));
bd5635a1
RP
496 return 0;
497 }
498
e1ce8aa5 499 get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, selected_frame,
bd5635a1
RP
500 regnum, (enum lval_type *)NULL);
501 return optim;
502}
503
504/* Return a `value' with the contents of register REGNUM
505 in its virtual format, with the type specified by
506 REGISTER_VIRTUAL_TYPE. */
507
326ae3e2 508value_ptr
bd5635a1
RP
509value_of_register (regnum)
510 int regnum;
511{
512 CORE_ADDR addr;
513 int optim;
326ae3e2 514 register value_ptr reg_val;
bd5635a1 515 char raw_buffer[MAX_REGISTER_RAW_SIZE];
bd5635a1
RP
516 enum lval_type lval;
517
518 get_saved_register (raw_buffer, &optim, &addr,
519 selected_frame, regnum, &lval);
520
48792545 521 reg_val = allocate_value (REGISTER_VIRTUAL_TYPE (regnum));
ad09cb2b
PS
522
523 /* Convert raw data to virtual format if necessary. */
524
525#ifdef REGISTER_CONVERTIBLE
526 if (REGISTER_CONVERTIBLE (regnum))
527 {
528 REGISTER_CONVERT_TO_VIRTUAL (regnum, REGISTER_VIRTUAL_TYPE (regnum),
48792545 529 raw_buffer, VALUE_CONTENTS_RAW (reg_val));
ad09cb2b
PS
530 }
531 else
532#endif
48792545 533 memcpy (VALUE_CONTENTS_RAW (reg_val), raw_buffer,
ad09cb2b 534 REGISTER_RAW_SIZE (regnum));
48792545
JK
535 VALUE_LVAL (reg_val) = lval;
536 VALUE_ADDRESS (reg_val) = addr;
537 VALUE_REGNO (reg_val) = regnum;
538 VALUE_OPTIMIZED_OUT (reg_val) = optim;
539 return reg_val;
bd5635a1
RP
540}
541\f
542/* Low level examining and depositing of registers.
543
544 The caller is responsible for making
545 sure that the inferior is stopped before calling the fetching routines,
546 or it will get garbage. (a change from GDB version 3, in which
547 the caller got the value from the last stop). */
548
549/* Contents of the registers in target byte order.
ade40d31 550 We allocate some extra slop since we do a lot of memcpy's around `registers',
bd5635a1
RP
551 and failing-soft is better than failing hard. */
552char registers[REGISTER_BYTES + /* SLOP */ 256];
553
554/* Nonzero if that register has been fetched. */
555char register_valid[NUM_REGS];
556
326ae3e2
KH
557/* The thread/process associated with the current set of registers. For now,
558 -1 is special, and means `no current process'. */
559int registers_pid = -1;
560
bd5635a1 561/* Indicate that registers may have changed, so invalidate the cache. */
326ae3e2 562
bd5635a1
RP
563void
564registers_changed ()
565{
566 int i;
326ae3e2
KH
567 int numregs = ARCH_NUM_REGS;
568
569 registers_pid = -1;
570
571 for (i = 0; i < numregs; i++)
bd5635a1 572 register_valid[i] = 0;
2b576293
C
573
574 if (registers_changed_hook)
575 registers_changed_hook ();
bd5635a1
RP
576}
577
578/* Indicate that all registers have been fetched, so mark them all valid. */
579void
580registers_fetched ()
581{
582 int i;
326ae3e2
KH
583 int numregs = ARCH_NUM_REGS;
584 for (i = 0; i < numregs; i++)
bd5635a1
RP
585 register_valid[i] = 1;
586}
587
2b576293
C
588/* read_register_bytes and write_register_bytes are generally a *BAD* idea.
589 They are inefficient because they need to check for partial updates, which
590 can only be done by scanning through all of the registers and seeing if the
591 bytes that are being read/written fall inside of an invalid register. [The
592 main reason this is necessary is that register sizes can vary, so a simple
593 index won't suffice.] It is far better to call read_register_gen if you
594 want to get at the raw register contents, as it only takes a regno as an
595 argument, and therefore can't do a partial register update. It would also
596 be good to have a write_register_gen for similar reasons.
597
598 Prior to the recent fixes to check for partial updates, both read and
599 write_register_bytes always checked to see if any registers were stale, and
600 then called target_fetch_registers (-1) to update the whole set. This
601 caused really slowed things down for remote targets. */
602
603/* Copy INLEN bytes of consecutive data from registers
604 starting with the INREGBYTE'th byte of register data
bd5635a1
RP
605 into memory at MYADDR. */
606
607void
2b576293
C
608read_register_bytes (inregbyte, myaddr, inlen)
609 int inregbyte;
bd5635a1 610 char *myaddr;
2b576293 611 int inlen;
bd5635a1 612{
2b576293
C
613 int inregend = inregbyte + inlen;
614 int regno;
326ae3e2
KH
615
616 if (registers_pid != inferior_pid)
617 {
618 registers_changed ();
619 registers_pid = inferior_pid;
620 }
621
2b576293
C
622 /* See if we are trying to read bytes from out-of-date registers. If so,
623 update just those registers. */
624
625 for (regno = 0; regno < NUM_REGS; regno++)
626 {
627 int regstart, regend;
628 int startin, endin;
629
630 if (register_valid[regno])
631 continue;
632
633 regstart = REGISTER_BYTE (regno);
634 regend = regstart + REGISTER_RAW_SIZE (regno);
635
636 startin = regstart >= inregbyte && regstart < inregend;
637 endin = regend > inregbyte && regend <= inregend;
638
639 if (!startin && !endin)
640 continue;
641
642 /* We've found an invalid register where at least one byte will be read.
643 Update it from the target. */
644
645 target_fetch_registers (regno);
646
647 if (!register_valid[regno])
648 error ("read_register_bytes: Couldn't update register %d.", regno);
649 }
650
bd5635a1 651 if (myaddr != NULL)
2b576293 652 memcpy (myaddr, &registers[inregbyte], inlen);
bd5635a1
RP
653}
654
655/* Read register REGNO into memory at MYADDR, which must be large enough
f2ebc25f
JK
656 for REGISTER_RAW_BYTES (REGNO). Target byte-order.
657 If the register is known to be the size of a CORE_ADDR or smaller,
658 read_register can be used instead. */
bd5635a1
RP
659void
660read_register_gen (regno, myaddr)
661 int regno;
662 char *myaddr;
663{
326ae3e2
KH
664 if (registers_pid != inferior_pid)
665 {
666 registers_changed ();
667 registers_pid = inferior_pid;
668 }
669
bd5635a1
RP
670 if (!register_valid[regno])
671 target_fetch_registers (regno);
0791c5ea
JK
672 memcpy (myaddr, &registers[REGISTER_BYTE (regno)],
673 REGISTER_RAW_SIZE (regno));
bd5635a1
RP
674}
675
2b576293
C
676/* Write register REGNO at MYADDR to the target. MYADDR points at
677 REGISTER_RAW_BYTES(REGNO), which must be in target byte-order. */
bd5635a1
RP
678
679void
2b576293
C
680write_register_gen (regno, myaddr)
681 int regno;
bd5635a1 682 char *myaddr;
bd5635a1 683{
2b576293
C
684 int size;
685
686 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
687 the registers array if something writes to this register. */
688 if (CANNOT_STORE_REGISTER (regno))
689 return;
690
326ae3e2
KH
691 if (registers_pid != inferior_pid)
692 {
693 registers_changed ();
694 registers_pid = inferior_pid;
695 }
696
2b576293
C
697 size = REGISTER_RAW_SIZE(regno);
698
699 /* If we have a valid copy of the register, and new value == old value,
700 then don't bother doing the actual store. */
701
702 if (register_valid [regno]
703 && memcmp (&registers[REGISTER_BYTE (regno)], myaddr, size) == 0)
704 return;
705
706 target_prepare_to_store ();
707
708 memcpy (&registers[REGISTER_BYTE (regno)], myaddr, size);
709
710 register_valid [regno] = 1;
711
712 target_store_registers (regno);
713}
714
715/* Copy INLEN bytes of consecutive data from memory at MYADDR
716 into registers starting with the MYREGSTART'th byte of register data. */
717
718void
719write_register_bytes (myregstart, myaddr, inlen)
720 int myregstart;
721 char *myaddr;
722 int inlen;
723{
724 int myregend = myregstart + inlen;
725 int regno;
726
727 target_prepare_to_store ();
728
729 /* Scan through the registers updating any that are covered by the range
730 myregstart<=>myregend using write_register_gen, which does nice things
731 like handling threads, and avoiding updates when the new and old contents
732 are the same. */
733
734 for (regno = 0; regno < NUM_REGS; regno++)
735 {
736 int regstart, regend;
737 int startin, endin;
738 char regbuf[MAX_REGISTER_RAW_SIZE];
739
740 regstart = REGISTER_BYTE (regno);
741 regend = regstart + REGISTER_RAW_SIZE (regno);
742
743 startin = regstart >= myregstart && regstart < myregend;
744 endin = regend > myregstart && regend <= myregend;
745
746 if (!startin && !endin)
747 continue; /* Register is completely out of range */
748
749 if (startin && endin) /* register is completely in range */
750 {
751 write_register_gen (regno, myaddr + (regstart - myregstart));
752 continue;
753 }
754
755 /* We may be doing a partial update of an invalid register. Update it
756 from the target before scribbling on it. */
757 read_register_gen (regno, regbuf);
758
759 if (startin)
760 memcpy (registers + regstart,
761 myaddr + regstart - myregstart,
762 myregend - regstart);
763 else /* endin */
764 memcpy (registers + myregstart,
765 myaddr,
766 regend - myregstart);
767 target_store_registers (regno);
768 }
bd5635a1
RP
769}
770
ade40d31
RP
771/* Return the raw contents of register REGNO, regarding it as an integer. */
772/* This probably should be returning LONGEST rather than CORE_ADDR. */
bd5635a1
RP
773
774CORE_ADDR
775read_register (regno)
776 int regno;
777{
326ae3e2
KH
778 if (registers_pid != inferior_pid)
779 {
780 registers_changed ();
781 registers_pid = inferior_pid;
782 }
783
bd5635a1
RP
784 if (!register_valid[regno])
785 target_fetch_registers (regno);
0791c5ea 786
ade40d31
RP
787 return extract_address (&registers[REGISTER_BYTE (regno)],
788 REGISTER_RAW_SIZE(regno));
bd5635a1
RP
789}
790
326ae3e2
KH
791CORE_ADDR
792read_register_pid (regno, pid)
793 int regno, pid;
794{
795 int save_pid;
796 CORE_ADDR retval;
797
798 if (pid == inferior_pid)
799 return read_register (regno);
800
801 save_pid = inferior_pid;
802
803 inferior_pid = pid;
804
805 retval = read_register (regno);
806
807 inferior_pid = save_pid;
808
809 return retval;
810}
811
ade40d31 812/* Store VALUE, into the raw contents of register number REGNO. */
bd5635a1
RP
813
814void
815write_register (regno, val)
5573d7d4 816 int regno;
443abae1 817 LONGEST val;
bd5635a1 818{
ade40d31 819 PTR buf;
df14b38b 820 int size;
ade40d31 821
bd5635a1
RP
822 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
823 the registers array if something writes to this register. */
824 if (CANNOT_STORE_REGISTER (regno))
825 return;
826
326ae3e2
KH
827 if (registers_pid != inferior_pid)
828 {
829 registers_changed ();
830 registers_pid = inferior_pid;
831 }
832
ade40d31
RP
833 size = REGISTER_RAW_SIZE(regno);
834 buf = alloca (size);
835 store_signed_integer (buf, size, (LONGEST) val);
836
df14b38b
SC
837 /* If we have a valid copy of the register, and new value == old value,
838 then don't bother doing the actual store. */
bd5635a1 839
326ae3e2
KH
840 if (register_valid [regno]
841 && memcmp (&registers[REGISTER_BYTE (regno)], buf, size) == 0)
842 return;
df14b38b
SC
843
844 target_prepare_to_store ();
845
ade40d31 846 memcpy (&registers[REGISTER_BYTE (regno)], buf, size);
df14b38b
SC
847
848 register_valid [regno] = 1;
bd5635a1
RP
849
850 target_store_registers (regno);
851}
852
326ae3e2
KH
853static void
854write_register_pid (regno, val, pid)
855 int regno;
856 LONGEST val;
857 int pid;
858{
859 int save_pid;
860
861 if (pid == inferior_pid)
862 {
863 write_register (regno, val);
864 return;
865 }
866
867 save_pid = inferior_pid;
868
869 inferior_pid = pid;
870
871 write_register (regno, val);
872
873 inferior_pid = save_pid;
874}
875
bd5635a1
RP
876/* Record that register REGNO contains VAL.
877 This is used when the value is obtained from the inferior or core dump,
878 so there is no need to store the value there. */
879
880void
881supply_register (regno, val)
882 int regno;
883 char *val;
884{
326ae3e2
KH
885 if (registers_pid != inferior_pid)
886 {
887 registers_changed ();
888 registers_pid = inferior_pid;
889 }
890
bd5635a1 891 register_valid[regno] = 1;
0791c5ea
JK
892 memcpy (&registers[REGISTER_BYTE (regno)], val, REGISTER_RAW_SIZE (regno));
893
894 /* On some architectures, e.g. HPPA, there are a few stray bits in some
895 registers, that the rest of the code would like to ignore. */
896#ifdef CLEAN_UP_REGISTER_VALUE
897 CLEAN_UP_REGISTER_VALUE(regno, &registers[REGISTER_BYTE(regno)]);
898#endif
bd5635a1 899}
326ae3e2
KH
900
901
902/* This routine is getting awfully cluttered with #if's. It's probably
903 time to turn this into READ_PC and define it in the tm.h file.
904 Ditto for write_pc. */
905
906CORE_ADDR
907read_pc ()
908{
909#ifdef TARGET_READ_PC
910 return TARGET_READ_PC (inferior_pid);
911#else
912 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, inferior_pid));
913#endif
914}
915
916CORE_ADDR
917read_pc_pid (pid)
918 int pid;
919{
920#ifdef TARGET_READ_PC
921 return TARGET_READ_PC (pid);
922#else
923 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, pid));
924#endif
925}
926
927void
928write_pc (val)
929 CORE_ADDR val;
930{
931#ifdef TARGET_WRITE_PC
932 TARGET_WRITE_PC (val, inferior_pid);
933#else
934 write_register_pid (PC_REGNUM, val, inferior_pid);
935#ifdef NPC_REGNUM
936 write_register_pid (NPC_REGNUM, val + 4, inferior_pid);
937#ifdef NNPC_REGNUM
938 write_register_pid (NNPC_REGNUM, val + 8, inferior_pid);
939#endif
940#endif
941#endif
942}
943
944void
945write_pc_pid (val, pid)
946 CORE_ADDR val;
947 int pid;
948{
949#ifdef TARGET_WRITE_PC
950 TARGET_WRITE_PC (val, pid);
951#else
952 write_register_pid (PC_REGNUM, val, pid);
953#ifdef NPC_REGNUM
954 write_register_pid (NPC_REGNUM, val + 4, pid);
955#ifdef NNPC_REGNUM
956 write_register_pid (NNPC_REGNUM, val + 8, pid);
957#endif
958#endif
959#endif
960}
961
962/* Cope with strage ways of getting to the stack and frame pointers */
963
964CORE_ADDR
965read_sp ()
966{
967#ifdef TARGET_READ_SP
968 return TARGET_READ_SP ();
969#else
970 return read_register (SP_REGNUM);
971#endif
972}
973
974void
975write_sp (val)
976 CORE_ADDR val;
977{
978#ifdef TARGET_WRITE_SP
979 TARGET_WRITE_SP (val);
980#else
981 write_register (SP_REGNUM, val);
982#endif
983}
984
985CORE_ADDR
986read_fp ()
987{
988#ifdef TARGET_READ_FP
989 return TARGET_READ_FP ();
990#else
991 return read_register (FP_REGNUM);
992#endif
993}
994
995void
996write_fp (val)
997 CORE_ADDR val;
998{
999#ifdef TARGET_WRITE_FP
1000 TARGET_WRITE_FP (val);
1001#else
1002 write_register (FP_REGNUM, val);
1003#endif
1004}
bd5635a1 1005\f
443abae1
JK
1006/* Will calling read_var_value or locate_var_value on SYM end
1007 up caring what frame it is being evaluated relative to? SYM must
1008 be non-NULL. */
1009int
1010symbol_read_needs_frame (sym)
1011 struct symbol *sym;
1012{
1013 switch (SYMBOL_CLASS (sym))
1014 {
1015 /* All cases listed explicitly so that gcc -Wall will detect it if
1016 we failed to consider one. */
1017 case LOC_REGISTER:
1018 case LOC_ARG:
1019 case LOC_REF_ARG:
1020 case LOC_REGPARM:
1021 case LOC_REGPARM_ADDR:
1022 case LOC_LOCAL:
1023 case LOC_LOCAL_ARG:
1024 case LOC_BASEREG:
1025 case LOC_BASEREG_ARG:
1026 return 1;
1027
1028 case LOC_UNDEF:
1029 case LOC_CONST:
1030 case LOC_STATIC:
1031 case LOC_TYPEDEF:
1032
1033 case LOC_LABEL:
1034 /* Getting the address of a label can be done independently of the block,
1035 even if some *uses* of that address wouldn't work so well without
1036 the right frame. */
1037
1038 case LOC_BLOCK:
1039 case LOC_CONST_BYTES:
aa220473 1040 case LOC_UNRESOLVED:
443abae1
JK
1041 case LOC_OPTIMIZED_OUT:
1042 return 0;
1043 }
100f92e2 1044 return 1;
443abae1
JK
1045}
1046
bd5635a1
RP
1047/* Given a struct symbol for a variable,
1048 and a stack frame id, read the value of the variable
1049 and return a (pointer to a) struct value containing the value.
777bef06
JK
1050 If the variable cannot be found, return a zero pointer.
1051 If FRAME is NULL, use the selected_frame. */
bd5635a1 1052
326ae3e2 1053value_ptr
bd5635a1
RP
1054read_var_value (var, frame)
1055 register struct symbol *var;
326ae3e2 1056 struct frame_info *frame;
bd5635a1 1057{
326ae3e2 1058 register value_ptr v;
bd5635a1
RP
1059 struct type *type = SYMBOL_TYPE (var);
1060 CORE_ADDR addr;
bd5635a1
RP
1061 register int len;
1062
1063 v = allocate_value (type);
1064 VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
1065 len = TYPE_LENGTH (type);
1066
326ae3e2 1067 if (frame == NULL) frame = selected_frame;
bd5635a1
RP
1068
1069 switch (SYMBOL_CLASS (var))
1070 {
1071 case LOC_CONST:
ade40d31
RP
1072 /* Put the constant back in target format. */
1073 store_signed_integer (VALUE_CONTENTS_RAW (v), len,
1074 (LONGEST) SYMBOL_VALUE (var));
bd5635a1
RP
1075 VALUE_LVAL (v) = not_lval;
1076 return v;
1077
1078 case LOC_LABEL:
ade40d31
RP
1079 /* Put the constant back in target format. */
1080 store_address (VALUE_CONTENTS_RAW (v), len, SYMBOL_VALUE_ADDRESS (var));
bd5635a1
RP
1081 VALUE_LVAL (v) = not_lval;
1082 return v;
1083
1084 case LOC_CONST_BYTES:
36b9d39c
JG
1085 {
1086 char *bytes_addr;
1087 bytes_addr = SYMBOL_VALUE_BYTES (var);
0791c5ea 1088 memcpy (VALUE_CONTENTS_RAW (v), bytes_addr, len);
36b9d39c
JG
1089 VALUE_LVAL (v) = not_lval;
1090 return v;
1091 }
bd5635a1
RP
1092
1093 case LOC_STATIC:
bd5635a1
RP
1094 addr = SYMBOL_VALUE_ADDRESS (var);
1095 break;
1096
bd5635a1 1097 case LOC_ARG:
326ae3e2 1098 if (frame == NULL)
ade40d31 1099 return 0;
326ae3e2 1100 addr = FRAME_ARGS_ADDRESS (frame);
51b57ded 1101 if (!addr)
326ae3e2 1102 return 0;
bd5635a1
RP
1103 addr += SYMBOL_VALUE (var);
1104 break;
ade40d31 1105
bd5635a1 1106 case LOC_REF_ARG:
326ae3e2 1107 if (frame == NULL)
ade40d31 1108 return 0;
326ae3e2 1109 addr = FRAME_ARGS_ADDRESS (frame);
51b57ded 1110 if (!addr)
326ae3e2 1111 return 0;
bd5635a1 1112 addr += SYMBOL_VALUE (var);
ade40d31
RP
1113 addr = read_memory_unsigned_integer
1114 (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
bd5635a1 1115 break;
ade40d31 1116
bd5635a1
RP
1117 case LOC_LOCAL:
1118 case LOC_LOCAL_ARG:
326ae3e2 1119 if (frame == NULL)
ade40d31 1120 return 0;
326ae3e2 1121 addr = FRAME_LOCALS_ADDRESS (frame);
51b57ded 1122 addr += SYMBOL_VALUE (var);
bd5635a1
RP
1123 break;
1124
ade40d31
RP
1125 case LOC_BASEREG:
1126 case LOC_BASEREG_ARG:
1127 {
1128 char buf[MAX_REGISTER_RAW_SIZE];
1129 get_saved_register (buf, NULL, NULL, frame, SYMBOL_BASEREG (var),
1130 NULL);
1131 addr = extract_address (buf, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var)));
1132 addr += SYMBOL_VALUE (var);
1133 break;
1134 }
1135
bd5635a1
RP
1136 case LOC_TYPEDEF:
1137 error ("Cannot look up value of a typedef");
1138 break;
1139
1140 case LOC_BLOCK:
1141 VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
1142 return v;
1143
1144 case LOC_REGISTER:
1145 case LOC_REGPARM:
35247ccd 1146 case LOC_REGPARM_ADDR:
bd5635a1 1147 {
777bef06 1148 struct block *b;
bd5635a1 1149
777bef06
JK
1150 if (frame == NULL)
1151 return 0;
1152 b = get_frame_block (frame);
1153
bd5635a1 1154
35247ccd 1155 if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
0791c5ea 1156 {
326ae3e2
KH
1157 addr =
1158 value_as_pointer (value_from_register (lookup_pointer_type (type),
1159 SYMBOL_VALUE (var),
1160 frame));
0791c5ea
JK
1161 VALUE_LVAL (v) = lval_memory;
1162 }
bd5635a1 1163 else
326ae3e2 1164 return value_from_register (type, SYMBOL_VALUE (var), frame);
bd5635a1
RP
1165 }
1166 break;
1167
aa220473
SG
1168 case LOC_UNRESOLVED:
1169 {
1170 struct minimal_symbol *msym;
1171
1172 msym = lookup_minimal_symbol (SYMBOL_NAME (var), NULL, NULL);
1173 if (msym == NULL)
1174 return 0;
1175 addr = SYMBOL_VALUE_ADDRESS (msym);
1176 }
1177 break;
1178
35247ccd
SG
1179 case LOC_OPTIMIZED_OUT:
1180 VALUE_LVAL (v) = not_lval;
1181 VALUE_OPTIMIZED_OUT (v) = 1;
1182 return v;
1183
bd5635a1
RP
1184 default:
1185 error ("Cannot look up value of a botched symbol.");
1186 break;
1187 }
1188
1189 VALUE_ADDRESS (v) = addr;
1190 VALUE_LAZY (v) = 1;
1191 return v;
1192}
1193
1194/* Return a value of type TYPE, stored in register REGNUM, in frame
1195 FRAME. */
1196
326ae3e2 1197value_ptr
bd5635a1
RP
1198value_from_register (type, regnum, frame)
1199 struct type *type;
1200 int regnum;
326ae3e2 1201 struct frame_info *frame;
bd5635a1
RP
1202{
1203 char raw_buffer [MAX_REGISTER_RAW_SIZE];
bd5635a1
RP
1204 CORE_ADDR addr;
1205 int optim;
326ae3e2 1206 value_ptr v = allocate_value (type);
bd5635a1
RP
1207 char *value_bytes = 0;
1208 int value_bytes_copied = 0;
1209 int num_storage_locs;
1210 enum lval_type lval;
aa220473
SG
1211 int len;
1212
1213 CHECK_TYPEDEF (type);
1214 len = TYPE_LENGTH (type);
bd5635a1
RP
1215
1216 VALUE_REGNO (v) = regnum;
1217
1218 num_storage_locs = (len > REGISTER_VIRTUAL_SIZE (regnum) ?
1219 ((len - 1) / REGISTER_RAW_SIZE (regnum)) + 1 :
1220 1);
1221
0791c5ea
JK
1222 if (num_storage_locs > 1
1223#ifdef GDB_TARGET_IS_H8500
1224 || TYPE_CODE (type) == TYPE_CODE_PTR
1225#endif
1226 )
bd5635a1
RP
1227 {
1228 /* Value spread across multiple storage locations. */
1229
1230 int local_regnum;
1231 int mem_stor = 0, reg_stor = 0;
1232 int mem_tracking = 1;
1233 CORE_ADDR last_addr = 0;
5573d7d4 1234 CORE_ADDR first_addr = 0;
bd5635a1
RP
1235
1236 value_bytes = (char *) alloca (len + MAX_REGISTER_RAW_SIZE);
1237
1238 /* Copy all of the data out, whereever it may be. */
1239
0791c5ea
JK
1240#ifdef GDB_TARGET_IS_H8500
1241/* This piece of hideosity is required because the H8500 treats registers
1242 differently depending upon whether they are used as pointers or not. As a
1243 pointer, a register needs to have a page register tacked onto the front.
1244 An alternate way to do this would be to have gcc output different register
1245 numbers for the pointer & non-pointer form of the register. But, it
1246 doesn't, so we're stuck with this. */
1247
35247ccd
SG
1248 if (TYPE_CODE (type) == TYPE_CODE_PTR
1249 && len > 2)
bd5635a1 1250 {
0791c5ea
JK
1251 int page_regnum;
1252
1253 switch (regnum)
1254 {
1255 case R0_REGNUM: case R1_REGNUM: case R2_REGNUM: case R3_REGNUM:
1256 page_regnum = SEG_D_REGNUM;
1257 break;
1258 case R4_REGNUM: case R5_REGNUM:
1259 page_regnum = SEG_E_REGNUM;
1260 break;
1261 case R6_REGNUM: case R7_REGNUM:
1262 page_regnum = SEG_T_REGNUM;
1263 break;
1264 }
1265
1266 value_bytes[0] = 0;
1267 get_saved_register (value_bytes + 1,
bd5635a1
RP
1268 &optim,
1269 &addr,
1270 frame,
0791c5ea 1271 page_regnum,
bd5635a1 1272 &lval);
0791c5ea 1273
bd5635a1
RP
1274 if (lval == lval_register)
1275 reg_stor++;
1276 else
df14b38b
SC
1277 mem_stor++;
1278 first_addr = addr;
0791c5ea 1279 last_addr = addr;
bd5635a1 1280
0791c5ea
JK
1281 get_saved_register (value_bytes + 2,
1282 &optim,
1283 &addr,
1284 frame,
1285 regnum,
1286 &lval);
1287
1288 if (lval == lval_register)
1289 reg_stor++;
1290 else
1291 {
1292 mem_stor++;
1293 mem_tracking = mem_tracking && (addr == last_addr);
bd5635a1
RP
1294 }
1295 last_addr = addr;
1296 }
0791c5ea
JK
1297 else
1298#endif /* GDB_TARGET_IS_H8500 */
1299 for (local_regnum = regnum;
1300 value_bytes_copied < len;
1301 (value_bytes_copied += REGISTER_RAW_SIZE (local_regnum),
1302 ++local_regnum))
1303 {
1304 get_saved_register (value_bytes + value_bytes_copied,
1305 &optim,
1306 &addr,
1307 frame,
1308 local_regnum,
1309 &lval);
df14b38b
SC
1310
1311 if (regnum == local_regnum)
1312 first_addr = addr;
0791c5ea
JK
1313 if (lval == lval_register)
1314 reg_stor++;
1315 else
1316 {
1317 mem_stor++;
0791c5ea
JK
1318
1319 mem_tracking =
1320 (mem_tracking
1321 && (regnum == local_regnum
1322 || addr == last_addr));
1323 }
1324 last_addr = addr;
1325 }
bd5635a1
RP
1326
1327 if ((reg_stor && mem_stor)
1328 || (mem_stor && !mem_tracking))
1329 /* Mixed storage; all of the hassle we just went through was
1330 for some good purpose. */
1331 {
1332 VALUE_LVAL (v) = lval_reg_frame_relative;
1333 VALUE_FRAME (v) = FRAME_FP (frame);
1334 VALUE_FRAME_REGNUM (v) = regnum;
1335 }
1336 else if (mem_stor)
1337 {
1338 VALUE_LVAL (v) = lval_memory;
1339 VALUE_ADDRESS (v) = first_addr;
1340 }
1341 else if (reg_stor)
1342 {
1343 VALUE_LVAL (v) = lval_register;
1344 VALUE_ADDRESS (v) = first_addr;
1345 }
1346 else
1347 fatal ("value_from_register: Value not stored anywhere!");
1348
1349 VALUE_OPTIMIZED_OUT (v) = optim;
1350
1351 /* Any structure stored in more than one register will always be
1352 an integral number of registers. Otherwise, you'd need to do
1353 some fiddling with the last register copied here for little
1354 endian machines. */
1355
1356 /* Copy into the contents section of the value. */
0791c5ea 1357 memcpy (VALUE_CONTENTS_RAW (v), value_bytes, len);
bd5635a1 1358
df14b38b
SC
1359 /* Finally do any conversion necessary when extracting this
1360 type from more than one register. */
1361#ifdef REGISTER_CONVERT_TO_TYPE
1362 REGISTER_CONVERT_TO_TYPE(regnum, type, VALUE_CONTENTS_RAW(v));
1363#endif
bd5635a1
RP
1364 return v;
1365 }
1366
1367 /* Data is completely contained within a single register. Locate the
1368 register's contents in a real register or in core;
1369 read the data in raw format. */
1370
1371 get_saved_register (raw_buffer, &optim, &addr, frame, regnum, &lval);
1372 VALUE_OPTIMIZED_OUT (v) = optim;
1373 VALUE_LVAL (v) = lval;
1374 VALUE_ADDRESS (v) = addr;
ad09cb2b
PS
1375
1376 /* Convert raw data to virtual format if necessary. */
bd5635a1 1377
ad09cb2b 1378#ifdef REGISTER_CONVERTIBLE
bd5635a1
RP
1379 if (REGISTER_CONVERTIBLE (regnum))
1380 {
ad09cb2b
PS
1381 REGISTER_CONVERT_TO_VIRTUAL (regnum, type,
1382 raw_buffer, VALUE_CONTENTS_RAW (v));
bd5635a1
RP
1383 }
1384 else
ad09cb2b 1385#endif
bd5635a1
RP
1386 {
1387 /* Raw and virtual formats are the same for this register. */
1388
326ae3e2 1389 if (TARGET_BYTE_ORDER == BIG_ENDIAN && len < REGISTER_RAW_SIZE (regnum))
bd5635a1
RP
1390 {
1391 /* Big-endian, and we want less than full size. */
1392 VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len;
1393 }
bd5635a1 1394
ad09cb2b 1395 memcpy (VALUE_CONTENTS_RAW (v), raw_buffer + VALUE_OFFSET (v), len);
bd5635a1
RP
1396 }
1397
1398 return v;
1399}
1400\f
36b9d39c 1401/* Given a struct symbol for a variable or function,
bd5635a1 1402 and a stack frame id,
36b9d39c
JG
1403 return a (pointer to a) struct value containing the properly typed
1404 address. */
bd5635a1 1405
326ae3e2 1406value_ptr
bd5635a1
RP
1407locate_var_value (var, frame)
1408 register struct symbol *var;
326ae3e2 1409 struct frame_info *frame;
bd5635a1
RP
1410{
1411 CORE_ADDR addr = 0;
1412 struct type *type = SYMBOL_TYPE (var);
326ae3e2 1413 value_ptr lazy_value;
bd5635a1
RP
1414
1415 /* Evaluate it first; if the result is a memory address, we're fine.
1416 Lazy evaluation pays off here. */
1417
1418 lazy_value = read_var_value (var, frame);
1419 if (lazy_value == 0)
0791c5ea 1420 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
bd5635a1 1421
36b9d39c
JG
1422 if (VALUE_LAZY (lazy_value)
1423 || TYPE_CODE (type) == TYPE_CODE_FUNC)
bd5635a1
RP
1424 {
1425 addr = VALUE_ADDRESS (lazy_value);
7d9884b9 1426 return value_from_longest (lookup_pointer_type (type), (LONGEST) addr);
bd5635a1
RP
1427 }
1428
1429 /* Not a memory address; check what the problem was. */
1430 switch (VALUE_LVAL (lazy_value))
1431 {
1432 case lval_register:
1433 case lval_reg_frame_relative:
1434 error ("Address requested for identifier \"%s\" which is in a register.",
0791c5ea 1435 SYMBOL_SOURCE_NAME (var));
bd5635a1
RP
1436 break;
1437
1438 default:
1439 error ("Can't take address of \"%s\" which isn't an lvalue.",
0791c5ea 1440 SYMBOL_SOURCE_NAME (var));
bd5635a1
RP
1441 break;
1442 }
1443 return 0; /* For lint -- never reached */
1444}
This page took 0.280346 seconds and 4 git commands to generate.