gdbsupport/tdesc: print enum fields using 'evalue' syntax
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 1 Dec 2020 11:07:12 +0000 (11:07 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 1 Dec 2020 11:22:24 +0000 (11:22 +0000)
Currently when printing an XML description GDB prints enum values like
this:

  <enum id="levels_type" size="4">
    <field name="low" start="0"/>
    <field name="high" start="1"/>
  </enum>

This is incorrect, and is most likely a copy and paste error with the
struct and flags printing code.  The correct syntax is:

  <enum id="levels_type" size="4">
    <evalue name="low" value="0"/>
    <evalue name="high" value="1"/>
  </enum>

A test is included to cover this functionality.

gdb/testsuite/ChangeLog:

* gdb.xml/maint-xml-dump-03.xml: New file.

gdbsupport/ChangeLog:

* tdesc.cc (print_xml_feature::visit): Print enum fields using
'evalue' syntax.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.xml/maint-xml-dump-03.xml [new file with mode: 0644]
gdbsupport/ChangeLog
gdbsupport/tdesc.cc

index 882d02f5ef17267d3d6cbcdbcd9bdfb8fba8d831..5966355266a20f86dff2803761f5ca94add9523f 100644 (file)
@@ -1,3 +1,7 @@
+2020-12-01  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.xml/maint-xml-dump-03.xml: New file.
+
 2020-11-30  Tom de Vries  <tdevries@suse.de>
 
        PR symtab/26905
diff --git a/gdb/testsuite/gdb.xml/maint-xml-dump-03.xml b/gdb/testsuite/gdb.xml/maint-xml-dump-03.xml
new file mode 100644 (file)
index 0000000..89741e6
--- /dev/null
@@ -0,0 +1,13 @@
+<target>
+  <feature name="abc">
+    <enum id="levels_type" size="4">
+      <evalue name="low" value="0"/>
+      <evalue name="high" value="1"/>
+    </enum>
+    <flags id="flags_type" size="4">
+      <field name="X" start="0" end="0" type="bool"/>
+      <field name="LEVEL" start="1" end="1" type="levels_type"/>
+    </flags>
+    <reg name="flags" bitsize="32" type="flags_type" regnum="0"/>
+  </feature>
+</target>
index a77f1c9fd86df2b4692e06183a42a952c55084af..88a0413e8b9fb98ddfb5635458346388565f27b9 100644 (file)
@@ -1,3 +1,8 @@
+2020-12-01  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * tdesc.cc (print_xml_feature::visit): Print enum fields using
+       'evalue' syntax.
+
 2020-12-01  Chungyi Chi  <demonic@csie.io>
 
        * tdesc.cc (print_xml_feature::visit): Print enum size attribute.
index 2bc0247907dc6d23dd6434b8810704f8aa302c5a..c062a771b58c633728e54d6a815f0784013ffa14 100644 (file)
@@ -355,8 +355,10 @@ void print_xml_feature::visit (const tdesc_type_with_fields *t)
        string_appendf (tmp, " size=\"%d\"", t->size);
       string_appendf (tmp, ">");
       add_line (tmp);
+      /* The 'start' of the field is reused as the enum value.  The 'end'
+        of the field is always set to -1 for enum values.  */
       for (const tdesc_type_field &f : t->fields)
-       add_line ("  <field name=\"%s\" start=\"%d\"/>",
+       add_line ("  <evalue name=\"%s\" value=\"%d\"/>",
                  f.name.c_str (), f.start);
       break;