diff options
author | Jim Blandy <jimb@codesourcery.com> | 2000-04-14 18:43:41 +0000 |
---|---|---|
committer | Jim Blandy <jimb@codesourcery.com> | 2000-04-14 18:43:41 +0000 |
commit | 4478b372e973afcd2253fe4c1ec3f2d083ac3943 (patch) | |
tree | 8140dc777f65fea1264b2d52a191ed79b61eb069 /gdb/findvar.c | |
parent | d84dd0c55ec2daf8bc3430098b22760478b4b68b (diff) | |
download | gdb-4478b372e973afcd2253fe4c1ec3f2d083ac3943.zip gdb-4478b372e973afcd2253fe4c1ec3f2d083ac3943.tar.gz gdb-4478b372e973afcd2253fe4c1ec3f2d083ac3943.tar.bz2 |
* gdbarch.sh (POINTER_TO_ADDRESS, ADDRESS_TO_POINTER): Two new
functions which architectures can redefine, defaulting to
generic_pointer_to_address and generic_address_to_pointer.
* findvar.c (extract_typed_address, store_typed_address,
generic_pointer_to_address, generic_address_to_pointer): New
functions.
(POINTER_TO_ADDRESS, ADDRESS_TO_POINTER): Provide default
definitions.
(extract_address, store_address): Doc fixes.
* values.c (value_as_pointer): Doc fix.
(value_from_pointer): New function.
* defs.h (extract_typed_address, store_typed_address): New
declarations.
* inferior.h (generic_address_to_pointer,
generic_pointer_to_address): New declarations.
* value.h (value_from_pointer): New declaration.
* ax-gdb.c (const_var_ref): Use value_from_pointer, not
value_from_longest.
* blockframe.c (generic_push_dummy_frame): Use read_pc and
read_sp, not read_register.
* c-valprint.c (c_val_print): Use extract_typed_address instead of
extract_address to extract vtable entries and references.
* cp-valprint.c (cp_print_value_fields): Use value_from_pointer
instead of value_from_longest to extract the vtable's address.
* eval.c (evaluate_subexp_standard): Use value_from_pointer
instead of value_from_longest to compute `this', and for doing
pointer-to-member dereferencing.
* findvar.c (read_register): Use extract_unsigned_integer, not
extract_address.
(read_var_value): Use store_typed_address instead of store_address
for building label values.
(locate_var_value): Use value_from_pointer instead of
value_from_longest.
* hppa-tdep.c (find_stub_with_shl_get): Use value_from_pointer,
instead of value_from_longest, to build arguments to __d_shl_get.
* printcmd.c (set_next_address): Use value_from_pointer, not
value_from_longest.
(x_command): Use value_from_pointer, not value_from_longest.
* tracepoint.c (set_traceframe_context): Use value_from_pointer,
not value_from_longest.
* valarith.c (value_add, value_sub): Use value_from_pointer, not
value_from_longest.
* valops.c (find_function_in_inferior, value_coerce_array,
value_coerce_function, value_addr, hand_function_call): Same.
* value.h (COERCE_REF): Use unpack_pointer, not unpack_long.
* values.c (unpack_long): Use extract_typed_address to produce
addresses from pointers and references, not extract_address.
(value_from_longest): Use store_typed_address instead of
store_address to produce pointer and reference values.
Diffstat (limited to 'gdb/findvar.c')
-rw-r--r-- | gdb/findvar.c | 110 |
1 files changed, 98 insertions, 12 deletions
diff --git a/gdb/findvar.c b/gdb/findvar.c index 98a7133..10f9c3f 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -169,6 +169,20 @@ extract_long_unsigned_integer (void *addr, int orig_len, LONGEST *pval) return 0; } + +/* Treat the LEN bytes at ADDR as a target-format address, and return + that address. ADDR is a buffer in the GDB process, not in the + inferior. + + This function should only be used by target-specific code. It + assumes that a pointer has the same representation as that thing's + address represented as an integer. Some machines use word + addresses, or similarly munged things, for certain types of + pointers, so that assumption doesn't hold everywhere. + + Common code should use extract_typed_address instead, or something + else based on POINTER_TO_ADDRESS. */ + CORE_ADDR extract_address (void *addr, int len) { @@ -177,6 +191,25 @@ extract_address (void *addr, int len) return (CORE_ADDR) extract_unsigned_integer (addr, len); } + +#ifndef POINTER_TO_ADDRESS +#define POINTER_TO_ADDRESS generic_pointer_to_address +#endif + +/* Treat the bytes at BUF as a pointer of type TYPE, and return the + address it represents. */ +CORE_ADDR +extract_typed_address (void *buf, struct type *type) +{ + if (TYPE_CODE (type) != TYPE_CODE_PTR + && TYPE_CODE (type) != TYPE_CODE_REF) + internal_error ("findvar.c (generic_pointer_to_address): " + "type is not a pointer or reference"); + + return POINTER_TO_ADDRESS (type, buf); +} + + void store_signed_integer (void *addr, int len, LONGEST val) { @@ -231,14 +264,43 @@ store_unsigned_integer (void *addr, int len, ULONGEST val) } } -/* Store the literal address "val" into - gdb-local memory pointed to by "addr" - for "len" bytes. */ +/* Store the address VAL as a LEN-byte value in target byte order at + ADDR. ADDR is a buffer in the GDB process, not in the inferior. + + This function should only be used by target-specific code. It + assumes that a pointer has the same representation as that thing's + address represented as an integer. Some machines use word + addresses, or similarly munged things, for certain types of + pointers, so that assumption doesn't hold everywhere. + + Common code should use store_typed_address instead, or something else + based on ADDRESS_TO_POINTER. */ void store_address (void *addr, int len, LONGEST val) { store_unsigned_integer (addr, len, val); } + + +#ifndef ADDRESS_TO_POINTER +#define ADDRESS_TO_POINTER generic_address_to_pointer +#endif + +/* Store the address ADDR as a pointer of type TYPE at BUF, in target + form. */ +void +store_typed_address (void *buf, struct type *type, CORE_ADDR addr) +{ + if (TYPE_CODE (type) != TYPE_CODE_PTR + && TYPE_CODE (type) != TYPE_CODE_REF) + internal_error ("findvar.c (generic_address_to_pointer): " + "type is not a pointer or reference"); + + ADDRESS_TO_POINTER (type, buf, addr); +} + + + /* Extract a floating-point number from a target-order byte-stream at ADDR. Returns the value as type DOUBLEST. @@ -445,7 +507,8 @@ default_get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval) if (raw_buffer != NULL) { /* Put it back in target format. */ - store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), (LONGEST) addr); + store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), + (LONGEST) addr); } if (addrp != NULL) *addrp = 0; @@ -831,8 +894,9 @@ read_register (regno) if (!register_valid[regno]) target_fetch_registers (regno); - return (CORE_ADDR) extract_address (®isters[REGISTER_BYTE (regno)], - REGISTER_RAW_SIZE (regno)); + return ((CORE_ADDR) + extract_unsigned_integer (®isters[REGISTER_BYTE (regno)], + REGISTER_RAW_SIZE (regno))); } CORE_ADDR @@ -1150,6 +1214,25 @@ write_fp (val) { TARGET_WRITE_FP (val); } + + +/* Given a pointer of type TYPE in target form in BUF, return the + address it represents. */ +CORE_ADDR +generic_pointer_to_address (struct type *type, char *buf) +{ + return extract_address (buf, TYPE_LENGTH (type)); +} + + +/* Given an address, store it as a pointer of type TYPE in target + format in BUF. */ +void +generic_address_to_pointer (struct type *type, char *buf, CORE_ADDR addr) +{ + store_address (buf, TYPE_LENGTH (type), addr); +} + /* Will calling read_var_value or locate_var_value on SYM end up caring what frame it is being evaluated relative to? SYM must @@ -1231,12 +1314,15 @@ read_var_value (var, frame) case LOC_LABEL: /* Put the constant back in target format. */ if (overlay_debugging) - store_address (VALUE_CONTENTS_RAW (v), len, - (LONGEST) symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var), - SYMBOL_BFD_SECTION (var))); + { + CORE_ADDR addr + = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var), + SYMBOL_BFD_SECTION (var)); + store_typed_address (VALUE_CONTENTS_RAW (v), type, addr); + } else - store_address (VALUE_CONTENTS_RAW (v), len, - (LONGEST) SYMBOL_VALUE_ADDRESS (var)); + store_typed_address (VALUE_CONTENTS_RAW (v), type, + SYMBOL_VALUE_ADDRESS (var)); VALUE_LVAL (v) = not_lval; return v; @@ -1678,7 +1764,7 @@ locate_var_value (var, frame) value_ptr val; addr = VALUE_ADDRESS (lazy_value); - val = value_from_longest (lookup_pointer_type (type), (LONGEST) addr); + val = value_from_pointer (lookup_pointer_type (type), addr); VALUE_BFD_SECTION (val) = VALUE_BFD_SECTION (lazy_value); return val; } |