From 80fa4b2a606763e71c4b599fa88288f554a0ea5b Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 24 May 2022 10:15:17 -0600 Subject: 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. --- gdb/python/python.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'gdb/python/python.c') diff --git a/gdb/python/python.c b/gdb/python/python.c index 11aaa7a..9bef225 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1571,6 +1571,14 @@ gdbpy_progspaces (PyObject *unused1, PyObject *unused2) return list.release (); } +/* Return the name of the current language. */ + +static PyObject * +gdbpy_current_language (PyObject *unused1, PyObject *unused2) +{ + return host_string_to_python_string (current_language->name ()).release (); +} + /* The "current" objfile. This is set when gdb detects that a new @@ -2534,6 +2542,10 @@ Format ADDRESS, an address within PROG_SPACE, a gdb.Progspace, using\n\ ARCH, a gdb.Architecture to determine the address size. The format of\n\ the returned string is 'ADDRESS ' without the quotes." }, + { "current_language", gdbpy_current_language, METH_NOARGS, + "current_language () -> string\n\ +Return the name of the currently selected language." }, + {NULL, NULL, 0, NULL} }; -- cgit v1.1