Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 1/5] [pre-commit] Check xml files
Date: Wed, 26 Aug 2026 23:22:05 +0200	[thread overview]
Message-ID: <20260826212209.925066-2-tdevries@suse.de> (raw)
In-Reply-To: <20260826212209.925066-1-tdevries@suse.de>

Add two pre-commit checks to check xml files (*.xml, *.xsl and
./gdb/doc/stack_frame.svg).

The first one is check-xml [1].  This just checks for well-formedness.  It's
enabled by default.

The second one is xmllint [2].  This has more elaborate checks.  But because
it's C-based, it's not enabled by default.

[1] https://github.com/pre-commit/pre-commit-hooks#check-xml
[2] https://gnome.pages.gitlab.gnome.org/libxml2/xmllint.html
---
 .pre-commit-config.yaml | 27 +++++++++++++
 gdb/contrib/xmllint.sh  | 87 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+)
 create mode 100755 gdb/contrib/xmllint.sh

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 53e4c5033c1..622d56936fb 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -109,6 +109,19 @@ repos:
       - id: yamllint
         files: '^\.pre-commit-config.yaml$'
 
+  # Out-of-the-box hooks.
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v6.0.0
+    hooks:
+      # This just checks for well-formedness.  For better xml checking, see
+      # xmllint (disabled by default) below.
+      - id: &id5 check-xml
+        name: *id5
+        files: &gdb_xml_files '^(gdb|gdbserver|gdbsupport)/.*\.(xml|xsl|svg)$'
+        # Exclude:
+        # - gdb.xml/tdesc-bogus.xml (malformed)
+        exclude: ^gdb/testsuite/gdb.xml/tdesc-bogus.xml$
+
   # Local hooks.
   - repo: local
     hooks:
@@ -146,6 +159,20 @@ repos:
         language: unsupported_script
         entry: gdb/contrib/check-file-mode.sh
         files: *gdb_files
+      - id: &id6 xmllint
+        name: *id6
+        # The xmllint.sh script calls xmllint.  Users need to install xmllint
+        # and its dependencies.  It's not clear what the supported versions
+        # are, but this has been tested with libxml version 21308.
+        language: unsupported_script
+        entry: gdb/contrib/xmllint.sh
+        files: *gdb_xml_files
+        # Disabled by default, because pre-commit doesn't install xmllint for
+        # you.  To use this hook, do:
+        #   $ pre-commit run --hook-stage manual xmllint --files ...
+        #   $ pre-commit run --hook-stage manual xmllint --all-files
+        # or similar.
+        stages: [manual]
 
 # Local Variables:
 # indent-tabs-mode: nil
diff --git a/gdb/contrib/xmllint.sh b/gdb/contrib/xmllint.sh
new file mode 100755
index 00000000000..748e096bbef
--- /dev/null
+++ b/gdb/contrib/xmllint.sh
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+# Copyright (C) 2026 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/>.
+
+# Wrapper around xmllint to make it exit with non-zero if there is any output.
+
+tmp=""
+
+cleanup()
+{
+    if [ "$tmp" != "" ]; then
+	rm -f "$tmp"
+    fi
+}
+
+# Schedule cleanup.
+trap cleanup EXIT
+
+tmp=$(mktemp)
+
+check_basic=""
+check_includes=""
+for f in "$@"; do
+    case $f in
+        gdb/testsuite/gdb.xml/tdesc-bogus.xml)
+	    # Malformed.
+	    continue
+	    ;;
+	gdb/testsuite/gdb.xml/bad-include.xml \
+	    | gdb/testsuite/gdb.xml/core-only.xml \
+	    | gdb/testsuite/gdb.xml/extra-regs.xml \
+	    | gdb/testsuite/gdb.xml/loop.xml)
+            # Don't check includes for:
+            # - gdb.xml/bad-include.xml (XInclude error: nonexistent.xml)
+            # - gdb.xml/{core-only,extra-regs}.xml (XInclude error: core-regs.xml)
+            # - gdb.xml/loop.xml (XInclude error: loop.xml)
+	    check_basic="$check_basic $f"
+	    ;;
+	*)
+	    check_includes="$check_includes $f"
+	    ;;
+    esac
+done
+
+st1=0
+if [ "$check_basic" != "" ]; then
+    xmllint --noout \
+	    $check_basic \
+	    > "$tmp" \
+	    2>&1; st1=$?
+fi
+
+st2=0
+if [ "$check_includes" != "" ]; then
+    # Provide the --path parts to let xmllint find the .dtd files.
+    xmllint --noout --xinclude --path gdb/syscalls --path gdb/features \
+	    $check_includes \
+	    >> "$tmp" \
+	    2>&1; st2=$?
+fi
+
+if [ $st1 -eq 0 ] && [ $st2 -eq 0 ]; then
+    st=0
+else
+    st=1
+fi
+
+if [ -s "$tmp" ]; then
+    cat "$tmp"
+    if [ $st -eq 0 ]; then
+	st=1
+    fi
+fi
+
+exit $st
-- 
2.51.0


  reply	other threads:[~2026-08-26 21:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 21:22 [PATCH v2 0/5] [gdb] xml linting Tom de Vries
2026-08-26 21:22 ` Tom de Vries [this message]
2026-08-26 21:22 ` [PATCH v2 2/5] [gdb] Fix xmllint namespace errors Tom de Vries
2026-08-26 21:22 ` [PATCH v2 3/5] [gdb] Fix target element validity error in features/gdb-target.dtd Tom de Vries
2026-08-26 21:22 ` [PATCH v2 4/5] [gdb] Fix syscalls-info -> syscalls_info in syscalls/gdb-syscalls.dtd Tom de Vries
2026-08-26 21:22 ` [PATCH v2 5/5] [pre-commit] Use --valid with xmllint Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260826212209.925066-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox