From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uJqYJmgSrGrRZRcAWB0awg (envelope-from ) for ; Thu, 17 Sep 2026 12:16:40 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=k0QYXOUe; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 87D541E06A; Thu, 17 Sep 2026 12:16:40 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7E2B71E01F for ; Thu, 17 Sep 2026 12:16:39 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 430114BAE7F9 for ; Thu, 17 Sep 2026 16:16:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 430114BAE7F9 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=k0QYXOUe Received: from mail-oi2-x11.google.com (mail-oi2-x11.google.com [IPv6:2607:f8b0:4864:32::11]) by sourceware.org (Postfix) with ESMTPS id F351C4B9DB50 for ; Thu, 17 Sep 2026 16:16:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F351C4B9DB50 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F351C4B9DB50 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:32::11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789661774; cv=none; b=JShfwnS9x9rlmhXc6uTeTPYHH0Aal5Et3e+CRu5HoXC3JztR+Jfz0FD+vMlfqqNNfpkOhP8N9pHmMyQXWPXly5sIwsXligm49ql+fenQIGSfXYX9ffWFWvQTNxIr9plvYUN8ldmgpEKDxPtIeoG08+I6JEnHJ8NDxFI3XU5m2so= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789661774; c=relaxed/simple; bh=PKUkWIrnvOv+KgckWlvHTnLwgY7yIIvq9PGk2w9DbXc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=l+cxCvvfnxf+1ZRifadGi5J1Mi979MHqKeRYCL5YLZXIxvZ5e0GjJmS7RjrZ+9K+RJr0SscodE3hXZdKF7S5ddvwEclRT3k8fbPIM9jwNB/Q4P38t+BGBrh8tqaeCNPjyMa4ZZXyyMv706Rv+IdK9DKKTwQ+VkV/wfcCntlX2UQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=k0QYXOUe DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F351C4B9DB50 Received: by mail-oi2-x11.google.com with SMTP id 5614622812f47-4c17f382ff5so466206b6e.1 for ; Thu, 17 Sep 2026 09:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1789661773; x=1790266573; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Tb5Jt3UM6C78Mlnit6TEiaPtgXLz5oZDbfwQ64FONIo=; b=k0QYXOUeD/zVycA2nWS1pmM6g9ctSrC/CG3CCKHLx/fNKnW3kBWYrdWaksHvjcxIfT 9uQMy/hTt8Q+8UlVYIPrtQLIAmnAjRCX8BNSruv3SivSUi5+pyi3DSyIZ7uiDyx+VUkU gLvsfu2MlDknQon0EYPBaJIrthvNtQeRCyRYIUUgnyJlnnNfPcYWHQuBCXzdoX+okDlL KkX0nhADIeKR4SeEClOaUIgE1y3fuznbLpi/XmiPNCas09RIegE5nVLqGvbsjzoq7MN0 cF+KWLgewshIBs0xEQlUXlY8x4tFBTP9N2xHBPHl1De1a8N+EsJxskdt9MvHhujkRhqc TTmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789661773; x=1790266573; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Tb5Jt3UM6C78Mlnit6TEiaPtgXLz5oZDbfwQ64FONIo=; b=G4r6BbdbzvoGe7vEJXoWIFe/xr4d2iiyR0nLXmS27Wc/xeUKzN0QIg5sNjhs5fMrFj 0g+UWz/UFCfSR40/6vy6NYnyeDPNX9wlEKlBCRhcP0ZGuH+GRCh5t9Q22wJAaQbefp/g QOkx9MzLZcxhNMxOkTxJ0D8B/ZX8bnjuB5DgszX4tp4cyrDd7LklzdSmYdXVu/5B3vlN AAnd0PtmT7UepN68XEhRK8imFHVBxIoLz5fZK1DQrJkBltyZ6pb+3Fkk8D/aNYd1myPc opbIBiSgXeG3oQ3vpCEbrqdXXpCaotFRwbM2k9HbfL0w5ER21M99st1fJzf5wwUu+KRs MhUg== X-Gm-Message-State: AFuF++mXx/NijD9+zHEMs+RXEG3KhsGIqMAfguMk5JgWEULFGMuGKzTH tQT6NJap64kob78ZzPTv1iyAQbnsMqgfv+uxEdUVHcQwlbbD5V5dUcYHyp4CtvIpv0cfoeuHqLy UfwaOAw== X-Gm-Gg: AYBFou0QpX+xndXKj4DF59shpAGN74XcDQWij+XyxN486w8isgjVTrVgF4Z7cCpcVbP sUqUw2ssyQEwtOnBa1cEQMRUf4uWCo8jUMY9jxNo5pGyYSvJqZTyV23YrbiI9gW+VmoDAqwsIv8 EpwJ7YzJBaNiHuW8/52iHHX0uTDjGYu8z5Nr2NjPTkZdcKOHI2wAB/qnOK6S2vWeDCFfdlQU/Ef EsRHE9pvvVykpM43c5HBeB+UAbGferM98rj6NzfxNu1wfjZhjW6VwkfYD+H2pzd8/SWpyTDGRwN +IPyqhdHJV01Q9kZV1JxfIjUSZjFI9pGo9UGsTf5sw+h7sPXGmF/NqQRbuERzihmiRZs31HeRtW W+s1QZtDwJ30kokUMlgGxSVt0ast8eHgrrOZCQajwS4/+U35DjTJX5h9nLhWRpygiZ+KgXVYRzU sn2xt3L5WPAVGeV/NkserhdgCd/W8Eu41RELWlSpQTTj3yURjeZMC9fLj5IMlmGFhU/Ko8fAW3B bxsgdYOwQblIsxGXg== X-Received: by 2002:a05:6808:30aa:b0:4c3:b3e:4e72 with SMTP id 5614622812f47-4ca4a2ee24amr9124687b6e.12.1789661773209; Thu, 17 Sep 2026 09:16:13 -0700 (PDT) Received: from bapiya (75-166-229-74.hlrn.qwest.net. [75.166.229.74]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-80c46dbe483sm2779426a34.20.2026.09.17.09.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 09:16:12 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Remove ui_out::do_field_fmt Date: Thu, 17 Sep 2026 10:16:11 -0600 Message-ID: <20260917161611.3104728-1-tromey@adacore.com> X-Mailer: git-send-email 2.55.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org A user pointed out that certain MI output was not correctly quoted. He tracked this down to mi_ui_out::do_field_fmt. Looking into this, it seems to me that do_field_fmt is not needed at all. Instead, ui_out can handle the formatting, and then delegate to do_field_string. This approach fixes the original bug, because the MI implementation of do_field_string does perform the quoting. This also slips in a small change to use checked_static_cast in mi_ui_out::main_stream. Regression tested on x86-64 Fedora 43. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34599 --- gdb/cli-out.c | 15 ------------ gdb/cli-out.h | 4 ---- gdb/mi/mi-out.c | 54 +++++++++++++++++++++++++++++-------------- gdb/mi/mi-out.h | 4 ---- gdb/python/py-mi.c | 12 ---------- gdb/python/py-uiout.h | 4 ---- gdb/ui-out.c | 11 ++++----- gdb/ui-out.h | 4 ---- 8 files changed, 42 insertions(+), 66 deletions(-) diff --git a/gdb/cli-out.c b/gdb/cli-out.c index d8ac13ab827..0c339d0e819 100644 --- a/gdb/cli-out.c +++ b/gdb/cli-out.c @@ -187,21 +187,6 @@ cli_ui_out::do_field_string (int fldno, int width, ui_align align, field_separator (); } -/* Output field containing ARGS using printf formatting in FORMAT. */ - -void -cli_ui_out::do_field_fmt (int fldno, int width, ui_align align, - const char *fldname, const ui_file_style &style, - const char *format, va_list args) -{ - if (m_suppress_output) - return; - - std::string str = string_vprintf (format, args); - - do_field_string (fldno, width, align, fldname, str.c_str (), style); -} - void cli_ui_out::do_spaces (int numspaces) { diff --git a/gdb/cli-out.h b/gdb/cli-out.h index 74307074a7c..4c7ae6e656e 100644 --- a/gdb/cli-out.h +++ b/gdb/cli-out.h @@ -65,10 +65,6 @@ class cli_ui_out : public ui_out const char *fldname, const char *string, const ui_file_style &style) override; - virtual void do_field_fmt (int fldno, int width, ui_align align, - const char *fldname, const ui_file_style &style, - const char *format, va_list args) - override ATTRIBUTE_PRINTF (7, 0); virtual void do_spaces (int numspaces) override; virtual void do_text (const char *string) override; virtual void do_message (ui_file_style ¤t_style, diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c index 41b0ee8cdbd..cba6acbbab5 100644 --- a/gdb/mi/mi-out.c +++ b/gdb/mi/mi-out.c @@ -27,6 +27,7 @@ #include "ui-out.h" #include "utils.h" #include "gdbsupport/gdb-checked-static-cast.h" +#include "gdbsupport/selftest.h" /* Mark beginning of a table. */ @@ -140,22 +141,6 @@ mi_ui_out::do_field_string (int fldno, int width, ui_align align, gdb_printf (stream, "\""); } -void -mi_ui_out::do_field_fmt (int fldno, int width, ui_align align, - const char *fldname, const ui_file_style &style, - const char *format, va_list args) -{ - ui_file *stream = m_streams.back (); - field_separator (); - - if (fldname) - gdb_printf (stream, "%s=\"", fldname); - else - gdb_puts ("\"", stream); - gdb_vprintf (stream, format, args); - gdb_puts ("\"", stream); -} - void mi_ui_out::do_spaces (int numspaces) { @@ -257,7 +242,7 @@ mi_ui_out::main_stream () { gdb_assert (m_streams.size () == 1); - return (string_file *) m_streams.back (); + return gdb::checked_static_cast (m_streams.back ()); } /* Initialize a progress update to be displayed with @@ -371,3 +356,38 @@ mi_out_rewind (ui_out *uiout) { return as_mi_ui_out (uiout)->rewind (); } + +#if GDB_SELF_TEST + +namespace selftests +{ + +static void +mi_check (mi_ui_out &uiout, const char *expected) +{ + string_file *stream + = gdb::checked_static_cast (uiout.current_stream ()); + SELF_CHECK (stream->string () == expected); + uiout.rewind (); +} + +static void +test_mi_out () +{ + /* The version doesn't matter for these tests. */ + mi_ui_out uiout (2); + + uiout.field_fmt ("field", "%s", "test \"quoted\""); + mi_check (uiout, ",field=\"test \\\"quoted\\\"\""); +} + +} + +#endif + +INIT_GDB_FILE (mi_out) +{ +#if GDB_SELF_TEST + selftests::register_test ("mi-out", selftests::test_mi_out); +#endif /* GDB_SELF_TEST */ +} diff --git a/gdb/mi/mi-out.h b/gdb/mi/mi-out.h index d1d26718ac4..ce1e5dadc4c 100644 --- a/gdb/mi/mi-out.h +++ b/gdb/mi/mi-out.h @@ -72,10 +72,6 @@ class mi_ui_out : public ui_out virtual void do_field_string (int fldno, int width, ui_align align, const char *fldname, const char *string, const ui_file_style &style) override; - virtual void do_field_fmt (int fldno, int width, ui_align align, - const char *fldname, const ui_file_style &style, - const char *format, va_list args) - override ATTRIBUTE_PRINTF (7,0); virtual void do_spaces (int numspaces) override; virtual void do_text (const char *string) override; virtual void do_message (ui_file_style ¤t_style, diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c index 73daefecb20..7e8105fdade 100644 --- a/gdb/python/py-mi.c +++ b/gdb/python/py-mi.c @@ -119,18 +119,6 @@ py_ui_out::do_field_string (int fldno, int width, ui_align align, add_field (fldname, val); } -void -py_ui_out::do_field_fmt (int fldno, int width, ui_align align, - const char *fldname, const ui_file_style &style, - const char *format, va_list args) -{ - if (m_error.has_value ()) - return; - - std::string str = string_vprintf (format, args); - do_field_string (fldno, width, align, fldname, str.c_str (), style); -} - /* Implementation of the gdb.execute_mi command. */ PyObject * diff --git a/gdb/python/py-uiout.h b/gdb/python/py-uiout.h index 21c068e9077..5a1ee9c09b3 100644 --- a/gdb/python/py-uiout.h +++ b/gdb/python/py-uiout.h @@ -98,10 +98,6 @@ class py_ui_out : public ui_out void do_field_string (int fldno, int width, ui_align align, const char *fldname, const char *string, const ui_file_style &style) override; - void do_field_fmt (int fldno, int width, ui_align align, - const char *fldname, const ui_file_style &style, - const char *format, va_list args) override - ATTRIBUTE_PRINTF (7, 0); void do_spaces (int numspaces) override { } diff --git a/gdb/ui-out.c b/gdb/ui-out.c index ac792b43905..45bb1d821a1 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -534,9 +534,9 @@ ui_out::field_fmt (const char *fldname, const char *format, ...) verify_field (&fldno, &width, &align); va_start (args, format); - - do_field_fmt (fldno, width, align, fldname, ui_file_style (), format, args); - + std::string str = string_vprintf (format, args); + do_field_string (fldno, width, align, fldname, str.c_str (), + ui_file_style ()); va_end (args); } @@ -552,9 +552,8 @@ ui_out::field_fmt (const char *fldname, const ui_file_style &style, verify_field (&fldno, &width, &align); va_start (args, format); - - do_field_fmt (fldno, width, align, fldname, style, format, args); - + std::string str = string_vprintf (format, args); + do_field_string (fldno, width, align, fldname, str.c_str (), style); va_end (args); } diff --git a/gdb/ui-out.h b/gdb/ui-out.h index 0c82e82bf6e..26d4a6b7d0e 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -360,10 +360,6 @@ class ui_out virtual void do_field_string (int fldno, int width, ui_align align, const char *fldname, const char *string, const ui_file_style &style) = 0; - virtual void do_field_fmt (int fldno, int width, ui_align align, - const char *fldname, const ui_file_style &style, - const char *format, va_list args) - ATTRIBUTE_PRINTF (7, 0) = 0; virtual void do_spaces (int numspaces) = 0; virtual void do_text (const char *string) = 0; base-commit: 0595410d007e5f628e14717cd268e557e166675f -- 2.55.0