[patch] python(+solib error): save/restore error state
Doug Evans
dje@google.com
Fri Oct 8 20:20:00 GMT 2010
On Fri, Oct 8, 2010 at 1:08 PM, Doug Evans <dje@google.com> wrote:
> On Fri, Oct 8, 2010 at 12:11 PM, Jan Kratochvil
> <jan.kratochvil@redhat.com> wrote:
>> @@ -768,6 +782,13 @@ source_python_script_for_objfile (struct objfile *objfile,
>> clear the error indicator. */
>> PyRun_SimpleFile (stream, file);
>>
>> + if (PyErr_Occurred ())
>> + {
>> + gdbpy_print_stack ();
>> + error (_("Error reading python script %s for object file %s"), file,
>> + objfile->name);
>> + }
>> +
>> do_cleanups (cleanups);
>> gdbpy_current_objfile = NULL;
>> }
>
> Hi. Most of the patch seems great, but it raises a question that I
> think needs to be answered.
>
> The comment above this code says:
>
> /* Note: If an exception occurs python will print the traceback and
> clear the error indicator. */
>
> ISTM that either this comment is wrong or the above patch is wrong, or
> some combination thereof.
>
> Also, if there is a problem here, then presumably source_python_script
> has the same problem, but I don't see it addressed in this patch.
>
> Plus if PyRun_SimpleFile can leave an outstanding error, we should
> research whether PyRun_SimpleString has the same problem. I see
> python.c checks the result of PyRun_SimpleString and calls
> gdbpy_print_stack if there's an error. Except that the python docs
> say there is no way to get the error.
>
> ref: http://docs.python.org/c-api/veryhigh.html?highlight=pyrun_simplestring#PyRun_SimpleString
>
> The docs for PyRun_SimpleFile suggest the same, there is no way to get
> the error.
>
> So, am I misreading the python docs or do we need the above patch?
> (and then if not, do we need the calls to gdbpy_print_stack after the
> calls to PyRun_SimpleString? Some experiments are in order - off to do
> some ...
>
Better yet, "use the source Luke ..." 1/2 :-).
Looking at the sources for PyRun_SimpleFile, I see PyErr_Print being
called before -1 is returned.
Similarly for PyRun_SimpleString.
Am I missing something?
More information about the Gdb-patches
mailing list