From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eRIBFC8UU2g3pxMAWB0awg (envelope-from ) for ; Wed, 18 Jun 2025 15:31:59 -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=RBz/V15S; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3BCA91E11C; Wed, 18 Jun 2025 15:31:59 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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_MED,RCVD_IN_SBL_CSS,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 11AFB1E089 for ; Wed, 18 Jun 2025 15:31:54 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77E163956BB4 for ; Wed, 18 Jun 2025 19:31:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77E163956BB4 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=RBz/V15S Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 6B102385114B for ; Wed, 18 Jun 2025 19:30:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B102385114B 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 6B102385114B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750275014; cv=none; b=rRGulv2U14EmdAWYNYRJyM7oMEAgATFXRACq/MjuCAiKavoPkvx4TmrEI/dr5pIgBTnxEeexk0ojDyYkrSjvd70UoinqmgM1hvjtMZlOZvBK9Y/EU5i30qmuPRgIhz7kAl7Ojs8JLF1E0kjOevnXh0svkN/WGOSh7vBSspTdVZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750275014; c=relaxed/simple; bh=yKUwjjKFXlbKK5Wcvzf79tdt7K0Vf7x46ojpv5VrNEI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qzQYn6aX7sq0m5GsvN/GREuZXlchJPRSTyz6VVMqLDWSEVl95s/0wiBrcWRnJ3QqUPtB9C+piV8DImQv3k9YNWzLB+liYBTmyTsVrI1Hzohay5x8RfWYYhdeJr+ZnGOSMV0KeCFMMb7IUmfsFLvDFs4rGfDXW3tidPd/fttsFCU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B102385114B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750275014; 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=opDE44h+N17bll5CqyXH4bxu30QSJOnD1w7QrX+M7TM=; b=RBz/V15Sx2O70vmmGCN2cikI60NX60p0CSRDjqOlcuj/+tqH4vE0dAmpf60zfSRllhR1g2 xHpKLF3Ix2A2avha+QBXJl4r1H0FOPskx1292czTiJ6w+/oU+2xPnFUEK784YXH+hqy8B9 mS6EYme+UoNjDcjQxZiRd4u6PnZP1zQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-m1ffYYPnP-an-m_ma6fUSA-1; Wed, 18 Jun 2025 15:30:12 -0400 X-MC-Unique: m1ffYYPnP-an-m_ma6fUSA-1 X-Mimecast-MFC-AGG-ID: m1ffYYPnP-an-m_ma6fUSA_1750275012 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-451d5600a54so140215e9.2 for ; Wed, 18 Jun 2025 12:30:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750275011; x=1750879811; 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=opDE44h+N17bll5CqyXH4bxu30QSJOnD1w7QrX+M7TM=; b=bG6FVtZrZRan8jw08ZmJEeyGh6bElSMdhfrKi4wvgAMkecLBdk1WST+wZDfioGIdl3 P95oZ8i2cL9C0bngDOBCZROnTxAE7Pb26sPiQKMePlwBnVvfxiXJOMSHX59LWtFgvGh9 IHRN9uzroB2c+XZS7/ShtyqW2fhRavkgHaR5BgwdOW83DBPhesqLu/b3rRPolOlavjv7 LOdZcGIx1SgsfsIZSbAIVrBRdxyS53FG5Ds5s0Ai3HRosRQgn00dWEf8Z6vK4QS9FS47 qcVo+kLubr2AKo/EygPpXpQLr3zFAqR9bgj2zMY4KxDzPISplQX6rCYIX0L0Eoemoayo Jtcg== X-Gm-Message-State: AOJu0YyycbOQfPJb8YCHfiQz9+XbGe2cvk7uBlFHy1tdXE1hXsOihbI8 Vx07plbP/tZ7TJQZhoipEpgaeiMRoiodK8pJ6car2wzt7fliCeQPD3Wc1+mpU0oYCxMQIYLw4cQ EFV9pvFtEfiTIKrHCxoQWLsEqe9Q0ROlxJ9WWSr4zdDYh+N2u8vKXyR7r4FCbRGrXsPdHXWdIaK wiZHgcjknEYyHsBc8N4e6ky+Ph959dTk+/6f1y8fyKCjcYJN8= X-Gm-Gg: ASbGncuIe8FFhg6gN8oe5ckvuEG1BEBa29QwaajBNWgffafmRDkE5ZsKkpPfjop8Esu N2Lv80EC4BY7qR6zPaoxbat0fGjLHtL2gTqXqJJP28YBW/ma78b5bHztZvfZufroEdGOK6HXoCw Dcb1AAjfylrpyyP2H36/UAiGs8PlW8kyn1JWXhH0Zx/rBx9SMJDlUBJJuegHjZIUtf91vRAcHEO EbEbu/Nh/3weRvSNJT/fbjxxpSN5RjQVeS8yX7eAB9iE1aSHLESPZ151jSEASPrvj+t1KEkW7/V Cbp8fDK3pHhMZeNWAVr7txyEEyTld303Ozm7bzrQkQNXwN4= X-Received: by 2002:a05:600c:3584:b0:451:df07:f437 with SMTP id 5b1f17b1804b1-4533cac908fmr186949035e9.30.1750275010743; Wed, 18 Jun 2025 12:30:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1xQGS77BnJQeVj0YkD/nyCkJUaAdPtRnvted/MEOUI9q6CGISu4mdrFS7NN+owL2qWNBgbw== X-Received: by 2002:a05:600c:3584:b0:451:df07:f437 with SMTP id 5b1f17b1804b1-4533cac908fmr186948725e9.30.1750275010169; Wed, 18 Jun 2025 12:30:10 -0700 (PDT) Received: from localhost (92.40.184.196.threembb.co.uk. [92.40.184.196]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-453599c9854sm18499805e9.1.2025.06.18.12.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 12:30:09 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv4 0/4] Python Style API Date: Wed, 18 Jun 2025 20:30:00 +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: yxWpajhXJjtz4qCnF1_Va38mDmPxb8zJNIFKjvgfEEU_1750275012 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. 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: 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: 56443763a8304ee7bec3b773f98104c754c5d517 -- 2.47.1