Commit | Line | Data |
---|---|---|
32178cab | 1 | /* Cache and manage the values of registers for GDB, the GNU debugger. |
3fadccb3 | 2 | |
32d0add0 | 3 | Copyright (C) 1986-2015 Free Software Foundation, Inc. |
32178cab MS |
4 | |
5 | This file is part of GDB. | |
6 | ||
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
32178cab MS |
10 | (at your option) any later version. |
11 | ||
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
32178cab MS |
19 | |
20 | #include "defs.h" | |
32178cab MS |
21 | #include "inferior.h" |
22 | #include "target.h" | |
23 | #include "gdbarch.h" | |
705152c5 | 24 | #include "gdbcmd.h" |
4e052eda | 25 | #include "regcache.h" |
b59ff9d5 | 26 | #include "reggroups.h" |
f4c5303c | 27 | #include "observer.h" |
c21236dc | 28 | #include "remote.h" |
d3eaaf66 | 29 | #include "valprint.h" |
0b309272 | 30 | #include "regset.h" |
32178cab MS |
31 | |
32 | /* | |
33 | * DATA STRUCTURE | |
34 | * | |
35 | * Here is the actual register cache. | |
36 | */ | |
37 | ||
3fadccb3 | 38 | /* Per-architecture object describing the layout of a register cache. |
0df8b418 | 39 | Computed once when the architecture is created. */ |
3fadccb3 AC |
40 | |
41 | struct gdbarch_data *regcache_descr_handle; | |
42 | ||
43 | struct regcache_descr | |
44 | { | |
45 | /* The architecture this descriptor belongs to. */ | |
46 | struct gdbarch *gdbarch; | |
47 | ||
bb1db049 AC |
48 | /* The raw register cache. Each raw (or hard) register is supplied |
49 | by the target interface. The raw cache should not contain | |
50 | redundant information - if the PC is constructed from two | |
d2f0b918 | 51 | registers then those registers and not the PC lives in the raw |
bb1db049 | 52 | cache. */ |
3fadccb3 AC |
53 | int nr_raw_registers; |
54 | long sizeof_raw_registers; | |
ee99023e | 55 | long sizeof_raw_register_status; |
3fadccb3 | 56 | |
d138e37a AC |
57 | /* The cooked register space. Each cooked register in the range |
58 | [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw | |
59 | register. The remaining [NR_RAW_REGISTERS | |
02f60eae | 60 | .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto |
d138e37a | 61 | both raw registers and memory by the architecture methods |
02f60eae | 62 | gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */ |
d138e37a | 63 | int nr_cooked_registers; |
067df2e5 | 64 | long sizeof_cooked_registers; |
ee99023e | 65 | long sizeof_cooked_register_status; |
d138e37a | 66 | |
86d31898 | 67 | /* Offset and size (in 8 bit bytes), of each register in the |
d138e37a | 68 | register cache. All registers (including those in the range |
99e42fd8 PA |
69 | [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an |
70 | offset. */ | |
3fadccb3 | 71 | long *register_offset; |
3fadccb3 | 72 | long *sizeof_register; |
3fadccb3 | 73 | |
bb425013 AC |
74 | /* Cached table containing the type of each register. */ |
75 | struct type **register_type; | |
3fadccb3 AC |
76 | }; |
77 | ||
3fadccb3 AC |
78 | static void * |
79 | init_regcache_descr (struct gdbarch *gdbarch) | |
80 | { | |
81 | int i; | |
82 | struct regcache_descr *descr; | |
83 | gdb_assert (gdbarch != NULL); | |
84 | ||
bb425013 | 85 | /* Create an initial, zero filled, table. */ |
116f06ea | 86 | descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr); |
3fadccb3 | 87 | descr->gdbarch = gdbarch; |
3fadccb3 | 88 | |
d138e37a AC |
89 | /* Total size of the register space. The raw registers are mapped |
90 | directly onto the raw register cache while the pseudo's are | |
3fadccb3 | 91 | either mapped onto raw-registers or memory. */ |
214e098a UW |
92 | descr->nr_cooked_registers = gdbarch_num_regs (gdbarch) |
93 | + gdbarch_num_pseudo_regs (gdbarch); | |
ee99023e PA |
94 | descr->sizeof_cooked_register_status |
95 | = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); | |
3fadccb3 | 96 | |
bb425013 | 97 | /* Fill in a table of register types. */ |
116f06ea | 98 | descr->register_type |
3e43a32a MS |
99 | = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, |
100 | struct type *); | |
bb425013 | 101 | for (i = 0; i < descr->nr_cooked_registers; i++) |
336a3131 | 102 | descr->register_type[i] = gdbarch_register_type (gdbarch, i); |
bb425013 | 103 | |
bb1db049 AC |
104 | /* Construct a strictly RAW register cache. Don't allow pseudo's |
105 | into the register cache. */ | |
214e098a | 106 | descr->nr_raw_registers = gdbarch_num_regs (gdbarch); |
ee99023e | 107 | descr->sizeof_raw_register_status = gdbarch_num_regs (gdbarch); |
bb1db049 | 108 | |
067df2e5 | 109 | /* Lay out the register cache. |
3fadccb3 | 110 | |
bb425013 AC |
111 | NOTE: cagney/2002-05-22: Only register_type() is used when |
112 | constructing the register cache. It is assumed that the | |
113 | register's raw size, virtual size and type length are all the | |
114 | same. */ | |
3fadccb3 AC |
115 | |
116 | { | |
117 | long offset = 0; | |
123f5f96 | 118 | |
116f06ea AC |
119 | descr->sizeof_register |
120 | = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long); | |
121 | descr->register_offset | |
122 | = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long); | |
99e42fd8 PA |
123 | for (i = 0; i < descr->nr_raw_registers; i++) |
124 | { | |
125 | descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]); | |
126 | descr->register_offset[i] = offset; | |
127 | offset += descr->sizeof_register[i]; | |
128 | gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]); | |
129 | } | |
130 | /* Set the real size of the raw register cache buffer. */ | |
131 | descr->sizeof_raw_registers = offset; | |
132 | ||
133 | for (; i < descr->nr_cooked_registers; i++) | |
3fadccb3 | 134 | { |
bb425013 | 135 | descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]); |
3fadccb3 AC |
136 | descr->register_offset[i] = offset; |
137 | offset += descr->sizeof_register[i]; | |
123a958e | 138 | gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]); |
3fadccb3 | 139 | } |
99e42fd8 | 140 | /* Set the real size of the readonly register cache buffer. */ |
067df2e5 | 141 | descr->sizeof_cooked_registers = offset; |
3fadccb3 AC |
142 | } |
143 | ||
3fadccb3 AC |
144 | return descr; |
145 | } | |
146 | ||
147 | static struct regcache_descr * | |
148 | regcache_descr (struct gdbarch *gdbarch) | |
149 | { | |
150 | return gdbarch_data (gdbarch, regcache_descr_handle); | |
151 | } | |
152 | ||
bb425013 AC |
153 | /* Utility functions returning useful register attributes stored in |
154 | the regcache descr. */ | |
155 | ||
156 | struct type * | |
157 | register_type (struct gdbarch *gdbarch, int regnum) | |
158 | { | |
159 | struct regcache_descr *descr = regcache_descr (gdbarch); | |
123f5f96 | 160 | |
bb425013 AC |
161 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); |
162 | return descr->register_type[regnum]; | |
163 | } | |
164 | ||
0ed04cce AC |
165 | /* Utility functions returning useful register attributes stored in |
166 | the regcache descr. */ | |
167 | ||
08a617da AC |
168 | int |
169 | register_size (struct gdbarch *gdbarch, int regnum) | |
170 | { | |
171 | struct regcache_descr *descr = regcache_descr (gdbarch); | |
172 | int size; | |
123f5f96 | 173 | |
f57d151a | 174 | gdb_assert (regnum >= 0 |
214e098a UW |
175 | && regnum < (gdbarch_num_regs (gdbarch) |
176 | + gdbarch_num_pseudo_regs (gdbarch))); | |
08a617da | 177 | size = descr->sizeof_register[regnum]; |
08a617da AC |
178 | return size; |
179 | } | |
180 | ||
3fadccb3 AC |
181 | /* The register cache for storing raw register values. */ |
182 | ||
183 | struct regcache | |
184 | { | |
185 | struct regcache_descr *descr; | |
6c95b8df PA |
186 | |
187 | /* The address space of this register cache (for registers where it | |
188 | makes sense, like PC or SP). */ | |
189 | struct address_space *aspace; | |
190 | ||
51b1fe4e | 191 | /* The register buffers. A read-only register cache can hold the |
f57d151a UW |
192 | full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write |
193 | register cache can only hold [0 .. gdbarch_num_regs). */ | |
2d522557 | 194 | gdb_byte *registers; |
ee99023e PA |
195 | /* Register cache status. */ |
196 | signed char *register_status; | |
2d28509a AC |
197 | /* Is this a read-only cache? A read-only cache is used for saving |
198 | the target's register state (e.g, across an inferior function | |
199 | call or just before forcing a function return). A read-only | |
200 | cache can only be updated via the methods regcache_dup() and | |
201 | regcache_cpy(). The actual contents are determined by the | |
202 | reggroup_save and reggroup_restore methods. */ | |
203 | int readonly_p; | |
594f7785 UW |
204 | /* If this is a read-write cache, which thread's registers is |
205 | it connected to? */ | |
206 | ptid_t ptid; | |
3fadccb3 AC |
207 | }; |
208 | ||
99e42fd8 PA |
209 | static struct regcache * |
210 | regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace, | |
211 | int readonly_p) | |
3fadccb3 AC |
212 | { |
213 | struct regcache_descr *descr; | |
214 | struct regcache *regcache; | |
123f5f96 | 215 | |
3fadccb3 AC |
216 | gdb_assert (gdbarch != NULL); |
217 | descr = regcache_descr (gdbarch); | |
70ba0933 | 218 | regcache = XNEW (struct regcache); |
3fadccb3 | 219 | regcache->descr = descr; |
99e42fd8 PA |
220 | regcache->readonly_p = readonly_p; |
221 | if (readonly_p) | |
222 | { | |
223 | regcache->registers | |
fc270c35 | 224 | = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers); |
ee99023e | 225 | regcache->register_status |
fc270c35 | 226 | = XCNEWVEC (signed char, descr->sizeof_cooked_register_status); |
99e42fd8 PA |
227 | } |
228 | else | |
229 | { | |
230 | regcache->registers | |
fc270c35 | 231 | = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers); |
ee99023e | 232 | regcache->register_status |
fc270c35 | 233 | = XCNEWVEC (signed char, descr->sizeof_raw_register_status); |
99e42fd8 | 234 | } |
d37346f0 | 235 | regcache->aspace = aspace; |
594f7785 | 236 | regcache->ptid = minus_one_ptid; |
3fadccb3 AC |
237 | return regcache; |
238 | } | |
239 | ||
99e42fd8 PA |
240 | struct regcache * |
241 | regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace) | |
242 | { | |
243 | return regcache_xmalloc_1 (gdbarch, aspace, 1); | |
244 | } | |
245 | ||
3fadccb3 AC |
246 | void |
247 | regcache_xfree (struct regcache *regcache) | |
248 | { | |
249 | if (regcache == NULL) | |
250 | return; | |
51b1fe4e | 251 | xfree (regcache->registers); |
ee99023e | 252 | xfree (regcache->register_status); |
3fadccb3 AC |
253 | xfree (regcache); |
254 | } | |
255 | ||
b9362cc7 | 256 | static void |
36160dc4 AC |
257 | do_regcache_xfree (void *data) |
258 | { | |
259 | regcache_xfree (data); | |
260 | } | |
261 | ||
262 | struct cleanup * | |
263 | make_cleanup_regcache_xfree (struct regcache *regcache) | |
264 | { | |
265 | return make_cleanup (do_regcache_xfree, regcache); | |
266 | } | |
267 | ||
b94ade42 PL |
268 | /* Cleanup routines for invalidating a register. */ |
269 | ||
270 | struct register_to_invalidate | |
271 | { | |
272 | struct regcache *regcache; | |
273 | int regnum; | |
274 | }; | |
275 | ||
276 | static void | |
277 | do_regcache_invalidate (void *data) | |
278 | { | |
279 | struct register_to_invalidate *reg = data; | |
280 | ||
281 | regcache_invalidate (reg->regcache, reg->regnum); | |
282 | } | |
283 | ||
284 | static struct cleanup * | |
285 | make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum) | |
286 | { | |
287 | struct register_to_invalidate* reg = XNEW (struct register_to_invalidate); | |
288 | ||
289 | reg->regcache = regcache; | |
290 | reg->regnum = regnum; | |
291 | return make_cleanup_dtor (do_regcache_invalidate, (void *) reg, xfree); | |
292 | } | |
293 | ||
41d35cb0 MK |
294 | /* Return REGCACHE's architecture. */ |
295 | ||
296 | struct gdbarch * | |
297 | get_regcache_arch (const struct regcache *regcache) | |
298 | { | |
299 | return regcache->descr->gdbarch; | |
300 | } | |
301 | ||
6c95b8df PA |
302 | struct address_space * |
303 | get_regcache_aspace (const struct regcache *regcache) | |
304 | { | |
305 | return regcache->aspace; | |
306 | } | |
307 | ||
51b1fe4e AC |
308 | /* Return a pointer to register REGNUM's buffer cache. */ |
309 | ||
2d522557 | 310 | static gdb_byte * |
9a661b68 | 311 | register_buffer (const struct regcache *regcache, int regnum) |
51b1fe4e AC |
312 | { |
313 | return regcache->registers + regcache->descr->register_offset[regnum]; | |
314 | } | |
315 | ||
2d28509a | 316 | void |
5602984a AC |
317 | regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read, |
318 | void *src) | |
2d28509a AC |
319 | { |
320 | struct gdbarch *gdbarch = dst->descr->gdbarch; | |
2d522557 | 321 | gdb_byte buf[MAX_REGISTER_SIZE]; |
2d28509a | 322 | int regnum; |
123f5f96 | 323 | |
2d28509a | 324 | /* The DST should be `read-only', if it wasn't then the save would |
5602984a | 325 | end up trying to write the register values back out to the |
2d28509a | 326 | target. */ |
2d28509a AC |
327 | gdb_assert (dst->readonly_p); |
328 | /* Clear the dest. */ | |
329 | memset (dst->registers, 0, dst->descr->sizeof_cooked_registers); | |
ee99023e PA |
330 | memset (dst->register_status, 0, |
331 | dst->descr->sizeof_cooked_register_status); | |
2d28509a | 332 | /* Copy over any registers (identified by their membership in the |
f57d151a UW |
333 | save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs + |
334 | gdbarch_num_pseudo_regs) range is checked since some architectures need | |
5602984a | 335 | to save/restore `cooked' registers that live in memory. */ |
2d28509a AC |
336 | for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++) |
337 | { | |
338 | if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup)) | |
339 | { | |
05d1431c | 340 | enum register_status status = cooked_read (src, regnum, buf); |
123f5f96 | 341 | |
05d1431c PA |
342 | if (status == REG_VALID) |
343 | memcpy (register_buffer (dst, regnum), buf, | |
344 | register_size (gdbarch, regnum)); | |
345 | else | |
5602984a | 346 | { |
05d1431c PA |
347 | gdb_assert (status != REG_UNKNOWN); |
348 | ||
349 | memset (register_buffer (dst, regnum), 0, | |
5602984a | 350 | register_size (gdbarch, regnum)); |
5602984a | 351 | } |
05d1431c | 352 | dst->register_status[regnum] = status; |
2d28509a AC |
353 | } |
354 | } | |
355 | } | |
356 | ||
349d1385 | 357 | static void |
5602984a AC |
358 | regcache_restore (struct regcache *dst, |
359 | regcache_cooked_read_ftype *cooked_read, | |
2d522557 | 360 | void *cooked_read_context) |
2d28509a AC |
361 | { |
362 | struct gdbarch *gdbarch = dst->descr->gdbarch; | |
2d522557 | 363 | gdb_byte buf[MAX_REGISTER_SIZE]; |
2d28509a | 364 | int regnum; |
123f5f96 | 365 | |
5602984a AC |
366 | /* The dst had better not be read-only. If it is, the `restore' |
367 | doesn't make much sense. */ | |
2d28509a | 368 | gdb_assert (!dst->readonly_p); |
2d28509a | 369 | /* Copy over any registers, being careful to only restore those that |
f57d151a UW |
370 | were both saved and need to be restored. The full [0 .. gdbarch_num_regs |
371 | + gdbarch_num_pseudo_regs) range is checked since some architectures need | |
5602984a AC |
372 | to save/restore `cooked' registers that live in memory. */ |
373 | for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++) | |
2d28509a | 374 | { |
5602984a | 375 | if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup)) |
2d28509a | 376 | { |
349d1385 | 377 | enum register_status status; |
123f5f96 | 378 | |
349d1385 DM |
379 | status = cooked_read (cooked_read_context, regnum, buf); |
380 | if (status == REG_VALID) | |
5602984a | 381 | regcache_cooked_write (dst, regnum, buf); |
2d28509a AC |
382 | } |
383 | } | |
384 | } | |
385 | ||
05d1431c | 386 | static enum register_status |
2d522557 | 387 | do_cooked_read (void *src, int regnum, gdb_byte *buf) |
5602984a AC |
388 | { |
389 | struct regcache *regcache = src; | |
123f5f96 | 390 | |
05d1431c | 391 | return regcache_cooked_read (regcache, regnum, buf); |
5602984a AC |
392 | } |
393 | ||
bd49952b JK |
394 | static void regcache_cpy_no_passthrough (struct regcache *dst, |
395 | struct regcache *src); | |
396 | ||
3fadccb3 AC |
397 | void |
398 | regcache_cpy (struct regcache *dst, struct regcache *src) | |
399 | { | |
3fadccb3 AC |
400 | gdb_assert (src != NULL && dst != NULL); |
401 | gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); | |
402 | gdb_assert (src != dst); | |
2d28509a | 403 | gdb_assert (src->readonly_p || dst->readonly_p); |
6c95b8df | 404 | |
2d28509a | 405 | if (!src->readonly_p) |
5602984a | 406 | regcache_save (dst, do_cooked_read, src); |
2d28509a | 407 | else if (!dst->readonly_p) |
5602984a | 408 | regcache_restore (dst, do_cooked_read, src); |
2d28509a AC |
409 | else |
410 | regcache_cpy_no_passthrough (dst, src); | |
3fadccb3 AC |
411 | } |
412 | ||
bd49952b JK |
413 | /* Copy/duplicate the contents of a register cache. Unlike regcache_cpy, |
414 | which is pass-through, this does not go through to the target. | |
415 | Only values values already in the cache are transferred. The SRC and DST | |
416 | buffers must not overlap. */ | |
417 | ||
418 | static void | |
3fadccb3 AC |
419 | regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src) |
420 | { | |
3fadccb3 AC |
421 | gdb_assert (src != NULL && dst != NULL); |
422 | gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); | |
423 | /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough | |
ee99023e PA |
424 | move of data into a thread's regcache. Doing this would be silly |
425 | - it would mean that regcache->register_status would be | |
426 | completely invalid. */ | |
99e42fd8 | 427 | gdb_assert (dst->readonly_p && src->readonly_p); |
6c95b8df | 428 | |
99e42fd8 PA |
429 | memcpy (dst->registers, src->registers, |
430 | dst->descr->sizeof_cooked_registers); | |
ee99023e PA |
431 | memcpy (dst->register_status, src->register_status, |
432 | dst->descr->sizeof_cooked_register_status); | |
3fadccb3 AC |
433 | } |
434 | ||
435 | struct regcache * | |
436 | regcache_dup (struct regcache *src) | |
437 | { | |
438 | struct regcache *newbuf; | |
123f5f96 | 439 | |
d37346f0 | 440 | newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src)); |
3fadccb3 AC |
441 | regcache_cpy (newbuf, src); |
442 | return newbuf; | |
443 | } | |
444 | ||
39181896 | 445 | enum register_status |
ee99023e | 446 | regcache_register_status (const struct regcache *regcache, int regnum) |
3fadccb3 AC |
447 | { |
448 | gdb_assert (regcache != NULL); | |
6ed7ea50 UW |
449 | gdb_assert (regnum >= 0); |
450 | if (regcache->readonly_p) | |
451 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); | |
452 | else | |
453 | gdb_assert (regnum < regcache->descr->nr_raw_registers); | |
454 | ||
ee99023e | 455 | return regcache->register_status[regnum]; |
3fadccb3 AC |
456 | } |
457 | ||
9c5ea4d9 UW |
458 | void |
459 | regcache_invalidate (struct regcache *regcache, int regnum) | |
460 | { | |
461 | gdb_assert (regcache != NULL); | |
462 | gdb_assert (regnum >= 0); | |
463 | gdb_assert (!regcache->readonly_p); | |
464 | gdb_assert (regnum < regcache->descr->nr_raw_registers); | |
ee99023e | 465 | regcache->register_status[regnum] = REG_UNKNOWN; |
9c5ea4d9 UW |
466 | } |
467 | ||
468 | ||
3fadccb3 | 469 | /* Global structure containing the current regcache. */ |
3fadccb3 | 470 | |
5ebd2499 | 471 | /* NOTE: this is a write-through cache. There is no "dirty" bit for |
32178cab MS |
472 | recording if the register values have been changed (eg. by the |
473 | user). Therefore all registers must be written back to the | |
474 | target when appropriate. */ | |
475 | ||
c2250ad1 | 476 | struct regcache_list |
594f7785 | 477 | { |
c2250ad1 UW |
478 | struct regcache *regcache; |
479 | struct regcache_list *next; | |
480 | }; | |
481 | ||
482 | static struct regcache_list *current_regcache; | |
483 | ||
484 | struct regcache * | |
e2d96639 YQ |
485 | get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch, |
486 | struct address_space *aspace) | |
c2250ad1 UW |
487 | { |
488 | struct regcache_list *list; | |
489 | struct regcache *new_regcache; | |
594f7785 | 490 | |
c2250ad1 UW |
491 | for (list = current_regcache; list; list = list->next) |
492 | if (ptid_equal (list->regcache->ptid, ptid) | |
493 | && get_regcache_arch (list->regcache) == gdbarch) | |
494 | return list->regcache; | |
594f7785 | 495 | |
e2d96639 YQ |
496 | new_regcache = regcache_xmalloc_1 (gdbarch, aspace, 0); |
497 | new_regcache->ptid = ptid; | |
498 | ||
499 | list = xmalloc (sizeof (struct regcache_list)); | |
500 | list->regcache = new_regcache; | |
501 | list->next = current_regcache; | |
502 | current_regcache = list; | |
503 | ||
504 | return new_regcache; | |
505 | } | |
506 | ||
507 | struct regcache * | |
508 | get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch) | |
509 | { | |
510 | struct address_space *aspace; | |
511 | ||
b78974c3 PA |
512 | /* For the benefit of "maint print registers" & co when debugging an |
513 | executable, allow dumping the regcache even when there is no | |
514 | thread selected (target_thread_address_space internal-errors if | |
515 | no address space is found). Note that normal user commands will | |
516 | fail higher up on the call stack due to no | |
517 | target_has_registers. */ | |
518 | aspace = (ptid_equal (null_ptid, ptid) | |
519 | ? NULL | |
520 | : target_thread_address_space (ptid)); | |
521 | ||
e2d96639 | 522 | return get_thread_arch_aspace_regcache (ptid, gdbarch, aspace); |
594f7785 UW |
523 | } |
524 | ||
c2250ad1 UW |
525 | static ptid_t current_thread_ptid; |
526 | static struct gdbarch *current_thread_arch; | |
527 | ||
528 | struct regcache * | |
529 | get_thread_regcache (ptid_t ptid) | |
530 | { | |
531 | if (!current_thread_arch || !ptid_equal (current_thread_ptid, ptid)) | |
532 | { | |
533 | current_thread_ptid = ptid; | |
534 | current_thread_arch = target_thread_architecture (ptid); | |
535 | } | |
536 | ||
537 | return get_thread_arch_regcache (ptid, current_thread_arch); | |
538 | } | |
539 | ||
540 | struct regcache * | |
541 | get_current_regcache (void) | |
594f7785 UW |
542 | { |
543 | return get_thread_regcache (inferior_ptid); | |
544 | } | |
32178cab | 545 | |
361c8ade GB |
546 | /* See common/common-regcache.h. */ |
547 | ||
548 | struct regcache * | |
549 | get_thread_regcache_for_ptid (ptid_t ptid) | |
550 | { | |
551 | return get_thread_regcache (ptid); | |
552 | } | |
32178cab | 553 | |
f4c5303c OF |
554 | /* Observer for the target_changed event. */ |
555 | ||
2c0b251b | 556 | static void |
f4c5303c OF |
557 | regcache_observer_target_changed (struct target_ops *target) |
558 | { | |
559 | registers_changed (); | |
560 | } | |
561 | ||
5231c1fd PA |
562 | /* Update global variables old ptids to hold NEW_PTID if they were |
563 | holding OLD_PTID. */ | |
564 | static void | |
565 | regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) | |
566 | { | |
c2250ad1 UW |
567 | struct regcache_list *list; |
568 | ||
569 | for (list = current_regcache; list; list = list->next) | |
570 | if (ptid_equal (list->regcache->ptid, old_ptid)) | |
571 | list->regcache->ptid = new_ptid; | |
5231c1fd PA |
572 | } |
573 | ||
32178cab MS |
574 | /* Low level examining and depositing of registers. |
575 | ||
576 | The caller is responsible for making sure that the inferior is | |
577 | stopped before calling the fetching routines, or it will get | |
578 | garbage. (a change from GDB version 3, in which the caller got the | |
579 | value from the last stop). */ | |
580 | ||
581 | /* REGISTERS_CHANGED () | |
582 | ||
583 | Indicate that registers may have changed, so invalidate the cache. */ | |
584 | ||
585 | void | |
e66408ed | 586 | registers_changed_ptid (ptid_t ptid) |
32178cab | 587 | { |
e66408ed | 588 | struct regcache_list *list, **list_link; |
c2250ad1 | 589 | |
e66408ed PA |
590 | list = current_regcache; |
591 | list_link = ¤t_regcache; | |
592 | while (list) | |
c2250ad1 | 593 | { |
e66408ed PA |
594 | if (ptid_match (list->regcache->ptid, ptid)) |
595 | { | |
596 | struct regcache_list *dead = list; | |
597 | ||
598 | *list_link = list->next; | |
599 | regcache_xfree (list->regcache); | |
600 | list = *list_link; | |
601 | xfree (dead); | |
602 | continue; | |
603 | } | |
604 | ||
605 | list_link = &list->next; | |
606 | list = *list_link; | |
c2250ad1 | 607 | } |
32178cab | 608 | |
c34fd852 | 609 | if (ptid_match (current_thread_ptid, ptid)) |
041274d8 PA |
610 | { |
611 | current_thread_ptid = null_ptid; | |
612 | current_thread_arch = NULL; | |
613 | } | |
32178cab | 614 | |
c34fd852 | 615 | if (ptid_match (inferior_ptid, ptid)) |
041274d8 PA |
616 | { |
617 | /* We just deleted the regcache of the current thread. Need to | |
618 | forget about any frames we have cached, too. */ | |
619 | reinit_frame_cache (); | |
620 | } | |
621 | } | |
c2250ad1 | 622 | |
041274d8 PA |
623 | void |
624 | registers_changed (void) | |
625 | { | |
626 | registers_changed_ptid (minus_one_ptid); | |
a5d9d57d | 627 | |
32178cab MS |
628 | /* Force cleanup of any alloca areas if using C alloca instead of |
629 | a builtin alloca. This particular call is used to clean up | |
630 | areas allocated by low level target code which may build up | |
631 | during lengthy interactions between gdb and the target before | |
632 | gdb gives control to the user (ie watchpoints). */ | |
633 | alloca (0); | |
32178cab MS |
634 | } |
635 | ||
05d1431c | 636 | enum register_status |
2d522557 | 637 | regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf) |
61a0eb5b | 638 | { |
3fadccb3 AC |
639 | gdb_assert (regcache != NULL && buf != NULL); |
640 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
3fadccb3 AC |
641 | /* Make certain that the register cache is up-to-date with respect |
642 | to the current thread. This switching shouldn't be necessary | |
643 | only there is still only one target side register cache. Sigh! | |
644 | On the bright side, at least there is a regcache object. */ | |
788c8b10 PA |
645 | if (!regcache->readonly_p |
646 | && regcache_register_status (regcache, regnum) == REG_UNKNOWN) | |
3fadccb3 | 647 | { |
788c8b10 | 648 | struct cleanup *old_chain = save_inferior_ptid (); |
123f5f96 | 649 | |
788c8b10 PA |
650 | inferior_ptid = regcache->ptid; |
651 | target_fetch_registers (regcache, regnum); | |
652 | do_cleanups (old_chain); | |
653 | ||
654 | /* A number of targets can't access the whole set of raw | |
655 | registers (because the debug API provides no means to get at | |
656 | them). */ | |
657 | if (regcache->register_status[regnum] == REG_UNKNOWN) | |
658 | regcache->register_status[regnum] = REG_UNAVAILABLE; | |
3fadccb3 | 659 | } |
05d1431c PA |
660 | |
661 | if (regcache->register_status[regnum] != REG_VALID) | |
662 | memset (buf, 0, regcache->descr->sizeof_register[regnum]); | |
663 | else | |
664 | memcpy (buf, register_buffer (regcache, regnum), | |
665 | regcache->descr->sizeof_register[regnum]); | |
666 | ||
667 | return regcache->register_status[regnum]; | |
61a0eb5b AC |
668 | } |
669 | ||
05d1431c | 670 | enum register_status |
28fc6740 AC |
671 | regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val) |
672 | { | |
2d522557 | 673 | gdb_byte *buf; |
05d1431c | 674 | enum register_status status; |
123f5f96 | 675 | |
28fc6740 AC |
676 | gdb_assert (regcache != NULL); |
677 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
678 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
05d1431c PA |
679 | status = regcache_raw_read (regcache, regnum, buf); |
680 | if (status == REG_VALID) | |
681 | *val = extract_signed_integer | |
682 | (buf, regcache->descr->sizeof_register[regnum], | |
683 | gdbarch_byte_order (regcache->descr->gdbarch)); | |
684 | else | |
685 | *val = 0; | |
686 | return status; | |
28fc6740 AC |
687 | } |
688 | ||
05d1431c | 689 | enum register_status |
28fc6740 AC |
690 | regcache_raw_read_unsigned (struct regcache *regcache, int regnum, |
691 | ULONGEST *val) | |
692 | { | |
2d522557 | 693 | gdb_byte *buf; |
05d1431c | 694 | enum register_status status; |
123f5f96 | 695 | |
28fc6740 AC |
696 | gdb_assert (regcache != NULL); |
697 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
698 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
05d1431c PA |
699 | status = regcache_raw_read (regcache, regnum, buf); |
700 | if (status == REG_VALID) | |
701 | *val = extract_unsigned_integer | |
702 | (buf, regcache->descr->sizeof_register[regnum], | |
703 | gdbarch_byte_order (regcache->descr->gdbarch)); | |
704 | else | |
705 | *val = 0; | |
706 | return status; | |
28fc6740 AC |
707 | } |
708 | ||
c00dcbe9 MK |
709 | void |
710 | regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val) | |
711 | { | |
712 | void *buf; | |
123f5f96 | 713 | |
c00dcbe9 MK |
714 | gdb_assert (regcache != NULL); |
715 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers); | |
716 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
e17a4113 UW |
717 | store_signed_integer (buf, regcache->descr->sizeof_register[regnum], |
718 | gdbarch_byte_order (regcache->descr->gdbarch), val); | |
c00dcbe9 MK |
719 | regcache_raw_write (regcache, regnum, buf); |
720 | } | |
721 | ||
722 | void | |
723 | regcache_raw_write_unsigned (struct regcache *regcache, int regnum, | |
724 | ULONGEST val) | |
725 | { | |
726 | void *buf; | |
123f5f96 | 727 | |
c00dcbe9 MK |
728 | gdb_assert (regcache != NULL); |
729 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers); | |
730 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
e17a4113 UW |
731 | store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], |
732 | gdbarch_byte_order (regcache->descr->gdbarch), val); | |
c00dcbe9 MK |
733 | regcache_raw_write (regcache, regnum, buf); |
734 | } | |
735 | ||
05d1431c | 736 | enum register_status |
2d522557 | 737 | regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf) |
68365089 | 738 | { |
d138e37a | 739 | gdb_assert (regnum >= 0); |
68365089 AC |
740 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); |
741 | if (regnum < regcache->descr->nr_raw_registers) | |
05d1431c | 742 | return regcache_raw_read (regcache, regnum, buf); |
2d28509a | 743 | else if (regcache->readonly_p |
05d1431c PA |
744 | && regcache->register_status[regnum] != REG_UNKNOWN) |
745 | { | |
746 | /* Read-only register cache, perhaps the cooked value was | |
747 | cached? */ | |
05d1431c PA |
748 | if (regcache->register_status[regnum] == REG_VALID) |
749 | memcpy (buf, register_buffer (regcache, regnum), | |
750 | regcache->descr->sizeof_register[regnum]); | |
751 | else | |
752 | memset (buf, 0, regcache->descr->sizeof_register[regnum]); | |
753 | ||
754 | return regcache->register_status[regnum]; | |
755 | } | |
3543a589 TT |
756 | else if (gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch)) |
757 | { | |
758 | struct value *mark, *computed; | |
759 | enum register_status result = REG_VALID; | |
760 | ||
761 | mark = value_mark (); | |
762 | ||
763 | computed = gdbarch_pseudo_register_read_value (regcache->descr->gdbarch, | |
764 | regcache, regnum); | |
765 | if (value_entirely_available (computed)) | |
766 | memcpy (buf, value_contents_raw (computed), | |
767 | regcache->descr->sizeof_register[regnum]); | |
768 | else | |
769 | { | |
770 | memset (buf, 0, regcache->descr->sizeof_register[regnum]); | |
771 | result = REG_UNAVAILABLE; | |
772 | } | |
773 | ||
774 | value_free_to_mark (mark); | |
775 | ||
776 | return result; | |
777 | } | |
d138e37a | 778 | else |
05d1431c PA |
779 | return gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache, |
780 | regnum, buf); | |
61a0eb5b AC |
781 | } |
782 | ||
3543a589 TT |
783 | struct value * |
784 | regcache_cooked_read_value (struct regcache *regcache, int regnum) | |
785 | { | |
786 | gdb_assert (regnum >= 0); | |
787 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); | |
788 | ||
789 | if (regnum < regcache->descr->nr_raw_registers | |
790 | || (regcache->readonly_p | |
791 | && regcache->register_status[regnum] != REG_UNKNOWN) | |
792 | || !gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch)) | |
793 | { | |
794 | struct value *result; | |
795 | ||
796 | result = allocate_value (register_type (regcache->descr->gdbarch, | |
797 | regnum)); | |
798 | VALUE_LVAL (result) = lval_register; | |
799 | VALUE_REGNUM (result) = regnum; | |
800 | ||
801 | /* It is more efficient in general to do this delegation in this | |
802 | direction than in the other one, even though the value-based | |
803 | API is preferred. */ | |
804 | if (regcache_cooked_read (regcache, regnum, | |
805 | value_contents_raw (result)) == REG_UNAVAILABLE) | |
806 | mark_value_bytes_unavailable (result, 0, | |
807 | TYPE_LENGTH (value_type (result))); | |
808 | ||
809 | return result; | |
810 | } | |
811 | else | |
812 | return gdbarch_pseudo_register_read_value (regcache->descr->gdbarch, | |
813 | regcache, regnum); | |
814 | } | |
815 | ||
05d1431c | 816 | enum register_status |
a378f419 AC |
817 | regcache_cooked_read_signed (struct regcache *regcache, int regnum, |
818 | LONGEST *val) | |
819 | { | |
05d1431c | 820 | enum register_status status; |
2d522557 | 821 | gdb_byte *buf; |
123f5f96 | 822 | |
a378f419 | 823 | gdb_assert (regcache != NULL); |
a66a9c23 | 824 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers); |
a378f419 | 825 | buf = alloca (regcache->descr->sizeof_register[regnum]); |
05d1431c PA |
826 | status = regcache_cooked_read (regcache, regnum, buf); |
827 | if (status == REG_VALID) | |
828 | *val = extract_signed_integer | |
829 | (buf, regcache->descr->sizeof_register[regnum], | |
830 | gdbarch_byte_order (regcache->descr->gdbarch)); | |
831 | else | |
832 | *val = 0; | |
833 | return status; | |
a378f419 AC |
834 | } |
835 | ||
05d1431c | 836 | enum register_status |
a378f419 AC |
837 | regcache_cooked_read_unsigned (struct regcache *regcache, int regnum, |
838 | ULONGEST *val) | |
839 | { | |
05d1431c | 840 | enum register_status status; |
2d522557 | 841 | gdb_byte *buf; |
123f5f96 | 842 | |
a378f419 | 843 | gdb_assert (regcache != NULL); |
a66a9c23 | 844 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers); |
a378f419 | 845 | buf = alloca (regcache->descr->sizeof_register[regnum]); |
05d1431c PA |
846 | status = regcache_cooked_read (regcache, regnum, buf); |
847 | if (status == REG_VALID) | |
848 | *val = extract_unsigned_integer | |
849 | (buf, regcache->descr->sizeof_register[regnum], | |
850 | gdbarch_byte_order (regcache->descr->gdbarch)); | |
851 | else | |
852 | *val = 0; | |
853 | return status; | |
a378f419 AC |
854 | } |
855 | ||
a66a9c23 AC |
856 | void |
857 | regcache_cooked_write_signed (struct regcache *regcache, int regnum, | |
858 | LONGEST val) | |
859 | { | |
860 | void *buf; | |
123f5f96 | 861 | |
a66a9c23 AC |
862 | gdb_assert (regcache != NULL); |
863 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers); | |
864 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
e17a4113 UW |
865 | store_signed_integer (buf, regcache->descr->sizeof_register[regnum], |
866 | gdbarch_byte_order (regcache->descr->gdbarch), val); | |
a66a9c23 AC |
867 | regcache_cooked_write (regcache, regnum, buf); |
868 | } | |
869 | ||
870 | void | |
871 | regcache_cooked_write_unsigned (struct regcache *regcache, int regnum, | |
872 | ULONGEST val) | |
873 | { | |
874 | void *buf; | |
123f5f96 | 875 | |
a66a9c23 AC |
876 | gdb_assert (regcache != NULL); |
877 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers); | |
878 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
e17a4113 UW |
879 | store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], |
880 | gdbarch_byte_order (regcache->descr->gdbarch), val); | |
a66a9c23 AC |
881 | regcache_cooked_write (regcache, regnum, buf); |
882 | } | |
883 | ||
61a0eb5b | 884 | void |
2d522557 AC |
885 | regcache_raw_write (struct regcache *regcache, int regnum, |
886 | const gdb_byte *buf) | |
61a0eb5b | 887 | { |
b94ade42 PL |
888 | struct cleanup *chain_before_save_inferior; |
889 | struct cleanup *chain_before_invalidate_register; | |
594f7785 | 890 | |
3fadccb3 AC |
891 | gdb_assert (regcache != NULL && buf != NULL); |
892 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
2d28509a | 893 | gdb_assert (!regcache->readonly_p); |
3fadccb3 | 894 | |
3fadccb3 AC |
895 | /* On the sparc, writing %g0 is a no-op, so we don't even want to |
896 | change the registers array if something writes to this register. */ | |
214e098a | 897 | if (gdbarch_cannot_store_register (get_regcache_arch (regcache), regnum)) |
3fadccb3 AC |
898 | return; |
899 | ||
3fadccb3 | 900 | /* If we have a valid copy of the register, and new value == old |
0df8b418 | 901 | value, then don't bother doing the actual store. */ |
ee99023e | 902 | if (regcache_register_status (regcache, regnum) == REG_VALID |
3fadccb3 AC |
903 | && (memcmp (register_buffer (regcache, regnum), buf, |
904 | regcache->descr->sizeof_register[regnum]) == 0)) | |
905 | return; | |
906 | ||
b94ade42 | 907 | chain_before_save_inferior = save_inferior_ptid (); |
594f7785 UW |
908 | inferior_ptid = regcache->ptid; |
909 | ||
316f2060 | 910 | target_prepare_to_store (regcache); |
3fadccb3 AC |
911 | memcpy (register_buffer (regcache, regnum), buf, |
912 | regcache->descr->sizeof_register[regnum]); | |
ee99023e | 913 | regcache->register_status[regnum] = REG_VALID; |
b94ade42 PL |
914 | |
915 | /* Register a cleanup function for invalidating the register after it is | |
916 | written, in case of a failure. */ | |
917 | chain_before_invalidate_register | |
918 | = make_cleanup_regcache_invalidate (regcache, regnum); | |
919 | ||
56be3814 | 920 | target_store_registers (regcache, regnum); |
594f7785 | 921 | |
b94ade42 PL |
922 | /* The target did not throw an error so we can discard invalidating the |
923 | register and restore the cleanup chain to what it was. */ | |
924 | discard_cleanups (chain_before_invalidate_register); | |
925 | ||
926 | do_cleanups (chain_before_save_inferior); | |
61a0eb5b AC |
927 | } |
928 | ||
68365089 | 929 | void |
2d522557 AC |
930 | regcache_cooked_write (struct regcache *regcache, int regnum, |
931 | const gdb_byte *buf) | |
68365089 | 932 | { |
d138e37a | 933 | gdb_assert (regnum >= 0); |
68365089 AC |
934 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); |
935 | if (regnum < regcache->descr->nr_raw_registers) | |
936 | regcache_raw_write (regcache, regnum, buf); | |
d138e37a | 937 | else |
68365089 | 938 | gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache, |
d8124050 | 939 | regnum, buf); |
61a0eb5b AC |
940 | } |
941 | ||
06c0b04e AC |
942 | /* Perform a partial register transfer using a read, modify, write |
943 | operation. */ | |
944 | ||
945 | typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum, | |
946 | void *buf); | |
947 | typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum, | |
948 | const void *buf); | |
949 | ||
05d1431c | 950 | static enum register_status |
06c0b04e AC |
951 | regcache_xfer_part (struct regcache *regcache, int regnum, |
952 | int offset, int len, void *in, const void *out, | |
05d1431c PA |
953 | enum register_status (*read) (struct regcache *regcache, |
954 | int regnum, | |
955 | gdb_byte *buf), | |
2d522557 AC |
956 | void (*write) (struct regcache *regcache, int regnum, |
957 | const gdb_byte *buf)) | |
06c0b04e AC |
958 | { |
959 | struct regcache_descr *descr = regcache->descr; | |
fc1a4b47 | 960 | gdb_byte reg[MAX_REGISTER_SIZE]; |
123f5f96 | 961 | |
06c0b04e AC |
962 | gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]); |
963 | gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]); | |
964 | /* Something to do? */ | |
965 | if (offset + len == 0) | |
05d1431c | 966 | return REG_VALID; |
0df8b418 | 967 | /* Read (when needed) ... */ |
06c0b04e AC |
968 | if (in != NULL |
969 | || offset > 0 | |
970 | || offset + len < descr->sizeof_register[regnum]) | |
971 | { | |
05d1431c PA |
972 | enum register_status status; |
973 | ||
06c0b04e | 974 | gdb_assert (read != NULL); |
05d1431c PA |
975 | status = read (regcache, regnum, reg); |
976 | if (status != REG_VALID) | |
977 | return status; | |
06c0b04e | 978 | } |
0df8b418 | 979 | /* ... modify ... */ |
06c0b04e AC |
980 | if (in != NULL) |
981 | memcpy (in, reg + offset, len); | |
982 | if (out != NULL) | |
983 | memcpy (reg + offset, out, len); | |
984 | /* ... write (when needed). */ | |
985 | if (out != NULL) | |
986 | { | |
987 | gdb_assert (write != NULL); | |
988 | write (regcache, regnum, reg); | |
989 | } | |
05d1431c PA |
990 | |
991 | return REG_VALID; | |
06c0b04e AC |
992 | } |
993 | ||
05d1431c | 994 | enum register_status |
06c0b04e | 995 | regcache_raw_read_part (struct regcache *regcache, int regnum, |
2d522557 | 996 | int offset, int len, gdb_byte *buf) |
06c0b04e AC |
997 | { |
998 | struct regcache_descr *descr = regcache->descr; | |
123f5f96 | 999 | |
06c0b04e | 1000 | gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); |
05d1431c PA |
1001 | return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, |
1002 | regcache_raw_read, regcache_raw_write); | |
06c0b04e AC |
1003 | } |
1004 | ||
1005 | void | |
1006 | regcache_raw_write_part (struct regcache *regcache, int regnum, | |
2d522557 | 1007 | int offset, int len, const gdb_byte *buf) |
06c0b04e AC |
1008 | { |
1009 | struct regcache_descr *descr = regcache->descr; | |
123f5f96 | 1010 | |
06c0b04e AC |
1011 | gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); |
1012 | regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, | |
1013 | regcache_raw_read, regcache_raw_write); | |
1014 | } | |
1015 | ||
05d1431c | 1016 | enum register_status |
06c0b04e | 1017 | regcache_cooked_read_part (struct regcache *regcache, int regnum, |
2d522557 | 1018 | int offset, int len, gdb_byte *buf) |
06c0b04e AC |
1019 | { |
1020 | struct regcache_descr *descr = regcache->descr; | |
123f5f96 | 1021 | |
06c0b04e | 1022 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); |
05d1431c PA |
1023 | return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, |
1024 | regcache_cooked_read, regcache_cooked_write); | |
06c0b04e AC |
1025 | } |
1026 | ||
1027 | void | |
1028 | regcache_cooked_write_part (struct regcache *regcache, int regnum, | |
2d522557 | 1029 | int offset, int len, const gdb_byte *buf) |
06c0b04e AC |
1030 | { |
1031 | struct regcache_descr *descr = regcache->descr; | |
123f5f96 | 1032 | |
06c0b04e AC |
1033 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); |
1034 | regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, | |
1035 | regcache_cooked_read, regcache_cooked_write); | |
1036 | } | |
32178cab | 1037 | |
a16d75cc | 1038 | /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */ |
9a661b68 MK |
1039 | |
1040 | void | |
6618125d | 1041 | regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf) |
9a661b68 MK |
1042 | { |
1043 | void *regbuf; | |
1044 | size_t size; | |
1045 | ||
a16d75cc | 1046 | gdb_assert (regcache != NULL); |
9a661b68 MK |
1047 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); |
1048 | gdb_assert (!regcache->readonly_p); | |
1049 | ||
9a661b68 MK |
1050 | regbuf = register_buffer (regcache, regnum); |
1051 | size = regcache->descr->sizeof_register[regnum]; | |
1052 | ||
1053 | if (buf) | |
ee99023e PA |
1054 | { |
1055 | memcpy (regbuf, buf, size); | |
1056 | regcache->register_status[regnum] = REG_VALID; | |
1057 | } | |
9a661b68 | 1058 | else |
ee99023e PA |
1059 | { |
1060 | /* This memset not strictly necessary, but better than garbage | |
1061 | in case the register value manages to escape somewhere (due | |
1062 | to a bug, no less). */ | |
1063 | memset (regbuf, 0, size); | |
1064 | regcache->register_status[regnum] = REG_UNAVAILABLE; | |
1065 | } | |
9a661b68 MK |
1066 | } |
1067 | ||
1068 | /* Collect register REGNUM from REGCACHE and store its contents in BUF. */ | |
1069 | ||
1070 | void | |
6618125d | 1071 | regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf) |
9a661b68 MK |
1072 | { |
1073 | const void *regbuf; | |
1074 | size_t size; | |
1075 | ||
1076 | gdb_assert (regcache != NULL && buf != NULL); | |
1077 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
1078 | ||
1079 | regbuf = register_buffer (regcache, regnum); | |
1080 | size = regcache->descr->sizeof_register[regnum]; | |
1081 | memcpy (buf, regbuf, size); | |
1082 | } | |
1083 | ||
0b309272 AA |
1084 | /* Transfer a single or all registers belonging to a certain register |
1085 | set to or from a buffer. This is the main worker function for | |
1086 | regcache_supply_regset and regcache_collect_regset. */ | |
1087 | ||
1088 | static void | |
1089 | regcache_transfer_regset (const struct regset *regset, | |
1090 | const struct regcache *regcache, | |
1091 | struct regcache *out_regcache, | |
1092 | int regnum, const void *in_buf, | |
1093 | void *out_buf, size_t size) | |
1094 | { | |
1095 | const struct regcache_map_entry *map; | |
1096 | int offs = 0, count; | |
1097 | ||
1098 | for (map = regset->regmap; (count = map->count) != 0; map++) | |
1099 | { | |
1100 | int regno = map->regno; | |
1101 | int slot_size = map->size; | |
1102 | ||
1103 | if (slot_size == 0 && regno != REGCACHE_MAP_SKIP) | |
1104 | slot_size = regcache->descr->sizeof_register[regno]; | |
1105 | ||
1106 | if (regno == REGCACHE_MAP_SKIP | |
1107 | || (regnum != -1 | |
1108 | && (regnum < regno || regnum >= regno + count))) | |
1109 | offs += count * slot_size; | |
1110 | ||
1111 | else if (regnum == -1) | |
1112 | for (; count--; regno++, offs += slot_size) | |
1113 | { | |
1114 | if (offs + slot_size > size) | |
1115 | break; | |
1116 | ||
1117 | if (out_buf) | |
1118 | regcache_raw_collect (regcache, regno, | |
1119 | (gdb_byte *) out_buf + offs); | |
1120 | else | |
1121 | regcache_raw_supply (out_regcache, regno, in_buf | |
1122 | ? (const gdb_byte *) in_buf + offs | |
1123 | : NULL); | |
1124 | } | |
1125 | else | |
1126 | { | |
1127 | /* Transfer a single register and return. */ | |
1128 | offs += (regnum - regno) * slot_size; | |
1129 | if (offs + slot_size > size) | |
1130 | return; | |
1131 | ||
1132 | if (out_buf) | |
1133 | regcache_raw_collect (regcache, regnum, | |
1134 | (gdb_byte *) out_buf + offs); | |
1135 | else | |
1136 | regcache_raw_supply (out_regcache, regnum, in_buf | |
1137 | ? (const gdb_byte *) in_buf + offs | |
1138 | : NULL); | |
1139 | return; | |
1140 | } | |
1141 | } | |
1142 | } | |
1143 | ||
1144 | /* Supply register REGNUM from BUF to REGCACHE, using the register map | |
1145 | in REGSET. If REGNUM is -1, do this for all registers in REGSET. | |
1146 | If BUF is NULL, set the register(s) to "unavailable" status. */ | |
1147 | ||
1148 | void | |
1149 | regcache_supply_regset (const struct regset *regset, | |
1150 | struct regcache *regcache, | |
1151 | int regnum, const void *buf, size_t size) | |
1152 | { | |
1153 | regcache_transfer_regset (regset, regcache, regcache, regnum, | |
1154 | buf, NULL, size); | |
1155 | } | |
1156 | ||
1157 | /* Collect register REGNUM from REGCACHE to BUF, using the register | |
1158 | map in REGSET. If REGNUM is -1, do this for all registers in | |
1159 | REGSET. */ | |
1160 | ||
1161 | void | |
1162 | regcache_collect_regset (const struct regset *regset, | |
1163 | const struct regcache *regcache, | |
1164 | int regnum, void *buf, size_t size) | |
1165 | { | |
1166 | regcache_transfer_regset (regset, regcache, NULL, regnum, | |
1167 | NULL, buf, size); | |
1168 | } | |
1169 | ||
193cb69f | 1170 | |
515630c5 | 1171 | /* Special handling for register PC. */ |
32178cab MS |
1172 | |
1173 | CORE_ADDR | |
515630c5 | 1174 | regcache_read_pc (struct regcache *regcache) |
32178cab | 1175 | { |
61a1198a UW |
1176 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1177 | ||
32178cab MS |
1178 | CORE_ADDR pc_val; |
1179 | ||
61a1198a UW |
1180 | if (gdbarch_read_pc_p (gdbarch)) |
1181 | pc_val = gdbarch_read_pc (gdbarch, regcache); | |
cde9ea48 | 1182 | /* Else use per-frame method on get_current_frame. */ |
214e098a | 1183 | else if (gdbarch_pc_regnum (gdbarch) >= 0) |
cde9ea48 | 1184 | { |
61a1198a | 1185 | ULONGEST raw_val; |
123f5f96 | 1186 | |
05d1431c PA |
1187 | if (regcache_cooked_read_unsigned (regcache, |
1188 | gdbarch_pc_regnum (gdbarch), | |
1189 | &raw_val) == REG_UNAVAILABLE) | |
1190 | throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available")); | |
1191 | ||
214e098a | 1192 | pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val); |
cde9ea48 AC |
1193 | } |
1194 | else | |
515630c5 UW |
1195 | internal_error (__FILE__, __LINE__, |
1196 | _("regcache_read_pc: Unable to find PC")); | |
32178cab MS |
1197 | return pc_val; |
1198 | } | |
1199 | ||
32178cab | 1200 | void |
515630c5 | 1201 | regcache_write_pc (struct regcache *regcache, CORE_ADDR pc) |
32178cab | 1202 | { |
61a1198a UW |
1203 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1204 | ||
61a1198a UW |
1205 | if (gdbarch_write_pc_p (gdbarch)) |
1206 | gdbarch_write_pc (gdbarch, regcache, pc); | |
214e098a | 1207 | else if (gdbarch_pc_regnum (gdbarch) >= 0) |
3e8c568d | 1208 | regcache_cooked_write_unsigned (regcache, |
214e098a | 1209 | gdbarch_pc_regnum (gdbarch), pc); |
61a1198a UW |
1210 | else |
1211 | internal_error (__FILE__, __LINE__, | |
515630c5 | 1212 | _("regcache_write_pc: Unable to update PC")); |
edb3359d DJ |
1213 | |
1214 | /* Writing the PC (for instance, from "load") invalidates the | |
1215 | current frame. */ | |
1216 | reinit_frame_cache (); | |
32178cab MS |
1217 | } |
1218 | ||
32178cab | 1219 | |
705152c5 MS |
1220 | static void |
1221 | reg_flush_command (char *command, int from_tty) | |
1222 | { | |
1223 | /* Force-flush the register cache. */ | |
1224 | registers_changed (); | |
1225 | if (from_tty) | |
a3f17187 | 1226 | printf_filtered (_("Register cache flushed.\n")); |
705152c5 MS |
1227 | } |
1228 | ||
af030b9a AC |
1229 | enum regcache_dump_what |
1230 | { | |
3e43a32a | 1231 | regcache_dump_none, regcache_dump_raw, |
c21236dc PA |
1232 | regcache_dump_cooked, regcache_dump_groups, |
1233 | regcache_dump_remote | |
af030b9a AC |
1234 | }; |
1235 | ||
1236 | static void | |
1237 | regcache_dump (struct regcache *regcache, struct ui_file *file, | |
1238 | enum regcache_dump_what what_to_dump) | |
1239 | { | |
1240 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); | |
b59ff9d5 | 1241 | struct gdbarch *gdbarch = regcache->descr->gdbarch; |
af030b9a AC |
1242 | int regnum; |
1243 | int footnote_nr = 0; | |
1244 | int footnote_register_size = 0; | |
1245 | int footnote_register_offset = 0; | |
1246 | int footnote_register_type_name_null = 0; | |
1247 | long register_offset = 0; | |
e362b510 | 1248 | gdb_byte buf[MAX_REGISTER_SIZE]; |
af030b9a AC |
1249 | |
1250 | #if 0 | |
af030b9a AC |
1251 | fprintf_unfiltered (file, "nr_raw_registers %d\n", |
1252 | regcache->descr->nr_raw_registers); | |
1253 | fprintf_unfiltered (file, "nr_cooked_registers %d\n", | |
1254 | regcache->descr->nr_cooked_registers); | |
1255 | fprintf_unfiltered (file, "sizeof_raw_registers %ld\n", | |
1256 | regcache->descr->sizeof_raw_registers); | |
ee99023e PA |
1257 | fprintf_unfiltered (file, "sizeof_raw_register_status %ld\n", |
1258 | regcache->descr->sizeof_raw_register_status); | |
f57d151a | 1259 | fprintf_unfiltered (file, "gdbarch_num_regs %d\n", |
214e098a | 1260 | gdbarch_num_regs (gdbarch)); |
f57d151a | 1261 | fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n", |
214e098a | 1262 | gdbarch_num_pseudo_regs (gdbarch)); |
af030b9a AC |
1263 | #endif |
1264 | ||
1265 | gdb_assert (regcache->descr->nr_cooked_registers | |
214e098a UW |
1266 | == (gdbarch_num_regs (gdbarch) |
1267 | + gdbarch_num_pseudo_regs (gdbarch))); | |
af030b9a AC |
1268 | |
1269 | for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++) | |
1270 | { | |
1271 | /* Name. */ | |
1272 | if (regnum < 0) | |
1273 | fprintf_unfiltered (file, " %-10s", "Name"); | |
1274 | else | |
1275 | { | |
214e098a | 1276 | const char *p = gdbarch_register_name (gdbarch, regnum); |
123f5f96 | 1277 | |
af030b9a AC |
1278 | if (p == NULL) |
1279 | p = ""; | |
1280 | else if (p[0] == '\0') | |
1281 | p = "''"; | |
1282 | fprintf_unfiltered (file, " %-10s", p); | |
1283 | } | |
1284 | ||
1285 | /* Number. */ | |
1286 | if (regnum < 0) | |
1287 | fprintf_unfiltered (file, " %4s", "Nr"); | |
1288 | else | |
1289 | fprintf_unfiltered (file, " %4d", regnum); | |
1290 | ||
1291 | /* Relative number. */ | |
1292 | if (regnum < 0) | |
1293 | fprintf_unfiltered (file, " %4s", "Rel"); | |
214e098a | 1294 | else if (regnum < gdbarch_num_regs (gdbarch)) |
af030b9a AC |
1295 | fprintf_unfiltered (file, " %4d", regnum); |
1296 | else | |
f57d151a | 1297 | fprintf_unfiltered (file, " %4d", |
214e098a | 1298 | (regnum - gdbarch_num_regs (gdbarch))); |
af030b9a AC |
1299 | |
1300 | /* Offset. */ | |
1301 | if (regnum < 0) | |
1302 | fprintf_unfiltered (file, " %6s ", "Offset"); | |
1303 | else | |
1304 | { | |
1305 | fprintf_unfiltered (file, " %6ld", | |
1306 | regcache->descr->register_offset[regnum]); | |
a7e3c2ad | 1307 | if (register_offset != regcache->descr->register_offset[regnum] |
d3b22ed5 AC |
1308 | || (regnum > 0 |
1309 | && (regcache->descr->register_offset[regnum] | |
1310 | != (regcache->descr->register_offset[regnum - 1] | |
1311 | + regcache->descr->sizeof_register[regnum - 1]))) | |
1312 | ) | |
af030b9a AC |
1313 | { |
1314 | if (!footnote_register_offset) | |
1315 | footnote_register_offset = ++footnote_nr; | |
1316 | fprintf_unfiltered (file, "*%d", footnote_register_offset); | |
1317 | } | |
1318 | else | |
1319 | fprintf_unfiltered (file, " "); | |
1320 | register_offset = (regcache->descr->register_offset[regnum] | |
1321 | + regcache->descr->sizeof_register[regnum]); | |
1322 | } | |
1323 | ||
1324 | /* Size. */ | |
1325 | if (regnum < 0) | |
1326 | fprintf_unfiltered (file, " %5s ", "Size"); | |
1327 | else | |
01e1877c AC |
1328 | fprintf_unfiltered (file, " %5ld", |
1329 | regcache->descr->sizeof_register[regnum]); | |
af030b9a AC |
1330 | |
1331 | /* Type. */ | |
b59ff9d5 AC |
1332 | { |
1333 | const char *t; | |
123f5f96 | 1334 | |
b59ff9d5 AC |
1335 | if (regnum < 0) |
1336 | t = "Type"; | |
1337 | else | |
1338 | { | |
1339 | static const char blt[] = "builtin_type"; | |
123f5f96 | 1340 | |
b59ff9d5 AC |
1341 | t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum)); |
1342 | if (t == NULL) | |
1343 | { | |
1344 | char *n; | |
123f5f96 | 1345 | |
b59ff9d5 AC |
1346 | if (!footnote_register_type_name_null) |
1347 | footnote_register_type_name_null = ++footnote_nr; | |
b435e160 | 1348 | n = xstrprintf ("*%d", footnote_register_type_name_null); |
b59ff9d5 AC |
1349 | make_cleanup (xfree, n); |
1350 | t = n; | |
1351 | } | |
1352 | /* Chop a leading builtin_type. */ | |
61012eef | 1353 | if (startswith (t, blt)) |
b59ff9d5 AC |
1354 | t += strlen (blt); |
1355 | } | |
1356 | fprintf_unfiltered (file, " %-15s", t); | |
1357 | } | |
1358 | ||
1359 | /* Leading space always present. */ | |
1360 | fprintf_unfiltered (file, " "); | |
af030b9a AC |
1361 | |
1362 | /* Value, raw. */ | |
1363 | if (what_to_dump == regcache_dump_raw) | |
1364 | { | |
1365 | if (regnum < 0) | |
1366 | fprintf_unfiltered (file, "Raw value"); | |
1367 | else if (regnum >= regcache->descr->nr_raw_registers) | |
1368 | fprintf_unfiltered (file, "<cooked>"); | |
ee99023e | 1369 | else if (regcache_register_status (regcache, regnum) == REG_UNKNOWN) |
af030b9a | 1370 | fprintf_unfiltered (file, "<invalid>"); |
ee99023e PA |
1371 | else if (regcache_register_status (regcache, regnum) == REG_UNAVAILABLE) |
1372 | fprintf_unfiltered (file, "<unavailable>"); | |
af030b9a AC |
1373 | else |
1374 | { | |
1375 | regcache_raw_read (regcache, regnum, buf); | |
d3eaaf66 AB |
1376 | print_hex_chars (file, buf, |
1377 | regcache->descr->sizeof_register[regnum], | |
1378 | gdbarch_byte_order (gdbarch)); | |
af030b9a AC |
1379 | } |
1380 | } | |
1381 | ||
1382 | /* Value, cooked. */ | |
1383 | if (what_to_dump == regcache_dump_cooked) | |
1384 | { | |
1385 | if (regnum < 0) | |
1386 | fprintf_unfiltered (file, "Cooked value"); | |
1387 | else | |
1388 | { | |
05d1431c PA |
1389 | enum register_status status; |
1390 | ||
1391 | status = regcache_cooked_read (regcache, regnum, buf); | |
1392 | if (status == REG_UNKNOWN) | |
1393 | fprintf_unfiltered (file, "<invalid>"); | |
1394 | else if (status == REG_UNAVAILABLE) | |
1395 | fprintf_unfiltered (file, "<unavailable>"); | |
1396 | else | |
d3eaaf66 AB |
1397 | print_hex_chars (file, buf, |
1398 | regcache->descr->sizeof_register[regnum], | |
1399 | gdbarch_byte_order (gdbarch)); | |
af030b9a AC |
1400 | } |
1401 | } | |
1402 | ||
b59ff9d5 AC |
1403 | /* Group members. */ |
1404 | if (what_to_dump == regcache_dump_groups) | |
1405 | { | |
1406 | if (regnum < 0) | |
1407 | fprintf_unfiltered (file, "Groups"); | |
1408 | else | |
1409 | { | |
b59ff9d5 | 1410 | const char *sep = ""; |
6c7d17ba | 1411 | struct reggroup *group; |
123f5f96 | 1412 | |
6c7d17ba AC |
1413 | for (group = reggroup_next (gdbarch, NULL); |
1414 | group != NULL; | |
1415 | group = reggroup_next (gdbarch, group)) | |
b59ff9d5 | 1416 | { |
6c7d17ba | 1417 | if (gdbarch_register_reggroup_p (gdbarch, regnum, group)) |
b59ff9d5 | 1418 | { |
3e43a32a MS |
1419 | fprintf_unfiltered (file, |
1420 | "%s%s", sep, reggroup_name (group)); | |
b59ff9d5 AC |
1421 | sep = ","; |
1422 | } | |
1423 | } | |
1424 | } | |
1425 | } | |
1426 | ||
c21236dc PA |
1427 | /* Remote packet configuration. */ |
1428 | if (what_to_dump == regcache_dump_remote) | |
1429 | { | |
1430 | if (regnum < 0) | |
1431 | { | |
1432 | fprintf_unfiltered (file, "Rmt Nr g/G Offset"); | |
1433 | } | |
1434 | else if (regnum < regcache->descr->nr_raw_registers) | |
1435 | { | |
1436 | int pnum, poffset; | |
1437 | ||
1438 | if (remote_register_number_and_offset (get_regcache_arch (regcache), regnum, | |
1439 | &pnum, &poffset)) | |
1440 | fprintf_unfiltered (file, "%7d %11d", pnum, poffset); | |
1441 | } | |
1442 | } | |
1443 | ||
af030b9a AC |
1444 | fprintf_unfiltered (file, "\n"); |
1445 | } | |
1446 | ||
1447 | if (footnote_register_size) | |
1448 | fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n", | |
1449 | footnote_register_size); | |
1450 | if (footnote_register_offset) | |
1451 | fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n", | |
1452 | footnote_register_offset); | |
1453 | if (footnote_register_type_name_null) | |
1454 | fprintf_unfiltered (file, | |
1455 | "*%d: Register type's name NULL.\n", | |
1456 | footnote_register_type_name_null); | |
1457 | do_cleanups (cleanups); | |
1458 | } | |
1459 | ||
1460 | static void | |
1461 | regcache_print (char *args, enum regcache_dump_what what_to_dump) | |
1462 | { | |
1463 | if (args == NULL) | |
28c38f10 | 1464 | regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump); |
af030b9a AC |
1465 | else |
1466 | { | |
724b958c | 1467 | struct cleanup *cleanups; |
af030b9a | 1468 | struct ui_file *file = gdb_fopen (args, "w"); |
123f5f96 | 1469 | |
af030b9a | 1470 | if (file == NULL) |
e2e0b3e5 | 1471 | perror_with_name (_("maintenance print architecture")); |
724b958c | 1472 | cleanups = make_cleanup_ui_file_delete (file); |
28c38f10 | 1473 | regcache_dump (get_current_regcache (), file, what_to_dump); |
724b958c | 1474 | do_cleanups (cleanups); |
af030b9a AC |
1475 | } |
1476 | } | |
1477 | ||
1478 | static void | |
1479 | maintenance_print_registers (char *args, int from_tty) | |
1480 | { | |
1481 | regcache_print (args, regcache_dump_none); | |
1482 | } | |
1483 | ||
1484 | static void | |
1485 | maintenance_print_raw_registers (char *args, int from_tty) | |
1486 | { | |
1487 | regcache_print (args, regcache_dump_raw); | |
1488 | } | |
1489 | ||
1490 | static void | |
1491 | maintenance_print_cooked_registers (char *args, int from_tty) | |
1492 | { | |
1493 | regcache_print (args, regcache_dump_cooked); | |
1494 | } | |
1495 | ||
b59ff9d5 AC |
1496 | static void |
1497 | maintenance_print_register_groups (char *args, int from_tty) | |
1498 | { | |
1499 | regcache_print (args, regcache_dump_groups); | |
1500 | } | |
1501 | ||
c21236dc PA |
1502 | static void |
1503 | maintenance_print_remote_registers (char *args, int from_tty) | |
1504 | { | |
1505 | regcache_print (args, regcache_dump_remote); | |
1506 | } | |
1507 | ||
b9362cc7 AC |
1508 | extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */ |
1509 | ||
32178cab MS |
1510 | void |
1511 | _initialize_regcache (void) | |
1512 | { | |
3e43a32a MS |
1513 | regcache_descr_handle |
1514 | = gdbarch_data_register_post_init (init_regcache_descr); | |
705152c5 | 1515 | |
f4c5303c | 1516 | observer_attach_target_changed (regcache_observer_target_changed); |
5231c1fd | 1517 | observer_attach_thread_ptid_changed (regcache_thread_ptid_changed); |
f4c5303c | 1518 | |
705152c5 | 1519 | add_com ("flushregs", class_maintenance, reg_flush_command, |
1bedd215 | 1520 | _("Force gdb to flush its register cache (maintainer command)")); |
39f77062 | 1521 | |
3e43a32a MS |
1522 | add_cmd ("registers", class_maintenance, maintenance_print_registers, |
1523 | _("Print the internal register configuration.\n" | |
1524 | "Takes an optional file parameter."), &maintenanceprintlist); | |
af030b9a | 1525 | add_cmd ("raw-registers", class_maintenance, |
3e43a32a MS |
1526 | maintenance_print_raw_registers, |
1527 | _("Print the internal register configuration " | |
1528 | "including raw values.\n" | |
1529 | "Takes an optional file parameter."), &maintenanceprintlist); | |
af030b9a | 1530 | add_cmd ("cooked-registers", class_maintenance, |
3e43a32a MS |
1531 | maintenance_print_cooked_registers, |
1532 | _("Print the internal register configuration " | |
1533 | "including cooked values.\n" | |
1534 | "Takes an optional file parameter."), &maintenanceprintlist); | |
b59ff9d5 | 1535 | add_cmd ("register-groups", class_maintenance, |
3e43a32a MS |
1536 | maintenance_print_register_groups, |
1537 | _("Print the internal register configuration " | |
1538 | "including each register's group.\n" | |
1539 | "Takes an optional file parameter."), | |
af030b9a | 1540 | &maintenanceprintlist); |
c21236dc PA |
1541 | add_cmd ("remote-registers", class_maintenance, |
1542 | maintenance_print_remote_registers, _("\ | |
1543 | Print the internal register configuration including each register's\n\ | |
1544 | remote register number and buffer offset in the g/G packets.\n\ | |
1545 | Takes an optional file parameter."), | |
1546 | &maintenanceprintlist); | |
af030b9a | 1547 | |
32178cab | 1548 | } |