Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv5 0/4] Python Style API
Date: Wed, 25 Jun 2025 15:42:53 +0100	[thread overview]
Message-ID: <cover.1750862458.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1750274641.git.aburgess@redhat.com>

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.

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: 125881849ad75f05d6c35fdb02a290cb740a75d4
-- 
2.47.1


  parent reply	other threads:[~2025-06-25 14:43 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-04  9:39 [PATCH 0/2] " Andrew Burgess
2025-06-04  9:39 ` [PATCH 1/2] gdb/python: add gdb.Style class Andrew Burgess
2025-06-04  9:39 ` [PATCH 2/2] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-06 13:38 ` [PATCHv2 0/2] Python Style API Andrew Burgess
2025-06-06 13:38   ` [PATCHv2 1/2] gdb/python: add gdb.Style class Andrew Burgess
2025-06-06 14:21     ` Eli Zaretskii
2025-06-06 13:38   ` [PATCHv2 2/2] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-07 10:44   ` [PATCHv3 0/2] Python Style API Andrew Burgess
2025-06-07 10:44     ` [PATCHv3 1/2] gdb/python: add gdb.Style class Andrew Burgess
2025-06-07 10:44     ` [PATCHv3 2/2] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-09 15:54     ` [PATCHv3 0/2] Python Style API Andrew Burgess
2025-06-18 19:30     ` [PATCHv4 0/4] " Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-18 19:30       ` [PATCHv4 4/4] gdb: extend gdb.write to support styled output Andrew Burgess
2025-06-25 14:42       ` Andrew Burgess [this message]
2025-06-25 14:42         ` [PATCHv5 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-06-25 14:42         ` [PATCHv5 4/4] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-07-07 14:43         ` [PATCHv6 0/4] Python Style API Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-07-07 14:43           ` [PATCHv6 4/4] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-08-13 10:25           ` [PATCHv7 0/4] Fix for gdb.Color + pagination AND new gdb.Style API Andrew Burgess
2025-08-13 10:25             ` [PATCHv7 1/4] gdb: allow gdb.Color to work correctly with pagination Andrew Burgess
2025-08-24 16:13               ` Andrew Burgess
2025-08-25 10:21                 ` Tom de Vries
2025-08-26 14:35                   ` [PATCH] gdb/testsuite: work around empty substring bug in expect Andrew Burgess
2025-08-27  6:24                     ` Tom de Vries
2025-08-13 10:29             ` [PATCHv7 2/4] gdb/python: add gdb.Style class Andrew Burgess
2025-08-13 10:30             ` [PATCHv7 4/4] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-08-13 12:37               ` Eli Zaretskii
2025-08-13 10:34             ` [PATCHv7 3/4] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-08-13 13:05               ` Eli Zaretskii
2025-08-13 13:05               ` Eli Zaretskii
2025-08-27 11:34             ` [PATCHv8 0/3] new gdb.Style API Andrew Burgess
2025-08-27 11:34               ` [PATCHv8 1/3] gdb/python: add gdb.Style class Andrew Burgess
2025-09-16 16:47                 ` Tom Tromey
2025-09-23 16:59                   ` Andrew Burgess
2025-08-27 11:34               ` [PATCHv8 2/3] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-09-16 16:50                 ` Tom Tromey
2025-08-27 11:34               ` [PATCHv8 3/3] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-09-16 16:56                 ` Tom Tromey
2025-09-23 17:05                   ` Andrew Burgess
2025-09-23 18:38                     ` Tom Tromey
2025-09-23 16:54               ` [PATCHv9 0/3] new gdb.Style API Andrew Burgess
2025-09-23 16:54                 ` [PATCHv9 1/3] gdb/python: add gdb.Style class Andrew Burgess
2025-09-23 16:54                 ` [PATCHv9 2/3] gdb/python: new class gdb.StyleParameterSet Andrew Burgess
2025-09-23 16:54                 ` [PATCHv9 3/3] gdb/python: extend gdb.write to support styled output Andrew Burgess
2025-10-03 19:27                 ` [PATCHv9 0/3] new gdb.Style API Tom Tromey
2025-10-05 12:51                   ` Andrew Burgess
2025-10-05 15:16                     ` Tom de Vries
2025-10-05 17:59                       ` Tom Tromey
2025-10-06  9:01                         ` Andrew Burgess
2025-10-05 18:03                       ` Andrew Burgess
2025-10-05 18:41                         ` Tom de Vries
2025-10-06  9:01                           ` Andrew Burgess
2025-10-06 12:29                             ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1750862458.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox