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

Khoo Yit Phang
2012-01-12T00:54:33Z

Hi,

On Jan 11, 2012, at 3:51 PM, Tom Tromey wrote:

> 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> + v = PyRun_StringFlags (command,
> Yit> + from_tty ? Py_single_input : Py_file_input,
> Yit> + d, d, NULL);
> Yit> + if (v == NULL)
> Yit> + {
> Yit> + int interrupt = PyErr_ExceptionMatches (PyExc_KeyboardInterrupt);
> Yit> + PyErr_Print ();
>
> gdbpy_print_stack.

I've ran the testsuite, and of course, there were many test failures, probably spurious and I'll update. However, a number of errors turn out to be due to adding gdbpy_print_stack, because the original lines of code that I replaced (python:249 and python.c:273) simply called error like:

if (PyRun_SimpleString (arg))
error (_("Error while executing Python code."));

Should I defer your suggested change to a separate patch?

Yit
January 11, 2012