This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]