Commit | Line | Data |
---|---|---|
c906108c SS |
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. | |
4 | ||
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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. | |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b JM |
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, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "symtab.h" | |
24 | #include "gdbtypes.h" | |
25 | #include "frame.h" | |
26 | #include "value.h" | |
27 | #include "gdbcore.h" | |
28 | #include "inferior.h" | |
29 | #include "target.h" | |
30 | #include "gdb_string.h" | |
31 | #include "floatformat.h" | |
c5aa993b | 32 | #include "symfile.h" /* for overlay functions */ |
c906108c SS |
33 | |
34 | /* This is used to indicate that we don't know the format of the floating point | |
35 | number. Typically, this is useful for native ports, where the actual format | |
36 | is irrelevant, since no conversions will be taking place. */ | |
37 | ||
38 | const struct floatformat floatformat_unknown; | |
39 | ||
40 | /* Registers we shouldn't try to store. */ | |
41 | #if !defined (CANNOT_STORE_REGISTER) | |
42 | #define CANNOT_STORE_REGISTER(regno) 0 | |
43 | #endif | |
44 | ||
45 | static void write_register_gen PARAMS ((int, char *)); | |
46 | ||
c5aa993b | 47 | static int read_relative_register_raw_bytes_for_frame PARAMS ((int regnum, char *myaddr, struct frame_info * frame)); |
7a292a7a | 48 | |
c906108c SS |
49 | /* Basic byte-swapping routines. GDB has needed these for a long time... |
50 | All extract a target-format integer at ADDR which is LEN bytes long. */ | |
51 | ||
52 | #if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8 | |
53 | /* 8 bit characters are a pretty safe assumption these days, so we | |
54 | assume it throughout all these swapping routines. If we had to deal with | |
55 | 9 bit characters, we would need to make len be in bits and would have | |
56 | to re-write these routines... */ | |
c5aa993b | 57 | you lose |
c906108c SS |
58 | #endif |
59 | ||
a9ac8f51 AC |
60 | LONGEST |
61 | extract_signed_integer (void *addr, int len) | |
c906108c SS |
62 | { |
63 | LONGEST retval; | |
64 | unsigned char *p; | |
c5aa993b | 65 | unsigned char *startaddr = (unsigned char *) addr; |
c906108c SS |
66 | unsigned char *endaddr = startaddr + len; |
67 | ||
68 | if (len > (int) sizeof (LONGEST)) | |
69 | error ("\ | |
70 | That operation is not available on integers of more than %d bytes.", | |
71 | sizeof (LONGEST)); | |
72 | ||
73 | /* Start at the most significant end of the integer, and work towards | |
74 | the least significant. */ | |
75 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
76 | { | |
77 | p = startaddr; | |
78 | /* Do the sign extension once at the start. */ | |
c5aa993b | 79 | retval = ((LONGEST) * p ^ 0x80) - 0x80; |
c906108c SS |
80 | for (++p; p < endaddr; ++p) |
81 | retval = (retval << 8) | *p; | |
82 | } | |
83 | else | |
84 | { | |
85 | p = endaddr - 1; | |
86 | /* Do the sign extension once at the start. */ | |
c5aa993b | 87 | retval = ((LONGEST) * p ^ 0x80) - 0x80; |
c906108c SS |
88 | for (--p; p >= startaddr; --p) |
89 | retval = (retval << 8) | *p; | |
90 | } | |
91 | return retval; | |
92 | } | |
93 | ||
94 | ULONGEST | |
a9ac8f51 | 95 | extract_unsigned_integer (void *addr, int len) |
c906108c SS |
96 | { |
97 | ULONGEST retval; | |
98 | unsigned char *p; | |
c5aa993b | 99 | unsigned char *startaddr = (unsigned char *) addr; |
c906108c SS |
100 | unsigned char *endaddr = startaddr + len; |
101 | ||
102 | if (len > (int) sizeof (ULONGEST)) | |
103 | error ("\ | |
104 | That operation is not available on integers of more than %d bytes.", | |
105 | sizeof (ULONGEST)); | |
106 | ||
107 | /* Start at the most significant end of the integer, and work towards | |
108 | the least significant. */ | |
109 | retval = 0; | |
110 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
111 | { | |
112 | for (p = startaddr; p < endaddr; ++p) | |
113 | retval = (retval << 8) | *p; | |
114 | } | |
115 | else | |
116 | { | |
117 | for (p = endaddr - 1; p >= startaddr; --p) | |
118 | retval = (retval << 8) | *p; | |
119 | } | |
120 | return retval; | |
121 | } | |
122 | ||
123 | /* Sometimes a long long unsigned integer can be extracted as a | |
124 | LONGEST value. This is done so that we can print these values | |
125 | better. If this integer can be converted to a LONGEST, this | |
126 | function returns 1 and sets *PVAL. Otherwise it returns 0. */ | |
127 | ||
128 | int | |
a9ac8f51 | 129 | extract_long_unsigned_integer (void *addr, int orig_len, LONGEST *pval) |
c906108c SS |
130 | { |
131 | char *p, *first_addr; | |
132 | int len; | |
133 | ||
134 | len = orig_len; | |
135 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
136 | { | |
137 | for (p = (char *) addr; | |
138 | len > (int) sizeof (LONGEST) && p < (char *) addr + orig_len; | |
139 | p++) | |
140 | { | |
141 | if (*p == 0) | |
142 | len--; | |
143 | else | |
144 | break; | |
145 | } | |
146 | first_addr = p; | |
147 | } | |
148 | else | |
149 | { | |
150 | first_addr = (char *) addr; | |
151 | for (p = (char *) addr + orig_len - 1; | |
152 | len > (int) sizeof (LONGEST) && p >= (char *) addr; | |
153 | p--) | |
154 | { | |
155 | if (*p == 0) | |
156 | len--; | |
157 | else | |
158 | break; | |
159 | } | |
160 | } | |
161 | ||
162 | if (len <= (int) sizeof (LONGEST)) | |
163 | { | |
164 | *pval = (LONGEST) extract_unsigned_integer (first_addr, | |
165 | sizeof (LONGEST)); | |
166 | return 1; | |
167 | } | |
168 | ||
169 | return 0; | |
170 | } | |
171 | ||
4478b372 JB |
172 | |
173 | /* Treat the LEN bytes at ADDR as a target-format address, and return | |
174 | that address. ADDR is a buffer in the GDB process, not in the | |
175 | inferior. | |
176 | ||
177 | This function should only be used by target-specific code. It | |
178 | assumes that a pointer has the same representation as that thing's | |
179 | address represented as an integer. Some machines use word | |
180 | addresses, or similarly munged things, for certain types of | |
181 | pointers, so that assumption doesn't hold everywhere. | |
182 | ||
183 | Common code should use extract_typed_address instead, or something | |
184 | else based on POINTER_TO_ADDRESS. */ | |
185 | ||
c906108c | 186 | CORE_ADDR |
a9ac8f51 | 187 | extract_address (void *addr, int len) |
c906108c SS |
188 | { |
189 | /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure | |
190 | whether we want this to be true eventually. */ | |
c5aa993b | 191 | return (CORE_ADDR) extract_unsigned_integer (addr, len); |
c906108c SS |
192 | } |
193 | ||
4478b372 | 194 | |
4478b372 JB |
195 | /* Treat the bytes at BUF as a pointer of type TYPE, and return the |
196 | address it represents. */ | |
197 | CORE_ADDR | |
198 | extract_typed_address (void *buf, struct type *type) | |
199 | { | |
200 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
201 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
c0aba12e | 202 | internal_error ("findvar.c (extract_typed_address): " |
4478b372 JB |
203 | "type is not a pointer or reference"); |
204 | ||
205 | return POINTER_TO_ADDRESS (type, buf); | |
206 | } | |
207 | ||
208 | ||
c906108c | 209 | void |
a9ac8f51 | 210 | store_signed_integer (void *addr, int len, LONGEST val) |
c906108c SS |
211 | { |
212 | unsigned char *p; | |
c5aa993b | 213 | unsigned char *startaddr = (unsigned char *) addr; |
c906108c SS |
214 | unsigned char *endaddr = startaddr + len; |
215 | ||
216 | /* Start at the least significant end of the integer, and work towards | |
217 | the most significant. */ | |
218 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
219 | { | |
220 | for (p = endaddr - 1; p >= startaddr; --p) | |
221 | { | |
222 | *p = val & 0xff; | |
223 | val >>= 8; | |
224 | } | |
225 | } | |
226 | else | |
227 | { | |
228 | for (p = startaddr; p < endaddr; ++p) | |
229 | { | |
230 | *p = val & 0xff; | |
231 | val >>= 8; | |
232 | } | |
233 | } | |
234 | } | |
235 | ||
236 | void | |
a9ac8f51 | 237 | store_unsigned_integer (void *addr, int len, ULONGEST val) |
c906108c SS |
238 | { |
239 | unsigned char *p; | |
c5aa993b | 240 | unsigned char *startaddr = (unsigned char *) addr; |
c906108c SS |
241 | unsigned char *endaddr = startaddr + len; |
242 | ||
243 | /* Start at the least significant end of the integer, and work towards | |
244 | the most significant. */ | |
245 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
246 | { | |
247 | for (p = endaddr - 1; p >= startaddr; --p) | |
248 | { | |
249 | *p = val & 0xff; | |
250 | val >>= 8; | |
251 | } | |
252 | } | |
253 | else | |
254 | { | |
255 | for (p = startaddr; p < endaddr; ++p) | |
256 | { | |
257 | *p = val & 0xff; | |
258 | val >>= 8; | |
259 | } | |
260 | } | |
261 | } | |
262 | ||
4478b372 JB |
263 | /* Store the address VAL as a LEN-byte value in target byte order at |
264 | ADDR. ADDR is a buffer in the GDB process, not in the inferior. | |
265 | ||
266 | This function should only be used by target-specific code. It | |
267 | assumes that a pointer has the same representation as that thing's | |
268 | address represented as an integer. Some machines use word | |
269 | addresses, or similarly munged things, for certain types of | |
270 | pointers, so that assumption doesn't hold everywhere. | |
271 | ||
272 | Common code should use store_typed_address instead, or something else | |
273 | based on ADDRESS_TO_POINTER. */ | |
c906108c | 274 | void |
a9ac8f51 | 275 | store_address (void *addr, int len, LONGEST val) |
c906108c | 276 | { |
c906108c SS |
277 | store_unsigned_integer (addr, len, val); |
278 | } | |
4478b372 JB |
279 | |
280 | ||
4478b372 JB |
281 | /* Store the address ADDR as a pointer of type TYPE at BUF, in target |
282 | form. */ | |
283 | void | |
284 | store_typed_address (void *buf, struct type *type, CORE_ADDR addr) | |
285 | { | |
286 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
287 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
c0aba12e | 288 | internal_error ("findvar.c (store_typed_address): " |
4478b372 JB |
289 | "type is not a pointer or reference"); |
290 | ||
291 | ADDRESS_TO_POINTER (type, buf, addr); | |
292 | } | |
293 | ||
294 | ||
295 | ||
c906108c | 296 | \f |
c906108c SS |
297 | /* Extract a floating-point number from a target-order byte-stream at ADDR. |
298 | Returns the value as type DOUBLEST. | |
299 | ||
300 | If the host and target formats agree, we just copy the raw data into the | |
301 | appropriate type of variable and return, letting the host increase precision | |
302 | as necessary. Otherwise, we call the conversion routine and let it do the | |
303 | dirty work. */ | |
304 | ||
305 | DOUBLEST | |
3db87ba3 | 306 | extract_floating (void *addr, int len) |
c906108c SS |
307 | { |
308 | DOUBLEST dretval; | |
309 | ||
3db87ba3 | 310 | if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT) |
c906108c SS |
311 | { |
312 | if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT) | |
313 | { | |
314 | float retval; | |
315 | ||
316 | memcpy (&retval, addr, sizeof (retval)); | |
317 | return retval; | |
318 | } | |
319 | else | |
320 | floatformat_to_doublest (TARGET_FLOAT_FORMAT, addr, &dretval); | |
321 | } | |
3db87ba3 | 322 | else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT) |
c906108c SS |
323 | { |
324 | if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT) | |
325 | { | |
326 | double retval; | |
327 | ||
328 | memcpy (&retval, addr, sizeof (retval)); | |
329 | return retval; | |
330 | } | |
331 | else | |
332 | floatformat_to_doublest (TARGET_DOUBLE_FORMAT, addr, &dretval); | |
333 | } | |
3db87ba3 | 334 | else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT) |
c906108c SS |
335 | { |
336 | if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT) | |
337 | { | |
338 | DOUBLEST retval; | |
339 | ||
340 | memcpy (&retval, addr, sizeof (retval)); | |
341 | return retval; | |
342 | } | |
343 | else | |
344 | floatformat_to_doublest (TARGET_LONG_DOUBLE_FORMAT, addr, &dretval); | |
345 | } | |
346 | else | |
347 | { | |
348 | error ("Can't deal with a floating point number of %d bytes.", len); | |
349 | } | |
350 | ||
351 | return dretval; | |
352 | } | |
353 | ||
354 | void | |
3db87ba3 | 355 | store_floating (void *addr, int len, DOUBLEST val) |
c906108c | 356 | { |
3db87ba3 | 357 | if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT) |
c906108c SS |
358 | { |
359 | if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT) | |
360 | { | |
361 | float floatval = val; | |
362 | ||
363 | memcpy (addr, &floatval, sizeof (floatval)); | |
364 | } | |
365 | else | |
366 | floatformat_from_doublest (TARGET_FLOAT_FORMAT, &val, addr); | |
367 | } | |
3db87ba3 | 368 | else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT) |
c906108c SS |
369 | { |
370 | if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT) | |
371 | { | |
372 | double doubleval = val; | |
373 | ||
374 | memcpy (addr, &doubleval, sizeof (doubleval)); | |
375 | } | |
376 | else | |
377 | floatformat_from_doublest (TARGET_DOUBLE_FORMAT, &val, addr); | |
378 | } | |
3db87ba3 | 379 | else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT) |
c906108c SS |
380 | { |
381 | if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT) | |
382 | memcpy (addr, &val, sizeof (val)); | |
383 | else | |
384 | floatformat_from_doublest (TARGET_LONG_DOUBLE_FORMAT, &val, addr); | |
385 | } | |
386 | else | |
387 | { | |
388 | error ("Can't deal with a floating point number of %d bytes.", len); | |
389 | } | |
390 | } | |
391 | \f | |
c906108c SS |
392 | |
393 | /* Return the address in which frame FRAME's value of register REGNUM | |
394 | has been saved in memory. Or return zero if it has not been saved. | |
395 | If REGNUM specifies the SP, the value we return is actually | |
396 | the SP value, not an address where it was saved. */ | |
397 | ||
398 | CORE_ADDR | |
399 | find_saved_register (frame, regnum) | |
400 | struct frame_info *frame; | |
401 | int regnum; | |
402 | { | |
403 | register struct frame_info *frame1 = NULL; | |
404 | register CORE_ADDR addr = 0; | |
405 | ||
406 | if (frame == NULL) /* No regs saved if want current frame */ | |
407 | return 0; | |
408 | ||
409 | #ifdef HAVE_REGISTER_WINDOWS | |
410 | /* We assume that a register in a register window will only be saved | |
411 | in one place (since the name changes and/or disappears as you go | |
412 | towards inner frames), so we only call get_frame_saved_regs on | |
413 | the current frame. This is directly in contradiction to the | |
414 | usage below, which assumes that registers used in a frame must be | |
415 | saved in a lower (more interior) frame. This change is a result | |
416 | of working on a register window machine; get_frame_saved_regs | |
417 | always returns the registers saved within a frame, within the | |
418 | context (register namespace) of that frame. */ | |
419 | ||
420 | /* However, note that we don't want this to return anything if | |
421 | nothing is saved (if there's a frame inside of this one). Also, | |
422 | callers to this routine asking for the stack pointer want the | |
423 | stack pointer saved for *this* frame; this is returned from the | |
424 | next frame. */ | |
c5aa993b JM |
425 | |
426 | if (REGISTER_IN_WINDOW_P (regnum)) | |
c906108c SS |
427 | { |
428 | frame1 = get_next_frame (frame); | |
c5aa993b JM |
429 | if (!frame1) |
430 | return 0; /* Registers of this frame are active. */ | |
431 | ||
c906108c | 432 | /* Get the SP from the next frame in; it will be this |
c5aa993b | 433 | current frame. */ |
c906108c | 434 | if (regnum != SP_REGNUM) |
c5aa993b JM |
435 | frame1 = frame; |
436 | ||
c906108c SS |
437 | FRAME_INIT_SAVED_REGS (frame1); |
438 | return frame1->saved_regs[regnum]; /* ... which might be zero */ | |
439 | } | |
440 | #endif /* HAVE_REGISTER_WINDOWS */ | |
441 | ||
442 | /* Note that this next routine assumes that registers used in | |
443 | frame x will be saved only in the frame that x calls and | |
444 | frames interior to it. This is not true on the sparc, but the | |
445 | above macro takes care of it, so we should be all right. */ | |
446 | while (1) | |
447 | { | |
448 | QUIT; | |
449 | frame1 = get_prev_frame (frame1); | |
450 | if (frame1 == 0 || frame1 == frame) | |
451 | break; | |
452 | FRAME_INIT_SAVED_REGS (frame1); | |
453 | if (frame1->saved_regs[regnum]) | |
454 | addr = frame1->saved_regs[regnum]; | |
455 | } | |
456 | ||
457 | return addr; | |
458 | } | |
459 | ||
460 | /* Find register number REGNUM relative to FRAME and put its (raw, | |
461 | target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the | |
462 | variable was optimized out (and thus can't be fetched). Set *LVAL | |
463 | to lval_memory, lval_register, or not_lval, depending on whether | |
464 | the value was fetched from memory, from a register, or in a strange | |
465 | and non-modifiable way (e.g. a frame pointer which was calculated | |
466 | rather than fetched). Set *ADDRP to the address, either in memory | |
467 | on as a REGISTER_BYTE offset into the registers array. | |
468 | ||
469 | Note that this implementation never sets *LVAL to not_lval. But | |
470 | it can be replaced by defining GET_SAVED_REGISTER and supplying | |
471 | your own. | |
472 | ||
473 | The argument RAW_BUFFER must point to aligned memory. */ | |
474 | ||
475 | void | |
7a292a7a | 476 | default_get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval) |
c906108c SS |
477 | char *raw_buffer; |
478 | int *optimized; | |
479 | CORE_ADDR *addrp; | |
480 | struct frame_info *frame; | |
481 | int regnum; | |
482 | enum lval_type *lval; | |
483 | { | |
484 | CORE_ADDR addr; | |
485 | ||
486 | if (!target_has_registers) | |
487 | error ("No registers."); | |
488 | ||
489 | /* Normal systems don't optimize out things with register numbers. */ | |
490 | if (optimized != NULL) | |
491 | *optimized = 0; | |
492 | addr = find_saved_register (frame, regnum); | |
493 | if (addr != 0) | |
494 | { | |
495 | if (lval != NULL) | |
496 | *lval = lval_memory; | |
497 | if (regnum == SP_REGNUM) | |
498 | { | |
499 | if (raw_buffer != NULL) | |
500 | { | |
501 | /* Put it back in target format. */ | |
4478b372 JB |
502 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), |
503 | (LONGEST) addr); | |
c906108c SS |
504 | } |
505 | if (addrp != NULL) | |
506 | *addrp = 0; | |
507 | return; | |
508 | } | |
509 | if (raw_buffer != NULL) | |
510 | read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum)); | |
511 | } | |
512 | else | |
513 | { | |
514 | if (lval != NULL) | |
515 | *lval = lval_register; | |
516 | addr = REGISTER_BYTE (regnum); | |
517 | if (raw_buffer != NULL) | |
518 | read_register_gen (regnum, raw_buffer); | |
519 | } | |
520 | if (addrp != NULL) | |
521 | *addrp = addr; | |
522 | } | |
7a292a7a SS |
523 | |
524 | #if !defined (GET_SAVED_REGISTER) | |
525 | #define GET_SAVED_REGISTER(raw_buffer, optimized, addrp, frame, regnum, lval) \ | |
526 | default_get_saved_register(raw_buffer, optimized, addrp, frame, regnum, lval) | |
527 | #endif | |
528 | void | |
529 | get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval) | |
530 | char *raw_buffer; | |
531 | int *optimized; | |
532 | CORE_ADDR *addrp; | |
533 | struct frame_info *frame; | |
534 | int regnum; | |
535 | enum lval_type *lval; | |
536 | { | |
537 | GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval); | |
538 | } | |
c906108c SS |
539 | |
540 | /* Copy the bytes of register REGNUM, relative to the input stack frame, | |
541 | into our memory at MYADDR, in target byte order. | |
542 | The number of bytes copied is REGISTER_RAW_SIZE (REGNUM). | |
543 | ||
544 | Returns 1 if could not be read, 0 if could. */ | |
545 | ||
7a292a7a | 546 | static int |
c906108c SS |
547 | read_relative_register_raw_bytes_for_frame (regnum, myaddr, frame) |
548 | int regnum; | |
549 | char *myaddr; | |
550 | struct frame_info *frame; | |
551 | { | |
552 | int optim; | |
553 | if (regnum == FP_REGNUM && frame) | |
554 | { | |
555 | /* Put it back in target format. */ | |
c5aa993b JM |
556 | store_address (myaddr, REGISTER_RAW_SIZE (FP_REGNUM), |
557 | (LONGEST) FRAME_FP (frame)); | |
c906108c SS |
558 | |
559 | return 0; | |
560 | } | |
561 | ||
562 | get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, frame, | |
c5aa993b | 563 | regnum, (enum lval_type *) NULL); |
c906108c | 564 | |
c5aa993b JM |
565 | if (register_valid[regnum] < 0) |
566 | return 1; /* register value not available */ | |
c906108c SS |
567 | |
568 | return optim; | |
569 | } | |
570 | ||
571 | /* Copy the bytes of register REGNUM, relative to the current stack frame, | |
572 | into our memory at MYADDR, in target byte order. | |
573 | The number of bytes copied is REGISTER_RAW_SIZE (REGNUM). | |
574 | ||
575 | Returns 1 if could not be read, 0 if could. */ | |
576 | ||
577 | int | |
578 | read_relative_register_raw_bytes (regnum, myaddr) | |
579 | int regnum; | |
580 | char *myaddr; | |
581 | { | |
c5aa993b | 582 | return read_relative_register_raw_bytes_for_frame (regnum, myaddr, |
c906108c SS |
583 | selected_frame); |
584 | } | |
585 | ||
586 | /* Return a `value' with the contents of register REGNUM | |
587 | in its virtual format, with the type specified by | |
588 | REGISTER_VIRTUAL_TYPE. | |
589 | ||
590 | NOTE: returns NULL if register value is not available. | |
591 | Caller will check return value or die! */ | |
592 | ||
593 | value_ptr | |
594 | value_of_register (regnum) | |
595 | int regnum; | |
596 | { | |
597 | CORE_ADDR addr; | |
598 | int optim; | |
599 | register value_ptr reg_val; | |
600 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
601 | enum lval_type lval; | |
602 | ||
603 | get_saved_register (raw_buffer, &optim, &addr, | |
604 | selected_frame, regnum, &lval); | |
605 | ||
606 | if (register_valid[regnum] < 0) | |
c5aa993b | 607 | return NULL; /* register value not available */ |
c906108c SS |
608 | |
609 | reg_val = allocate_value (REGISTER_VIRTUAL_TYPE (regnum)); | |
610 | ||
611 | /* Convert raw data to virtual format if necessary. */ | |
612 | ||
c906108c SS |
613 | if (REGISTER_CONVERTIBLE (regnum)) |
614 | { | |
615 | REGISTER_CONVERT_TO_VIRTUAL (regnum, REGISTER_VIRTUAL_TYPE (regnum), | |
616 | raw_buffer, VALUE_CONTENTS_RAW (reg_val)); | |
617 | } | |
392a587b JM |
618 | else if (REGISTER_RAW_SIZE (regnum) == REGISTER_VIRTUAL_SIZE (regnum)) |
619 | memcpy (VALUE_CONTENTS_RAW (reg_val), raw_buffer, | |
620 | REGISTER_RAW_SIZE (regnum)); | |
c906108c | 621 | else |
96baa820 JM |
622 | internal_error ("Register \"%s\" (%d) has conflicting raw (%d) and virtual (%d) size", |
623 | REGISTER_NAME (regnum), | |
624 | regnum, | |
625 | REGISTER_RAW_SIZE (regnum), | |
626 | REGISTER_VIRTUAL_SIZE (regnum)); | |
c906108c SS |
627 | VALUE_LVAL (reg_val) = lval; |
628 | VALUE_ADDRESS (reg_val) = addr; | |
629 | VALUE_REGNO (reg_val) = regnum; | |
630 | VALUE_OPTIMIZED_OUT (reg_val) = optim; | |
631 | return reg_val; | |
632 | } | |
633 | \f | |
634 | /* Low level examining and depositing of registers. | |
635 | ||
636 | The caller is responsible for making | |
637 | sure that the inferior is stopped before calling the fetching routines, | |
638 | or it will get garbage. (a change from GDB version 3, in which | |
639 | the caller got the value from the last stop). */ | |
640 | ||
7a292a7a | 641 | /* Contents and state of the registers (in target byte order). */ |
c906108c | 642 | |
7a292a7a | 643 | char *registers; |
c906108c | 644 | |
7a292a7a SS |
645 | /* VALID_REGISTER is non-zero if it has been fetched, -1 if the |
646 | register value was not available. */ | |
647 | ||
648 | signed char *register_valid; | |
c906108c SS |
649 | |
650 | /* The thread/process associated with the current set of registers. For now, | |
651 | -1 is special, and means `no current process'. */ | |
652 | int registers_pid = -1; | |
653 | ||
654 | /* Indicate that registers may have changed, so invalidate the cache. */ | |
655 | ||
656 | void | |
657 | registers_changed () | |
658 | { | |
659 | int i; | |
660 | int numregs = ARCH_NUM_REGS; | |
661 | ||
662 | registers_pid = -1; | |
663 | ||
664 | /* Force cleanup of any alloca areas if using C alloca instead of | |
665 | a builtin alloca. This particular call is used to clean up | |
666 | areas allocated by low level target code which may build up | |
667 | during lengthy interactions between gdb and the target before | |
668 | gdb gives control to the user (ie watchpoints). */ | |
669 | alloca (0); | |
670 | ||
671 | for (i = 0; i < numregs; i++) | |
672 | register_valid[i] = 0; | |
673 | ||
674 | if (registers_changed_hook) | |
675 | registers_changed_hook (); | |
676 | } | |
677 | ||
678 | /* Indicate that all registers have been fetched, so mark them all valid. */ | |
679 | void | |
680 | registers_fetched () | |
681 | { | |
682 | int i; | |
683 | int numregs = ARCH_NUM_REGS; | |
684 | for (i = 0; i < numregs; i++) | |
685 | register_valid[i] = 1; | |
686 | } | |
687 | ||
c2d11a7d JM |
688 | /* read_register_bytes and write_register_bytes are generally a *BAD* |
689 | idea. They are inefficient because they need to check for partial | |
690 | updates, which can only be done by scanning through all of the | |
691 | registers and seeing if the bytes that are being read/written fall | |
692 | inside of an invalid register. [The main reason this is necessary | |
693 | is that register sizes can vary, so a simple index won't suffice.] | |
694 | It is far better to call read_register_gen and write_register_gen | |
695 | if you want to get at the raw register contents, as it only takes a | |
696 | regno as an argument, and therefore can't do a partial register | |
697 | update. | |
698 | ||
699 | Prior to the recent fixes to check for partial updates, both read | |
700 | and write_register_bytes always checked to see if any registers | |
701 | were stale, and then called target_fetch_registers (-1) to update | |
702 | the whole set. This caused really slowed things down for remote | |
703 | targets. */ | |
c906108c SS |
704 | |
705 | /* Copy INLEN bytes of consecutive data from registers | |
706 | starting with the INREGBYTE'th byte of register data | |
707 | into memory at MYADDR. */ | |
708 | ||
709 | void | |
710 | read_register_bytes (inregbyte, myaddr, inlen) | |
711 | int inregbyte; | |
712 | char *myaddr; | |
713 | int inlen; | |
714 | { | |
715 | int inregend = inregbyte + inlen; | |
716 | int regno; | |
717 | ||
718 | if (registers_pid != inferior_pid) | |
719 | { | |
720 | registers_changed (); | |
721 | registers_pid = inferior_pid; | |
722 | } | |
723 | ||
724 | /* See if we are trying to read bytes from out-of-date registers. If so, | |
725 | update just those registers. */ | |
726 | ||
727 | for (regno = 0; regno < NUM_REGS; regno++) | |
728 | { | |
729 | int regstart, regend; | |
c906108c SS |
730 | |
731 | if (register_valid[regno]) | |
732 | continue; | |
733 | ||
734 | if (REGISTER_NAME (regno) == NULL || *REGISTER_NAME (regno) == '\0') | |
735 | continue; | |
736 | ||
737 | regstart = REGISTER_BYTE (regno); | |
738 | regend = regstart + REGISTER_RAW_SIZE (regno); | |
739 | ||
c2d11a7d JM |
740 | if (regend <= inregbyte || inregend <= regstart) |
741 | /* The range the user wants to read doesn't overlap with regno. */ | |
c906108c SS |
742 | continue; |
743 | ||
744 | /* We've found an invalid register where at least one byte will be read. | |
c5aa993b | 745 | Update it from the target. */ |
c906108c SS |
746 | target_fetch_registers (regno); |
747 | ||
748 | if (!register_valid[regno]) | |
749 | error ("read_register_bytes: Couldn't update register %d.", regno); | |
750 | } | |
751 | ||
752 | if (myaddr != NULL) | |
753 | memcpy (myaddr, ®isters[inregbyte], inlen); | |
754 | } | |
755 | ||
756 | /* Read register REGNO into memory at MYADDR, which must be large enough | |
757 | for REGISTER_RAW_BYTES (REGNO). Target byte-order. | |
758 | If the register is known to be the size of a CORE_ADDR or smaller, | |
759 | read_register can be used instead. */ | |
760 | void | |
761 | read_register_gen (regno, myaddr) | |
762 | int regno; | |
763 | char *myaddr; | |
764 | { | |
765 | if (registers_pid != inferior_pid) | |
766 | { | |
767 | registers_changed (); | |
768 | registers_pid = inferior_pid; | |
769 | } | |
770 | ||
771 | if (!register_valid[regno]) | |
772 | target_fetch_registers (regno); | |
773 | memcpy (myaddr, ®isters[REGISTER_BYTE (regno)], | |
774 | REGISTER_RAW_SIZE (regno)); | |
775 | } | |
776 | ||
777 | /* Write register REGNO at MYADDR to the target. MYADDR points at | |
778 | REGISTER_RAW_BYTES(REGNO), which must be in target byte-order. */ | |
779 | ||
780 | static void | |
781 | write_register_gen (regno, myaddr) | |
782 | int regno; | |
783 | char *myaddr; | |
784 | { | |
785 | int size; | |
786 | ||
787 | /* On the sparc, writing %g0 is a no-op, so we don't even want to change | |
788 | the registers array if something writes to this register. */ | |
789 | if (CANNOT_STORE_REGISTER (regno)) | |
790 | return; | |
791 | ||
792 | if (registers_pid != inferior_pid) | |
793 | { | |
794 | registers_changed (); | |
795 | registers_pid = inferior_pid; | |
796 | } | |
797 | ||
c5aa993b | 798 | size = REGISTER_RAW_SIZE (regno); |
c906108c SS |
799 | |
800 | /* If we have a valid copy of the register, and new value == old value, | |
801 | then don't bother doing the actual store. */ | |
802 | ||
c5aa993b | 803 | if (register_valid[regno] |
c906108c SS |
804 | && memcmp (®isters[REGISTER_BYTE (regno)], myaddr, size) == 0) |
805 | return; | |
c5aa993b | 806 | |
c906108c SS |
807 | target_prepare_to_store (); |
808 | ||
809 | memcpy (®isters[REGISTER_BYTE (regno)], myaddr, size); | |
810 | ||
c5aa993b | 811 | register_valid[regno] = 1; |
c906108c SS |
812 | |
813 | target_store_registers (regno); | |
814 | } | |
815 | ||
816 | /* Copy INLEN bytes of consecutive data from memory at MYADDR | |
817 | into registers starting with the MYREGSTART'th byte of register data. */ | |
818 | ||
819 | void | |
820 | write_register_bytes (myregstart, myaddr, inlen) | |
821 | int myregstart; | |
822 | char *myaddr; | |
823 | int inlen; | |
824 | { | |
825 | int myregend = myregstart + inlen; | |
826 | int regno; | |
827 | ||
828 | target_prepare_to_store (); | |
829 | ||
830 | /* Scan through the registers updating any that are covered by the range | |
831 | myregstart<=>myregend using write_register_gen, which does nice things | |
832 | like handling threads, and avoiding updates when the new and old contents | |
833 | are the same. */ | |
834 | ||
835 | for (regno = 0; regno < NUM_REGS; regno++) | |
836 | { | |
837 | int regstart, regend; | |
c906108c SS |
838 | |
839 | regstart = REGISTER_BYTE (regno); | |
840 | regend = regstart + REGISTER_RAW_SIZE (regno); | |
841 | ||
c2d11a7d JM |
842 | /* Is this register completely outside the range the user is writing? */ |
843 | if (myregend <= regstart || regend <= myregstart) | |
844 | /* do nothing */ ; | |
c906108c | 845 | |
c2d11a7d JM |
846 | /* Is this register completely within the range the user is writing? */ |
847 | else if (myregstart <= regstart && regend <= myregend) | |
848 | write_register_gen (regno, myaddr + (regstart - myregstart)); | |
c906108c | 849 | |
c2d11a7d JM |
850 | /* The register partially overlaps the range being written. */ |
851 | else | |
c906108c | 852 | { |
c2d11a7d JM |
853 | char regbuf[MAX_REGISTER_RAW_SIZE]; |
854 | /* What's the overlap between this register's bytes and | |
855 | those the caller wants to write? */ | |
856 | int overlapstart = max (regstart, myregstart); | |
857 | int overlapend = min (regend, myregend); | |
c906108c | 858 | |
c2d11a7d JM |
859 | /* We may be doing a partial update of an invalid register. |
860 | Update it from the target before scribbling on it. */ | |
861 | read_register_gen (regno, regbuf); | |
862 | ||
863 | memcpy (registers + overlapstart, | |
864 | myaddr + (overlapstart - myregstart), | |
865 | overlapend - overlapstart); | |
866 | ||
867 | target_store_registers (regno); | |
868 | } | |
c906108c SS |
869 | } |
870 | } | |
871 | ||
c2d11a7d | 872 | |
c906108c SS |
873 | /* Return the raw contents of register REGNO, regarding it as an integer. */ |
874 | /* This probably should be returning LONGEST rather than CORE_ADDR. */ | |
875 | ||
876 | CORE_ADDR | |
877 | read_register (regno) | |
878 | int regno; | |
879 | { | |
880 | if (registers_pid != inferior_pid) | |
881 | { | |
882 | registers_changed (); | |
883 | registers_pid = inferior_pid; | |
884 | } | |
885 | ||
886 | if (!register_valid[regno]) | |
887 | target_fetch_registers (regno); | |
888 | ||
4478b372 JB |
889 | return ((CORE_ADDR) |
890 | extract_unsigned_integer (®isters[REGISTER_BYTE (regno)], | |
891 | REGISTER_RAW_SIZE (regno))); | |
c906108c SS |
892 | } |
893 | ||
894 | CORE_ADDR | |
895 | read_register_pid (regno, pid) | |
896 | int regno, pid; | |
897 | { | |
898 | int save_pid; | |
899 | CORE_ADDR retval; | |
900 | ||
901 | if (pid == inferior_pid) | |
902 | return read_register (regno); | |
903 | ||
904 | save_pid = inferior_pid; | |
905 | ||
906 | inferior_pid = pid; | |
907 | ||
908 | retval = read_register (regno); | |
909 | ||
910 | inferior_pid = save_pid; | |
911 | ||
912 | return retval; | |
913 | } | |
914 | ||
915 | /* Store VALUE, into the raw contents of register number REGNO. | |
916 | This should probably write a LONGEST rather than a CORE_ADDR */ | |
917 | ||
918 | void | |
919 | write_register (regno, val) | |
920 | int regno; | |
921 | LONGEST val; | |
922 | { | |
923 | PTR buf; | |
924 | int size; | |
925 | ||
926 | /* On the sparc, writing %g0 is a no-op, so we don't even want to change | |
927 | the registers array if something writes to this register. */ | |
928 | if (CANNOT_STORE_REGISTER (regno)) | |
929 | return; | |
930 | ||
931 | if (registers_pid != inferior_pid) | |
932 | { | |
933 | registers_changed (); | |
934 | registers_pid = inferior_pid; | |
935 | } | |
936 | ||
c5aa993b | 937 | size = REGISTER_RAW_SIZE (regno); |
c906108c | 938 | buf = alloca (size); |
c5aa993b | 939 | store_signed_integer (buf, size, (LONGEST) val); |
c906108c SS |
940 | |
941 | /* If we have a valid copy of the register, and new value == old value, | |
942 | then don't bother doing the actual store. */ | |
943 | ||
c5aa993b | 944 | if (register_valid[regno] |
c906108c SS |
945 | && memcmp (®isters[REGISTER_BYTE (regno)], buf, size) == 0) |
946 | return; | |
c5aa993b | 947 | |
c906108c SS |
948 | target_prepare_to_store (); |
949 | ||
950 | memcpy (®isters[REGISTER_BYTE (regno)], buf, size); | |
951 | ||
c5aa993b | 952 | register_valid[regno] = 1; |
c906108c SS |
953 | |
954 | target_store_registers (regno); | |
955 | } | |
956 | ||
957 | void | |
958 | write_register_pid (regno, val, pid) | |
959 | int regno; | |
960 | CORE_ADDR val; | |
961 | int pid; | |
962 | { | |
963 | int save_pid; | |
964 | ||
965 | if (pid == inferior_pid) | |
966 | { | |
967 | write_register (regno, val); | |
968 | return; | |
969 | } | |
970 | ||
971 | save_pid = inferior_pid; | |
972 | ||
973 | inferior_pid = pid; | |
974 | ||
975 | write_register (regno, val); | |
976 | ||
977 | inferior_pid = save_pid; | |
978 | } | |
979 | ||
980 | /* Record that register REGNO contains VAL. | |
981 | This is used when the value is obtained from the inferior or core dump, | |
982 | so there is no need to store the value there. | |
983 | ||
984 | If VAL is a NULL pointer, then it's probably an unsupported register. We | |
985 | just set it's value to all zeros. We might want to record this fact, and | |
986 | report it to the users of read_register and friends. | |
c5aa993b | 987 | */ |
c906108c SS |
988 | |
989 | void | |
990 | supply_register (regno, val) | |
991 | int regno; | |
992 | char *val; | |
993 | { | |
994 | #if 1 | |
995 | if (registers_pid != inferior_pid) | |
996 | { | |
997 | registers_changed (); | |
998 | registers_pid = inferior_pid; | |
999 | } | |
1000 | #endif | |
1001 | ||
1002 | register_valid[regno] = 1; | |
1003 | if (val) | |
1004 | memcpy (®isters[REGISTER_BYTE (regno)], val, REGISTER_RAW_SIZE (regno)); | |
1005 | else | |
1006 | memset (®isters[REGISTER_BYTE (regno)], '\000', REGISTER_RAW_SIZE (regno)); | |
1007 | ||
1008 | /* On some architectures, e.g. HPPA, there are a few stray bits in some | |
1009 | registers, that the rest of the code would like to ignore. */ | |
1010 | #ifdef CLEAN_UP_REGISTER_VALUE | |
c5aa993b | 1011 | CLEAN_UP_REGISTER_VALUE (regno, ®isters[REGISTER_BYTE (regno)]); |
c906108c SS |
1012 | #endif |
1013 | } | |
1014 | ||
1015 | ||
1016 | /* This routine is getting awfully cluttered with #if's. It's probably | |
1017 | time to turn this into READ_PC and define it in the tm.h file. | |
0f71a2f6 JM |
1018 | Ditto for write_pc. |
1019 | ||
1020 | 1999-06-08: The following were re-written so that it assumes the | |
1021 | existance of a TARGET_READ_PC et.al. macro. A default generic | |
1022 | version of that macro is made available where needed. | |
1023 | ||
1024 | Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled | |
1025 | by the multi-arch framework, it will eventually be possible to | |
1026 | eliminate the intermediate read_pc_pid(). The client would call | |
1027 | TARGET_READ_PC directly. (cagney). */ | |
1028 | ||
1029 | #ifndef TARGET_READ_PC | |
1030 | #define TARGET_READ_PC generic_target_read_pc | |
1031 | #endif | |
1032 | ||
1033 | CORE_ADDR | |
745b8ca0 | 1034 | generic_target_read_pc (int pid) |
0f71a2f6 JM |
1035 | { |
1036 | #ifdef PC_REGNUM | |
1037 | if (PC_REGNUM >= 0) | |
1038 | { | |
1039 | CORE_ADDR pc_val = ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, pid)); | |
1040 | return pc_val; | |
1041 | } | |
1042 | #endif | |
96baa820 | 1043 | internal_error ("generic_target_read_pc"); |
0f71a2f6 JM |
1044 | return 0; |
1045 | } | |
c906108c SS |
1046 | |
1047 | CORE_ADDR | |
1048 | read_pc_pid (pid) | |
1049 | int pid; | |
1050 | { | |
c5aa993b JM |
1051 | int saved_inferior_pid; |
1052 | CORE_ADDR pc_val; | |
c906108c SS |
1053 | |
1054 | /* In case pid != inferior_pid. */ | |
1055 | saved_inferior_pid = inferior_pid; | |
1056 | inferior_pid = pid; | |
c5aa993b | 1057 | |
c906108c | 1058 | pc_val = TARGET_READ_PC (pid); |
c906108c SS |
1059 | |
1060 | inferior_pid = saved_inferior_pid; | |
1061 | return pc_val; | |
1062 | } | |
1063 | ||
1064 | CORE_ADDR | |
1065 | read_pc () | |
1066 | { | |
1067 | return read_pc_pid (inferior_pid); | |
1068 | } | |
1069 | ||
0f71a2f6 JM |
1070 | #ifndef TARGET_WRITE_PC |
1071 | #define TARGET_WRITE_PC generic_target_write_pc | |
1072 | #endif | |
1073 | ||
1074 | void | |
1075 | generic_target_write_pc (pc, pid) | |
1076 | CORE_ADDR pc; | |
1077 | int pid; | |
1078 | { | |
1079 | #ifdef PC_REGNUM | |
1080 | if (PC_REGNUM >= 0) | |
1081 | write_register_pid (PC_REGNUM, pc, pid); | |
1082 | #ifdef NPC_REGNUM | |
1083 | if (NPC_REGNUM >= 0) | |
1084 | write_register_pid (NPC_REGNUM, pc + 4, pid); | |
1085 | #ifdef NNPC_REGNUM | |
1086 | if (NNPC_REGNUM >= 0) | |
1087 | write_register_pid (NNPC_REGNUM, pc + 8, pid); | |
1088 | #endif | |
1089 | #endif | |
1090 | #else | |
96baa820 | 1091 | internal_error ("generic_target_write_pc"); |
0f71a2f6 JM |
1092 | #endif |
1093 | } | |
1094 | ||
c906108c SS |
1095 | void |
1096 | write_pc_pid (pc, pid) | |
1097 | CORE_ADDR pc; | |
1098 | int pid; | |
1099 | { | |
c5aa993b | 1100 | int saved_inferior_pid; |
c906108c SS |
1101 | |
1102 | /* In case pid != inferior_pid. */ | |
1103 | saved_inferior_pid = inferior_pid; | |
1104 | inferior_pid = pid; | |
c5aa993b | 1105 | |
c906108c | 1106 | TARGET_WRITE_PC (pc, pid); |
c906108c SS |
1107 | |
1108 | inferior_pid = saved_inferior_pid; | |
1109 | } | |
1110 | ||
1111 | void | |
1112 | write_pc (pc) | |
1113 | CORE_ADDR pc; | |
1114 | { | |
1115 | write_pc_pid (pc, inferior_pid); | |
1116 | } | |
1117 | ||
1118 | /* Cope with strage ways of getting to the stack and frame pointers */ | |
1119 | ||
0f71a2f6 JM |
1120 | #ifndef TARGET_READ_SP |
1121 | #define TARGET_READ_SP generic_target_read_sp | |
1122 | #endif | |
1123 | ||
1124 | CORE_ADDR | |
1125 | generic_target_read_sp () | |
1126 | { | |
1127 | #ifdef SP_REGNUM | |
1128 | if (SP_REGNUM >= 0) | |
1129 | return read_register (SP_REGNUM); | |
1130 | #endif | |
96baa820 | 1131 | internal_error ("generic_target_read_sp"); |
0f71a2f6 JM |
1132 | } |
1133 | ||
c906108c SS |
1134 | CORE_ADDR |
1135 | read_sp () | |
1136 | { | |
c906108c | 1137 | return TARGET_READ_SP (); |
0f71a2f6 JM |
1138 | } |
1139 | ||
1140 | #ifndef TARGET_WRITE_SP | |
1141 | #define TARGET_WRITE_SP generic_target_write_sp | |
1142 | #endif | |
1143 | ||
1144 | void | |
1145 | generic_target_write_sp (val) | |
1146 | CORE_ADDR val; | |
1147 | { | |
1148 | #ifdef SP_REGNUM | |
1149 | if (SP_REGNUM >= 0) | |
1150 | { | |
1151 | write_register (SP_REGNUM, val); | |
1152 | return; | |
1153 | } | |
c906108c | 1154 | #endif |
96baa820 | 1155 | internal_error ("generic_target_write_sp"); |
c906108c SS |
1156 | } |
1157 | ||
1158 | void | |
1159 | write_sp (val) | |
1160 | CORE_ADDR val; | |
1161 | { | |
c906108c | 1162 | TARGET_WRITE_SP (val); |
0f71a2f6 JM |
1163 | } |
1164 | ||
1165 | #ifndef TARGET_READ_FP | |
1166 | #define TARGET_READ_FP generic_target_read_fp | |
c906108c | 1167 | #endif |
0f71a2f6 JM |
1168 | |
1169 | CORE_ADDR | |
1170 | generic_target_read_fp () | |
1171 | { | |
1172 | #ifdef FP_REGNUM | |
1173 | if (FP_REGNUM >= 0) | |
1174 | return read_register (FP_REGNUM); | |
1175 | #endif | |
96baa820 | 1176 | internal_error ("generic_target_read_fp"); |
c906108c SS |
1177 | } |
1178 | ||
1179 | CORE_ADDR | |
1180 | read_fp () | |
1181 | { | |
c906108c | 1182 | return TARGET_READ_FP (); |
0f71a2f6 JM |
1183 | } |
1184 | ||
1185 | #ifndef TARGET_WRITE_FP | |
1186 | #define TARGET_WRITE_FP generic_target_write_fp | |
1187 | #endif | |
1188 | ||
1189 | void | |
1190 | generic_target_write_fp (val) | |
1191 | CORE_ADDR val; | |
1192 | { | |
1193 | #ifdef FP_REGNUM | |
1194 | if (FP_REGNUM >= 0) | |
1195 | { | |
1196 | write_register (FP_REGNUM, val); | |
1197 | return; | |
1198 | } | |
c906108c | 1199 | #endif |
96baa820 | 1200 | internal_error ("generic_target_write_fp"); |
c906108c SS |
1201 | } |
1202 | ||
1203 | void | |
1204 | write_fp (val) | |
1205 | CORE_ADDR val; | |
1206 | { | |
c906108c | 1207 | TARGET_WRITE_FP (val); |
c906108c | 1208 | } |
4478b372 JB |
1209 | |
1210 | ||
1211 | /* Given a pointer of type TYPE in target form in BUF, return the | |
1212 | address it represents. */ | |
1213 | CORE_ADDR | |
1214 | generic_pointer_to_address (struct type *type, char *buf) | |
1215 | { | |
1216 | return extract_address (buf, TYPE_LENGTH (type)); | |
1217 | } | |
1218 | ||
1219 | ||
1220 | /* Given an address, store it as a pointer of type TYPE in target | |
1221 | format in BUF. */ | |
1222 | void | |
1223 | generic_address_to_pointer (struct type *type, char *buf, CORE_ADDR addr) | |
1224 | { | |
1225 | store_address (buf, TYPE_LENGTH (type), addr); | |
1226 | } | |
1227 | ||
c906108c SS |
1228 | \f |
1229 | /* Will calling read_var_value or locate_var_value on SYM end | |
1230 | up caring what frame it is being evaluated relative to? SYM must | |
1231 | be non-NULL. */ | |
1232 | int | |
1233 | symbol_read_needs_frame (sym) | |
1234 | struct symbol *sym; | |
1235 | { | |
1236 | switch (SYMBOL_CLASS (sym)) | |
1237 | { | |
1238 | /* All cases listed explicitly so that gcc -Wall will detect it if | |
c5aa993b | 1239 | we failed to consider one. */ |
c906108c SS |
1240 | case LOC_REGISTER: |
1241 | case LOC_ARG: | |
1242 | case LOC_REF_ARG: | |
1243 | case LOC_REGPARM: | |
1244 | case LOC_REGPARM_ADDR: | |
1245 | case LOC_LOCAL: | |
1246 | case LOC_LOCAL_ARG: | |
1247 | case LOC_BASEREG: | |
1248 | case LOC_BASEREG_ARG: | |
1249 | case LOC_THREAD_LOCAL_STATIC: | |
1250 | return 1; | |
1251 | ||
1252 | case LOC_UNDEF: | |
1253 | case LOC_CONST: | |
1254 | case LOC_STATIC: | |
1255 | case LOC_INDIRECT: | |
1256 | case LOC_TYPEDEF: | |
1257 | ||
1258 | case LOC_LABEL: | |
1259 | /* Getting the address of a label can be done independently of the block, | |
c5aa993b JM |
1260 | even if some *uses* of that address wouldn't work so well without |
1261 | the right frame. */ | |
c906108c SS |
1262 | |
1263 | case LOC_BLOCK: | |
1264 | case LOC_CONST_BYTES: | |
1265 | case LOC_UNRESOLVED: | |
1266 | case LOC_OPTIMIZED_OUT: | |
1267 | return 0; | |
1268 | } | |
1269 | return 1; | |
1270 | } | |
1271 | ||
1272 | /* Given a struct symbol for a variable, | |
1273 | and a stack frame id, read the value of the variable | |
1274 | and return a (pointer to a) struct value containing the value. | |
1275 | If the variable cannot be found, return a zero pointer. | |
1276 | If FRAME is NULL, use the selected_frame. */ | |
1277 | ||
1278 | value_ptr | |
1279 | read_var_value (var, frame) | |
1280 | register struct symbol *var; | |
1281 | struct frame_info *frame; | |
1282 | { | |
1283 | register value_ptr v; | |
1284 | struct type *type = SYMBOL_TYPE (var); | |
1285 | CORE_ADDR addr; | |
1286 | register int len; | |
1287 | ||
1288 | v = allocate_value (type); | |
1289 | VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */ | |
1290 | VALUE_BFD_SECTION (v) = SYMBOL_BFD_SECTION (var); | |
1291 | ||
1292 | len = TYPE_LENGTH (type); | |
1293 | ||
c5aa993b JM |
1294 | if (frame == NULL) |
1295 | frame = selected_frame; | |
c906108c SS |
1296 | |
1297 | switch (SYMBOL_CLASS (var)) | |
1298 | { | |
1299 | case LOC_CONST: | |
1300 | /* Put the constant back in target format. */ | |
1301 | store_signed_integer (VALUE_CONTENTS_RAW (v), len, | |
1302 | (LONGEST) SYMBOL_VALUE (var)); | |
1303 | VALUE_LVAL (v) = not_lval; | |
1304 | return v; | |
1305 | ||
1306 | case LOC_LABEL: | |
1307 | /* Put the constant back in target format. */ | |
1308 | if (overlay_debugging) | |
4478b372 JB |
1309 | { |
1310 | CORE_ADDR addr | |
1311 | = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var), | |
1312 | SYMBOL_BFD_SECTION (var)); | |
1313 | store_typed_address (VALUE_CONTENTS_RAW (v), type, addr); | |
1314 | } | |
c906108c | 1315 | else |
4478b372 JB |
1316 | store_typed_address (VALUE_CONTENTS_RAW (v), type, |
1317 | SYMBOL_VALUE_ADDRESS (var)); | |
c906108c SS |
1318 | VALUE_LVAL (v) = not_lval; |
1319 | return v; | |
1320 | ||
1321 | case LOC_CONST_BYTES: | |
1322 | { | |
1323 | char *bytes_addr; | |
1324 | bytes_addr = SYMBOL_VALUE_BYTES (var); | |
1325 | memcpy (VALUE_CONTENTS_RAW (v), bytes_addr, len); | |
1326 | VALUE_LVAL (v) = not_lval; | |
1327 | return v; | |
1328 | } | |
1329 | ||
1330 | case LOC_STATIC: | |
1331 | if (overlay_debugging) | |
1332 | addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var), | |
1333 | SYMBOL_BFD_SECTION (var)); | |
1334 | else | |
1335 | addr = SYMBOL_VALUE_ADDRESS (var); | |
1336 | break; | |
1337 | ||
1338 | case LOC_INDIRECT: | |
1339 | /* The import slot does not have a real address in it from the | |
1340 | dynamic loader (dld.sl on HP-UX), if the target hasn't begun | |
c5aa993b | 1341 | execution yet, so check for that. */ |
c906108c | 1342 | if (!target_has_execution) |
c5aa993b | 1343 | error ("\ |
c906108c SS |
1344 | Attempt to access variable defined in different shared object or load module when\n\ |
1345 | addresses have not been bound by the dynamic loader. Try again when executable is running."); | |
c5aa993b | 1346 | |
c906108c SS |
1347 | addr = SYMBOL_VALUE_ADDRESS (var); |
1348 | addr = read_memory_unsigned_integer | |
1349 | (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
1350 | break; | |
1351 | ||
1352 | case LOC_ARG: | |
1353 | if (frame == NULL) | |
1354 | return 0; | |
1355 | addr = FRAME_ARGS_ADDRESS (frame); | |
1356 | if (!addr) | |
1357 | return 0; | |
1358 | addr += SYMBOL_VALUE (var); | |
1359 | break; | |
1360 | ||
1361 | case LOC_REF_ARG: | |
1362 | if (frame == NULL) | |
1363 | return 0; | |
1364 | addr = FRAME_ARGS_ADDRESS (frame); | |
1365 | if (!addr) | |
1366 | return 0; | |
1367 | addr += SYMBOL_VALUE (var); | |
1368 | addr = read_memory_unsigned_integer | |
1369 | (addr, TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
1370 | break; | |
1371 | ||
1372 | case LOC_LOCAL: | |
1373 | case LOC_LOCAL_ARG: | |
1374 | if (frame == NULL) | |
1375 | return 0; | |
1376 | addr = FRAME_LOCALS_ADDRESS (frame); | |
1377 | addr += SYMBOL_VALUE (var); | |
1378 | break; | |
1379 | ||
1380 | case LOC_BASEREG: | |
1381 | case LOC_BASEREG_ARG: | |
1382 | { | |
1383 | char buf[MAX_REGISTER_RAW_SIZE]; | |
1384 | get_saved_register (buf, NULL, NULL, frame, SYMBOL_BASEREG (var), | |
1385 | NULL); | |
1386 | addr = extract_address (buf, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var))); | |
1387 | addr += SYMBOL_VALUE (var); | |
1388 | break; | |
1389 | } | |
c5aa993b | 1390 | |
c906108c SS |
1391 | case LOC_THREAD_LOCAL_STATIC: |
1392 | { | |
c5aa993b JM |
1393 | char buf[MAX_REGISTER_RAW_SIZE]; |
1394 | ||
1395 | get_saved_register (buf, NULL, NULL, frame, SYMBOL_BASEREG (var), | |
c906108c | 1396 | NULL); |
c5aa993b JM |
1397 | addr = extract_address (buf, REGISTER_RAW_SIZE (SYMBOL_BASEREG (var))); |
1398 | addr += SYMBOL_VALUE (var); | |
1399 | break; | |
c906108c | 1400 | } |
c5aa993b | 1401 | |
c906108c SS |
1402 | case LOC_TYPEDEF: |
1403 | error ("Cannot look up value of a typedef"); | |
1404 | break; | |
1405 | ||
1406 | case LOC_BLOCK: | |
1407 | if (overlay_debugging) | |
c5aa993b | 1408 | VALUE_ADDRESS (v) = symbol_overlayed_address |
c906108c SS |
1409 | (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_BFD_SECTION (var)); |
1410 | else | |
1411 | VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (var)); | |
1412 | return v; | |
1413 | ||
1414 | case LOC_REGISTER: | |
1415 | case LOC_REGPARM: | |
1416 | case LOC_REGPARM_ADDR: | |
1417 | { | |
1418 | struct block *b; | |
1419 | int regno = SYMBOL_VALUE (var); | |
1420 | value_ptr regval; | |
1421 | ||
1422 | if (frame == NULL) | |
1423 | return 0; | |
1424 | b = get_frame_block (frame); | |
1425 | ||
1426 | if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR) | |
1427 | { | |
1428 | regval = value_from_register (lookup_pointer_type (type), | |
c5aa993b | 1429 | regno, |
c906108c SS |
1430 | frame); |
1431 | ||
1432 | if (regval == NULL) | |
1433 | error ("Value of register variable not available."); | |
1434 | ||
c5aa993b | 1435 | addr = value_as_pointer (regval); |
c906108c SS |
1436 | VALUE_LVAL (v) = lval_memory; |
1437 | } | |
1438 | else | |
1439 | { | |
1440 | regval = value_from_register (type, regno, frame); | |
1441 | ||
1442 | if (regval == NULL) | |
1443 | error ("Value of register variable not available."); | |
1444 | return regval; | |
1445 | } | |
1446 | } | |
1447 | break; | |
1448 | ||
1449 | case LOC_UNRESOLVED: | |
1450 | { | |
1451 | struct minimal_symbol *msym; | |
1452 | ||
1453 | msym = lookup_minimal_symbol (SYMBOL_NAME (var), NULL, NULL); | |
1454 | if (msym == NULL) | |
1455 | return 0; | |
1456 | if (overlay_debugging) | |
1457 | addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (msym), | |
1458 | SYMBOL_BFD_SECTION (msym)); | |
1459 | else | |
1460 | addr = SYMBOL_VALUE_ADDRESS (msym); | |
1461 | } | |
1462 | break; | |
1463 | ||
1464 | case LOC_OPTIMIZED_OUT: | |
1465 | VALUE_LVAL (v) = not_lval; | |
1466 | VALUE_OPTIMIZED_OUT (v) = 1; | |
1467 | return v; | |
1468 | ||
1469 | default: | |
1470 | error ("Cannot look up value of a botched symbol."); | |
1471 | break; | |
1472 | } | |
1473 | ||
1474 | VALUE_ADDRESS (v) = addr; | |
1475 | VALUE_LAZY (v) = 1; | |
1476 | return v; | |
1477 | } | |
1478 | ||
1479 | /* Return a value of type TYPE, stored in register REGNUM, in frame | |
1480 | FRAME. | |
1481 | ||
1482 | NOTE: returns NULL if register value is not available. | |
1483 | Caller will check return value or die! */ | |
1484 | ||
1485 | value_ptr | |
1486 | value_from_register (type, regnum, frame) | |
1487 | struct type *type; | |
1488 | int regnum; | |
1489 | struct frame_info *frame; | |
1490 | { | |
c5aa993b | 1491 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; |
c906108c SS |
1492 | CORE_ADDR addr; |
1493 | int optim; | |
1494 | value_ptr v = allocate_value (type); | |
1495 | char *value_bytes = 0; | |
1496 | int value_bytes_copied = 0; | |
1497 | int num_storage_locs; | |
1498 | enum lval_type lval; | |
1499 | int len; | |
1500 | ||
1501 | CHECK_TYPEDEF (type); | |
1502 | len = TYPE_LENGTH (type); | |
1503 | ||
da59e081 JM |
1504 | /* Pointers on D10V are really only 16 bits, but we lie to gdb elsewhere... */ |
1505 | if (GDB_TARGET_IS_D10V && TYPE_CODE (type) == TYPE_CODE_PTR) | |
1506 | len = 2; | |
1507 | ||
c906108c SS |
1508 | VALUE_REGNO (v) = regnum; |
1509 | ||
1510 | num_storage_locs = (len > REGISTER_VIRTUAL_SIZE (regnum) ? | |
1511 | ((len - 1) / REGISTER_RAW_SIZE (regnum)) + 1 : | |
1512 | 1); | |
1513 | ||
1514 | if (num_storage_locs > 1 | |
1515 | #ifdef GDB_TARGET_IS_H8500 | |
1516 | || TYPE_CODE (type) == TYPE_CODE_PTR | |
1517 | #endif | |
c5aa993b | 1518 | ) |
c906108c SS |
1519 | { |
1520 | /* Value spread across multiple storage locations. */ | |
c5aa993b | 1521 | |
c906108c SS |
1522 | int local_regnum; |
1523 | int mem_stor = 0, reg_stor = 0; | |
1524 | int mem_tracking = 1; | |
1525 | CORE_ADDR last_addr = 0; | |
1526 | CORE_ADDR first_addr = 0; | |
1527 | ||
1528 | value_bytes = (char *) alloca (len + MAX_REGISTER_RAW_SIZE); | |
1529 | ||
1530 | /* Copy all of the data out, whereever it may be. */ | |
1531 | ||
1532 | #ifdef GDB_TARGET_IS_H8500 | |
1533 | /* This piece of hideosity is required because the H8500 treats registers | |
1534 | differently depending upon whether they are used as pointers or not. As a | |
1535 | pointer, a register needs to have a page register tacked onto the front. | |
1536 | An alternate way to do this would be to have gcc output different register | |
1537 | numbers for the pointer & non-pointer form of the register. But, it | |
1538 | doesn't, so we're stuck with this. */ | |
1539 | ||
1540 | if (TYPE_CODE (type) == TYPE_CODE_PTR | |
1541 | && len > 2) | |
1542 | { | |
1543 | int page_regnum; | |
1544 | ||
1545 | switch (regnum) | |
1546 | { | |
c5aa993b JM |
1547 | case R0_REGNUM: |
1548 | case R1_REGNUM: | |
1549 | case R2_REGNUM: | |
1550 | case R3_REGNUM: | |
c906108c SS |
1551 | page_regnum = SEG_D_REGNUM; |
1552 | break; | |
c5aa993b JM |
1553 | case R4_REGNUM: |
1554 | case R5_REGNUM: | |
c906108c SS |
1555 | page_regnum = SEG_E_REGNUM; |
1556 | break; | |
c5aa993b JM |
1557 | case R6_REGNUM: |
1558 | case R7_REGNUM: | |
c906108c SS |
1559 | page_regnum = SEG_T_REGNUM; |
1560 | break; | |
1561 | } | |
1562 | ||
1563 | value_bytes[0] = 0; | |
1564 | get_saved_register (value_bytes + 1, | |
1565 | &optim, | |
1566 | &addr, | |
1567 | frame, | |
1568 | page_regnum, | |
1569 | &lval); | |
1570 | ||
1571 | if (register_valid[page_regnum] == -1) | |
1572 | return NULL; /* register value not available */ | |
1573 | ||
1574 | if (lval == lval_register) | |
1575 | reg_stor++; | |
1576 | else | |
1577 | mem_stor++; | |
1578 | first_addr = addr; | |
1579 | last_addr = addr; | |
1580 | ||
1581 | get_saved_register (value_bytes + 2, | |
1582 | &optim, | |
1583 | &addr, | |
1584 | frame, | |
1585 | regnum, | |
1586 | &lval); | |
1587 | ||
1588 | if (register_valid[regnum] == -1) | |
1589 | return NULL; /* register value not available */ | |
1590 | ||
1591 | if (lval == lval_register) | |
1592 | reg_stor++; | |
1593 | else | |
1594 | { | |
1595 | mem_stor++; | |
1596 | mem_tracking = mem_tracking && (addr == last_addr); | |
1597 | } | |
1598 | last_addr = addr; | |
1599 | } | |
1600 | else | |
c5aa993b | 1601 | #endif /* GDB_TARGET_IS_H8500 */ |
c906108c SS |
1602 | for (local_regnum = regnum; |
1603 | value_bytes_copied < len; | |
1604 | (value_bytes_copied += REGISTER_RAW_SIZE (local_regnum), | |
1605 | ++local_regnum)) | |
1606 | { | |
1607 | get_saved_register (value_bytes + value_bytes_copied, | |
1608 | &optim, | |
1609 | &addr, | |
1610 | frame, | |
1611 | local_regnum, | |
1612 | &lval); | |
1613 | ||
c5aa993b JM |
1614 | if (register_valid[local_regnum] == -1) |
1615 | return NULL; /* register value not available */ | |
c906108c SS |
1616 | |
1617 | if (regnum == local_regnum) | |
1618 | first_addr = addr; | |
1619 | if (lval == lval_register) | |
1620 | reg_stor++; | |
1621 | else | |
1622 | { | |
1623 | mem_stor++; | |
c5aa993b | 1624 | |
c906108c SS |
1625 | mem_tracking = |
1626 | (mem_tracking | |
1627 | && (regnum == local_regnum | |
1628 | || addr == last_addr)); | |
1629 | } | |
1630 | last_addr = addr; | |
1631 | } | |
1632 | ||
1633 | if ((reg_stor && mem_stor) | |
1634 | || (mem_stor && !mem_tracking)) | |
1635 | /* Mixed storage; all of the hassle we just went through was | |
1636 | for some good purpose. */ | |
1637 | { | |
1638 | VALUE_LVAL (v) = lval_reg_frame_relative; | |
1639 | VALUE_FRAME (v) = FRAME_FP (frame); | |
1640 | VALUE_FRAME_REGNUM (v) = regnum; | |
1641 | } | |
1642 | else if (mem_stor) | |
1643 | { | |
1644 | VALUE_LVAL (v) = lval_memory; | |
1645 | VALUE_ADDRESS (v) = first_addr; | |
1646 | } | |
1647 | else if (reg_stor) | |
1648 | { | |
1649 | VALUE_LVAL (v) = lval_register; | |
1650 | VALUE_ADDRESS (v) = first_addr; | |
1651 | } | |
1652 | else | |
96baa820 | 1653 | internal_error ("value_from_register: Value not stored anywhere!"); |
c906108c SS |
1654 | |
1655 | VALUE_OPTIMIZED_OUT (v) = optim; | |
1656 | ||
1657 | /* Any structure stored in more than one register will always be | |
c5aa993b JM |
1658 | an integral number of registers. Otherwise, you'd need to do |
1659 | some fiddling with the last register copied here for little | |
1660 | endian machines. */ | |
c906108c SS |
1661 | |
1662 | /* Copy into the contents section of the value. */ | |
1663 | memcpy (VALUE_CONTENTS_RAW (v), value_bytes, len); | |
1664 | ||
1665 | /* Finally do any conversion necessary when extracting this | |
1666 | type from more than one register. */ | |
1667 | #ifdef REGISTER_CONVERT_TO_TYPE | |
c5aa993b | 1668 | REGISTER_CONVERT_TO_TYPE (regnum, type, VALUE_CONTENTS_RAW (v)); |
c906108c SS |
1669 | #endif |
1670 | return v; | |
1671 | } | |
1672 | ||
1673 | /* Data is completely contained within a single register. Locate the | |
1674 | register's contents in a real register or in core; | |
1675 | read the data in raw format. */ | |
1676 | ||
1677 | get_saved_register (raw_buffer, &optim, &addr, frame, regnum, &lval); | |
1678 | ||
1679 | if (register_valid[regnum] == -1) | |
c5aa993b | 1680 | return NULL; /* register value not available */ |
c906108c SS |
1681 | |
1682 | VALUE_OPTIMIZED_OUT (v) = optim; | |
1683 | VALUE_LVAL (v) = lval; | |
1684 | VALUE_ADDRESS (v) = addr; | |
1685 | ||
1686 | /* Convert raw data to virtual format if necessary. */ | |
c5aa993b | 1687 | |
c906108c SS |
1688 | if (REGISTER_CONVERTIBLE (regnum)) |
1689 | { | |
1690 | REGISTER_CONVERT_TO_VIRTUAL (regnum, type, | |
1691 | raw_buffer, VALUE_CONTENTS_RAW (v)); | |
1692 | } | |
1693 | else | |
c906108c SS |
1694 | { |
1695 | /* Raw and virtual formats are the same for this register. */ | |
1696 | ||
1697 | if (TARGET_BYTE_ORDER == BIG_ENDIAN && len < REGISTER_RAW_SIZE (regnum)) | |
1698 | { | |
c5aa993b | 1699 | /* Big-endian, and we want less than full size. */ |
c906108c SS |
1700 | VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len; |
1701 | } | |
1702 | ||
1703 | memcpy (VALUE_CONTENTS_RAW (v), raw_buffer + VALUE_OFFSET (v), len); | |
1704 | } | |
c5aa993b | 1705 | |
da59e081 JM |
1706 | if (GDB_TARGET_IS_D10V |
1707 | && TYPE_CODE (type) == TYPE_CODE_PTR | |
1708 | && TYPE_TARGET_TYPE (type) | |
1709 | && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC)) | |
1710 | { | |
1711 | /* pointer to function */ | |
1712 | unsigned long num; | |
1713 | unsigned short snum; | |
1714 | snum = (unsigned short) extract_unsigned_integer (VALUE_CONTENTS_RAW (v), 2); | |
1715 | num = D10V_MAKE_IADDR (snum); | |
1716 | store_address (VALUE_CONTENTS_RAW (v), 4, num); | |
1717 | } | |
1718 | else if (GDB_TARGET_IS_D10V | |
1719 | && TYPE_CODE (type) == TYPE_CODE_PTR) | |
1720 | { | |
1721 | /* pointer to data */ | |
1722 | unsigned long num; | |
1723 | unsigned short snum; | |
1724 | snum = (unsigned short) extract_unsigned_integer (VALUE_CONTENTS_RAW (v), 2); | |
1725 | num = D10V_MAKE_DADDR (snum); | |
1726 | store_address (VALUE_CONTENTS_RAW (v), 4, num); | |
1727 | } | |
1728 | ||
c906108c SS |
1729 | return v; |
1730 | } | |
1731 | \f | |
1732 | /* Given a struct symbol for a variable or function, | |
1733 | and a stack frame id, | |
1734 | return a (pointer to a) struct value containing the properly typed | |
1735 | address. */ | |
1736 | ||
1737 | value_ptr | |
1738 | locate_var_value (var, frame) | |
1739 | register struct symbol *var; | |
1740 | struct frame_info *frame; | |
1741 | { | |
1742 | CORE_ADDR addr = 0; | |
1743 | struct type *type = SYMBOL_TYPE (var); | |
1744 | value_ptr lazy_value; | |
1745 | ||
1746 | /* Evaluate it first; if the result is a memory address, we're fine. | |
1747 | Lazy evaluation pays off here. */ | |
1748 | ||
1749 | lazy_value = read_var_value (var, frame); | |
1750 | if (lazy_value == 0) | |
1751 | error ("Address of \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var)); | |
1752 | ||
1753 | if (VALUE_LAZY (lazy_value) | |
1754 | || TYPE_CODE (type) == TYPE_CODE_FUNC) | |
1755 | { | |
1756 | value_ptr val; | |
1757 | ||
1758 | addr = VALUE_ADDRESS (lazy_value); | |
4478b372 | 1759 | val = value_from_pointer (lookup_pointer_type (type), addr); |
c906108c SS |
1760 | VALUE_BFD_SECTION (val) = VALUE_BFD_SECTION (lazy_value); |
1761 | return val; | |
1762 | } | |
1763 | ||
1764 | /* Not a memory address; check what the problem was. */ | |
c5aa993b | 1765 | switch (VALUE_LVAL (lazy_value)) |
c906108c SS |
1766 | { |
1767 | case lval_register: | |
1768 | case lval_reg_frame_relative: | |
1769 | error ("Address requested for identifier \"%s\" which is in a register.", | |
1770 | SYMBOL_SOURCE_NAME (var)); | |
1771 | break; | |
1772 | ||
1773 | default: | |
1774 | error ("Can't take address of \"%s\" which isn't an lvalue.", | |
1775 | SYMBOL_SOURCE_NAME (var)); | |
1776 | break; | |
1777 | } | |
c5aa993b | 1778 | return 0; /* For lint -- never reached */ |
c906108c | 1779 | } |
7a292a7a | 1780 | \f |
c5aa993b | 1781 | |
7a292a7a SS |
1782 | static void build_findvar PARAMS ((void)); |
1783 | static void | |
1784 | build_findvar () | |
1785 | { | |
1786 | /* We allocate some extra slop since we do a lot of memcpy's around | |
1787 | `registers', and failing-soft is better than failing hard. */ | |
1788 | int sizeof_registers = REGISTER_BYTES + /* SLOP */ 256; | |
1789 | int sizeof_register_valid = NUM_REGS * sizeof (*register_valid); | |
1790 | registers = xmalloc (sizeof_registers); | |
1791 | memset (registers, 0, sizeof_registers); | |
1792 | register_valid = xmalloc (sizeof_register_valid); | |
1793 | memset (register_valid, 0, sizeof_register_valid); | |
1794 | } | |
1795 | ||
1796 | void _initialize_findvar PARAMS ((void)); | |
1797 | void | |
1798 | _initialize_findvar () | |
1799 | { | |
1800 | build_findvar (); | |
0f71a2f6 JM |
1801 | |
1802 | register_gdbarch_swap (®isters, sizeof (registers), NULL); | |
1803 | register_gdbarch_swap (®ister_valid, sizeof (register_valid), NULL); | |
1804 | register_gdbarch_swap (NULL, 0, build_findvar); | |
7a292a7a | 1805 | } |