binutils-gdb/gdbsupport
Andrew Burgess caa7fd04f6 gdb: New maintenance command to print XML target description
This commit adds a new maintenance command that dumps the current
target description as an XML document.  This is a maintenance command
as I currently only see this being useful for GDB developers, or for
people debugging a new remote target.

By default the command will print whatever the current target
description is, whether this was delivered by the remote, loaded by
the user from a file, or if it is a built in target within GDB.

The command can also take an optional filename argument.  In this case
GDB loads a target description from the file, and then reprints it.
This could be useful for testing GDB's parsing of target descriptions,
or to check that GDB can successfully parse a particular XML
description.

It is worth noting that the XML description printed will not be an
exact copy of the document fed into GDB.  For example this minimal
input file:

  <target>
    <feature name="abc">
      <reg name="r1" bitsize="32"/>
    </feature>
  </target>

Will produce this output:

  (gdb) maint print xml-tdesc path/to/file.xml
  <?xml version="1.0"?>
  <!DOCTYPE target SYSTEM "gdb-target.dtd">
  <target>
    <feature name="abc">
      <reg name="r1" bitsize="32" type="int" regnum="0"/>
    </feature>
  </target>

Notice that GDB filled in both the 'type' and 'regnum' fields of the
<reg>.  I think this is actually a positive as it means we get to
really understand how GDB processed the document, if GDB made some
assumptions that differ to those the user expected then hopefully this
will bring those issues to the users attention.

To implement this I have tweaked the output produced by the
print_xml_feature which is defined within the gdbsupport/ directory.
The changes I have made to this class are:

  1. The <architecture>...</architecture> tags are now not produced if
  the architecture name is NULL.

  2. The <osabi>...</osabi> tags get a newline at the end.

  3. And, the whole XML document is indented using white space in a
  nested fashion (as in the example output above).

I think that these changes should be fine, the print_xml_feature class
is used:

  1. In gdbserver to generate an XML document to send as the target
  description to GDB.

  2. In GDB as part of a self-check function, a target_desc is
  converted to XML then parsed back into a target_desc.  We then check
  the before and after target_desc objects are the same.

  3. In the new 'maint print xml-tdesc' command.

In all of these use cases adding the extra white space should be fine.

gdbsupport/ChangeLog:

	* 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.

gdb/ChangeLog:

	* target-descriptions.c (tdesc_architecture_name): Protect against
	NULL pointer dereference.
	(maint_print_xml_tdesc_cmd): New function.
	(_initialize_target_descriptions): Register new 'maint print
	xml-tdesc' command and give it the filename completer.
	* NEWS: Mention new 'maint print xml-tdesc' command.

gdb/testsuite/ChangeLog:

	* gdb.xml/tdesc-reload.c: New file.
	* gdb.xml/tdesc-reload.exp: New file.
	* gdb.xml/maint-xml-dump-01.xml: New file.
	* gdb.xml/maint-xml-dump-02.xml: New file.
	* gdb.xml/maint-xml-dump.exp: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Document new 'maint print
	xml-desc' command.
