Custom types in target description XMLs

Shahab Vahedi shahab.vahedi@gmail.com
Tue Jul 13 19:08:54 GMT 2021


Hello,

I have difficulties defining a custom register type in a target
description XML format. For the sake of argument, consider the
32-bit register below with it's own contrived fields:

bit:   31     ...     11  10  9   8  7  ...  0
      ,-----------------.---.---.---.---------.
      | dont_care_field | g | u | b | version |
      `-----------------^---^---^---^---------'

I've come up with two definitions. One uses the "flag" and the
other uses the "struct" type. However, both have their issues
in representing the correct values. The definitions are as
follows:

-----------------------------8<-----------------------------
<?xml version="1.0"?>

<!DOCTYPE feature SYSTEM "gdb-target.dtd">
<feature name="org.gnu.gdb.arc.fpu">
  <flags id="flag_type" size="4">
    <field name="version" start="0"  end="7"  type="int" />
    <field name="b"       start="8"  end="8"  type="bool"/>
    <field name="u"       start="9"  end="9"  type="bool"/>
    <field name="g"       start="10" end="10" type="bool"/>
    <field name=""        start="11" end="31"            />
  </flags>
  <struct id="struct_type" size="4">
    <field name="version" start="0"  end="7"  type="int" />
    <field name="b"       start="8"  end="8"  type="bool"/>
    <field name="u"       start="9"  end="9"  type="bool"/>
    <field name="g"       start="10" end="10" type="bool"/>
    <field name=""        start="11" end="31"            />
  </struct>
  <reg name="f_reg" bitsize="32" type="flag_type"/>
  <reg name="s_reg" bitsize="32" type="struct_type"/>
</feature>
----------------------------->8-----------------------------

The value reported by GDBstub (QEMU) is 0x1337 for both registers:

0  x   1    3    3    7
     0001 0011 0011 0111

version: 0x37 (55)
b: true
u: true
g: false

However, this is how GDB prints them:

---------------------- [ gdb ] ----------------------
(gdb) info reg $f_reg
f_reg          0x1337              [ version=0 b u ]
-----------------------------------------------------

Here, while "$f_reg" holds the correct value (0x1337), the
"version" field is 0 instead of 55. "b", "u", and "g" fields
are inferred correctly though.

---------------------- [ gdb ] ----------------------
(gdb) info reg $s_reg
s_reg          {
  version = 0x37,
  b = 0xff,
  u = 0xff,
  g = 0x0
} {
  version = 55,
  b = -1,
  u = -1,
  g = false
}
-----------------------------------------------------

The register with struct type on the other hand, interprets
"version" correctly while misjudging the "boolean" fields that
are set.

Am I doing something wrong or this could be a bug in parsing?
If latter is the case, I will dive into the code to find the
root cause. I just need someone to confirm it first.


Thanks,
Shahab


More information about the Gdb mailing list