cs01 / gdbgui

Browser-based frontend to gdb (gnu debugger). Add breakpoints, view the stack, visualize data structures, and more in C, C++, Go, Rust, and Fortran. Run gdbgui from the terminal and a new tab will open in your browser.
https://gdbgui.com
GNU General Public License v3.0
9.9k stars 499 forks source link

add interactive pty to frontend #295

Closed cs01 closed 4 years ago

cs01 commented 5 years ago

Is your feature request related to a problem? Please describe. The frontend terminal is not truly interactive. gdb behaves differently when it is connected to a terminal and will prompt and wait for user responses rather than assume things and carry on.

Describe the solution you'd like A fully interactive terminal with gdb in the frontend. xterm.js can be used to render the terminal, and Python pty's can be used on the backend. One will be created for the user to interact with, and another for the UI to send/receive gdb's mi2 messages.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context https://xtermjs.org/ can be used to render the terminal in the frontend.

The new-ui command can be used to split I/O between the UI for the gui and the terminal for the user. https://sourceware.org/gdb/onlinedocs/gdb/Interpreters.html

cs01 commented 5 years ago

I am able to create two ptys: one for the user to interact with, and another for the UI to interact with by using an mi2 interpreter. I first create a pty for mi2 protocol. I get its path (such as /dev/pts/19) then run cat in it. Next I create another pty and run gdb in it, and run the command new-ui mi2 /dev/pts/19. At this point I expect to be able to write arbitrary mi2 commands to /dev/pts/19, and parse mi2 responses from it, but it doesn't really work. Occasionally a message is read from it, but nothing seems to happen when I write to it. Any ideas where I am going wrong here? Should I not be running cat?

You can test this with gdbgui commit 2621c26b3d (branch cs01/use-pty), and pygdbmi commit 535522b99f71e1 (branch cs01/refactor).

The user-facing terminal works pretty well; it's just a matter of getting the mi2 messages passed back and forth to keep the UI in sync. image

simark commented 5 years ago

I don't have time to look at your code right now, but I just wanted to point out that this is used (and works) for cdt-gdb-adapter:

https://github.com/eclipse-cdt/cdt-gdb-adapter/blob/478303332c5d1385e301b71e437a68f1c8551825/src/GDBBackend.ts#L61

So there's hope :)

cs01 commented 5 years ago

Thanks! Got it working. I had two threads competing to read from the pty at the same time.

cs01 commented 5 years ago

Your link did give me more confidence that I wasn't wasting my time and there was a solution though 😄

simark commented 5 years ago

Nice :). I'll have to try it.

cs01 commented 5 years ago

It would be great to get some folks testing it before it's released! I'll let you know when it's ready for testing.