diff options
| author | Andrew Burgess <aburgess@redhat.com> | 2025-06-12 14:29:16 +0100 |
|---|---|---|
| committer | Andrew Burgess <aburgess@redhat.com> | 2025-06-19 10:31:14 +0100 |
| commit | d8e6b67b18d1864a7ca1bd0bb4fabe949fad2135 (patch) | |
| tree | 6d81b06bf5ef8efdb95792611fedefd9d6ac5c11 /gdb/python/python.c | |
| parent | 86a5d1eb9b03ff391a551bf5594c0aa9898f9989 (diff) | |
| download | binutils-d8e6b67b18d1864a7ca1bd0bb4fabe949fad2135.zip binutils-d8e6b67b18d1864a7ca1bd0bb4fabe949fad2135.tar.gz binutils-d8e6b67b18d1864a7ca1bd0bb4fabe949fad2135.tar.bz2 | |
gdb/python: introduce gdb.warning() function
This commit adds a new gdb.warning() function. This function takes a
string and then calls GDB's internal warning() function. This will
display the string as a warning.
Using gdb.warning() means that the message will get the new emoji
prefix if the user has that feature turned on. Also, the message will
be sent to gdb.STDERR without the user having to remember to print to
the correct stream.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python/python.c')
| -rw-r--r-- | gdb/python/python.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c index 7c3d0d1..ff50c42 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1630,6 +1630,40 @@ gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw) Py_RETURN_NONE; } +/* Implement gdb.warning(). Takes a single text string argument and emit a + warning using GDB's 'warning' function. The input text string must not + be empty. */ + +static PyObject * +gdbpy_warning (PyObject *self, PyObject *args, PyObject *kw) +{ + const char *text; + static const char *keywords[] = { "text", nullptr }; + + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &text)) + return nullptr; + + if (strlen (text) == 0) + { + PyErr_SetString (PyExc_ValueError, + _("Empty text string passed to gdb.warning")); + return nullptr; + } + + try + { + warning ("%s", text); + } + catch (const gdb_exception &ex) + { + /* The warning() call probably cannot throw an exception. But just + in case it ever does. */ + return gdbpy_handle_gdb_exception (nullptr, ex); + } + + Py_RETURN_NONE; +} + /* Return non-zero if print-stack is not "none". */ int @@ -3124,6 +3158,12 @@ Return the current print options." }, METH_VARARGS | METH_KEYWORDS, "notify_mi (name, data) -> None\n\ Output async record to MI channels if any." }, + + { "warning", (PyCFunction) gdbpy_warning, + METH_VARARGS | METH_KEYWORDS, + "warning (text) -> None\n\ +Print a warning." }, + {NULL, NULL, 0, NULL} }; |
