aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/ChangeLog13
-rw-r--r--gdbsupport/tdesc.cc104
-rw-r--r--gdbsupport/tdesc.h23
3 files changed, 107 insertions, 33 deletions
diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog
index 2e5cbba..b2fbc56 100644
--- a/gdbsupport/ChangeLog
+++ b/gdbsupport/ChangeLog
@@ -1,5 +1,18 @@
2020-06-23 Andrew Burgess <andrew.burgess@embecosm.com>
+ * tdesc.cc (print_xml_feature::visit_pre): Use add_line to add
+ output content, and call indent as needed in all overloaded
+ variants.
+ (print_xml_feature::visit_post): Likewise.
+ (print_xml_feature::visit): Likewise.
+ (print_xml_feature::add_line): Two new overloaded functions.
+ * tdesc.h (print_xml_feature::indent): New member function.
+ (print_xml_feature::add_line): Two new overloaded member
+ functions.
+ (print_xml_feature::m_depth): New member variable.
+
+2020-06-23 Andrew Burgess <andrew.burgess@embecosm.com>
+
* tdesc.cc (print_xml_feature::visit_pre): Print compatible
information.
* tdesc.h (struct tdesc_compatible_info): Declare new struct.
diff --git a/gdbsupport/tdesc.cc b/gdbsupport/tdesc.cc
index 63f41cb..624588b 100644
--- a/gdbsupport/tdesc.cc
+++ b/gdbsupport/tdesc.cc
@@ -294,12 +294,14 @@ tdesc_add_enum_value (tdesc_type_with_fields *type, int value,
void print_xml_feature::visit_pre (const tdesc_feature *e)
{
- string_appendf (*m_buffer, "<feature name=\"%s\">\n", e->name.c_str ());
+ add_line ("<feature name=\"%s\">", e->name.c_str ());
+ indent (1);
}
void print_xml_feature::visit_post (const tdesc_feature *e)
{
- string_appendf (*m_buffer, "</feature>\n");
+ indent (-1);
+ add_line ("</feature>");
}
void print_xml_feature::visit (const tdesc_type_builtin *t)
@@ -309,8 +311,8 @@ void print_xml_feature::visit (const tdesc_type_builtin *t)
void print_xml_feature::visit (const tdesc_type_vector *t)
{
- string_appendf (*m_buffer, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>\n",
- t->name.c_str (), t->element_type->name.c_str (), t->count);
+ add_line ("<vector id=\"%s\" type=\"%s\" count=\"%d\"/>",
+ t->name.c_str (), t->element_type->name.c_str (), t->count);
}
void print_xml_feature::visit (const tdesc_type_with_fields *t)
@@ -319,7 +321,9 @@ void print_xml_feature::visit (const tdesc_type_with_fields *t)
gdb_assert (t->kind >= TDESC_TYPE_STRUCT && t->kind <= TDESC_TYPE_ENUM);
- string_appendf (*m_buffer,
+ std::string tmp;
+
+ string_appendf (tmp,
"<%s id=\"%s\"", types[t->kind - TDESC_TYPE_STRUCT],
t->name.c_str ());
@@ -328,33 +332,37 @@ void print_xml_feature::visit (const tdesc_type_with_fields *t)
case TDESC_TYPE_STRUCT:
case TDESC_TYPE_FLAGS:
if (t->size > 0)
- string_appendf (*m_buffer, " size=\"%d\"", t->size);
- string_appendf (*m_buffer, ">\n");
+ string_appendf (tmp, " size=\"%d\"", t->size);
+ string_appendf (tmp, ">");
+ add_line (tmp);
for (const tdesc_type_field &f : t->fields)
{
- string_appendf (*m_buffer, " <field name=\"%s\" ", f.name.c_str ());
- if (f.start == -1)
- string_appendf (*m_buffer, "type=\"%s\"/>\n",
- f.type->name.c_str ());
- else
- string_appendf (*m_buffer, "start=\"%d\" end=\"%d\"/>\n", f.start,
+ tmp.clear ();
+ string_appendf (tmp, " <field name=\"%s\"", f.name.c_str ());
+ if (f.start != -1)
+ string_appendf (tmp, " start=\"%d\" end=\"%d\"", f.start,
f.end);
+ string_appendf (tmp, " type=\"%s\"/>",
+ f.type->name.c_str ());
+ add_line (tmp);
}
break;
case TDESC_TYPE_ENUM:
- string_appendf (*m_buffer, ">\n");
+ string_appendf (tmp, ">");
+ add_line (tmp);
for (const tdesc_type_field &f : t->fields)
- string_appendf (*m_buffer, " <field name=\"%s\" start=\"%d\"/>\n",
- f.name.c_str (), f.start);
+ add_line (" <field name=\"%s\" start=\"%d\"/>",
+ f.name.c_str (), f.start);
break;
case TDESC_TYPE_UNION:
- string_appendf (*m_buffer, ">\n");
+ string_appendf (tmp, ">");
+ add_line (tmp);
for (const tdesc_type_field &f : t->fields)
- string_appendf (*m_buffer, " <field name=\"%s\" type=\"%s\"/>\n",
- f.name.c_str (), f.type->name.c_str ());
+ add_line (" <field name=\"%s\" type=\"%s\"/>",
+ f.name.c_str (), f.type->name.c_str ());
break;
default:
@@ -362,46 +370,78 @@ void print_xml_feature::visit (const tdesc_type_with_fields *t)
t->name.c_str ());
}
- string_appendf (*m_buffer, "</%s>\n", types[t->kind - TDESC_TYPE_STRUCT]);
+ add_line ("</%s>", types[t->kind - TDESC_TYPE_STRUCT]);
}
void print_xml_feature::visit (const tdesc_reg *r)
{
- string_appendf (*m_buffer,
+ std::string tmp;
+
+ string_appendf (tmp,
"<reg name=\"%s\" bitsize=\"%d\" type=\"%s\" regnum=\"%ld\"",
r->name.c_str (), r->bitsize, r->type.c_str (),
r->target_regnum);
if (r->group.length () > 0)
- string_appendf (*m_buffer, " group=\"%s\"", r->group.c_str ());
+ string_appendf (tmp, " group=\"%s\"", r->group.c_str ());
if (r->save_restore == 0)
- string_appendf (*m_buffer, " save-restore=\"no\"");
+ string_appendf (tmp, " save-restore=\"no\"");
- string_appendf (*m_buffer, "/>\n");
+ string_appendf (tmp, "/>");
+
+ add_line (tmp);
}
void print_xml_feature::visit_pre (const target_desc *e)
{
#ifndef IN_PROCESS_AGENT
- string_appendf (*m_buffer, "<?xml version=\"1.0\"?>\n");
- string_appendf (*m_buffer, "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n");
- string_appendf (*m_buffer, "<target>\n<architecture>%s</architecture>\n",
- tdesc_architecture_name (e));
+ add_line ("<?xml version=\"1.0\"?>");
+ add_line ("<!DOCTYPE target SYSTEM \"gdb-target.dtd\">");
+ add_line ("<target>");
+ indent (1);
+ if (tdesc_architecture_name (e))
+ add_line ("<architecture>%s</architecture>",
+ tdesc_architecture_name (e));
const char *osabi = tdesc_osabi_name (e);
if (osabi != nullptr)
- string_appendf (*m_buffer, "<osabi>%s</osabi>", osabi);
+ add_line ("<osabi>%s</osabi>", osabi);
const std::vector<tdesc_compatible_info_up> &compatible_list
= tdesc_compatible_info_list (e);
for (const auto &c : compatible_list)
- string_appendf (*m_buffer, "<compatible>%s</compatible>\n",
- tdesc_compatible_info_arch_name (c));
+ add_line ("<compatible>%s</compatible>",
+ tdesc_compatible_info_arch_name (c));
#endif
}
void print_xml_feature::visit_post (const target_desc *e)
{
- string_appendf (*m_buffer, "</target>\n");
+ indent (-1);
+ add_line ("</target>");
+}
+
+/* See gdbsupport/tdesc.h. */
+
+void
+print_xml_feature::add_line (const std::string &str)
+{
+ string_appendf (*m_buffer, "%*s", m_depth, "");
+ string_appendf (*m_buffer, "%s", str.c_str ());
+ string_appendf (*m_buffer, "\n");
+}
+
+/* See gdbsupport/tdesc.h. */
+
+void
+print_xml_feature::add_line (const char *fmt, ...)
+{
+ std::string tmp;
+
+ va_list ap;
+ va_start (ap, fmt);
+ string_vappendf (tmp, fmt, ap);
+ va_end (ap);
+ add_line (tmp);
}
diff --git a/gdbsupport/tdesc.h b/gdbsupport/tdesc.h
index 0cdcf56..73caf24 100644
--- a/gdbsupport/tdesc.h
+++ b/gdbsupport/tdesc.h
@@ -410,7 +410,8 @@ class print_xml_feature : public tdesc_element_visitor
{
public:
print_xml_feature (std::string *buffer_)
- : m_buffer (buffer_)
+ : m_buffer (buffer_),
+ m_depth (0)
{}
void visit_pre (const target_desc *e) override;
@@ -423,7 +424,27 @@ public:
void visit (const tdesc_reg *reg) override;
private:
+
+ /* Called with a positive value of ADJUST when we move inside an element,
+ for example inside <target>, and with a negative value when we leave
+ the element. In this class this function does nothing, but a
+ sub-class can override this to track the current level of nesting. */
+ void indent (int adjust)
+ {
+ m_depth += (adjust * 2);
+ }
+
+ /* Functions to add lines to the output buffer M_BUFFER. Each of these
+ functions appends a newline, so don't include one in the strings being
+ passed. */
+ void add_line (const std::string &str);
+ void add_line (const char *fmt, ...);
+
+ /* The buffer we are writing too. */
std::string *m_buffer;
+
+ /* The current indentation depth. */
+ int m_depth;
};
#endif /* COMMON_TDESC_H */