Add gdb.current_language and gdb.Frame.language

This adds the gdb.current_language function, which can be used to find
the current language without (1) ever having the value "auto" or (2)
having to parse the output of "show language".

It also adds the gdb.Frame.language, which can be used to find the
language of a given frame.  This is normally preferable if one has a
Frame object handy.
This commit is contained in:
Tom Tromey
2022-05-24 10:15:17 -06:00
parent 46c7fd95fc
commit 80fa4b2a60
7 changed files with 78 additions and 0 deletions

View File

@ -598,6 +598,29 @@ frapy_level (PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
/* The language for this frame. */
static PyObject *
frapy_language (PyObject *self, PyObject *args)
{
try
{
struct frame_info *fi;
FRAPY_REQUIRE_VALID (self, fi);
enum language lang = get_frame_language (fi);
const language_defn *lang_def = language_def (lang);
return host_string_to_python_string (lang_def->name ()).release ();
}
catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
Py_RETURN_NONE;
}
/* Implementation of gdb.newest_frame () -> gdb.Frame.
Returns the newest frame object. */
@ -771,6 +794,8 @@ Return the value of the variable in this frame." },
"Select this frame as the user's current frame." },
{ "level", frapy_level, METH_NOARGS,
"The stack level of this frame." },
{ "language", frapy_language, METH_NOARGS,
"The language of this frame." },
{NULL} /* Sentinel */
};