Commit | Line | Data |
---|---|---|
d65fe839 | 1 | /* Cache and manage the values of registers for GDB, the GNU debugger. |
96cb11df AC |
2 | |
3 | Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, | |
4 | 2001, 2002 Free Software Foundation, Inc. | |
d65fe839 AC |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
22 | ||
23 | #include "defs.h" | |
24 | #include "frame.h" | |
25 | #include "target.h" | |
26 | #include "value.h" | |
39f77062 | 27 | #include "inferior.h" /* for inferior_ptid */ |
4e052eda | 28 | #include "regcache.h" |
d65fe839 AC |
29 | |
30 | /* FIND_SAVED_REGISTER () | |
31 | ||
32 | Return the address in which frame FRAME's value of register REGNUM | |
33 | has been saved in memory. Or return zero if it has not been saved. | |
34 | If REGNUM specifies the SP, the value we return is actually | |
35 | the SP value, not an address where it was saved. */ | |
36 | ||
37 | CORE_ADDR | |
38 | find_saved_register (struct frame_info *frame, int regnum) | |
39 | { | |
40 | register struct frame_info *frame1 = NULL; | |
41 | register CORE_ADDR addr = 0; | |
42 | ||
43 | if (frame == NULL) /* No regs saved if want current frame */ | |
44 | return 0; | |
45 | ||
d65fe839 AC |
46 | /* Note that this next routine assumes that registers used in |
47 | frame x will be saved only in the frame that x calls and | |
48 | frames interior to it. This is not true on the sparc, but the | |
49 | above macro takes care of it, so we should be all right. */ | |
50 | while (1) | |
51 | { | |
52 | QUIT; | |
aa40ec90 JT |
53 | frame1 = get_next_frame (frame); |
54 | if (frame1 == 0) | |
d65fe839 | 55 | break; |
aa40ec90 | 56 | frame = frame1; |
d65fe839 AC |
57 | FRAME_INIT_SAVED_REGS (frame1); |
58 | if (frame1->saved_regs[regnum]) | |
59 | addr = frame1->saved_regs[regnum]; | |
60 | } | |
61 | ||
62 | return addr; | |
63 | } | |
64 | ||
65 | /* DEFAULT_GET_SAVED_REGISTER () | |
66 | ||
67 | Find register number REGNUM relative to FRAME and put its (raw, | |
68 | target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the | |
69 | variable was optimized out (and thus can't be fetched). Set *LVAL | |
70 | to lval_memory, lval_register, or not_lval, depending on whether | |
71 | the value was fetched from memory, from a register, or in a strange | |
72 | and non-modifiable way (e.g. a frame pointer which was calculated | |
73 | rather than fetched). Set *ADDRP to the address, either in memory | |
74 | on as a REGISTER_BYTE offset into the registers array. | |
75 | ||
76 | Note that this implementation never sets *LVAL to not_lval. But | |
77 | it can be replaced by defining GET_SAVED_REGISTER and supplying | |
78 | your own. | |
79 | ||
80 | The argument RAW_BUFFER must point to aligned memory. */ | |
81 | ||
82 | static void | |
83 | default_get_saved_register (char *raw_buffer, | |
84 | int *optimized, | |
85 | CORE_ADDR *addrp, | |
86 | struct frame_info *frame, | |
87 | int regnum, | |
88 | enum lval_type *lval) | |
89 | { | |
90 | CORE_ADDR addr; | |
91 | ||
92 | if (!target_has_registers) | |
93 | error ("No registers."); | |
94 | ||
95 | /* Normal systems don't optimize out things with register numbers. */ | |
96 | if (optimized != NULL) | |
97 | *optimized = 0; | |
98 | addr = find_saved_register (frame, regnum); | |
99 | if (addr != 0) | |
100 | { | |
101 | if (lval != NULL) | |
102 | *lval = lval_memory; | |
103 | if (regnum == SP_REGNUM) | |
104 | { | |
105 | if (raw_buffer != NULL) | |
106 | { | |
107 | /* Put it back in target format. */ | |
108 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), | |
109 | (LONGEST) addr); | |
110 | } | |
111 | if (addrp != NULL) | |
112 | *addrp = 0; | |
113 | return; | |
114 | } | |
115 | if (raw_buffer != NULL) | |
116 | target_read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum)); | |
117 | } | |
118 | else | |
119 | { | |
120 | if (lval != NULL) | |
121 | *lval = lval_register; | |
122 | addr = REGISTER_BYTE (regnum); | |
123 | if (raw_buffer != NULL) | |
124 | read_register_gen (regnum, raw_buffer); | |
125 | } | |
126 | if (addrp != NULL) | |
127 | *addrp = addr; | |
128 | } | |
129 | ||
130 | #if !defined (GET_SAVED_REGISTER) | |
131 | #define GET_SAVED_REGISTER(raw_buffer, optimized, addrp, frame, regnum, lval) \ | |
132 | default_get_saved_register(raw_buffer, optimized, addrp, frame, regnum, lval) | |
133 | #endif | |
134 | ||
135 | void | |
136 | get_saved_register (char *raw_buffer, | |
137 | int *optimized, | |
138 | CORE_ADDR *addrp, | |
139 | struct frame_info *frame, | |
140 | int regnum, | |
141 | enum lval_type *lval) | |
142 | { | |
143 | GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval); | |
144 | } | |
145 | ||
cda5a58a | 146 | /* frame_register_read () |
d65fe839 | 147 | |
cda5a58a | 148 | Find and return the value of REGNUM for the specified stack frame. |
d65fe839 AC |
149 | The number of bytes copied is REGISTER_RAW_SIZE (REGNUM). |
150 | ||
cda5a58a | 151 | Returns 0 if the register value could not be found. */ |
d65fe839 | 152 | |
cda5a58a AC |
153 | int |
154 | frame_register_read (struct frame_info *frame, int regnum, void *myaddr) | |
d65fe839 AC |
155 | { |
156 | int optim; | |
d65fe839 AC |
157 | get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, frame, |
158 | regnum, (enum lval_type *) NULL); | |
159 | ||
c97dcfc7 AC |
160 | /* FIXME: cagney/2002-05-15: This test, is just bogus. |
161 | ||
162 | It indicates that the target failed to supply a value for a | |
163 | register because it was "not available" at this time. Problem | |
164 | is, the target still has the register and so get saved_register() | |
165 | may be returning a value saved on the stack. */ | |
166 | ||
d65fe839 | 167 | if (register_cached (regnum) < 0) |
cda5a58a | 168 | return 0; /* register value not available */ |
d65fe839 | 169 | |
cda5a58a | 170 | return !optim; |
d65fe839 | 171 | } |