Re: Make the "python" command resemble the standard Python interpreter

Khoo Yit Phang
2012-01-13T21:37:54Z

(Sorry if you received a duplicate email, my previous reply was rejected by gdb-patches.)

Hi,

On Jan 13, 2012, at 8:56 AM, Phil Muldoon wrote:

> Tom Tromey <tromey@redhat.com> writes:
>
>>>>>>> "Yit" == Khoo Yit Phang <khooyp@cs.umd.edu> writes:
>>
>> 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.

Tom's email did not include all the code: the other cases are handled via gdbpy_convert_exception.

> Also, the cleanup in the TRY_CATCH seems weird?

Can you clarify?

In this case, gdbpy_suspend_sigint_handler suspends Python's interrupt handler and reverts to GDB's. The cleanup handler resumes Python's interrupt handler, and additionally captures any changes to GDB's signal handler, and so has to be run before returning to Python.

>> 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.

Sounds reasonable.

Yit
January 13, 2012