This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v3 8/8] Python: Fix exception handling in py-record-btrace.c
- From: Tim Wiederhake <tim dot wiederhake at intel dot com>
- To: gdb-patches at sourceware dot org
- Cc: markus dot t dot metzger at intel dot com, brobecker at adacore dot com, qiyaoltc at gmail dot com
- Date: Mon, 24 Apr 2017 10:35:40 +0200
- Subject: [PATCH v3 8/8] Python: Fix exception handling in py-record-btrace.c
- Authentication-results: sourceware.org; auth=none
- References: <1493022940-29973-1-git-send-email-tim.wiederhake@intel.com>
GDB_PY_HANDLE_EXCEPTION does not handle all exceptions. Replace with call to
gdbpy_convert_exception.
2017-04-24 Tim Wiederhake <tim.wiederhake@intel.com>
gdb/ChangeLog:
python/py-record-btrace.c (btpy_insn_sal, btpy_insn_data,
btpy_insn_decode, recpy_bt_goto): Handle all exceptions.
---
gdb/python/py-record-btrace.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index d684561..674a3aa 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -213,7 +213,7 @@ recpy_bt_insn_sal (PyObject *self, void *closure)
}
CATCH (except, RETURN_MASK_ALL)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ gdbpy_convert_exception (except);
}
END_CATCH
@@ -286,10 +286,14 @@ recpy_bt_insn_data (PyObject *self, void *closure)
CATCH (except, RETURN_MASK_ALL)
{
xfree (buffer);
- GDB_PY_HANDLE_EXCEPTION (except);
+ buffer = NULL;
+ gdbpy_convert_exception (except);
}
END_CATCH
+ if (buffer == NULL)
+ return NULL;
+
object = PyBytes_FromStringAndSize ((const char*) buffer, insn->size);
xfree (buffer);
@@ -312,21 +316,23 @@ recpy_bt_insn_decoded (PyObject *self, void *closure)
{
const btrace_insn * const insn = btrace_insn_from_recpy_insn (self);
string_file strfile;
+ int length = 0;
if (insn == NULL)
return NULL;
TRY
{
- gdb_print_insn (target_gdbarch (), insn->pc, &strfile, NULL);
+ length = gdb_print_insn (target_gdbarch (), insn->pc, &strfile, NULL);
}
CATCH (except, RETURN_MASK_ALL)
{
gdbpy_convert_exception (except);
- return NULL;
}
END_CATCH
+ if (length == 0)
+ return NULL;
return PyBytes_FromString (strfile.string ().c_str ());
}
@@ -776,6 +782,7 @@ recpy_bt_goto (PyObject *self, PyObject *args)
const recpy_record_object * const record = (recpy_record_object *) self;
struct thread_info * const tinfo = find_thread_ptid (record->ptid);
const recpy_element_object *obj;
+ PyObject *ret = NULL;
if (tinfo == NULL || btrace_is_empty (tinfo))
return PyErr_Format (gdbpy_gdb_error, _("Empty branch trace."));
@@ -796,14 +803,17 @@ recpy_bt_goto (PyObject *self, PyObject *args)
target_goto_record_end ();
else
target_goto_record (obj->number);
+
+ Py_INCREF (Py_None);
+ ret = Py_None;
}
CATCH (except, RETURN_MASK_ALL)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ gdbpy_convert_exception (except);
}
END_CATCH
- Py_RETURN_NONE;
+ return ret;
}
/* BtraceList methods. */
--
2.7.4