aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-05-24 10:15:17 -0600
committerTom Tromey <tromey@adacore.com>2022-06-01 06:15:53 -0600
commit80fa4b2a606763e71c4b599fa88288f554a0ea5b (patch)
tree251f21a9776f96cc0a0b83e905968385cb409b48 /gdb/python
parent46c7fd95fc42466a5a8c3b3d70925f1a8af68de3 (diff)
downloadgdb-80fa4b2a606763e71c4b599fa88288f554a0ea5b.zip
gdb-80fa4b2a606763e71c4b599fa88288f554a0ea5b.tar.gz
gdb-80fa4b2a606763e71c4b599fa88288f554a0ea5b.tar.bz2
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.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-frame.c25
-rw-r--r--gdb/python/python.c12
2 files changed, 37 insertions, 0 deletions
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 769e28c..9a28c36 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -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 */
};
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 <SYMBOL+OFFSET>' 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}
};