[RFC,6/8] mi/python: Handle python exception when executiong python-defined MI commands
Commit Message
Respond with ^error,msg="..." when an unhandled python exception is thrown
while invoking python-defined MI command. The error message is taken from
python exception object.
gdb/Changelog:
* python/py-micmd.c (py_mi_invoke): Handle exceptions thrown in Python
code.
---
gdb/ChangeLog | 5 +++++
gdb/python/py-micmd.c | 18 ++++++++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
Comments
>>>>> "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:
Jan> Respond with ^error,msg="..." when an unhandled python exception is thrown
Jan> while invoking python-defined MI command. The error message is taken from
Jan> python exception object.
Jan> gdb/Changelog:
Jan> * python/py-micmd.c (py_mi_invoke): Handle exceptions thrown in Python
Jan> code.
This seems reasonable but it also seems like it should just be part of
the patch adding this new function. If you're worried about joint
authorship, it's pretty common to just list two names in the ChangeLog.
thanks,
Tom
> This seems reasonable but it also seems like it should just be part of
> the patch adding this new function. If you're worried about joint
> authorship, it's pretty common to just list two names in the ChangeLog.
>
Yes, that's the reason why commits are structured this way. I did not want
to change Didier's commuts without him.
I'll do as you suggested and squash commits.
Thanks for reviewing!
Jan
> thanks,
> Tom
@@ -1,3 +1,8 @@
+2018-12-10 Jan Vrany <jan.vrany@fit.cvut.cz>
+
+ * python/py-micmd.c (py_mi_invoke): Handle exceptions thrown in Python
+ code.
+
2018-12-10 Jan Vrany <jan.vrany@fit.cvut.cz>
* python/py-micmd.c (parse_mi_result): Polish to make the output
@@ -115,14 +115,28 @@ py_mi_invoke (void *py_obj, char **argv, int argc)
error (_("Failed to create the python arguments list."));
}
}
-
+
+ gdb_assert (PyErr_Occurred () == NULL);
gdbpy_ref<> result (PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst, argobj.get (),
NULL));
+ if (PyErr_Occurred () != NULL)
+ {
+ gdbpy_err_fetch ex;
+ gdb::unique_xmalloc_ptr<char> ex_msg (ex.to_string());
- if (result != nullptr)
+ if (ex_msg == NULL || *ex_msg == '\0')
+ error (_("Failed to execute command"));
+ else
+ error (_(ex_msg.get ()));
+ }
+ else if (result != nullptr)
{
if (Py_None != result) parse_mi_result (result.get (), "result");
}
+ else
+ {
+ error (_("Command invoke() method returned NULL but no python exception is set"));
+ }
}
/* Parse the name of the MI command to register.