[Lldb-commits] [lldb] [lldb][lldb-server] Enable sending RegisterFlags as XML (PR #69951)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 24 03:13:32 PDT 2023


================
@@ -175,3 +175,35 @@ std::string RegisterFlags::AsTable(uint32_t max_width) const {
 
   return table;
 }
+
+void RegisterFlags::ToXML(StreamString &strm) const {
+  // Example XML:
+  // <flags id="cpsr_flags" size="4">
+  //   <field name="incorrect" start="0" end="0"/>
+  // </flags>
+  strm.Indent();
+  strm << "<flags id=\"" << GetID() << "\" ";
+  strm.Printf("size=\"%d\"", GetSize());
+  strm << ">";
+  for (const Field &field : m_fields) {
+    // Skip padding fields.
+    if (field.GetName().empty())
+      continue;
+
+    strm << "\n";
+    strm.IndentMore();
+    field.ToXML(strm);
+    strm.IndentLess();
+  }
+  strm.PutChar('\n');
+  strm.Indent("</flags>\n");
+}
+
+void RegisterFlags::Field::ToXML(StreamString &strm) const {
+  // Example XML:
+  // <field name="correct" start="0" end="0"/>
+  strm.Indent();
+  strm << "<field name=\"" << GetName() << "\" ";
----------------
DavidSpickett wrote:

Good point. Register names, unlikely. The ID of the flag set is an internal detail so that's ok as is.

For field names I have seen ones like `Foo[N]` so `Foo<N>` isn't that unlikely, especially if you've got a lot of system registers. Split fields like `Foo[3:1<stuff>Foo[0]` aren't that uncommon. I could imagine `'` being used to mean `prime` like `Foo` and `Foo'`.

So I've used printHTMLEscaped to replace the reserved chars (which are the same as for XML), and gone ahead and committed some tests to check that lldb itself will convert those back to the original characters (https://github.com/llvm/llvm-project/commit/2325b3cfdadf266651294ff469ce600a8ee402ce).

https://github.com/llvm/llvm-project/pull/69951


More information about the lldb-commits mailing list