This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: Make the "python" command resemble the standard Python interpreter
- From: Phil Muldoon <pmuldoon at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: Khoo Yit Phang <khooyp at cs dot umd dot edu>, gdb-patches at sourceware dot org
- Date: Fri, 13 Jan 2012 13:56:14 +0000
- Subject: Re: Make the "python" command resemble the standard Python interpreter
- References: <A6FE1BE9-CD08-41A2-A1E8-F659140DA689@cs.umd.edu> <m3d3aq55ew.fsf@fleche.redhat.com>
- Reply-to: pmuldoon at redhat dot com
Tom Tromey <tromey@redhat.com> writes:
>>>>>> "Yit" == Khoo Yit Phang <khooyp@cs.umd.edu> writes:
> I think it would be better to make it not conflict somehow.
>
> Yit> + TRY_CATCH (except, RETURN_MASK_ALL)
> Yit> + {
> Yit> + struct cleanup *cleanup = gdbpy_suspend_sigint_handler ();
> Yit> + p = command_line_input (prompt, 0, "python");
> Yit> + do_cleanups (cleanup);
> Yit> + }
> Yit> +
> Yit> + /* Detect Ctrl-C and treat as KeyboardInterrupt. */
> Yit> + if (except.reason == RETURN_QUIT)
> Yit> + return NULL;
>
> Does this case need the Python exception to be set? If not, I think it
> would be good to expand this comment to explain the situation.
Yes, I think it does. If command_line_input fails for a reason other
than the one case of Ctrl-C, the exception I believe with be eaten.
Also, the cleanup in the TRY_CATCH seems weird?
> Yit> + m = PyImport_AddModule ("__main__");
> Yit> + if (m == NULL)
> Yit> + error (_("Error while executing Python code."));
>
> You have to do something with the Python exception here.
> Usually we use gdbpy_print_stack, but sometimes other things are
> appropriate.
> Yit> + d = PyModule_GetDict (m);
>
> Do we need error checking?
> I didn't look at the API docs.
Nope, PyModule_GetDict never fails. But given how things change in
Python (ie 3.x vs 2.x) it might be cautious just to add a check here
anyway.
Cheers,
Phil