[PATCH 3/4] Convert gdbpy_frame_stop_reason_string to the safety API
Tom Tromey <[email protected]>
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
This converts gdbpy_frame_stop_reason_string to the Python safety API.
This changes the function to accept keyword arguments as well,
following the outcome of an earlier discussion. A new test is added
for this.
---
gdb/python/py-frame.c | 20 ++++++++------------
gdb/python/python-internal.h | 3 ++-
gdb/python/python.c | 4 ++--
gdb/testsuite/gdb.python/py-frame.exp | 3 +++
4 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 3910f19ef83..4dd174cf5ae 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -466,24 +466,20 @@ gdbpy_selected_frame ()
/* Implementation of gdb.stop_reason_string (Integer) -> String.
Return a string explaining the unwind stop reason. */
-PyObject *
-gdbpy_frame_stop_reason_string (PyObject *self, PyObject *args)
+const char *
+gdbpy_frame_stop_reason_string (gdbpy_borrowed_ref<> args,
+ gdbpy_opt_borrowed_ref<> kw)
{
int reason;
- const char *str;
- if (!PyArg_ParseTuple (args, "i", &reason))
- return NULL;
+ static const char *keywords[] = { "reason", nullptr };
+ gdbpy_arg_parse_tuple_and_keywords (args, kw, "i", keywords, &reason);
if (reason < UNWIND_FIRST || reason > UNWIND_LAST)
- {
- PyErr_SetString (PyExc_ValueError,
- _("Invalid frame stop reason."));
- return NULL;
- }
+ gdbpy_err_set_string (PyExc_ValueError,
+ _("Invalid frame stop reason."));
- str = unwind_stop_reason_to_string ((enum unwind_stop_reason) reason);
- return PyUnicode_Decode (str, strlen (str), host_charset (), NULL);
+ return unwind_stop_reason_to_string ((enum unwind_stop_reason) reason);
}
/* Implements the equality comparison for Frame objects.
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 76ccdc6b0c6..5796b80037a 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -465,7 +465,8 @@ extern PyObject *gdbpy_history_count (PyObject *self, PyObject *args);
PyObject *gdbpy_convenience_variable (PyObject *self, PyObject *args);
PyObject *gdbpy_set_convenience_variable (PyObject *self, PyObject *args);
PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
-PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
+const char *gdbpy_frame_stop_reason_string (gdbpy_borrowed_ref<> args,
+ gdbpy_opt_borrowed_ref<> kw);
gdbpy_ref<> gdbpy_lookup_symbol (gdbpy_borrowed_ref<> args,
gdbpy_opt_borrowed_ref<> kw);
gdbpy_ref<> gdbpy_lookup_global_symbol (gdbpy_borrowed_ref<> args,
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 72c2d7bb10d..84e7c21377a 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -3165,9 +3165,9 @@ Return the newest frame object."),
noargs_function<gdbpy_selected_frame> ("selected_frame",
"selected_frame () -> gdb.Frame.\n\
Return the selected frame object."),
- { "frame_stop_reason_string", gdbpy_frame_stop_reason_string, METH_VARARGS,
+ varargs_function<gdbpy_frame_stop_reason_string> ("frame_stop_reason_string",
"stop_reason_string (Integer) -> String.\n\
-Return a string explaining unwind stop reason." },
+Return a string explaining unwind stop reason."),
{ "start_recording", gdbpy_start_recording, METH_VARARGS,
"start_recording ([method] [, format]) -> gdb.Record.\n\
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
index aebec651964..30692ed6dd8 100644
--- a/gdb/testsuite/gdb.python/py-frame.exp
+++ b/gdb/testsuite/gdb.python/py-frame.exp
@@ -137,6 +137,9 @@ gdb_test "python print ('result = %s' % (f0.type () == gdb.NORMAL_FRAME))" " = T
gdb_test "python print ('result = %s' % (f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON))" \
" = True" "test Frame.unwind_stop_reason"
gdb_test "python print ('result = %s' % gdb.frame_stop_reason_string (gdb.FRAME_UNWIND_INNER_ID))" " = previous frame inner to this frame \\(corrupt stack\\?\\)" "test gdb.frame_stop_reason_string"
+gdb_test "python print ('result = %s' % gdb.frame_stop_reason_string (reason=gdb.FRAME_UNWIND_INNER_ID))" \
+ " = previous frame inner to this frame \\(corrupt stack\\?\\)" \
+ "test gdb.frame_stop_reason_string with keyword"
gdb_test "python print ('result = %s' % f0.pc ())" " = ${::decimal}" "test Frame.pc"
gdb_test "python print ('result = %s' % (f0.older () == f1))" " = True" "test Frame.older"
gdb_test "python print ('result = %s' % (f1.newer () == f0))" " = True" "test Frame.newer"
--
2.49.0