Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ptpython's IPython embed doesn't work within GDB #546

Open
depau opened this issue Aug 21, 2023 · 0 comments
Open

ptpython's IPython embed doesn't work within GDB #546

depau opened this issue Aug 21, 2023 · 0 comments

Comments

@depau
Copy link

depau commented Aug 21, 2023

I'm trying to use PtPython with IPython inside the GDB integrated python console.

I wrote this GDB command to bring up a PtPython REPL within GDB:

ptpython_cmd.py

import sys

import gdb
from ptpython.ipython import embed


class PtPythonCommand(gdb.Command):
    def __init__(self) -> None:
        super().__init__("ptpython", gdb.COMMAND_USER)

    def invoke(self, arg: str, from_tty: bool):
        self.dont_repeat()

        if not from_tty:
            raise Exception("PtPython can only be launched from the TTY")

        stdout = sys.stdout
        stderr = sys.stderr
        stdin = sys.stdin

        try:
            sys.stdout = sys.__stdout__
            sys.stderr = sys.__stderr__
            sys.stdin = sys.__stdin__

            embed()

        except SystemExit as e:
            if e.code != 0:
                print("ptpython exited with code", e.code)

        finally:
            sys.stdout = stdout
            sys.stderr = stderr
            sys.stdin = stdin


PtPythonCommand()

Run gdb -ex "source ptpython_cmd.py" -ex ptpython to load the script and launch the custom command.

The shell is very broken and it doesn't display the TUI. However, if I use the regular PtPython embed, it works great (replace the embed import with from ptpython import embed to reproduce that).

I suppose there could be something wrong with the IPython embed. I'm not aware of any differences in the GDB python interpreter vs regular Python, but I suspect they might be messing with the asyncio event loop. I haven't found proof of this, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant