public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Shahab Vahedi <shahab.vahedi@gmail.com>
To: gdb@sourceware.org
Subject: Custom types in target description XMLs
Date: Tue, 13 Jul 2021 21:08:54 +0200	[thread overview]
Message-ID: <YO3kxtKlu4SLbHM2@gmail.com> (raw)

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

             reply	other threads:[~2021-07-13 19:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13 19:08 Shahab Vahedi [this message]
2021-07-15 14:37 ` Simon Marchi
2021-07-15 17:21   ` Shahab Vahedi
2021-08-02 11:51 ` Shahab Vahedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YO3kxtKlu4SLbHM2@gmail.com \
    --to=shahab.vahedi@gmail.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).