This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] python(+solib error): save/restore error state
- From: Doug Evans <dje at google dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Fri, 8 Oct 2010 13:08:27 -0700
- Subject: Re: [patch] python(+solib error): save/restore error state
- References: <20101008191154.GA13058@host1.dyn.jankratochvil.net>
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 ...