From: Luis Machado Date: Wed, 9 Sep 2020 20:20:15 +0000 (-0300) Subject: [Morello] Add support for capability/pointer/integer conversions X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ee5808b7c895fca48985162c25a37f16c2930ff;p=thirdparty%2Fbinutils-gdb.git [Morello] Add support for capability/pointer/integer conversions Enable hooks to allow custom conversions of capability/pointer/integer values. gdb/ChangeLog: 2020-10-20 Luis Machado * aarch64-tdep.c: Include inferior.h. (aarch64_pointer_to_address, aarch64_address_to_pointer) (aarch64_integer_to_address): New functions. (aarch64_gdbarch_init): Register hooks. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 59b06a9c81d..61ca19b468d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2020-10-20 Luis Machado + + * aarch64-tdep.c: Include inferior.h. + (aarch64_pointer_to_address, aarch64_address_to_pointer) + (aarch64_integer_to_address): New functions. + (aarch64_gdbarch_init): Register hooks. + 2020-10-20 Luis Machado * aarch64-linux-tdep.c: Include value.h. diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index f882a0a4652..47b435b888d 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -55,6 +55,9 @@ #include "gdbsupport/capability.h" +/* For address/int to pointer conversions. */ +#include "inferior.h" + #define submask(x) ((1L << ((x) + 1)) - 1) #define bit(obj,st) (((obj) >> (st)) & 1) #define bits(obj,st,fn) (((obj) >> (st)) & submask ((fn) - (st))) @@ -3491,6 +3494,51 @@ aarch64_address_class_name_to_type_flags (struct gdbarch *gdbarch, return false; } +/* Implements the gdbarch_pointer_to_address hook. */ + +static CORE_ADDR +aarch64_pointer_to_address (struct gdbarch *gdbarch, struct type *type, + const gdb_byte *buf) +{ + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + + if (type->length <= 8) + return signed_pointer_to_address (gdbarch, type, buf); + else + { + /* Convert a capability to a regular 64-bit address, discarding + the extra information. */ + return extract_unsigned_integer (buf, 8, byte_order); + } +} + +/* Implements the gdbarch_address_to_pointer hook. */ + +static void +aarch64_address_to_pointer (struct gdbarch *gdbarch, struct type *type, + gdb_byte *buf, CORE_ADDR addr) +{ + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + + if (type->length <= 8) + address_to_signed_pointer (gdbarch, type, buf, addr); + else + { + /* Create a fake capability with only the address part. */ + memset (buf, 0, type->length); + store_unsigned_integer (buf, 8, byte_order, addr); + } +} + +/* Implements the gdbarch_integer_to_address hook. */ + +static CORE_ADDR +aarch64_integer_to_address (struct gdbarch *gdbarch, + struct type *type, const gdb_byte *buf) +{ + return aarch64_pointer_to_address (gdbarch, type, buf); +} + /* Initialize the current architecture based on INFO. If possible, re-use an architecture from ARCHES, which is a list of architectures already created during this debugging session. @@ -3773,6 +3821,11 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) (gdbarch, aarch64_address_class_name_to_type_flags); set_gdbarch_address_class_type_flags_to_name (gdbarch, aarch64_address_class_type_flags_to_name); + + /* For converting between pointer/capability. */ + set_gdbarch_pointer_to_address (gdbarch, aarch64_pointer_to_address); + set_gdbarch_address_to_pointer (gdbarch, aarch64_address_to_pointer); + set_gdbarch_integer_to_address (gdbarch, aarch64_integer_to_address); } return gdbarch;