Re: recursion limit exceeded in Python API, but there's only one function in traceback

Phil Muldoon
2014-10-17T10:11:33Z

On 17/10/14 10:30, Ã–mer Sinan AÄŸacan wrote:
> I'm still having this problem. I just tried this:
>
> def handler():
> gdb.execute("continue")
> print "continue returned"
>
> This doesn't print anything, until the script fails with "maximum
> recursion depth". Then it prints lots of "continue returned" lines.
>
> So the problem is `gdb.execute` doesn't immediately return and that's
> causing Python stack to grow, because GDB is calling this function
> without returning anything to previous calls.
>
> I think I need a version of `gdb.execute` that returns immediately.
> ie. async version or something like that. Is such a thing possible?
>
> Thanks again.

Right. gdb.execute won't return until the command has completed.
Also the Python GIL has been acquired (as this is coming from the
Python interpreter) and so now Python is also blocked too. So in
effect the only thing running at this point is the gdb.execute command
that was invoked (in your case, the continue command). That will
return, and then the Python GIL will be released and the rest of the
script will continue.

I have a patch I need to upstream that adds a release_gil keyword to
gdb.execute. This optionally releases the GIL before executing the
command. But I have not got around to that yet.

A workaround would be to post any gdb.execute statements into the GDB
event loop. See gdb.post_event. That will return immediately and the
gdb.execute function will be scheduled to be called in the event loop.
Note there is no guarantee when this is. But as long as GDB is not
busy processing other events it usually means right away.

I'll work on posting that GIL patch soon.

Cheers

Phil