- *bytes_read = TARGET_ADDR_BIT / TARGET_CHAR_BIT;
- /* NOTE: cagney/2003-05-22: This extract is assuming that a DWARF 2
- address is always unsigned. That may or may not be true. */
- result = extract_unsigned_integer (buf, TARGET_ADDR_BIT / TARGET_CHAR_BIT);
- return result;
+ /* For most architectures, calling extract_unsigned_integer() alone
+ is sufficient for extracting an address. However, some
+ architectures (e.g. MIPS) use signed addresses and using
+ extract_unsigned_integer() will not produce a correct
+ result. Make sure we invoke gdbarch_integer_to_address()
+ for those architectures which require it.
+
+ The use of `unsigned_address_type' in the code below refers to
+ the type of buf and has no bearing on the signedness of the
+ address being returned. */
+
+ if (gdbarch_integer_to_address_p (gdbarch))
+ return gdbarch_integer_to_address
+ (gdbarch, unsigned_address_type (gdbarch, addr_size), buf);
+
+ return extract_unsigned_integer (buf, addr_size, byte_order);