]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/poke: Support non 8-bits targets
authorLancelot SIX <lsix@lancelotsix.com>
Mon, 19 Sep 2022 11:38:13 +0000 (12:38 +0100)
committerLancelot SIX <lancelot.six@amd.com>
Sat, 24 Sep 2022 20:41:15 +0000 (21:41 +0100)
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.

gdb/poke.c

index a2adb0e22460589fecc816140a232a7d1a99d4b0..e2833ed6bba9951cbcb61182b11e1ea66d32d393 100644 (file)
@@ -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 += "}";