mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-30 12:44:10 +08:00
caa7fd04f6
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.
84 lines
2.7 KiB
Plaintext
84 lines
2.7 KiB
Plaintext
# Copyright 2020 Free Software Foundation, Inc.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# Testing for 'maint print xml-tdesc'. Check we can print out the
|
|
# current target description and load it back in again.
|
|
|
|
if {[gdb_skip_xml_test]} {
|
|
unsupported "xml tests not being run"
|
|
return -1
|
|
}
|
|
|
|
standard_testfile
|
|
|
|
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
|
|
return -1
|
|
}
|
|
|
|
if ![runto_main] then {
|
|
fail "can't run to main"
|
|
return 0
|
|
}
|
|
|
|
# Three files we're going to write out to.
|
|
set xml_file_1 [standard_output_file outfile1.xml]
|
|
set xml_file_2 [standard_output_file outfile2.xml]
|
|
set xml_file_3 [standard_output_file outfile3.xml]
|
|
|
|
# Write the current target description to a file.
|
|
gdb_test_no_output "pipe maint print xml-tdesc | cat > $xml_file_1" \
|
|
"write current target description to file"
|
|
|
|
# Read the target description back in to GDB, and the write it back
|
|
# out to a file.
|
|
gdb_test_no_output \
|
|
"pipe maint print xml-tdesc $xml_file_1 | cat > $xml_file_2" \
|
|
"read previous xml description, and write it out to a second file"
|
|
|
|
# Check the two produced files are identical.
|
|
gdb_test "shell diff -s $xml_file_1 $xml_file_2" \
|
|
"Files \[^\r\n\]* are identical" \
|
|
"first two produced xml files are identical"
|
|
|
|
# Restart GDB.
|
|
clean_restart
|
|
|
|
# Change to use one of the target descriptions we wrote out earlier.
|
|
gdb_test_no_output "set tdesc filename $xml_file_1" \
|
|
"set target description to use"
|
|
|
|
# Load the executable.
|
|
gdb_load ${binfile}
|
|
|
|
# Run to `main' where we begin our tests.
|
|
if ![runto_main] then {
|
|
untested "could not run to main"
|
|
return -1
|
|
}
|
|
|
|
# Run info registers just to check this appears to run fine with the
|
|
# new target description.
|
|
gdb_test "info all-registers" ".*" \
|
|
"Run info registers"
|
|
|
|
# Write out the current target description.
|
|
gdb_test_no_output "pipe maint print xml-tdesc | cat > $xml_file_3" \
|
|
"write third target description to file"
|
|
|
|
# And check that it matches the original file we loaded.
|
|
gdb_test "shell diff -s $xml_file_1 $xml_file_3" \
|
|
"Files \[^\r\n\]* are identical" \
|
|
"first and third produced xml files are identical"
|