2020-06-23 22:17:20 +01:00
..
.dir-locals.el gdbserver/gdbsupport: Add .dir-locals.el file 2020-03-06 11:29:46 +00:00
.gitattributes gdb, gdbserver, gdbsupport: add .gitattributes files 2020-03-05 15:59:22 +01:00
ChangeLog gdb: New maintenance command to print XML target description 2020-06-23 22:17:20 +01:00
Makefile.am Move event-loop.[ch] to gdbsupport/ 2020-04-13 14:10:04 -06:00
Makefile.in Move event-loop.[ch] to gdbsupport/ 2020-04-13 14:10:04 -06:00
README
acinclude.m4 Move gdb/selftest.m4 to gdbsupport/selftest.m4 2020-03-12 14:19:38 -04:00
aclocal.m4
agent.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
agent.h
alt-stack.h
array-view.h
ax.def
block-signals.h
break-common.h
btrace-common.cc Don't pass NULL to memcpy in gdb 2020-03-31 07:29:53 -06:00
btrace-common.h Disable record btrace bts support for AMD processors 2020-05-14 17:56:33 -07:00
buffer.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
buffer.h
byte-vector.h
check-defines.el Add gdbsupport check-defines script 2020-01-14 16:25:04 -07:00
cleanups.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
cleanups.h
common-debug.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
common-debug.h
common-defs.h gdbsupport: include cstdlib in common-defs.h 2020-04-27 09:28:03 -04:00
common-exceptions.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
common-exceptions.h
common-gdbthread.h
common-inferior.cc gdbsupport: Let construct_inferior_arguments take gdb::array_view param 2020-05-25 11:38:45 -04:00
common-inferior.h gdbsupport: Let construct_inferior_arguments take gdb::array_view param 2020-05-25 11:38:45 -04:00
common-regcache.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
common-regcache.h gdb: protect some 'regcache_read_pc' calls 2020-05-14 13:59:53 +02:00
common-types.h Change gdbsupport not to rely on BFD 2020-03-12 13:32:16 -06:00
common-utils.cc gdbsupport: Drop now unused function 'stringify_argv' 2020-05-25 11:40:35 -04:00
common-utils.h gdbsupport: Drop now unused function 'stringify_argv' 2020-05-25 11:40:35 -04:00
common.m4 Move event-loop configury to common.m4 2020-04-13 14:10:03 -06:00
config.in Move event-loop configury to common.m4 2020-04-13 14:10:03 -06:00
configure Move event-loop configury to common.m4 2020-04-13 14:10:03 -06:00
configure.ac Move sourcing of development.sh to GDB_AC_COMMON 2020-03-12 14:18:00 -04:00
create-version.sh gdbsupport: Resolve shellcheck issues in create-version.sh script 2020-03-27 13:52:00 +00:00
def-vector.h
default-init-alloc.h
enum-flags.h
environ.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
environ.h
errors.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
errors.h Introduce and use flush_streams 2020-04-13 14:10:04 -06:00
event-loop.cc Move gdb_notifier comment 2020-04-13 14:10:04 -06:00
event-loop.h Move event-loop.[ch] to gdbsupport/ 2020-04-13 14:10:04 -06:00
fileio.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
fileio.h
filestuff.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
filestuff.h
filtered-iterator.h
format.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
format.h
forward-scope-exit.h
function-view.h
gdb-dlfcn.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
gdb-dlfcn.h Fix comment for 'gdb_dlopen' 2020-02-28 11:04:28 -05:00
gdb-safe-ctype.h Use safe-ctype.h (ISSPACE etc.) in symbol parsing & comparison 2020-05-23 12:46:37 +01:00
gdb-sigmask.h Fix typo (thead -> thread) 2020-04-28 11:38:26 +02:00
gdb_assert.h
gdb_binary_search.h Fix two typos in gdb_binary_search.h 2020-03-08 11:05:43 -06:00
gdb_locale.h
gdb_optional.h
gdb_proc_service.h Ensure proc-service symbols have default visibility (PR build/24805) 2020-01-16 19:14:14 +00:00
gdb_ref_ptr.h Mark move constructors as "noexcept" 2020-04-20 11:45:06 -06:00
gdb_select.h Move gdb_select.h to gdbsupport/ 2020-04-13 14:10:03 -06:00
gdb_setjmp.h
gdb_signals.h
gdb_splay_tree.h
gdb_string_view.h
gdb_string_view.tcc
gdb_sys_time.h
gdb_tilde_expand.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
gdb_tilde_expand.h
gdb_unique_ptr.h
gdb_unlinker.h
gdb_vecs.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
gdb_vecs.h
gdb_wait.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
gdb_wait.h
hash_enum.h
host-defs.h
job-control.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
job-control.h
netstuff.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
netstuff.h
new-op.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
next-iterator.h
observable.h
offset-type.h
parallel-for.h
pathstuff.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
pathstuff.h
poison.h
preprocessor.h
print-utils.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
print-utils.h
ptid.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
ptid.h
refcounted-object.h
rsp-low.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
rsp-low.h
run-time-clock.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
run-time-clock.h
safe-iterator.h
safe-strerror.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
scope-exit.h
scoped_fd.h Mark move constructors as "noexcept" 2020-04-20 11:45:06 -06:00
scoped_mmap.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
scoped_mmap.h Mark move constructors as "noexcept" 2020-04-20 11:45:06 -06:00
scoped_restore.h
selftest.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
selftest.h
selftest.m4 Move gdb/selftest.m4 to gdbsupport/selftest.m4 2020-03-12 14:19:38 -04:00
signals-state-save-restore.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
signals-state-save-restore.h
signals.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
symbol.h
tdesc.cc gdb: New maintenance command to print XML target description 2020-06-23 22:17:20 +01:00
tdesc.h gdb: New maintenance command to print XML target description 2020-06-23 22:17:20 +01:00
thread-pool.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
thread-pool.h
traits.h
underlying.h
valid-expr.h
version.h
warning.m4 gdb: enable -Wmissing-prototypes warning 2020-03-11 15:15:12 -04:00
x86-xstate.h
xml-utils.cc gdbsupport: rename source files to .cc 2020-02-13 16:27:03 -05:00
xml-utils.h

README

This is a helper library that is used by gdb and gdbserver.

To send patches, follow the gdb patch submission instructions in
../gdb/CONTRIBUTE.  For maintainers, see ../gdb/MAINTAINERS.