Re: Custom types in target description XMLs

Shahab Vahedi via Gdb <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
Hi Simon,

On Thu, Jul 15, 2021 at 10:37:39AM -0400, Simon Marchi wrote:
> Given the lack of response, I would say that nobody knows that off-hand,
> and you would need to dive into the code to check what is happening, if
> it's a GDB bug or something else.

I was just about to write another email. I have investigated both of the
problems and they seem like a bug to me.

The following change fixes the "field" type issue:

------------------------8<------------------------
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 0749f38983e..91602b41274 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1186,7 +1186,7 @@ val_print_type_code_flags (struct type *type, ...
 	    {
 	      unsigned field_len = TYPE_FIELD_BITSIZE (type, field);
 	      ULONGEST field_val
-		= val >> (TYPE_FIELD_BITPOS (type, field) - field_len + 1);
+		= val >> TYPE_FIELD_BITPOS (type, field);
 
 	      if (field_len < sizeof (ULONGEST) * TARGET_CHAR_BIT)
 		field_val &= ((ULONGEST) 1 << field_len) - 1;
------------------------>8------------------------

And this one solves the "struct" type problem:
------------------------8<------------------------
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 43c05d344d0..68e65ef8bb5 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5805,7 +5805,7 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
   builtin_type->builtin_string
     = arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
   builtin_type->builtin_bool
-    = arch_type (gdbarch, TYPE_CODE_BOOL, TARGET_CHAR_BIT, "bool");
+    = arch_boolean_type (gdbarch, TARGET_CHAR_BIT, 1, "bool");
 
   /* The following three are about decimal floating point types, which
      are 32-bits, 64-bits and 128-bits respectively.  */
------------------------>8------------------------

I will file two separate bugs and then submit the two patches with the
explanations.


Cheers,
Shahab
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.