diff options
| author | Andrew Burgess <aburgess@redhat.com> | 2025-06-17 18:09:49 +0100 |
|---|---|---|
| committer | Andrew Burgess <aburgess@redhat.com> | 2025-10-05 13:48:06 +0100 |
| commit | 3c724596812882cc0c3b653330551fae132d6475 (patch) | |
| tree | 5607b83fa5e5fba0dd3ff4b9b0123bcb990b284b /gdb/python/python-internal.h | |
| parent | d5214580a5f24cb1ca47f095e6d3554cb48eebbe (diff) | |
| download | binutils-3c724596812882cc0c3b653330551fae132d6475.zip binutils-3c724596812882cc0c3b653330551fae132d6475.tar.gz binutils-3c724596812882cc0c3b653330551fae132d6475.tar.bz2 | |
gdb/python: extend gdb.write to support styled output
It is already possible to produce styled output from Python by
converting the gdb.Style to its escape code sequence, and writing that
to the output stream.
But this commit adds an alternative option to the mix by extending the
existing gdb.write() function to accept a 'style' argument. The value
of this argument can be 'None' to indicate no style change should be
performed, this is the default, and matches the existing behaviour.
Or the new 'style' argument can be a gdb.Style object, in which case
the specified style is applied only for the string passed to
gdb.write, after which the default style is re-applied.
Using gdb.write with a style object more closely matches how GDB
handles styling internally, and has the benefit that the user doesn't
need to remember to restore the default style when they are done.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python/python-internal.h')
| -rw-r--r-- | gdb/python/python-internal.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index f61a175..dbb2d7e 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -570,6 +570,20 @@ struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj); frame_info_ptr frame_object_to_frame_info (PyObject *frame_obj); struct gdbarch *arch_object_to_gdbarch (PyObject *obj); +/* Return true if OBJ is a gdb.Style object. OBJ must not be NULL. */ + +extern bool gdbpy_is_style (PyObject *obj); + +/* Return the ui_file_style from OBJ, a gdb.Style object. OBJ must not be + NULL. + + It is possible that OBJ is a gdb.Style object, but the underlying style + cannot be fetched for some reason. If this happens then a Python error + is set and an empty optional is returned. */ + +extern std::optional<ui_file_style> + gdbpy_style_object_to_ui_file_style (PyObject *obj); + extern PyObject *gdbpy_execute_mi_command (PyObject *self, PyObject *args, PyObject *kw); |
