[PATCH v3 00/34] Towards great frontend GDB consoles

Pedro Alves
2016-05-06T12:35:19Z

Here's an update of the series I last posted here:
https://sourceware.org/ml/gdb-patches/2016-03/msg00388.html

New in v3:

- Now at 34 patches, from 25.

- ChangeLog entries

- A lot of missing comments.

- GDB manual / NEWS documentation bits written

- Testing infrustruture add, plus new tests.

This allowed testing on x64-64 Fedora 23 with all MI tests forced
to run MI on a separate UI, which revealed a few problems, all
addressed.

- Many bugs fixed, as exposed by the testsuite.

- Bugs reported by Marc Khozam fixed (interpreter-exec; repeat;
console stuck with -exec-run and "set inferior-tty").

- "info uis" command dropped for now.

Force-pushed to users/palves/console at sourceware.org.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Series intro:

This series provides a way to for frontends's GDB console to be on par
with gdb's native console running on a terminal.

The current support for implementing a GDB console that MI frontends
have available, based on "-interpreter-exec console", leaves readline,
history, completion, when to show/hide/print the prompt (sync vs async
execution), pagination, etc. all up to the frontend.

The end result is that all frontends have a real bad GDB console
experience, if they provide one at all.

GDB already has to handle all that for the native CLI, when GDB is
started without MI. This series leverages that. Instead, have
Eclipse create a pty and wrap it in a window widget -- the same as
Eclipse's shell console -- and start GDB in that pty. Then, create a
second pty for MI communication, and tell GDB to start a MI
interpreter there, with a new "new-ui mi /dev/pts/N" command.

GDB then creates/manages a CLI on its terminal, with readline,
history, etc., support all done by GDB.

It's also possible to start extra CLI consoles, with "new-ui console
/dev/pts/N". The current limitation is that these extra consoles
don't have readline active (work as if "set editing off"), because
there can only be one instance of readline in a process, currently.
(I have a readline patch that addresses it, but it'll need API and
implementation discussion and it may or not be accepted.)

It should be possible to start gdb in MI mode, and then start an extra
console, and support readline on that console (since there's still
just one readline user), though it'll need a little bit more work to
get there. I just didn't try it yet, but it's definitely possible.

My original prototype did start out by doing things the other way
around -- start GDB in MI mode, and then start an extra CLI console on
a separate tty. I handed over that (functional) prototype to Marc
Khouzam @ Eclipse CDT a while ago, and after experimentation and
discussion, we ended up concluding that starting GDB in CLI mode
instead was both easier and actually also makes it possible to support
an interesting use case -- connect an Eclipse frontend to a GDB that
is already running outside Eclipse. Say, you're debugging on a
terminal, and then suddendly decide to start Eclipse's Standalone
Debugger _reusing_ your existing GDB, without having to start the
debug session from scratch. Magic.

The current usage is "new-ui <interpreter> <tty>".

E.g., on a terminal run this scriplet:

$ cat gdb-client
#!/bin/bash

reset
tty
tail -f /dev/null

$ gdb-client
/dev/pts/15

Now run gdb on another terminal, and tell it to start an MI
interpreter on the tty of the other terminal:

...
(gdb) new-ui mi /dev/pts/15
New UI allocated

Now back to the the gdb-client terminal, we'll get an MI prompt, ready
for MI input:

/dev/pts/15
=thread-group-added,id="i1"
(gdb)

You can also start a new UI running a CLI, with:

(gdb) new-ui console /dev/pts/15

More details in patch 29, which actually adds the new-ui command.

In case I messed up something on this update, you can still find v1 on
my github:
https://github.com/palves/gdb/commits/palves/console-v2

