Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] gdb: use XML_GetCurrentLineNumber64 with expat >= 2.9.0
@ 2026-10-11 13:31 Simon Marchi
  2026-10-11 13:31 ` [PATCH 2/2] gdb: remove workarounds for old expat versions Simon Marchi
  2026-10-13  9:23 ` [PATCH 1/2] gdb: use XML_GetCurrentLineNumber64 with expat >= 2.9.0 Tom de Vries
  0 siblings, 2 replies; 4+ messages in thread
From: Simon Marchi @ 2026-10-11 13:31 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

When building against expat 2.9.0, I get:

      CXX    xml-support.o
    /home/smarchi/src/binutils-gdb/gdb/xml-support.c:182:39: error: 'XML_Size XML_GetCurrentLineNumber(XML_Parser)' is deprecated: please use XML_GetCurrentLineNumber64 instead [-Werror=deprecated-declarations]
      182 |   int line = XML_GetCurrentLineNumber (m_expat_parser);
          |              ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~

The functions that return XML_Size were deprecated in favor of the new
functions, with suffix 64, that return uint64_t.

Add a gdb_xml_get_current_line_number wrapper in gdb_expat.h, which
calls XML_GetCurrentLineNumber64 with expat 2.9.0 and later, and
XML_GetCurrentLineNumber otherwise.  Use it in xml-support.c.

The uint64_t gets truncated when converted to int, but that was already
true before, as XML_Size is 64-bits when building on an arch where
unsigned long is 64-bits.

Change-Id: I31a0657702cf45d9d7572276d5c8cc37aed41f79
---
 gdb/gdb_expat.h   | 16 ++++++++++++++++
 gdb/xml-support.c |  4 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gdb/gdb_expat.h b/gdb/gdb_expat.h
index 1feac7f764c0..756cf81be95c 100644
--- a/gdb/gdb_expat.h
+++ b/gdb/gdb_expat.h
@@ -35,4 +35,20 @@
 #define XMLCALL
 #endif
 
+/* Return the line number of PARSER's current position.
+
+   Expat 2.9.0 deprecates XML_GetCurrentLineNumber in favor of
+   XML_GetCurrentLineNumber64.  */
+
+static inline std::uint64_t
+gdb_xml_get_current_line_number (XML_Parser parser)
+{
+#if (XML_MAJOR_VERSION > 2 \
+     || (XML_MAJOR_VERSION == 2 && XML_MINOR_VERSION >= 9))
+  return XML_GetCurrentLineNumber64 (parser);
+#else
+  return XML_GetCurrentLineNumber (parser);
+#endif
+}
+
 #endif /* GDB_GDB_EXPAT_H */
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index d806b53c9fa2..7d86dbb8c698 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -179,7 +179,7 @@ gdb_xml_body_text (void *data, const XML_Char *text, int length)
 void
 gdb_xml_parser::vdebug (const char *format, va_list ap)
 {
-  int line = XML_GetCurrentLineNumber (m_expat_parser);
+  int line = gdb_xml_get_current_line_number (m_expat_parser);
 
   std::string message = string_vprintf (format, ap);
   if (line)
@@ -208,7 +208,7 @@ gdb_xml_debug (struct gdb_xml_parser *parser, const char *format, ...)
 void
 gdb_xml_parser::verror (const char *format, va_list ap)
 {
-  int line = XML_GetCurrentLineNumber (m_expat_parser);
+  int line = gdb_xml_get_current_line_number (m_expat_parser);
 
   m_last_line = line;
   throw_verror (XML_PARSE_ERROR, format, ap);

base-commit: 0aeb555307247b71116fd063f436d9311aadfbe0
-- 
2.56.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-13 14:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-11 13:31 [PATCH 1/2] gdb: use XML_GetCurrentLineNumber64 with expat >= 2.9.0 Simon Marchi
2026-10-11 13:31 ` [PATCH 2/2] gdb: remove workarounds for old expat versions Simon Marchi
2026-10-13  9:23 ` [PATCH 1/2] gdb: use XML_GetCurrentLineNumber64 with expat >= 2.9.0 Tom de Vries
2026-10-13 14:54   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox