diff options
author | Andrew Burgess <aburgess@redhat.com> | 2022-01-24 15:29:49 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2022-02-07 16:52:47 +0000 |
commit | 0642912e83168b9036d81e8a9950352d233affcb (patch) | |
tree | dedd33995145b8d2ba8e2d863ad3231a68d22907 /gdb/python | |
parent | 573269a87c89ae866db556428fe9ea63d6c4db5f (diff) | |
download | gdb-0642912e83168b9036d81e8a9950352d233affcb.zip gdb-0642912e83168b9036d81e8a9950352d233affcb.tar.gz gdb-0642912e83168b9036d81e8a9950352d233affcb.tar.bz2 |
gdb/python: allow Value.format_string to return styled output
Add a new argument to the gdb.Value.format_string method, 'styling'.
This argument is False by default.
When this argument is True, then the returned string can contain output
styling escape sequences.
When this argument is False, then the returned string will not contain
any styling escape sequences.
If the returned string is going to be printed to the user, then it is
often nice to retain the GDB styling.
For the testing, we need to adjust the TERM environment variable, as
we do for all the styling tests. I'm now running all of the C tests
in gdb.python/py-format-string.exp in an environment where styling
could be generated, but only my new test should actually produce
styled output, hopefully this will catch the case where a bug might
cause format_string to always produce styled output.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-value.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 6401d96..b546344 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -639,6 +639,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) "symbols", /* See set print symbol on|off. */ "unions", /* See set print union on|off. */ "address", /* See set print address on|off. */ + "styling", /* Should we apply styling. */ /* C++ options. */ "deref_refs", /* No corresponding setting. */ "actual_objects", /* See set print object on|off. */ @@ -683,13 +684,14 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) PyObject *symbols_obj = NULL; PyObject *unions_obj = NULL; PyObject *address_obj = NULL; + PyObject *styling_obj = Py_False; PyObject *deref_refs_obj = NULL; PyObject *actual_objects_obj = NULL; PyObject *static_members_obj = NULL; char *format = NULL; if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, - "|O!O!O!O!O!O!O!O!O!O!IIIs", + "|O!O!O!O!O!O!O!O!O!O!O!IIIs", keywords, &PyBool_Type, &raw_obj, &PyBool_Type, &pretty_arrays_obj, @@ -698,6 +700,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) &PyBool_Type, &symbols_obj, &PyBool_Type, &unions_obj, &PyBool_Type, &address_obj, + &PyBool_Type, &styling_obj, &PyBool_Type, &deref_refs_obj, &PyBool_Type, &actual_objects_obj, &PyBool_Type, &static_members_obj, @@ -752,7 +755,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) } } - string_file stb; + string_file stb (PyObject_IsTrue (styling_obj)); try { |