lebr0nli / GEP

GEP (GDB Enhanced Prompt) - a GDB plug-in to enhance your GDB with fzf history search, fish-like autosuggestions, tab auto-completion with fzf, and more!
MIT License
98 stars 7 forks source link

gdb doesn't import prompt_toolkit from $HOME/GEP/ #1

Closed dp12 closed 2 years ago

dp12 commented 2 years ago

This is a really cool plugin and I'm eager to use its features. However, when I try to load it with source ~/GEP/.gdbinit-gep.py, I get an error about "'_GdbOutputFile' object has no attribute 'fileno'". It looks like there's some issue with prompt_toolkit. To get a full backtrace, I did the following:

(gdb) python
>from prompt_toolkit import PromptSession
>p = PromptSession()
>end
Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "/home/dp12/.local/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 468, in __init__
    self.app = self._create_application(editing_mode, erase_when_done)
  File "/home/dp12/.local/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 719, in _create_application
    application: Application[_T] = Application(
  File "/home/dp12/.local/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 277, in __init__
    self.output = output or session.output
  File "/home/dp12/.local/lib/python3.8/site-packages/prompt_toolkit/application/current.py", line 70, in output
    self._output = create_output()
  File "/home/dp12/.local/lib/python3.8/site-packages/prompt_toolkit/output/defaults.py", line 77, in create_output
    return Vt100_Output.from_pty(
  File "/home/dp12/.local/lib/python3.8/site-packages/prompt_toolkit/output/vt100.py", line 466, in from_pty
    fd = stdout.fileno()
AttributeError: '_GdbOutputFile' object has no attribute 'fileno'
Error while executing Python code.

Any ideas about what might be happening?

lebr0nli commented 2 years ago

Hi, can you provide more information about the version of your gdb, Python, and prompt_toolkit?

By the way, this plugin only works with prompt_toolkit 2 now, so please ensure that you run pip install --target="$HOME/GEP/" prompt_toolkit==2.0.10 before using GEP.

dp12 commented 2 years ago

Thanks for the quick reply @lebr0nli! I guess I created the issue too soon. The fix was quick, but posting what I did for future users who run into this problem:

I tested what version of prompt_tookit I had installed by running the following in gdb:

pwndbg> python
>import prompt_toolkit
>print(prompt_toolkit.__version__)
>end
3.0.18

Of course, prompt_toolkit 3 won't work with this plugin. Even doing python -m pip install -Iv --target="$HOME/GEP/" prompt_toolkit==2.0.10 didn't seem to fix the issue; gdb stubbornly refused to use prompt_toolkit 2, so I had to uninstall the old prompt toolkit:

python -m pip uninstall prompt_toolkit

Then I re-ran the pip install of prompt_tookit 2 and everything started working.

lebr0nli commented 2 years ago

I think my import mechanism go wrong so even doing pip install --target="$HOME/GEP/" prompt_toolkit==2.0.10 didn't seem to fix the issue, I will try to fix this problem to let everyone who using prompt_toolkit 3 can use GEP without uninstalling it.

Thanks for the bug!