I want to debug a c++ program using gdb. I use the pi and the py commands to evaluate python commands from within gdb, which works fine when I invoke gdb from the command line. However, when I invoke gdb from within emacs using M-x gdb and then gdb -i=mi file_name, the following errors occur:

the pi command correctly opens an interactive python shell, but any input to this shell yields the errors like this:   


File "stdin", line 1
  -interpreter-exec console "2"
  SyntaxError: invalid syntax  


the py command works correctly for a single command (like py print 2+2), but not for multiple commands

I can get around those problems by starting gdb with gud-gdb, but then I dont have the support for gdb-many-windows. Maybe the problem is caused by the prompt after typing pi, which is no longer (gdb) but >>> instead?
I am going to go out on a limb and say this is a bug in gud mode.  The clue is the -interpreter-exec line in the error.
What happens here is that gud runs gdb in a special "MI" ("Machine Interface") mode.  In this mode, commands and their responses are designed to be machine-, rather than human-, readable.
To let GUIs provide a console interface to users, MI provides the -interpreter-exec command, which evaluates a command using some other gdb "interpreter" (which doesn't mean what you may think and in particular has nothing to do with Python).
So, gud sends user input to gdb, I believe, with -interpreter-exec console ....  But, in the case of a continuation line for a python command, this is the wrong thing to do.
I tried this out in Emacs and I was able to make it work for the python command when I spelled it out -- but py, pi, and python-interactive all failed.
gdb within emacs: python commands (py and pi)