aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/python.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python/python.c')
-rw-r--r--gdb/python/python.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 8f8030c..2aaa30c 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -36,6 +36,7 @@
#include "run-on-main-thread.h"
#include "observable.h"
#include "build-id.h"
+#include "cli/cli-style.h"
#if GDB_SELF_TEST
#include "gdbsupport/selftest.h"
@@ -660,12 +661,14 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
const char *arg;
PyObject *from_tty_obj = nullptr;
PyObject *to_string_obj = nullptr;
- static const char *keywords[] = { "command", "from_tty", "to_string",
- nullptr };
+ PyObject *styling = nullptr;
+ static const char *keywords[]
+ = { "command", "from_tty", "to_string", "styling", nullptr };
- if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!O!", keywords, &arg,
&PyBool_Type, &from_tty_obj,
- &PyBool_Type, &to_string_obj))
+ &PyBool_Type, &to_string_obj,
+ &PyBool_Type, &styling))
return nullptr;
bool from_tty = false;
@@ -686,6 +689,15 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
to_string = (cmp != 0);
}
+ bool styling_p = !to_string;
+ if (styling != nullptr)
+ {
+ int cmp = PyObject_IsTrue (styling);
+ if (cmp < 0)
+ return nullptr;
+ styling_p = (cmp != 0);
+ }
+
std::string to_string_res;
scoped_restore preventer = prevent_dont_repeat ();
@@ -745,14 +757,29 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
scoped_restore save_uiout = make_scoped_restore (&current_uiout);
+ /* If the Python 'styling' argument was False then temporarily
+ disable styling. Otherwise, don't do anything, styling could
+ already be disabled for some other reason, we shouldn't override
+ that and force styling on. */
+ std::optional<scoped_disable_styling> disable_styling;
+ if (!styling_p)
+ disable_styling.emplace ();
+
/* Use the console interpreter uiout to have the same print format
for console or MI. */
interp = interp_lookup (current_ui, "console");
current_uiout = interp->interp_ui_out ();
if (to_string)
- to_string_res = execute_control_commands_to_string (lines.get (),
- from_tty);
+ {
+ /* Pass 'true' here to always request styling, however, if
+ the scoped_disable_styling disabled styling, or the user
+ has globally disabled styling, then the output will not be
+ styled. */
+ to_string_res
+ = execute_control_commands_to_string (lines.get (), from_tty,
+ true);
+ }
else
execute_control_commands (lines.get (), from_tty);
}