aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLancelot SIX <lsix@lancelotsix.com>2022-09-19 12:38:13 +0100
committerLancelot SIX <lancelot.six@amd.com>2022-09-24 21:41:15 +0100
commit21c2659b8edc2cd70bfe291272bb5ea080a95b9a (patch)
treefd08aa7b4f6d24241cfb08f61f0fc36a20dba65e
parent9d13358a1331c2da7c3ef97d8be3da7c1ce519fc (diff)
downloadbinutils-21c2659b8edc2cd70bfe291272bb5ea080a95b9a.zip
binutils-21c2659b8edc2cd70bfe291272bb5ea080a95b9a.tar.gz
binutils-21c2659b8edc2cd70bfe291272bb5ea080a95b9a.tar.bz2
gdb/poke: Support non 8-bits targets
Some targets might have non 8-bits bytes. TYPE_CHECK (type) gives a number of host bytes. So to get the type length in bits we should use TYPE_CHECK (type) * HOST_CHAR_BITS. As far as I know, GDB does not support any non-8bits bytes hosts, but it does not hurt to make this change. It also underline that a GDB type’s length is given in host bytes, not target byte. When dealing with target bytes, we should use gdbarch_addressable_memory_unit_size to get the size of a memory unit (in multiple of 8 bits). I have no idea how libpoke would behave if the target has a non 8bits byte. Whatever libpoke does, this patch have GDB do the right thing.
-rw-r--r--gdb/poke.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/gdb/poke.c b/gdb/poke.c
index a2adb0e..e2833ed 100644
--- a/gdb/poke.c
+++ b/gdb/poke.c
@@ -313,9 +313,12 @@ poke_alien_token_handler (const char *id, char **errmsg)
alien_token.kind = PK_ALIEN_TOKEN_OFFSET;
alien_token.value.offset.magnitude = addr;
- alien_token.value.offset.width = 64;
+ alien_token.value.offset.width
+ = HOST_CHAR_BIT * sizeof (decltype (addr));
alien_token.value.offset.signed_p = 0;
- alien_token.value.offset.unit = 8;
+ alien_token.value.offset.unit
+ = (gdbarch_addressable_memory_unit_size (target_gdbarch ())
+ * 8);
}
else
{
@@ -338,9 +341,10 @@ poke_alien_token_handler (const char *id, char **errmsg)
alien_token.value.offset.magnitude
= value_as_address (value);
alien_token.value.offset.width
- = TYPE_LENGTH (type) * 8;
+ = TYPE_LENGTH (type) * HOST_CHAR_BIT;
alien_token.value.offset.signed_p = 0;
- alien_token.value.offset.unit = 8;
+ alien_token.value.offset.unit
+ = gdbarch_addressable_memory_unit_size (target_gdbarch ()) * 8;
}
else if (is_integral_type (type))
{
@@ -348,7 +352,7 @@ poke_alien_token_handler (const char *id, char **errmsg)
alien_token.value.integer.magnitude
= value_as_long (value);
alien_token.value.integer.width
- = TYPE_LENGTH (type) * 8;
+ = TYPE_LENGTH (type) * HOST_CHAR_BIT;
alien_token.value.integer.signed_p
= !type->is_unsigned ();
}
@@ -444,7 +448,7 @@ poke_add_type (struct type *type)
case TYPE_CODE_PTR:
{
str = ("offset<uint<"
- + (std::to_string (TYPE_LENGTH (type) * 8))
+ + (std::to_string (TYPE_LENGTH (type) * HOST_CHAR_BIT))
+ ">,B>");
break;
}
@@ -464,7 +468,7 @@ poke_add_type (struct type *type)
}
case TYPE_CODE_INT:
{
- size_t type_length = TYPE_LENGTH (type) * 8;
+ size_t type_length = TYPE_LENGTH (type) * HOST_CHAR_BIT;
if (type_length > 64)
goto skip;
@@ -530,12 +534,19 @@ poke_add_type (struct type *type)
if (field_name != "")
str += field_name;
if (field_bitpos != natural_bitpos)
- str += " @ " + (field_bitpos % 8 == 0
- ? std::to_string (field_bitpos / 8) + "#B"
- : std::to_string (field_bitpos) + "#b");
+ {
+ const size_t target_byte_size
+ = (gdbarch_addressable_memory_unit_size (target_gdbarch ())
+ * 8);
+ str += " @ " + (field_bitpos % target_byte_size == 0
+ ? std::to_string (field_bitpos
+ / target_byte_size) + "#B"
+ : std::to_string (field_bitpos) + "#b");
+ }
str += ";";
- natural_bitpos = field_bitpos + TYPE_LENGTH (field_type) * 8;
+ natural_bitpos
+ = field_bitpos + TYPE_LENGTH (field_type) * HOST_CHAR_BIT;
}
str += "}";