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