From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eX/WNjeB2WmaTBEAWB0awg (envelope-from ) for ; Fri, 10 Apr 2026 19:01:11 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=gY3p8VvF; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D89261E04F; Fri, 10 Apr 2026 19:01:11 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 DFD431E04F for ; Fri, 10 Apr 2026 19:01:10 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 6A4464BA23CA for ; Fri, 10 Apr 2026 23:01:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A4464BA23CA Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=gY3p8VvF Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id E8AE64BA2E15 for ; Fri, 10 Apr 2026 22:59:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8AE64BA2E15 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E8AE64BA2E15 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775861982; cv=none; b=ZtgNCab/5s4JF+wy7SnRxHy9H9s6AomWbAcetYk/MZsR7ftpUd73+flLYobbBJhe5Sf0+VheidaNpV5knlFnSgSyFUemR5VHb+DVb4Aeey1rFFAGzrBcvixRduviybWI75h3A+fSsgUz/OT5/S4thOrxTKA4Xxgp2g/+4GptOew= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775861982; c=relaxed/simple; bh=G6biQE9ciUdmIl6xU83KYlow9X9+8v8joOsmgsX9f5k=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=d/Am5BduzuVut26GBZfqJYX9GeAPp+CWTaj/PHDK7Ec/vd0WurhmcnkZiO6Tb0/49m23p1GpTqb5Izxq5AYIPmyI1g1t12Hui0b8oi6BDiEP7hS93aMC25q3znDzSD9AcKwo5YCWHFO+vKyX09kCLjP4X1Vvl0ikBd0XgwlCvGs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8AE64BA2E15 Received: from eig-obgw-6003b.ext.cloudfilter.net ([10.0.30.175]) by cmsmtp with ESMTPS id BEH8wPeDI4RkpBKpBwtkCk; Fri, 10 Apr 2026 22:59:41 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id BKpAwoy53HtqhBKpAw1qIF; Fri, 10 Apr 2026 22:59:40 +0000 X-Authority-Analysis: v=2.4 cv=AtXu3P9P c=1 sm=1 tr=0 ts=69d980dc a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=ItBw4LHWJt0A:10 a=Xa4QH4fhPVVw43cbqiYA:9 a=QEXdDO2ut3YA:10 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=NjkK8iJmAwRuCHDK35Q2bIg+C3YhTXrSoHwwYiRu1sg=; b=gY3p8VvFFfXP5+LYfRJO1UKLl/ lPUiSyoh2NDXo63IzukOOIx0gyv3JLAE1Phc8LmZcjabGcVaW28hQXqVAkDQkae4WiNwh2zkOVgK3 zsvcebM8gAEIr0Pv+1ehqEOrX; Received: from 75-166-225-82.hlrn.qwest.net ([75.166.225.82]:49954 helo=[192.168.122.1]) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wBKpA-00000001tnB-1LY8; Fri, 10 Apr 2026 16:59:40 -0600 From: Tom Tromey Date: Fri, 10 Apr 2026 16:59:41 -0600 Subject: [PATCH 1/5] Allow styling when using throw_* functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260410-unify-exceptions-v1-1-ea64dae971a8@tromey.com> References: <20260410-unify-exceptions-v1-0-ea64dae971a8@tromey.com> In-Reply-To: <20260410-unify-exceptions-v1-0-ea64dae971a8@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.225.82 X-Source-L: No X-Exim-ID: 1wBKpA-00000001tnB-1LY8 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-225-82.hlrn.qwest.net ([192.168.122.1]) [75.166.225.82]:49954 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfGMWbi4K3cRKrYHtAv6IHW1K1gmYaYycgcC9LZvETo/p2jw1dLoF6fHzHJmFwqbd2wo3xL0HTun8lWhqOeKiLr4MkQBKcuYoh5KOd1uzswKYZZ3JRdLJ kZ+9Yh/Oup81sw7bRuCIETACGH2ih1tRUGqQvyvGJuyjNfyud9Llcy29LyrMfKAGybcEnfzhCyFEcdQY+L1aNKR55nlAIPB20gA= 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 The throw_* family of functions use the varargs constructor for gdb_exception, which then calls string_vprintf. This means that styling cannot be applied here by gdb. This patch changes this code to use a client-supplied formatting function. For gdbserver this remains string_vprintf, but for gdb it now allows styling. I did look at unifying 'error' and the throw_* functions a bit more, but this would have meant unravelling some IPA code. --- gdb/utils.c | 10 ++++++++++ gdbserver/utils.cc | 12 ++++++++++++ gdbsupport/common-exceptions.h | 7 ++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gdb/utils.c b/gdb/utils.c index f5f19301460..988f2d876d1 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -182,6 +182,16 @@ vwarning (const char *string, va_list args) } } +/* See common-exceptions.h. */ + +std::string +vformat_exception (const char *fmt, va_list args) +{ + string_file text (true); + text.vprintf (fmt, args); + return text.release (); +} + /* Print an error message and return to command level. The first argument STRING is the error message, used as a fprintf string, and the remaining args are passed as arguments to it. */ diff --git a/gdbserver/utils.cc b/gdbserver/utils.cc index 9bc3fc4477e..468e803e34d 100644 --- a/gdbserver/utils.cc +++ b/gdbserver/utils.cc @@ -104,3 +104,15 @@ paddress (CORE_ADDR addr) { return phex_nz (addr); } + +#ifndef IN_PROCESS_AGENT + +/* See common-exceptions.h. */ + +std::string +vformat_exception (const char *fmt, va_list args) +{ + return string_vprintf (fmt, args); +} + +#endif /* IN_PROCESS_AGENT */ diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h index 5a50ff44c31..1f3bc84216e 100644 --- a/gdbsupport/common-exceptions.h +++ b/gdbsupport/common-exceptions.h @@ -116,6 +116,11 @@ enum errors { NR_ERRORS }; +/* The client application must provide this. It is a printf-like that + formats a string for an exception. */ +std::string vformat_exception (const char *fmt, va_list args) + ATTRIBUTE_PRINTF (1, 0); + struct gdb_exception { gdb_exception () @@ -142,7 +147,7 @@ struct gdb_exception ATTRIBUTE_PRINTF (4, 0) : reason (r), error (e), - message (std::make_shared (string_vprintf (fmt, ap))) + message (std::make_shared (vformat_exception (fmt, ap))) { } -- 2.49.0