GDB (API)
|
00001 /* Find a variable's value in memory, for GDB, the GNU debugger. 00002 00003 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "symtab.h" 00022 #include "gdbtypes.h" 00023 #include "frame.h" 00024 #include "value.h" 00025 #include "gdbcore.h" 00026 #include "inferior.h" 00027 #include "target.h" 00028 #include "gdb_string.h" 00029 #include "gdb_assert.h" 00030 #include "floatformat.h" 00031 #include "symfile.h" /* for overlay functions */ 00032 #include "regcache.h" 00033 #include "user-regs.h" 00034 #include "block.h" 00035 #include "objfiles.h" 00036 #include "language.h" 00037 00038 /* Basic byte-swapping routines. All 'extract' functions return a 00039 host-format integer from a target-format integer at ADDR which is 00040 LEN bytes long. */ 00041 00042 #if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8 00043 /* 8 bit characters are a pretty safe assumption these days, so we 00044 assume it throughout all these swapping routines. If we had to deal with 00045 9 bit characters, we would need to make len be in bits and would have 00046 to re-write these routines... */ 00047 you lose 00048 #endif 00049 00050 LONGEST 00051 extract_signed_integer (const gdb_byte *addr, int len, 00052 enum bfd_endian byte_order) 00053 { 00054 LONGEST retval; 00055 const unsigned char *p; 00056 const unsigned char *startaddr = addr; 00057 const unsigned char *endaddr = startaddr + len; 00058 00059 if (len > (int) sizeof (LONGEST)) 00060 error (_("\ 00061 That operation is not available on integers of more than %d bytes."), 00062 (int) sizeof (LONGEST)); 00063 00064 /* Start at the most significant end of the integer, and work towards 00065 the least significant. */ 00066 if (byte_order == BFD_ENDIAN_BIG) 00067 { 00068 p = startaddr; 00069 /* Do the sign extension once at the start. */ 00070 retval = ((LONGEST) * p ^ 0x80) - 0x80; 00071 for (++p; p < endaddr; ++p) 00072 retval = (retval << 8) | *p; 00073 } 00074 else 00075 { 00076 p = endaddr - 1; 00077 /* Do the sign extension once at the start. */ 00078 retval = ((LONGEST) * p ^ 0x80) - 0x80; 00079 for (--p; p >= startaddr; --p) 00080 retval = (retval << 8) | *p; 00081 } 00082 return retval; 00083 } 00084 00085 ULONGEST 00086 extract_unsigned_integer (const gdb_byte *addr, int len, 00087 enum bfd_endian byte_order) 00088 { 00089 ULONGEST retval; 00090 const unsigned char *p; 00091 const unsigned char *startaddr = addr; 00092 const unsigned char *endaddr = startaddr + len; 00093 00094 if (len > (int) sizeof (ULONGEST)) 00095 error (_("\ 00096 That operation is not available on integers of more than %d bytes."), 00097 (int) sizeof (ULONGEST)); 00098 00099 /* Start at the most significant end of the integer, and work towards 00100 the least significant. */ 00101 retval = 0; 00102 if (byte_order == BFD_ENDIAN_BIG) 00103 { 00104 for (p = startaddr; p < endaddr; ++p) 00105 retval = (retval << 8) | *p; 00106 } 00107 else 00108 { 00109 for (p = endaddr - 1; p >= startaddr; --p) 00110 retval = (retval << 8) | *p; 00111 } 00112 return retval; 00113 } 00114 00115 /* Sometimes a long long unsigned integer can be extracted as a 00116 LONGEST value. This is done so that we can print these values 00117 better. If this integer can be converted to a LONGEST, this 00118 function returns 1 and sets *PVAL. Otherwise it returns 0. */ 00119 00120 int 00121 extract_long_unsigned_integer (const gdb_byte *addr, int orig_len, 00122 enum bfd_endian byte_order, LONGEST *pval) 00123 { 00124 const gdb_byte *p; 00125 const gdb_byte *first_addr; 00126 int len; 00127 00128 len = orig_len; 00129 if (byte_order == BFD_ENDIAN_BIG) 00130 { 00131 for (p = addr; 00132 len > (int) sizeof (LONGEST) && p < addr + orig_len; 00133 p++) 00134 { 00135 if (*p == 0) 00136 len--; 00137 else 00138 break; 00139 } 00140 first_addr = p; 00141 } 00142 else 00143 { 00144 first_addr = addr; 00145 for (p = addr + orig_len - 1; 00146 len > (int) sizeof (LONGEST) && p >= addr; 00147 p--) 00148 { 00149 if (*p == 0) 00150 len--; 00151 else 00152 break; 00153 } 00154 } 00155 00156 if (len <= (int) sizeof (LONGEST)) 00157 { 00158 *pval = (LONGEST) extract_unsigned_integer (first_addr, 00159 sizeof (LONGEST), 00160 byte_order); 00161 return 1; 00162 } 00163 00164 return 0; 00165 } 00166 00167 00168 /* Treat the bytes at BUF as a pointer of type TYPE, and return the 00169 address it represents. */ 00170 CORE_ADDR 00171 extract_typed_address (const gdb_byte *buf, struct type *type) 00172 { 00173 if (TYPE_CODE (type) != TYPE_CODE_PTR 00174 && TYPE_CODE (type) != TYPE_CODE_REF) 00175 internal_error (__FILE__, __LINE__, 00176 _("extract_typed_address: " 00177 "type is not a pointer or reference")); 00178 00179 return gdbarch_pointer_to_address (get_type_arch (type), type, buf); 00180 } 00181 00182 /* All 'store' functions accept a host-format integer and store a 00183 target-format integer at ADDR which is LEN bytes long. */ 00184 00185 void 00186 store_signed_integer (gdb_byte *addr, int len, 00187 enum bfd_endian byte_order, LONGEST val) 00188 { 00189 gdb_byte *p; 00190 gdb_byte *startaddr = addr; 00191 gdb_byte *endaddr = startaddr + len; 00192 00193 /* Start at the least significant end of the integer, and work towards 00194 the most significant. */ 00195 if (byte_order == BFD_ENDIAN_BIG) 00196 { 00197 for (p = endaddr - 1; p >= startaddr; --p) 00198 { 00199 *p = val & 0xff; 00200 val >>= 8; 00201 } 00202 } 00203 else 00204 { 00205 for (p = startaddr; p < endaddr; ++p) 00206 { 00207 *p = val & 0xff; 00208 val >>= 8; 00209 } 00210 } 00211 } 00212 00213 void 00214 store_unsigned_integer (gdb_byte *addr, int len, 00215 enum bfd_endian byte_order, ULONGEST val) 00216 { 00217 unsigned char *p; 00218 unsigned char *startaddr = (unsigned char *) addr; 00219 unsigned char *endaddr = startaddr + len; 00220 00221 /* Start at the least significant end of the integer, and work towards 00222 the most significant. */ 00223 if (byte_order == BFD_ENDIAN_BIG) 00224 { 00225 for (p = endaddr - 1; p >= startaddr; --p) 00226 { 00227 *p = val & 0xff; 00228 val >>= 8; 00229 } 00230 } 00231 else 00232 { 00233 for (p = startaddr; p < endaddr; ++p) 00234 { 00235 *p = val & 0xff; 00236 val >>= 8; 00237 } 00238 } 00239 } 00240 00241 /* Store the address ADDR as a pointer of type TYPE at BUF, in target 00242 form. */ 00243 void 00244 store_typed_address (gdb_byte *buf, struct type *type, CORE_ADDR addr) 00245 { 00246 if (TYPE_CODE (type) != TYPE_CODE_PTR 00247 && TYPE_CODE (type) != TYPE_CODE_REF) 00248 internal_error (__FILE__, __LINE__, 00249 _("store_typed_address: " 00250 "type is not a pointer or reference")); 00251 00252 gdbarch_address_to_pointer (get_type_arch (type), type, buf, addr); 00253 } 00254 00255 00256 00257 /* Return a `value' with the contents of (virtual or cooked) register 00258 REGNUM as found in the specified FRAME. The register's type is 00259 determined by register_type(). */ 00260 00261 struct value * 00262 value_of_register (int regnum, struct frame_info *frame) 00263 { 00264 struct gdbarch *gdbarch = get_frame_arch (frame); 00265 struct value *reg_val; 00266 00267 /* User registers lie completely outside of the range of normal 00268 registers. Catch them early so that the target never sees them. */ 00269 if (regnum >= gdbarch_num_regs (gdbarch) 00270 + gdbarch_num_pseudo_regs (gdbarch)) 00271 return value_of_user_reg (regnum, frame); 00272 00273 reg_val = value_of_register_lazy (frame, regnum); 00274 value_fetch_lazy (reg_val); 00275 return reg_val; 00276 } 00277 00278 /* Return a `value' with the contents of (virtual or cooked) register 00279 REGNUM as found in the specified FRAME. The register's type is 00280 determined by register_type(). The value is not fetched. */ 00281 00282 struct value * 00283 value_of_register_lazy (struct frame_info *frame, int regnum) 00284 { 00285 struct gdbarch *gdbarch = get_frame_arch (frame); 00286 struct value *reg_val; 00287 00288 gdb_assert (regnum < (gdbarch_num_regs (gdbarch) 00289 + gdbarch_num_pseudo_regs (gdbarch))); 00290 00291 /* We should have a valid (i.e. non-sentinel) frame. */ 00292 gdb_assert (frame_id_p (get_frame_id (frame))); 00293 00294 reg_val = allocate_value_lazy (register_type (gdbarch, regnum)); 00295 VALUE_LVAL (reg_val) = lval_register; 00296 VALUE_REGNUM (reg_val) = regnum; 00297 VALUE_FRAME_ID (reg_val) = get_frame_id (frame); 00298 return reg_val; 00299 } 00300 00301 /* Given a pointer of type TYPE in target form in BUF, return the 00302 address it represents. */ 00303 CORE_ADDR 00304 unsigned_pointer_to_address (struct gdbarch *gdbarch, 00305 struct type *type, const gdb_byte *buf) 00306 { 00307 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00308 00309 return extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order); 00310 } 00311 00312 CORE_ADDR 00313 signed_pointer_to_address (struct gdbarch *gdbarch, 00314 struct type *type, const gdb_byte *buf) 00315 { 00316 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00317 00318 return extract_signed_integer (buf, TYPE_LENGTH (type), byte_order); 00319 } 00320 00321 /* Given an address, store it as a pointer of type TYPE in target 00322 format in BUF. */ 00323 void 00324 unsigned_address_to_pointer (struct gdbarch *gdbarch, struct type *type, 00325 gdb_byte *buf, CORE_ADDR addr) 00326 { 00327 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00328 00329 store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order, addr); 00330 } 00331 00332 void 00333 address_to_signed_pointer (struct gdbarch *gdbarch, struct type *type, 00334 gdb_byte *buf, CORE_ADDR addr) 00335 { 00336 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00337 00338 store_signed_integer (buf, TYPE_LENGTH (type), byte_order, addr); 00339 } 00340 00341 /* Will calling read_var_value or locate_var_value on SYM end 00342 up caring what frame it is being evaluated relative to? SYM must 00343 be non-NULL. */ 00344 int 00345 symbol_read_needs_frame (struct symbol *sym) 00346 { 00347 if (SYMBOL_COMPUTED_OPS (sym) != NULL) 00348 return SYMBOL_COMPUTED_OPS (sym)->read_needs_frame (sym); 00349 00350 switch (SYMBOL_CLASS (sym)) 00351 { 00352 /* All cases listed explicitly so that gcc -Wall will detect it if 00353 we failed to consider one. */ 00354 case LOC_COMPUTED: 00355 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method")); 00356 00357 case LOC_REGISTER: 00358 case LOC_ARG: 00359 case LOC_REF_ARG: 00360 case LOC_REGPARM_ADDR: 00361 case LOC_LOCAL: 00362 return 1; 00363 00364 case LOC_UNDEF: 00365 case LOC_CONST: 00366 case LOC_STATIC: 00367 case LOC_TYPEDEF: 00368 00369 case LOC_LABEL: 00370 /* Getting the address of a label can be done independently of the block, 00371 even if some *uses* of that address wouldn't work so well without 00372 the right frame. */ 00373 00374 case LOC_BLOCK: 00375 case LOC_CONST_BYTES: 00376 case LOC_UNRESOLVED: 00377 case LOC_OPTIMIZED_OUT: 00378 return 0; 00379 } 00380 return 1; 00381 } 00382 00383 /* Private data to be used with minsym_lookup_iterator_cb. */ 00384 00385 struct minsym_lookup_data 00386 { 00387 /* The name of the minimal symbol we are searching for. */ 00388 const char *name; 00389 00390 /* The field where the callback should store the minimal symbol 00391 if found. It should be initialized to NULL before the search 00392 is started. */ 00393 struct minimal_symbol *result; 00394 00395 /* The objfile in which the symbol was found. */ 00396 struct objfile *objfile; 00397 }; 00398 00399 /* A callback function for gdbarch_iterate_over_objfiles_in_search_order. 00400 It searches by name for a minimal symbol within the given OBJFILE. 00401 The arguments are passed via CB_DATA, which in reality is a pointer 00402 to struct minsym_lookup_data. */ 00403 00404 static int 00405 minsym_lookup_iterator_cb (struct objfile *objfile, void *cb_data) 00406 { 00407 struct minsym_lookup_data *data = (struct minsym_lookup_data *) cb_data; 00408 00409 gdb_assert (data->result == NULL); 00410 00411 data->result = lookup_minimal_symbol (data->name, NULL, objfile); 00412 data->objfile = objfile; 00413 00414 /* The iterator should stop iff a match was found. */ 00415 return (data->result != NULL); 00416 } 00417 00418 /* A default implementation for the "la_read_var_value" hook in 00419 the language vector which should work in most situations. */ 00420 00421 struct value * 00422 default_read_var_value (struct symbol *var, struct frame_info *frame) 00423 { 00424 struct value *v; 00425 struct type *type = SYMBOL_TYPE (var); 00426 CORE_ADDR addr; 00427 00428 /* Call check_typedef on our type to make sure that, if TYPE is 00429 a TYPE_CODE_TYPEDEF, its length is set to the length of the target type 00430 instead of zero. However, we do not replace the typedef type by the 00431 target type, because we want to keep the typedef in order to be able to 00432 set the returned value type description correctly. */ 00433 check_typedef (type); 00434 00435 if (symbol_read_needs_frame (var)) 00436 gdb_assert (frame); 00437 00438 if (SYMBOL_COMPUTED_OPS (var) != NULL) 00439 return SYMBOL_COMPUTED_OPS (var)->read_variable (var, frame); 00440 00441 switch (SYMBOL_CLASS (var)) 00442 { 00443 case LOC_CONST: 00444 /* Put the constant back in target format. */ 00445 v = allocate_value (type); 00446 store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type), 00447 gdbarch_byte_order (get_type_arch (type)), 00448 (LONGEST) SYMBOL_VALUE (var)); 00449 VALUE_LVAL (v) = not_lval; 00450 return v; 00451 00452 case LOC_LABEL: 00453 /* Put the constant back in target format. */ 00454 v = allocate_value (type); 00455 if (overlay_debugging) 00456 { 00457 CORE_ADDR addr 00458 = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var), 00459 SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (var), 00460 var)); 00461 00462 store_typed_address (value_contents_raw (v), type, addr); 00463 } 00464 else 00465 store_typed_address (value_contents_raw (v), type, 00466 SYMBOL_VALUE_ADDRESS (var)); 00467 VALUE_LVAL (v) = not_lval; 00468 return v; 00469 00470 case LOC_CONST_BYTES: 00471 v = allocate_value (type); 00472 memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), 00473 TYPE_LENGTH (type)); 00474 VALUE_LVAL (v) = not_lval; 00475 return v; 00476 00477 case LOC_STATIC: 00478 if (overlay_debugging) 00479 addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var), 00480 SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (var), 00481 var)); 00482 else 00483 addr = SYMBOL_VALUE_ADDRESS (var); 00484 break; 00485 00486 case LOC_ARG: 00487 addr = get_frame_args_address (frame); 00488 if (!addr) 00489 error (_("Unknown argument list address for `%s'."), 00490 SYMBOL_PRINT_NAME (var)); 00491 addr += SYMBOL_VALUE (var); 00492 break; 00493 00494 case LOC_REF_ARG: 00495 { 00496 struct value *ref; 00497 CORE_ADDR argref; 00498 00499 argref = get_frame_args_address (frame); 00500 if (!argref) 00501 error (_("Unknown argument list address for `%s'."), 00502 SYMBOL_PRINT_NAME (var)); 00503 argref += SYMBOL_VALUE (var); 00504 ref = value_at (lookup_pointer_type (type), argref); 00505 addr = value_as_address (ref); 00506 break; 00507 } 00508 00509 case LOC_LOCAL: 00510 addr = get_frame_locals_address (frame); 00511 addr += SYMBOL_VALUE (var); 00512 break; 00513 00514 case LOC_TYPEDEF: 00515 error (_("Cannot look up value of a typedef `%s'."), 00516 SYMBOL_PRINT_NAME (var)); 00517 break; 00518 00519 case LOC_BLOCK: 00520 if (overlay_debugging) 00521 addr = symbol_overlayed_address 00522 (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (var), 00523 var)); 00524 else 00525 addr = BLOCK_START (SYMBOL_BLOCK_VALUE (var)); 00526 break; 00527 00528 case LOC_REGISTER: 00529 case LOC_REGPARM_ADDR: 00530 { 00531 int regno = SYMBOL_REGISTER_OPS (var) 00532 ->register_number (var, get_frame_arch (frame)); 00533 struct value *regval; 00534 00535 if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR) 00536 { 00537 regval = value_from_register (lookup_pointer_type (type), 00538 regno, 00539 frame); 00540 00541 if (regval == NULL) 00542 error (_("Value of register variable not available for `%s'."), 00543 SYMBOL_PRINT_NAME (var)); 00544 00545 addr = value_as_address (regval); 00546 } 00547 else 00548 { 00549 regval = value_from_register (type, regno, frame); 00550 00551 if (regval == NULL) 00552 error (_("Value of register variable not available for `%s'."), 00553 SYMBOL_PRINT_NAME (var)); 00554 return regval; 00555 } 00556 } 00557 break; 00558 00559 case LOC_COMPUTED: 00560 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method")); 00561 00562 case LOC_UNRESOLVED: 00563 { 00564 struct minsym_lookup_data lookup_data; 00565 struct minimal_symbol *msym; 00566 struct obj_section *obj_section; 00567 00568 memset (&lookup_data, 0, sizeof (lookup_data)); 00569 lookup_data.name = SYMBOL_LINKAGE_NAME (var); 00570 00571 gdbarch_iterate_over_objfiles_in_search_order 00572 (get_objfile_arch (SYMBOL_SYMTAB (var)->objfile), 00573 minsym_lookup_iterator_cb, &lookup_data, 00574 SYMBOL_SYMTAB (var)->objfile); 00575 msym = lookup_data.result; 00576 00577 if (msym == NULL) 00578 error (_("No global symbol \"%s\"."), SYMBOL_LINKAGE_NAME (var)); 00579 if (overlay_debugging) 00580 addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (msym), 00581 SYMBOL_OBJ_SECTION (lookup_data.objfile, 00582 msym)); 00583 else 00584 addr = SYMBOL_VALUE_ADDRESS (msym); 00585 00586 obj_section = SYMBOL_OBJ_SECTION (lookup_data.objfile, msym); 00587 if (obj_section 00588 && (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) 00589 addr = target_translate_tls_address (obj_section->objfile, addr); 00590 } 00591 break; 00592 00593 case LOC_OPTIMIZED_OUT: 00594 return allocate_optimized_out_value (type); 00595 00596 default: 00597 error (_("Cannot look up value of a botched symbol `%s'."), 00598 SYMBOL_PRINT_NAME (var)); 00599 break; 00600 } 00601 00602 v = value_at_lazy (type, addr); 00603 return v; 00604 } 00605 00606 /* Calls VAR's language la_read_var_value hook with the given arguments. */ 00607 00608 struct value * 00609 read_var_value (struct symbol *var, struct frame_info *frame) 00610 { 00611 const struct language_defn *lang = language_def (SYMBOL_LANGUAGE (var)); 00612 00613 gdb_assert (lang != NULL); 00614 gdb_assert (lang->la_read_var_value != NULL); 00615 00616 return lang->la_read_var_value (var, frame); 00617 } 00618 00619 /* Install default attributes for register values. */ 00620 00621 struct value * 00622 default_value_from_register (struct type *type, int regnum, 00623 struct frame_info *frame) 00624 { 00625 struct gdbarch *gdbarch = get_frame_arch (frame); 00626 int len = TYPE_LENGTH (type); 00627 struct value *value = allocate_value (type); 00628 00629 VALUE_LVAL (value) = lval_register; 00630 VALUE_FRAME_ID (value) = get_frame_id (frame); 00631 VALUE_REGNUM (value) = regnum; 00632 00633 /* Any structure stored in more than one register will always be 00634 an integral number of registers. Otherwise, you need to do 00635 some fiddling with the last register copied here for little 00636 endian machines. */ 00637 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG 00638 && len < register_size (gdbarch, regnum)) 00639 /* Big-endian, and we want less than full size. */ 00640 set_value_offset (value, register_size (gdbarch, regnum) - len); 00641 else 00642 set_value_offset (value, 0); 00643 00644 return value; 00645 } 00646 00647 /* VALUE must be an lval_register value. If regnum is the value's 00648 associated register number, and len the length of the values type, 00649 read one or more registers in FRAME, starting with register REGNUM, 00650 until we've read LEN bytes. 00651 00652 If any of the registers we try to read are optimized out, then mark the 00653 complete resulting value as optimized out. */ 00654 00655 void 00656 read_frame_register_value (struct value *value, struct frame_info *frame) 00657 { 00658 struct gdbarch *gdbarch = get_frame_arch (frame); 00659 int offset = 0; 00660 int reg_offset = value_offset (value); 00661 int regnum = VALUE_REGNUM (value); 00662 int len = TYPE_LENGTH (check_typedef (value_type (value))); 00663 00664 gdb_assert (VALUE_LVAL (value) == lval_register); 00665 00666 /* Skip registers wholly inside of REG_OFFSET. */ 00667 while (reg_offset >= register_size (gdbarch, regnum)) 00668 { 00669 reg_offset -= register_size (gdbarch, regnum); 00670 regnum++; 00671 } 00672 00673 /* Copy the data. */ 00674 while (len > 0) 00675 { 00676 struct value *regval = get_frame_register_value (frame, regnum); 00677 int reg_len = TYPE_LENGTH (value_type (regval)) - reg_offset; 00678 00679 if (value_optimized_out (regval)) 00680 { 00681 set_value_optimized_out (value, 1); 00682 break; 00683 } 00684 00685 /* If the register length is larger than the number of bytes 00686 remaining to copy, then only copy the appropriate bytes. */ 00687 if (reg_len > len) 00688 reg_len = len; 00689 00690 value_contents_copy (value, offset, regval, reg_offset, reg_len); 00691 00692 offset += reg_len; 00693 len -= reg_len; 00694 reg_offset = 0; 00695 regnum++; 00696 } 00697 } 00698 00699 /* Return a value of type TYPE, stored in register REGNUM, in frame FRAME. */ 00700 00701 struct value * 00702 value_from_register (struct type *type, int regnum, struct frame_info *frame) 00703 { 00704 struct gdbarch *gdbarch = get_frame_arch (frame); 00705 struct type *type1 = check_typedef (type); 00706 struct value *v; 00707 00708 if (gdbarch_convert_register_p (gdbarch, regnum, type1)) 00709 { 00710 int optim, unavail, ok; 00711 00712 /* The ISA/ABI need to something weird when obtaining the 00713 specified value from this register. It might need to 00714 re-order non-adjacent, starting with REGNUM (see MIPS and 00715 i386). It might need to convert the [float] register into 00716 the corresponding [integer] type (see Alpha). The assumption 00717 is that gdbarch_register_to_value populates the entire value 00718 including the location. */ 00719 v = allocate_value (type); 00720 VALUE_LVAL (v) = lval_register; 00721 VALUE_FRAME_ID (v) = get_frame_id (frame); 00722 VALUE_REGNUM (v) = regnum; 00723 ok = gdbarch_register_to_value (gdbarch, frame, regnum, type1, 00724 value_contents_raw (v), &optim, 00725 &unavail); 00726 00727 if (!ok) 00728 { 00729 if (optim) 00730 set_value_optimized_out (v, 1); 00731 if (unavail) 00732 mark_value_bytes_unavailable (v, 0, TYPE_LENGTH (type)); 00733 } 00734 } 00735 else 00736 { 00737 /* Construct the value. */ 00738 v = gdbarch_value_from_register (gdbarch, type, regnum, frame); 00739 00740 /* Get the data. */ 00741 read_frame_register_value (v, frame); 00742 } 00743 00744 return v; 00745 } 00746 00747 /* Return contents of register REGNUM in frame FRAME as address, 00748 interpreted as value of type TYPE. Will abort if register 00749 value is not available. */ 00750 00751 CORE_ADDR 00752 address_from_register (struct type *type, int regnum, struct frame_info *frame) 00753 { 00754 struct value *value; 00755 CORE_ADDR result; 00756 00757 value = value_from_register (type, regnum, frame); 00758 gdb_assert (value); 00759 00760 if (value_optimized_out (value)) 00761 { 00762 /* This function is used while computing a location expression. 00763 Complain about the value being optimized out, rather than 00764 letting value_as_address complain about some random register 00765 the expression depends on not being saved. */ 00766 error_value_optimized_out (); 00767 } 00768 00769 result = value_as_address (value); 00770 release_value (value); 00771 value_free (value); 00772 00773 return result; 00774 } 00775