From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sfG/Fpvtrmigag0AWB0awg (envelope-from ) for ; Wed, 27 Aug 2025 07:35:55 -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=T9P5WCDp; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 57DB11E043; Wed, 27 Aug 2025 07:35:55 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.8 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_LOW,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no 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 3E9181E043 for ; Wed, 27 Aug 2025 07:35:54 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BD8FC3851C05 for ; Wed, 27 Aug 2025 11:35:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD8FC3851C05 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=T9P5WCDp 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 4E640385EC3B for ; Wed, 27 Aug 2025 11:34:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E640385EC3B 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 4E640385EC3B 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=1756294459; cv=none; b=tiLR1nlGAqNAZB1Ok8kVunQYMueo8z+JfbAsAfuCfUoLemEc8hwwrKkq78k0Fe4Q+kAupTMFAxc0MHYVxsTeOaxRFsEbXVCucAOUL+9VuPIIhrLtI5LrnlrikCATTekScAOOZmpUkD25l2xqxGjgzAqdcgGB7KYN17q20Z8B5jw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756294459; c=relaxed/simple; bh=qOV8FY3EmIAWahd2z5DILJafEnBKfA6opqwqamQjC94=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ahcEqNqBwJ+K+gruwRAJLtknC/ORybr4fscZrJpYs7U/7LeDwBkZ3CR14uxwmtr6rW3l65GswmtR9rRQM/If58CuwJf1zQHhZVNd1Ym0oM0GUF1dia44eZOojW2psAxUJvBVdKJViY78NBYRYjDNPTMytW32IZd2moyzWbuJFhY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E640385EC3B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756294459; 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=7wjWoRtOWn17ejcPylqjt1v8Svvv3L79hE/X3jeGLgk=; b=T9P5WCDphN4vfTfB3CvcwnptnImJvkxPOACkp4CS/EDSVyI+S2e8EBpn9t9nQQxdAaWc+e wgNfM5hTdyfpAkaH4/e2ZkJ4idkbLaO5+UH+wKoaJG2R5qvMTat6A62AWHIdQ7n6AcDN0c 0d2N3bikBuzfB+Kfbz1+k7JjuH95J/o= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-ZAcDQf4JMdKPwqcnCmqiVg-1; Wed, 27 Aug 2025 07:34:17 -0400 X-MC-Unique: ZAcDQf4JMdKPwqcnCmqiVg-1 X-Mimecast-MFC-AGG-ID: ZAcDQf4JMdKPwqcnCmqiVg_1756294456 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-45a1ad21752so4321405e9.1 for ; Wed, 27 Aug 2025 04:34:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756294456; x=1756899256; 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=7wjWoRtOWn17ejcPylqjt1v8Svvv3L79hE/X3jeGLgk=; b=p6jI1mUEdRToEq0/ZHSF+tf7hdqm4D32F7eVtU+2HMeCFAMSlcDkJoRgYrlUJH6sYf K3badvT8PgTQYyGCmUvHrcfsylOvPjRAjFURtbDCAlclmrXb81YJDjCnVPR4RJ2V1jY9 QUr827KGkhTjjaVcyyddGH1fUn6Jshwa2vJhm7JbDec5Bc9hK7Ngo4H1rVDYW7beXxXE 2bb1JN+pyRxZY52ZEO+lu3ODihYd9NHhYv7PZoWekPEPX8J0i71fuR4GKFqnwNq7+yGK UVbJd+3OIktmgAk5ReS4WEfUANY6ar6P0y6j0COfuK9N92uVVVJ870GoYopMIk6pAscg vMhg== X-Gm-Message-State: AOJu0YzZKellKt2Cf2KXG7oiRCbZ/bqpZVDpf3kVzwDXKGDqQWpSoA8I AZ6bLC7H9NI6lkNe8kO11np7by++HqbFbnx2HJ1daZjrLtyWiJUq1LC+21HSWjmNQxofyVB3yud vRTHG82byJ15yNCQ5Z609ODqbeggYLkuypAolOe3gx2KNKj2jLOonOSBpesc6eAOmhkcSI9FicA V2be2j/8cLGkBtXRfg42RO2njwKMY2de38tFJ82Eh1LTJf8Kg= X-Gm-Gg: ASbGnctqkjVlRPpLLSWP4OZ2W3hmIRo2p9m1jSMciy+6vuk9DL/CekbMqPTTMDD9Nc+ LTgJEsqogu0pYW9c/bl8/Jt4wH6SuRb4i/zENzQQ33ZxlYkhoXearl269U0BdIifAd0WYBf7FV2 QljSnCSfwcrj5UUYNXpjC99b1q3ut0TQswyu/7stLeZYq3XBPmtfaTUXgOdLzl8Yqzp3Vl/Pxo1 kiVxUl10SWULjmV3YCSplv24Ldwvd7pZbrThrpjOFEPjdq1VB4cUsmzg7xFtjEZFzkn+WucLCoe GfvWIcyYYoCilcwYvn8D79vj9xYo6sJ8aqY= X-Received: by 2002:a05:600c:4443:b0:459:e39e:e5a5 with SMTP id 5b1f17b1804b1-45b6870e392mr45163185e9.5.1756294456001; Wed, 27 Aug 2025 04:34:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG706q0e33M+kjmi1GT9K5019njYoSAnThyGDqqrH/Su0oJIoYRHdglLWW1PUDBB/rZZ/6nHA== X-Received: by 2002:a05:600c:4443:b0:459:e39e:e5a5 with SMTP id 5b1f17b1804b1-45b6870e392mr45162955e9.5.1756294455485; Wed, 27 Aug 2025 04:34:15 -0700 (PDT) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3c70ef55aabsm19752535f8f.23.2025.08.27.04.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Aug 2025 04:34:15 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv8 0/3] new gdb.Style API Date: Wed, 27 Aug 2025 12:34:09 +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: dLe36S3FQsrWM1DwuJgGy-Skz_l2OXKAN4Jb553aU3A_1756294456 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. In v7: - Rebased as there were more style related changes to master which caused some merged conflicts, and test failures. Both turned out to be trivial to fix. In v8: - I merged the gdb.Color + pagination fix, this leaves the 3 patches related to the gdb.Style API. - I've updated the tests in patch 3 to take commit e17e65798e4 into account. - No updates needed to the actual GDB changes. Thanks, Andrew --- Andrew Burgess (3): 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 | 30 +- .../gdb.python/py-color-pagination.exp | 61 +- .../gdb.python/py-color-pagination.py | 36 + .../gdb.python/py-style-parameter-set.exp | 366 ++++++++ gdb/testsuite/gdb.python/py-style.exp | 371 ++++++++ gdb/ui-style.h | 6 + 12 files changed, 2187 insertions(+), 8 deletions(-) create mode 100644 gdb/python/py-style.c create mode 100644 gdb/testsuite/gdb.python/py-style-parameter-set.exp create mode 100644 gdb/testsuite/gdb.python/py-style.exp base-commit: e17e65798e466913f384e7a568d991124798ecb4 -- 2.47.1