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, Boston, MA 02111-1307, USA. */
29 #include "gdb_string.h"
30 #include "floatformat.h"
31 #include "symfile.h" /* for overlay functions */
33 /* This is used to indicate that we don't know the format of the floating point
34 number. Typically, this is useful for native ports, where the actual format
35 is irrelevant, since no conversions will be taking place. */
37 const struct floatformat floatformat_unknown;
39 /* Registers we shouldn't try to store. */
40 #if !defined (CANNOT_STORE_REGISTER)
41 #define CANNOT_STORE_REGISTER(regno) 0
44 static void write_register_gen PARAMS ((int, char *));
46 /* Basic byte-swapping routines. GDB has needed these for a long time...
47 All extract a target-format integer at ADDR which is LEN bytes long. */
49 #if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8
50 /* 8 bit characters are a pretty safe assumption these days, so we
51 assume it throughout all these swapping routines. If we had to deal with
52 9 bit characters, we would need to make len be in bits and would have
53 to re-write these routines... */
58 extract_signed_integer (addr, len)
64 unsigned char *startaddr = (unsigned char *)addr;
65 unsigned char *endaddr = startaddr + len;
67 if (len > (int) sizeof (LONGEST))
69 That operation is not available on integers of more than %d bytes.",
72 /* Start at the most significant end of the integer, and work towards
73 the least significant. */
74 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
77 /* Do the sign extension once at the start. */
78 retval = ((LONGEST)*p ^ 0x80) - 0x80;
79 for (++p; p < endaddr; ++p)
80 retval = (retval << 8) | *p;
85 /* Do the sign extension once at the start. */
86 retval = ((LONGEST)*p ^ 0x80) - 0x80;
87 for (--p; p >= startaddr; --p)
88 retval = (retval << 8) | *p;
94 extract_unsigned_integer (addr, len)
100 unsigned char *startaddr = (unsigned char *)addr;
101 unsigned char *endaddr = startaddr + len;
103 if (len > (int) sizeof (ULONGEST))
105 That operation is not available on integers of more than %d bytes.",
108 /* Start at the most significant end of the integer, and work towards
109 the least significant. */
111 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
113 for (p = startaddr; p < endaddr; ++p)
114 retval = (retval << 8) | *p;
118 for (p = endaddr - 1; p >= startaddr; --p)
119 retval = (retval << 8) | *p;
124 /* Sometimes a long long unsigned integer can be extracted as a
125 LONGEST value. This is done so that we can print these values
126 better. If this integer can be converted to a LONGEST, this
127 function returns 1 and sets *PVAL. Otherwise it returns 0. */
130 extract_long_unsigned_integer (addr, orig_len, pval)
135 char *p, *first_addr;
139 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
141 for (p = (char *) addr;
142 len > (int) sizeof (LONGEST) && p < (char *) addr + orig_len;
154 first_addr = (char *) addr;
155 for (p = (char *) addr + orig_len - 1;
156 len > (int) sizeof (LONGEST) && p >= (char *) addr;
166 if (len <= (int) sizeof (LONGEST))
168 *pval = (LONGEST) extract_unsigned_integer (first_addr,
177 extract_address (addr, len)
181 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
182 whether we want this to be true eventually. */
183 return (CORE_ADDR)extract_unsigned_integer (addr, len);
187 store_signed_integer (addr, len, val)
193 unsigned char *startaddr = (unsigned char *)addr;
194 unsigned char *endaddr = startaddr + len;
196 /* Start at the least significant end of the integer, and work towards
197 the most significant. */
198 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
200 for (p = endaddr - 1; p >= startaddr; --p)
208 for (p = startaddr; p < endaddr; ++p)
217 store_unsigned_integer (addr, len, val)
223 unsigned char *startaddr = (unsigned char *)addr;
224 unsigned char *endaddr = startaddr + len;
226 /* Start at the least significant end of the integer, and work towards
227 the most significant. */
228 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
230 for (p = endaddr - 1; p >= startaddr; --p)
238 for (p = startaddr; p < endaddr; ++p)
246 /* Store the literal address "val" into
247 gdb-local memory pointed to by "addr"
250 store_address (addr, len, val)
255 if( TARGET_BYTE_ORDER == BIG_ENDIAN
256 && len != sizeof( LONGEST )) {
257 /* On big-endian machines (e.g., HPPA 2.0, narrow mode)
258 * just letting this fall through to the call below will
259 * lead to the wrong bits being stored.
261 * Only the simplest case is fixed here, the others just
262 * get the old behavior.
264 if( (len == sizeof( CORE_ADDR ))
265 && (sizeof( LONGEST ) == 2 * sizeof( CORE_ADDR ))) {
266 /* Watch out! The high bits are garbage! */
268 *(LONGEST*)&coerce = val;
270 store_unsigned_integer (addr, len, coerce[1] ); /* BIG_ENDIAN code! */
274 store_unsigned_integer (addr, len, val);
277 /* Swap LEN bytes at BUFFER between target and host byte-order. */
278 #define SWAP_FLOATING(buffer,len) \
281 if (TARGET_BYTE_ORDER != HOST_BYTE_ORDER) \
284 char *p = (char *)(buffer); \
285 char *q = ((char *)(buffer)) + len - 1; \
286 for (; p < q; p++, q--) \
296 /* Extract a floating-point number from a target-order byte-stream at ADDR.
297 Returns the value as type DOUBLEST.
299 If the host and target formats agree, we just copy the raw data into the
300 appropriate type of variable and return, letting the host increase precision
301 as necessary. Otherwise, we call the conversion routine and let it do the
305 extract_floating (addr, len)
311 if (len == sizeof (float))
313 if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
317 memcpy (&retval, addr, sizeof (retval));
321 floatformat_to_doublest (TARGET_FLOAT_FORMAT, addr, &dretval);
323 else if (len == sizeof (double))
325 if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
329 memcpy (&retval, addr, sizeof (retval));
333 floatformat_to_doublest (TARGET_DOUBLE_FORMAT, addr, &dretval);
335 else if (len == sizeof (DOUBLEST))
337 if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
341 memcpy (&retval, addr, sizeof (retval));
345 floatformat_to_doublest (TARGET_LONG_DOUBLE_FORMAT, addr, &dretval);
349 error ("Can't deal with a floating point number of %d bytes.", len);
356 store_floating (addr, len, val)
361 if (len == sizeof (float))
363 if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
365 float floatval = val;
367 memcpy (addr, &floatval, sizeof (floatval));
370 floatformat_from_doublest (TARGET_FLOAT_FORMAT, &val, addr);
372 else if (len == sizeof (double))
374 if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
376 double doubleval = val;
378 memcpy (addr, &doubleval, sizeof (doubleval));
381 floatformat_from_doublest (TARGET_DOUBLE_FORMAT, &val, addr);
383 else if (len == sizeof (DOUBLEST))
385 if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
386 memcpy (addr, &val, sizeof (val));
388 floatformat_from_doublest (TARGET_LONG_DOUBLE_FORMAT, &val, addr);
392 error ("Can't deal with a floating point number of %d bytes.", len);
396 #if !defined (GET_SAVED_REGISTER)
398 /* Return the address in which frame FRAME's value of register REGNUM
399 has been saved in memory. Or return zero if it has not been saved.
400 If REGNUM specifies the SP, the value we return is actually
401 the SP value, not an address where it was saved. */
404 find_saved_register (frame, regnum)
405 struct frame_info *frame;
408 register struct frame_info *frame1 = NULL;
409 register CORE_ADDR addr = 0;
411 if (frame == NULL) /* No regs saved if want current frame */
414 #ifdef HAVE_REGISTER_WINDOWS
415 /* We assume that a register in a register window will only be saved
416 in one place (since the name changes and/or disappears as you go
417 towards inner frames), so we only call get_frame_saved_regs on
418 the current frame. This is directly in contradiction to the
419 usage below, which assumes that registers used in a frame must be
420 saved in a lower (more interior) frame. This change is a result
421 of working on a register window machine; get_frame_saved_regs
422 always returns the registers saved within a frame, within the
423 context (register namespace) of that frame. */
425 /* However, note that we don't want this to return anything if
426 nothing is saved (if there's a frame inside of this one). Also,
427 callers to this routine asking for the stack pointer want the
428 stack pointer saved for *this* frame; this is returned from the
431 if (REGISTER_IN_WINDOW_P(regnum))
433 frame1 = get_next_frame (frame);
434 if (!frame1) return 0; /* Registers of this frame are active. */
436 /* Get the SP from the next frame in; it will be this
438 if (regnum != SP_REGNUM)
441 FRAME_INIT_SAVED_REGS (frame1);
442 return frame1->saved_regs[regnum]; /* ... which might be zero */
444 #endif /* HAVE_REGISTER_WINDOWS */
446 /* Note that this next routine assumes that registers used in
447 frame x will be saved only in the frame that x calls and
448 frames interior to it. This is not true on the sparc, but the
449 above macro takes care of it, so we should be all right. */
453 frame1 = get_prev_frame (frame1);
454 if (frame1 == 0 || frame1 == frame)
456 FRAME_INIT_SAVED_REGS (frame1);
457 if (frame1->saved_regs[regnum])
458 addr = frame1->saved_regs[regnum];
464 /* Find register number REGNUM relative to FRAME and put its (raw,
465 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
466 variable was optimized out (and thus can't be fetched). Set *LVAL
467 to lval_memory, lval_register, or not_lval, depending on whether
468 the value was fetched from memory, from a register, or in a strange
469 and non-modifiable way (e.g. a frame pointer which was calculated
470 rather than fetched). Set *ADDRP to the address, either in memory
471 on as a REGISTER_BYTE offset into the registers array.
473 Note that this implementation never sets *LVAL to not_lval. But
474 it can be replaced by defining GET_SAVED_REGISTER and supplying
477 The argument RAW_BUFFER must point to aligned memory. */
480 get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
484 struct frame_info *frame;
486 enum lval_type *lval;
490 if (!target_has_registers)
491 error ("No registers.");
493 /* Normal systems don't optimize out things with register numbers. */
494 if (optimized != NULL)
496 addr = find_saved_register (frame, regnum);
501 if (regnum == SP_REGNUM)
503 if (raw_buffer != NULL)
505 /* Put it back in target format. */
506 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), (LONGEST)addr);
512 if (raw_buffer != NULL)
513 read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
518 *lval = lval_register;
519 addr = REGISTER_BYTE (regnum);
520 if (raw_buffer != NULL)
521 read_register_gen (regnum, raw_buffer);
526 #endif /* GET_SAVED_REGISTER. */
528 /* Copy the bytes of register REGNUM, relative to the input stack frame,
529 into our memory at MYADDR, in target byte order.
530 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
532 Returns 1 if could not be read, 0 if could. */
535 read_relative_register_raw_bytes_for_frame (regnum, myaddr, frame)
538 struct frame_info *frame;
541 if (regnum == FP_REGNUM && frame)
543 /* Put it back in target format. */
544 store_address (myaddr, REGISTER_RAW_SIZE(FP_REGNUM),
545 (LONGEST)FRAME_FP(frame));
550 get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, frame,
551 regnum, (enum lval_type *)NULL);
553 if (register_valid [regnum] < 0)
554 return 1; /* register value not available */
559 /* Copy the bytes of register REGNUM, relative to the current stack frame,
560 into our memory at MYADDR, in target byte order.
561 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
563 Returns 1 if could not be read, 0 if could. */
566 read_relative_register_raw_bytes (regnum, myaddr)
570 return read_relative_register_raw_bytes_for_frame (regnum, myaddr,
574 /* Return a `value' with the contents of register REGNUM
575 in its virtual format, with the type specified by
576 REGISTER_VIRTUAL_TYPE.
578 NOTE: returns NULL if register value is not available.
579 Caller will check return value or die! */
582 value_of_register (regnum)
587 register value_ptr reg_val;
588 char raw_buffer[MAX_REGISTER_RAW_SIZE];
591 get_saved_register (raw_buffer, &optim, &addr,
592 selected_frame, regnum, &lval);
594 if (register_valid[regnum] < 0)
595 return NULL; /* register value not available */
597 reg_val = allocate_value (REGISTER_VIRTUAL_TYPE (regnum));
599 /* Convert raw data to virtual format if necessary. */
601 #ifdef REGISTER_CONVERTIBLE
602 if (REGISTER_CONVERTIBLE (regnum))
604 REGISTER_CONVERT_TO_VIRTUAL (regnum, REGISTER_VIRTUAL_TYPE (regnum),
605 raw_buffer, VALUE_CONTENTS_RAW (reg_val));
609 if (REGISTER_RAW_SIZE (regnum) == REGISTER_VIRTUAL_SIZE (regnum))
610 memcpy (VALUE_CONTENTS_RAW (reg_val), raw_buffer,
611 REGISTER_RAW_SIZE (regnum));
613 fatal ("Register \"%s\" (%d) has conflicting raw (%d) and virtual (%d) size",
614 REGISTER_NAME (regnum), regnum,
615 REGISTER_RAW_SIZE (regnum), REGISTER_VIRTUAL_SIZE (regnum));
616 VALUE_LVAL (reg_val) = lval;
617 VALUE_ADDRESS (reg_val) = addr;
618 VALUE_REGNO (reg_val) = regnum;
619 VALUE_OPTIMIZED_OUT (reg_val) = optim;
623 /* Low level examining and depositing of registers.
625 The caller is responsible for making
626 sure that the inferior is stopped before calling the fetching routines,
627 or it will get garbage. (a change from GDB version 3, in which
628 the caller got the value from the last stop). */
630 /* Contents of the registers in target byte order.
631 We allocate some extra slop since we do a lot of memcpy's around
632 `registers', and failing-soft is better than failing hard. */
634 char registers[REGISTER_BYTES + /* SLOP */ 256];
636 /* Nonzero if that register has been fetched,
637 -1 if register value not available. */
638 SIGNED char register_valid[NUM_REGS];
640 /* The thread/process associated with the current set of registers. For now,
641 -1 is special, and means `no current process'. */
642 int registers_pid = -1;
644 /* Indicate that registers may have changed, so invalidate the cache. */
650 int numregs = ARCH_NUM_REGS;
654 /* Force cleanup of any alloca areas if using C alloca instead of
655 a builtin alloca. This particular call is used to clean up
656 areas allocated by low level target code which may build up
657 during lengthy interactions between gdb and the target before
658 gdb gives control to the user (ie watchpoints). */
661 for (i = 0; i < numregs; i++)
662 register_valid[i] = 0;
664 if (registers_changed_hook)
665 registers_changed_hook ();
668 /* Indicate that all registers have been fetched, so mark them all valid. */
673 int numregs = ARCH_NUM_REGS;
674 for (i = 0; i < numregs; i++)
675 register_valid[i] = 1;
678 /* read_register_bytes and write_register_bytes are generally a *BAD* idea.
679 They are inefficient because they need to check for partial updates, which
680 can only be done by scanning through all of the registers and seeing if the
681 bytes that are being read/written fall inside of an invalid register. [The
682 main reason this is necessary is that register sizes can vary, so a simple
683 index won't suffice.] It is far better to call read_register_gen if you
684 want to get at the raw register contents, as it only takes a regno as an
685 argument, and therefore can't do a partial register update. It would also
686 be good to have a write_register_gen for similar reasons.
688 Prior to the recent fixes to check for partial updates, both read and
689 write_register_bytes always checked to see if any registers were stale, and
690 then called target_fetch_registers (-1) to update the whole set. This
691 caused really slowed things down for remote targets. */
693 /* Copy INLEN bytes of consecutive data from registers
694 starting with the INREGBYTE'th byte of register data
695 into memory at MYADDR. */
698 read_register_bytes (inregbyte, myaddr, inlen)
703 int inregend = inregbyte + inlen;
706 if (registers_pid != inferior_pid)
708 registers_changed ();
709 registers_pid = inferior_pid;
712 /* See if we are trying to read bytes from out-of-date registers. If so,
713 update just those registers. */
715 for (regno = 0; regno < NUM_REGS; regno++)
717 int regstart, regend;
720 if (register_valid[regno])
723 if (REGISTER_NAME (regno) == NULL || *REGISTER_NAME (regno) == '\0')
726 regstart = REGISTER_BYTE (regno);
727 regend = regstart + REGISTER_RAW_SIZE (regno);
729 startin = regstart >= inregbyte && regstart < inregend;
730 endin = regend > inregbyte && regend <= inregend;
732 if (!startin && !endin)
735 /* We've found an invalid register where at least one byte will be read.
736 Update it from the target. */
738 target_fetch_registers (regno);
740 if (!register_valid[regno])
741 error ("read_register_bytes: Couldn't update register %d.", regno);
745 memcpy (myaddr, ®isters[inregbyte], inlen);
748 /* Read register REGNO into memory at MYADDR, which must be large enough
749 for REGISTER_RAW_BYTES (REGNO). Target byte-order.
750 If the register is known to be the size of a CORE_ADDR or smaller,
751 read_register can be used instead. */
753 read_register_gen (regno, myaddr)
757 if (registers_pid != inferior_pid)
759 registers_changed ();
760 registers_pid = inferior_pid;
763 if (!register_valid[regno])
764 target_fetch_registers (regno);
765 memcpy (myaddr, ®isters[REGISTER_BYTE (regno)],
766 REGISTER_RAW_SIZE (regno));
769 /* Write register REGNO at MYADDR to the target. MYADDR points at
770 REGISTER_RAW_BYTES(REGNO), which must be in target byte-order. */
773 write_register_gen (regno, myaddr)
779 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
780 the registers array if something writes to this register. */
781 if (CANNOT_STORE_REGISTER (regno))
784 if (registers_pid != inferior_pid)
786 registers_changed ();
787 registers_pid = inferior_pid;
790 size = REGISTER_RAW_SIZE(regno);
792 /* If we have a valid copy of the register, and new value == old value,
793 then don't bother doing the actual store. */
795 if (register_valid [regno]
796 && memcmp (®isters[REGISTER_BYTE (regno)], myaddr, size) == 0)
799 target_prepare_to_store ();
801 memcpy (®isters[REGISTER_BYTE (regno)], myaddr, size);
803 register_valid [regno] = 1;
805 target_store_registers (regno);
808 /* Copy INLEN bytes of consecutive data from memory at MYADDR
809 into registers starting with the MYREGSTART'th byte of register data. */
812 write_register_bytes (myregstart, myaddr, inlen)
817 int myregend = myregstart + inlen;
820 target_prepare_to_store ();
822 /* Scan through the registers updating any that are covered by the range
823 myregstart<=>myregend using write_register_gen, which does nice things
824 like handling threads, and avoiding updates when the new and old contents
827 for (regno = 0; regno < NUM_REGS; regno++)
829 int regstart, regend;
831 char regbuf[MAX_REGISTER_RAW_SIZE];
833 regstart = REGISTER_BYTE (regno);
834 regend = regstart + REGISTER_RAW_SIZE (regno);
836 startin = regstart >= myregstart && regstart < myregend;
837 endin = regend > myregstart && regend <= myregend;
839 if (!startin && !endin)
840 continue; /* Register is completely out of range */
842 if (startin && endin) /* register is completely in range */
844 write_register_gen (regno, myaddr + (regstart - myregstart));
848 /* We may be doing a partial update of an invalid register. Update it
849 from the target before scribbling on it. */
850 read_register_gen (regno, regbuf);
853 memcpy (registers + regstart,
854 myaddr + regstart - myregstart,
855 myregend - regstart);
857 memcpy (registers + myregstart,
859 regend - myregstart);
860 target_store_registers (regno);
864 /* Return the raw contents of register REGNO, regarding it as an integer. */
865 /* This probably should be returning LONGEST rather than CORE_ADDR. */
868 read_register (regno)
871 if (registers_pid != inferior_pid)
873 registers_changed ();
874 registers_pid = inferior_pid;
877 if (!register_valid[regno])
878 target_fetch_registers (regno);
880 return (CORE_ADDR)extract_address (®isters[REGISTER_BYTE (regno)],
881 REGISTER_RAW_SIZE(regno));
885 read_register_pid (regno, pid)
891 if (pid == inferior_pid)
892 return read_register (regno);
894 save_pid = inferior_pid;
898 retval = read_register (regno);
900 inferior_pid = save_pid;
905 /* Store VALUE, into the raw contents of register number REGNO.
906 This should probably write a LONGEST rather than a CORE_ADDR */
909 write_register (regno, val)
916 /* On the sparc, writing %g0 is a no-op, so we don't even want to change
917 the registers array if something writes to this register. */
918 if (CANNOT_STORE_REGISTER (regno))
921 if (registers_pid != inferior_pid)
923 registers_changed ();
924 registers_pid = inferior_pid;
927 size = REGISTER_RAW_SIZE(regno);
929 store_signed_integer (buf, size, (LONGEST)val);
931 /* If we have a valid copy of the register, and new value == old value,
932 then don't bother doing the actual store. */
934 if (register_valid [regno]
935 && memcmp (®isters[REGISTER_BYTE (regno)], buf, size) == 0)
938 target_prepare_to_store ();
940 memcpy (®isters[REGISTER_BYTE (regno)], buf, size);
942 register_valid [regno] = 1;
944 target_store_registers (regno);
948 write_register_pid (regno, val, pid)
955 if (pid == inferior_pid)
957 write_register (regno, val);
961 save_pid = inferior_pid;
965 write_register (regno, val);
967 inferior_pid = save_pid;
970 /* Record that register REGNO contains VAL.
971 This is used when the value is obtained from the inferior or core dump,
972 so there is no need to store the value there.
974 If VAL is a NULL pointer, then it's probably an unsupported register. We
975 just set it's value to all zeros. We might want to record this fact, and
976 report it to the users of read_register and friends.
980 supply_register (regno, val)
985 if (registers_pid != inferior_pid)
987 registers_changed ();
988 registers_pid = inferior_pid;
992 register_valid[regno] = 1;
994 memcpy (®isters[REGISTER_BYTE (regno)], val, REGISTER_RAW_SIZE (regno));
996 memset (®isters[REGISTER_BYTE (regno)], '\000', REGISTER_RAW_SIZE (regno));
998 /* On some architectures, e.g. HPPA, there are a few stray bits in some
999 registers, that the rest of the code would like to ignore. */
1000 #ifdef CLEAN_UP_REGISTER_VALUE
1001 CLEAN_UP_REGISTER_VALUE(regno, ®isters[REGISTER_BYTE(regno)]);
1006 /* This routine is getting awfully cluttered with #if's. It's probably
1007 time to turn this into READ_PC and define it in the tm.h file.
1008 Ditto for write_pc. */
1014 int saved_inferior_pid;
1017 /* In case pid != inferior_pid. */
1018 saved_inferior_pid = inferior_pid;
1021 #ifdef TARGET_READ_PC
1022 pc_val = TARGET_READ_PC (pid);
1024 pc_val = ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, pid));
1027 inferior_pid = saved_inferior_pid;
1034 return read_pc_pid (inferior_pid);
1038 write_pc_pid (pc, pid)
1042 int saved_inferior_pid;
1044 /* In case pid != inferior_pid. */
1045 saved_inferior_pid = inferior_pid;
1048 #ifdef TARGET_WRITE_PC
1049 TARGET_WRITE_PC (pc, pid);
1051 write_register_pid (PC_REGNUM, pc, pid);
1053 write_register_pid (NPC_REGNUM, pc + 4, pid);
1055 write_register_pid (NNPC_REGNUM, pc + 8, pid);
1060 inferior_pid = saved_inferior_pid;
1067 write_pc_pid (pc, inferior_pid);
1070 /* Cope with strage ways of getting to the stack and frame pointers */
1075 #ifdef TARGET_READ_SP
1076 return TARGET_READ_SP ();
1078 return read_register (SP_REGNUM);
1086 #ifdef TARGET_WRITE_SP
1087 TARGET_WRITE_SP (val);
1089 write_register (SP_REGNUM, val);
1096 #ifdef TARGET_READ_FP
1097 return TARGET_READ_FP ();
1099 return read_register (FP_REGNUM);
1107 #ifdef TARGET_WRITE_FP
1108 TARGET_WRITE_FP (val);
1110 write_register (FP_REGNUM, val);
1114 /* Will calling read_var_value or locate_var_value on SYM end
1115 up caring what frame it is being evaluated relative to? SYM must
1118 symbol_read_needs_frame (sym)
1121 switch (SYMBOL_CLASS (sym))
1123 /* All cases listed explicitly so that gcc -Wall will detect it if
1124 we failed to consider one. */
1129 case LOC_REGPARM_ADDR:
1133 case LOC_BASEREG_ARG:
1134 case LOC_THREAD_LOCAL_STATIC:
1144 /* Getting the address of a label can be done independently of the block,
1145 even if some *uses* of that address wouldn't work so well without
1149 case LOC_CONST_BYTES:
1150 case LOC_UNRESOLVED:
1151 case LOC_OPTIMIZED_OUT:
1157 /* Given a struct symbol for a variable,
1158 and a stack frame id, read the value of the variable
1159 and return a (pointer to a) struct value containing the value.
1160 If the variable cannot be found, return a zero pointer.
1161 If FRAME is NULL, use the selected_frame. */
1164 read_var_value (var, frame)
1165 register struct symbol *var;
1166 struct frame_info *frame;
1168 register value_ptr v;
1169 struct type *type = SYMBOL_TYPE (var);
1173 v = allocate_value (type);
1174 VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
1175 VALUE_BFD_SECTION (v) = SYMBOL_BFD_SECTION (var);
1177 len = TYPE_LENGTH (type);
1179 if (frame == NULL) frame = selected_frame;
1181 switch (SYMBOL_CLASS (var))
1184 /* Put the constant back in target format. */
1185 store_signed_integer (VALUE_CONTENTS_RAW (v), len,
1186 (LONGEST) SYMBOL_VALUE (var));
1187 VALUE_LVAL (v) = not_lval;
1191 /* Put the constant back in target format. */
1192 if (overlay_debugging)
1193 store_address (VALUE_CONTENTS_RAW (v), len,
1194 (LONGEST)symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
1195 SYMBOL_BFD_SECTION (var)));
1197 store_address (VALUE_CONTENTS_RAW (v), len,
1198 (LONGEST)SYMBOL_VALUE_ADDRESS (var));
1199 VALUE_LVAL (v) = not_lval;
1202 case LOC_CONST_BYTES:
1205 bytes_addr = SYMBOL_VALUE_BYTES (var);
1206 memcpy (VALUE_CONTENTS_RAW (v), bytes_addr, len);
1207 VALUE_LVAL (v) = not_lval;
1212 if (overlay_debugging)
1213 addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
1214 SYMBOL_BFD_SECTION (var));
1216 addr = SYMBOL_VALUE_ADDRESS (var);
1220 /* The import slot does not have a real address in it from the
1221 dynamic loader (dld.sl on HP-UX), if the target hasn't begun
1222 execution yet, so check for that. */
1223 if (!target_has_execution)
1225 Attempt to access variable defined in different shared object or load module when\n\
1226 addresses have not been bound by the dynamic loader. Try again when executable is running.");
1228 addr = SYMBOL_VALUE_ADDRESS (var);
1229 addr = read_memory_unsigned_integer
1230 (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1236 addr = FRAME_ARGS_ADDRESS (frame);
1239 addr += SYMBOL_VALUE (var);
1245 addr = FRAME_ARGS_ADDRESS (frame);
1248 addr += SYMBOL_VALUE (var);
1249 addr = read_memory_unsigned_integer
1250 (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1257 addr = FRAME_LOCALS_ADDRESS (frame);
1258 addr += SYMBOL_VALUE (var);
1262 case LOC_BASEREG_ARG:
1264 char buf[MAX_REGISTER_RAW_SIZE];
1265 get_saved_register (buf, NULL, NULL, frame, SYMBOL_BASEREG (var),
1267 addr = extract_address (buf, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var)));
1268 addr += SYMBOL_VALUE (var);
1272 case LOC_THREAD_LOCAL_STATIC:
1274 char buf[MAX_REGISTER_RAW_SIZE];
1276 get_saved_register(buf, NULL, NULL, frame, SYMBOL_BASEREG (var),
1278 addr = extract_address (buf, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var)));
1279 addr += SYMBOL_VALUE (var );
1284 error ("Cannot look up value of a typedef");
1288 if (overlay_debugging)
1289 VALUE_ADDRESS (v) = symbol_overlayed_address
1290 (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_BFD_SECTION (var));
1292 VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
1297 case LOC_REGPARM_ADDR:
1300 int regno = SYMBOL_VALUE (var);
1305 b = get_frame_block (frame);
1307 if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
1309 regval = value_from_register (lookup_pointer_type (type),
1314 error ("Value of register variable not available.");
1316 addr = value_as_pointer (regval);
1317 VALUE_LVAL (v) = lval_memory;
1321 regval = value_from_register (type, regno, frame);
1324 error ("Value of register variable not available.");
1330 case LOC_UNRESOLVED:
1332 struct minimal_symbol *msym;
1334 msym = lookup_minimal_symbol (SYMBOL_NAME (var), NULL, NULL);
1337 if (overlay_debugging)
1338 addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (msym),
1339 SYMBOL_BFD_SECTION (msym));
1341 addr = SYMBOL_VALUE_ADDRESS (msym);
1345 case LOC_OPTIMIZED_OUT:
1346 VALUE_LVAL (v) = not_lval;
1347 VALUE_OPTIMIZED_OUT (v) = 1;
1351 error ("Cannot look up value of a botched symbol.");
1355 VALUE_ADDRESS (v) = addr;
1360 /* Return a value of type TYPE, stored in register REGNUM, in frame
1363 NOTE: returns NULL if register value is not available.
1364 Caller will check return value or die! */
1367 value_from_register (type, regnum, frame)
1370 struct frame_info *frame;
1372 char raw_buffer [MAX_REGISTER_RAW_SIZE];
1375 value_ptr v = allocate_value (type);
1376 char *value_bytes = 0;
1377 int value_bytes_copied = 0;
1378 int num_storage_locs;
1379 enum lval_type lval;
1382 CHECK_TYPEDEF (type);
1383 len = TYPE_LENGTH (type);
1385 VALUE_REGNO (v) = regnum;
1387 num_storage_locs = (len > REGISTER_VIRTUAL_SIZE (regnum) ?
1388 ((len - 1) / REGISTER_RAW_SIZE (regnum)) + 1 :
1391 if (num_storage_locs > 1
1392 #ifdef GDB_TARGET_IS_H8500
1393 || TYPE_CODE (type) == TYPE_CODE_PTR
1397 /* Value spread across multiple storage locations. */
1400 int mem_stor = 0, reg_stor = 0;
1401 int mem_tracking = 1;
1402 CORE_ADDR last_addr = 0;
1403 CORE_ADDR first_addr = 0;
1405 value_bytes = (char *) alloca (len + MAX_REGISTER_RAW_SIZE);
1407 /* Copy all of the data out, whereever it may be. */
1409 #ifdef GDB_TARGET_IS_H8500
1410 /* This piece of hideosity is required because the H8500 treats registers
1411 differently depending upon whether they are used as pointers or not. As a
1412 pointer, a register needs to have a page register tacked onto the front.
1413 An alternate way to do this would be to have gcc output different register
1414 numbers for the pointer & non-pointer form of the register. But, it
1415 doesn't, so we're stuck with this. */
1417 if (TYPE_CODE (type) == TYPE_CODE_PTR
1424 case R0_REGNUM: case R1_REGNUM: case R2_REGNUM: case R3_REGNUM:
1425 page_regnum = SEG_D_REGNUM;
1427 case R4_REGNUM: case R5_REGNUM:
1428 page_regnum = SEG_E_REGNUM;
1430 case R6_REGNUM: case R7_REGNUM:
1431 page_regnum = SEG_T_REGNUM;
1436 get_saved_register (value_bytes + 1,
1443 if (register_valid[page_regnum] == -1)
1444 return NULL; /* register value not available */
1446 if (lval == lval_register)
1453 get_saved_register (value_bytes + 2,
1460 if (register_valid[regnum] == -1)
1461 return NULL; /* register value not available */
1463 if (lval == lval_register)
1468 mem_tracking = mem_tracking && (addr == last_addr);
1473 #endif /* GDB_TARGET_IS_H8500 */
1474 for (local_regnum = regnum;
1475 value_bytes_copied < len;
1476 (value_bytes_copied += REGISTER_RAW_SIZE (local_regnum),
1479 get_saved_register (value_bytes + value_bytes_copied,
1486 if (register_valid[local_regnum] == -1)
1487 return NULL; /* register value not available */
1489 if (regnum == local_regnum)
1491 if (lval == lval_register)
1499 && (regnum == local_regnum
1500 || addr == last_addr));
1505 if ((reg_stor && mem_stor)
1506 || (mem_stor && !mem_tracking))
1507 /* Mixed storage; all of the hassle we just went through was
1508 for some good purpose. */
1510 VALUE_LVAL (v) = lval_reg_frame_relative;
1511 VALUE_FRAME (v) = FRAME_FP (frame);
1512 VALUE_FRAME_REGNUM (v) = regnum;
1516 VALUE_LVAL (v) = lval_memory;
1517 VALUE_ADDRESS (v) = first_addr;
1521 VALUE_LVAL (v) = lval_register;
1522 VALUE_ADDRESS (v) = first_addr;
1525 fatal ("value_from_register: Value not stored anywhere!");
1527 VALUE_OPTIMIZED_OUT (v) = optim;
1529 /* Any structure stored in more than one register will always be
1530 an integral number of registers. Otherwise, you'd need to do
1531 some fiddling with the last register copied here for little
1534 /* Copy into the contents section of the value. */
1535 memcpy (VALUE_CONTENTS_RAW (v), value_bytes, len);
1537 /* Finally do any conversion necessary when extracting this
1538 type from more than one register. */
1539 #ifdef REGISTER_CONVERT_TO_TYPE
1540 REGISTER_CONVERT_TO_TYPE(regnum, type, VALUE_CONTENTS_RAW(v));
1545 /* Data is completely contained within a single register. Locate the
1546 register's contents in a real register or in core;
1547 read the data in raw format. */
1549 get_saved_register (raw_buffer, &optim, &addr, frame, regnum, &lval);
1551 if (register_valid[regnum] == -1)
1552 return NULL; /* register value not available */
1554 VALUE_OPTIMIZED_OUT (v) = optim;
1555 VALUE_LVAL (v) = lval;
1556 VALUE_ADDRESS (v) = addr;
1558 /* Convert raw data to virtual format if necessary. */
1560 #ifdef REGISTER_CONVERTIBLE
1561 if (REGISTER_CONVERTIBLE (regnum))
1563 REGISTER_CONVERT_TO_VIRTUAL (regnum, type,
1564 raw_buffer, VALUE_CONTENTS_RAW (v));
1569 /* Raw and virtual formats are the same for this register. */
1571 if (TARGET_BYTE_ORDER == BIG_ENDIAN && len < REGISTER_RAW_SIZE (regnum))
1573 /* Big-endian, and we want less than full size. */
1574 VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len;
1577 memcpy (VALUE_CONTENTS_RAW (v), raw_buffer + VALUE_OFFSET (v), len);
1583 /* Given a struct symbol for a variable or function,
1584 and a stack frame id,
1585 return a (pointer to a) struct value containing the properly typed
1589 locate_var_value (var, frame)
1590 register struct symbol *var;
1591 struct frame_info *frame;
1594 struct type *type = SYMBOL_TYPE (var);
1595 value_ptr lazy_value;
1597 /* Evaluate it first; if the result is a memory address, we're fine.
1598 Lazy evaluation pays off here. */
1600 lazy_value = read_var_value (var, frame);
1601 if (lazy_value == 0)
1602 error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
1604 if (VALUE_LAZY (lazy_value)
1605 || TYPE_CODE (type) == TYPE_CODE_FUNC)
1609 addr = VALUE_ADDRESS (lazy_value);
1610 val = value_from_longest (lookup_pointer_type (type), (LONGEST) addr);
1611 VALUE_BFD_SECTION (val) = VALUE_BFD_SECTION (lazy_value);
1615 /* Not a memory address; check what the problem was. */
1616 switch (VALUE_LVAL (lazy_value))
1619 case lval_reg_frame_relative:
1620 error ("Address requested for identifier \"%s\" which is in a register.",
1621 SYMBOL_SOURCE_NAME (var));
1625 error ("Can't take address of \"%s\" which isn't an lvalue.",
1626 SYMBOL_SOURCE_NAME (var));
1629 return 0; /* For lint -- never reached */