From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8K16BX3da2g36i0AWB0awg (envelope-from ) for ; Mon, 07 Jul 2025 10:45:17 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FPcdNce8; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 107171E11C; Mon, 7 Jul 2025 10:45:17 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-10.1 required=5.0 tests=ARC_SIGNED,ARC_VALID, BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 48EB11E089 for ; Mon, 7 Jul 2025 10:45:16 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D3CEE385771D for ; Mon, 7 Jul 2025 14:45:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3CEE385771D Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FPcdNce8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id D8CBF3857839 for ; Mon, 7 Jul 2025 14:43:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8CBF3857839 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8CBF3857839 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1751899424; cv=none; b=IpAPgyrYJRaxCSIaD9d9u57kwEH271aWF6KOUzC/YBUhCXUCzbNnjYGio+IXxql/bkqZHVrDPf2DTA8ywty8raBvnUNPBTKrQZilvfZdrsK9M/0S2+CrbgiUrD1xcxYSpJdkj2eB9PdUIOXx1avFc6Q9BceRBAwBFAaWRkVbYXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1751899424; c=relaxed/simple; bh=w4v1lwo6fqxc00qMBhyIUIJreLS/ZV6j8aLbCh+GNtI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=t6qRwdyKmTZ4be1Hsr6oCECdW/VUfzVzDVJaDXLRNAvUxSmkhmfGjnZmxB7L6FLMlF0+a4xCcE26zmpcNgLG2T9oyk4GQk75U3vjPM0sB1Uhrq/cwAHvBNQagNf/5Kz+R407txTtHJfH043GrF3PQSRIUtAh8qrLhtizQnQ3SK0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8CBF3857839 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751899423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YiV/atlA1oVSyWrVBBr70DQ/jXuYElDSXacynAUDUZQ=; b=FPcdNce8LM8u0PHSx6bVo+LRmdmeTrwUX8yw1+nyUthupV5OpyMpe0A6A1wi0JsXTTe7tm tp+D3lftFp+MqAWQ9x74zMCCiAy/tufUJ3akdKk0hl6f2BBmEZCiavc5YmAE1I/GacyZ2L uTiZNRPm9uD3xpeuDxdd4gVkqiA+itw= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-568-k9gTaw2xOL-Igxel8fceeg-1; Mon, 07 Jul 2025 10:43:42 -0400 X-MC-Unique: k9gTaw2xOL-Igxel8fceeg-1 X-Mimecast-MFC-AGG-ID: k9gTaw2xOL-Igxel8fceeg_1751899422 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6fb520a74c8so60219806d6.1 for ; Mon, 07 Jul 2025 07:43:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751899421; x=1752504221; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YiV/atlA1oVSyWrVBBr70DQ/jXuYElDSXacynAUDUZQ=; b=idAQOkYOOupBxS+MXAP4yLkYmuceAcitlAfCRyGQavB99YnRlOcXX6q67ej/UFOM4q QDJczmOFNEnFFRWL4sf3nzC5rUFXLol5zi7QAuG4fPqGnLWA9IZHz8xWYCr32yhEUeWr Lw9Pv5Xsb03E59CASzY4I8BUJrq7kQpLZ0T7cy8PiPho7iba4nFOSt4xRshGSniuyYFI t8QBIDkTvWwZ/MxAMXj8FEv8KsCajVLwz7SQsbMmny2+aqcnR+Rekj2CPtwswAM31clx TtCDPW1EVZX8vz/cETuDsH9pMPMSkx+0B2obcc7nEEoUl06WRdNpI4VwhZbaoP4Pj8DO DV5w== X-Gm-Message-State: AOJu0YztiGFDvO1opV22w2vkByd3nTWhR3BHZdg23cOBGqGlHfbujTEB GPmE12u1VCpi8GARmOq0hWaug5Hfrr8pH5OC0BNrGOop1uxH8TtaHLd4v6j55ENG64OTQ+OYiVA IDLslomWe8XVlM4K84dOnJ9ZAqW3GNo1vQAWfOQwhQkf808Xow8PtjksBVhvO9pGWPXicTt3a2c 7r0HHWYROSIwNUopKzHPeU74di67AL4TOU0AIA9RAEmsTyZFg= X-Gm-Gg: ASbGncvrrxYrNDArcxQwVJNBh/c9ICgtv2iYrCDugWmTd3kjwVkFJzoVOkgOvRMgnYS 6MDPOQUvLkQ9XuaPo/9A3FSrlOtDPZcrmVNbhoJYxFe//svfxH7lzGq2SILXFM2ac003LMwDh82 N9P+P1ZFOOpKTT0RF1SmQykNqgJGJpM7i/H1AxbZlYAffC5bq53T0NCKwMl5YEYYq8DK0GP62F5 kUn2h8gmEGZXDMxa2SwKSB0nQ0Wzg1+QHmFgCi+MjxQ+0h6QBwg7N1JO+CjzHDiYm8uqa4rEKnv tFmZlyhCd2dR4+onyblIuXGlD4eg5YJtSOQGT4CQt9QKNW4= X-Received: by 2002:a05:6214:2a88:b0:6fd:8fc:e2fa with SMTP id 6a1803df08f44-702c6d8c490mr204817096d6.32.1751899421210; Mon, 07 Jul 2025 07:43:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHK1C6l71ctJ9JkFRB9mEniq+bzj0XBKSt0mEcvkNaKoFE8j/FL9Vh+9oZzMAho4KTpZXvjYA== X-Received: by 2002:a05:6214:2a88:b0:6fd:8fc:e2fa with SMTP id 6a1803df08f44-702c6d8c490mr204816456d6.32.1751899420625; Mon, 07 Jul 2025 07:43:40 -0700 (PDT) Received: from localhost (75.226.159.143.dyn.plus.net. [143.159.226.75]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d5dbe7bef2sm612408585a.55.2025.07.07.07.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jul 2025 07:43:40 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv6 0/4] Python Style API Date: Mon, 7 Jul 2025 15:43:26 +0100 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hTwNEMh0ht3eYpEfuvREQwHQreKNp2yylWQSidMR0Bk_1751899422 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 After the gdb.Color support was added to the Python API I wondered if this would be enough to easily add styling to custom Python commands. But I don't think it is, there's still lots that would need to be handled in user code, for example, the intensity setting. And having styles that track named styles (e.g. if I want to apply the 'filename' style to some text from Python). So this series builds on top of the gdb.Color API to provide a new gdb.Style API which, I hope, makes it easy to start writing Python commands that can use GDB's styles. Here's an example of a simple custome command that uses styles: import os class user_home_cmd(gdb.Command): def __init__(self): super().__init__("user-home", gdb.COMMAND_USER) self._style = gdb.Style('filename') def invoke(self, args, from_tty): print("The filename is %s." % (self._style.apply(os.environ['HOME']))) user_home_cmd() The new 'user-home' command prints the current users home directory using 'filename' style. Changing the 'filename' style and re-running the command will track the style changes. In v2: - Fixed an issue with the py-style-parameter-set.exp test; GDB was not started in a terminal with styling support in one case, so tests would fail depending on how the testsuite was being run. In v3: - Another test issue. This time, the error message given when parsing an argument of the wrong type changes with Python version. Relax the regexp to accept any 'TypeError' message. In v4: - Two new patches. First patch extends pager_file so that gdb.Color, and gdb.Style when it's added can work well with GDB's pager. Last patch extends the gdb.write() Python function to also support styling. - I've renamed some of the classes in python/py-style.c, nothing major, I replaced 'stylepy' with 'style' in some names. I think the new names are clearer, and better match the rest of GDB's Python API code. - Unfortunately, the new pager_file changes mean that this patch series now depends on this other patch: https://inbox.sourceware.org/gdb-patches/444008aeae2bb3c68cf868fa317374b3d7973860.1750197766.git.aburgess@redhat.com Without that patch there will be some failures in gdb.python/py-color-pagination.exp. I'm not proposing to merge this until that other patch, or something like it, is merged. But this series could be reviewed independently. In v5: - The pager_file styling fixes mentioned for v4 have now been merged to master. I've rebased this series on top of them, and all the tests are now passing. - I've tweaked the wording for a couple of the commit messages just to make things clearer. - No real code changes. In v6: - Rebased as there were some style related changes merged to master recently. No conflicts, and everything still works fine, so there are no real changes here. Thanks, Andrew --- Andrew Burgess (4): gdb: allow gdb.Color to work correctly with pagination gdb/python: add gdb.Style class gdb/python: new class gdb.StyleParameterSet gdb/python: extend gdb.write to support styled output gdb/Makefile.in | 1 + gdb/NEWS | 14 + gdb/doc/python.texi | 262 +++++- gdb/python/lib/gdb/__init__.py | 209 +++++ gdb/python/py-style.c | 824 ++++++++++++++++++ gdb/python/python-internal.h | 15 + gdb/python/python.c | 46 +- .../gdb.python/py-color-pagination.exp | 166 ++++ .../gdb.python/py-color-pagination.py | 82 ++ .../gdb.python/py-style-parameter-set.exp | 366 ++++++++ gdb/testsuite/gdb.python/py-style.exp | 371 ++++++++ gdb/ui-style.h | 6 + gdb/utils.c | 21 +- 13 files changed, 2366 insertions(+), 17 deletions(-) create mode 100644 gdb/python/py-style.c create mode 100644 gdb/testsuite/gdb.python/py-color-pagination.exp create mode 100644 gdb/testsuite/gdb.python/py-color-pagination.py create mode 100644 gdb/testsuite/gdb.python/py-style-parameter-set.exp create mode 100644 gdb/testsuite/gdb.python/py-style.exp base-commit: 1fe6ffd81e76a2799add18d9e1d5208a90c21ece -- 2.47.1