Pedro Alves (34):
Prepare gdb.python/mi-py-events.exp for Python/MI in separate channels
[Ada catchpoints] Fix "warning: failed to get exception name: No
definition of \"e.full_name\" in current context"
Introduce "struct ui"
Make gdb_stdout&co be per UI
Make the interpreters be per UI
Introduce interpreter factories
Make the intepreters output to all UIs
Always run async signal handlers in the main UI
Make instream be per UI
Make input_fd be per UI
Make out and error streams be per UI
Delete def_uiout
Make current_ui_out be per UI
Make command line editing (use of readline) be per UI
Always process target events in the main UI
Make target_terminal_inferior/ours almost nops on non-main UIs
Introduce display_mi_prompt
Make raw_stdout be per MI instance
Simplify starting the command event loop
Make gdb_in_secondary_prompt_p() be per UI
Replace the sync_execution global with a new enum prompt_state
tristate
Fix for spurious prompts in secondary UIs
New function should_print_stop_to_console
Push thread->control.command_interp to the struct thread_fsm
Only send sync execution command output to the UI that ran the command
Make main_ui be heap allocated
Handle UI's terminal closing
Make stdin be per UI
Add new command to create extra console/mi UI channels
[DOC] Document support for running interpreters on separate UI
channels
Add testing infrastruture bits for running with MI on a separate UI
Send deleted watchpoint-scope output to all UIs
Make mi-break.exp always expect breakpoint commands output on the main
UI
Always switch fork child to the main UI

gdb/doc/gdb.texinfo | 55 +-
gdb/NEWS | 16 +
gdb/ada-lang.c | 9 +
gdb/annotate.c | 15 +-
gdb/breakpoint.c | 61 +-
gdb/cli/cli-interp.c | 255 ++++--
gdb/cli/cli-interp.h | 32 +
gdb/cli/cli-script.c | 33 +-
gdb/compile/compile.c | 14 +-
gdb/defs.h | 4 +-
gdb/event-loop.c | 5 +
gdb/event-top.c | 343 ++++----
gdb/event-top.h | 13 +-
gdb/exceptions.c | 4 +-
gdb/fork-child.c | 22 +-
gdb/gdbthread.h | 5 -
gdb/guile/guile.c | 14 +-
gdb/guile/scm-ports.c | 6 +-
gdb/inf-loop.c | 2 +-
gdb/infcall.c | 50 +-
gdb/infcmd.c | 104 +--
gdb/inflow.c | 35 -
gdb/infrun.c | 157 ++--
gdb/infrun.h | 15 +-
gdb/interps.c | 288 +++++--
gdb/interps.h | 67 +-
gdb/linux-nat.c | 2 -
gdb/main.c | 53 +-
gdb/mi/mi-cmds.h | 3 -
gdb/mi/mi-common.h | 7 +
gdb/mi/mi-interp.c | 1131 +++++++++++++++-----------
gdb/mi/mi-main.c | 95 ++-
gdb/mi/mi-main.h | 4 +-
gdb/python/python.c | 15 +-
gdb/remote.c | 2 -
gdb/target.c | 40 +-
gdb/testsuite/README | 6 +
gdb/testsuite/gdb.ada/mi_catch_ex.exp | 41 +-
gdb/testsuite/gdb.gdb/selftest.exp | 4 +
gdb/testsuite/gdb.mi/mi-break.exp | 69 +-
gdb/testsuite/gdb.mi/mi-editing.exp | 37 +
gdb/testsuite/gdb.mi/mi-exec-run.exp | 158 ++++
gdb/testsuite/gdb.mi/mi-watch.exp | 85 +-
gdb/testsuite/gdb.opt/inline-cmds.c | 2 +-
gdb/testsuite/gdb.opt/inline-cmds.exp | 62 ++
gdb/testsuite/gdb.python/py-mi-events-gdb.py | 12 +-
gdb/testsuite/gdb.python/py-mi-events.exp | 21 +-
gdb/testsuite/lib/gdb.exp | 3 +-
gdb/testsuite/lib/mi-support.exp | 159 +++-
gdb/thread-fsm.c | 12 +-
gdb/thread-fsm.h | 23 +-
gdb/thread.c | 2 +-
gdb/top.c | 367 +++++++--
gdb/top.h | 174 +++-
gdb/tui/tui-interp.c | 175 +++-
gdb/tui/tui-io.c | 6 +-
gdb/tui/tui.c | 2 +-
gdb/ui-file.c | 4 +-
gdb/ui-file.h | 4 +-
gdb/ui-out.c | 184 -----
gdb/ui-out.h | 3 +-
gdb/utils.c | 7 +-
gdb/utils.h | 19 +-
63 files changed, 3090 insertions(+), 1527 deletions(-)
create mode 100644 gdb/cli/cli-interp.h
create mode 100644 gdb/testsuite/gdb.mi/mi-editing.exp
create mode 100644 gdb/testsuite/gdb.mi/mi-exec-run.exp

--
2.5.5