This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC] patch to make GDB open a new terminal window for the inferior
- From: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- To: gdb-patches ml <gdb-patches at sourceware dot org>
- Date: Tue, 19 May 2009 21:18:01 -0300
- Subject: [RFC] patch to make GDB open a new terminal window for the inferior
Hi,
I have this patch sitting in my hard disk for the past 1 year now, and I
still don't think I'll have the chance to work on it anytime soon:
It makes GDB open a new terminal window for each run of the inferior.
It's very rough at this point, and supports only urxvt terminal windows
because it was the only terminal program which seemed to accept being
given a master pty to use. I was meaning to modify the patch and GNU
screen to enable GDB to open a new screen window too, but still didn't
get around to that. It could also be integrated with the Python support
(e.g, call a python function which will return the master pty to use).
It's already functional though, and I believe it still applies cleanly.
To use the feature:
(gdb) tty urxvt
(gdb) run
I'm posting it to see what people think of it, and if anyone want to
adopt it for further development. Doug Evans already expressed interest
on IRC...
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
2009-05-29 Thiago Jung Bauermann <bauerman@br.ibm.com>
* inflow.c (new_tty_prefork): Open new pty and urxvt instance
for each run of the inferior.
=== modified file 'gdb/inflow.c'
--- gdb/inflow.c 2008-01-04 03:27:45 +0000
+++ gdb/inflow.c 2008-01-20 20:44:52 +0000
@@ -504,9 +504,58 @@ child_terminal_info (char *args, int fro
void
new_tty_prefork (const char *ttyname)
{
- /* Save the name for later, for determining whether we and the child
- are sharing a tty. */
- inferior_thisrun_terminal = ttyname;
+ if (ttyname && strcmp (ttyname, "urxvt") == 0)
+ {
+ int master, res;
+ char *pty_fd;
+
+ master = open ("/dev/ptmx", O_RDWR | O_NOCTTY);
+ if (master == -1)
+ {
+ print_sys_errmsg ("/dev/ptmx", errno);
+ _exit (1);
+ }
+
+ res = asprintf (&pty_fd, "%d", master);
+ if (res < 0)
+ error ("Can't allocate memory for starting the terminal emulator.\n");
+
+ /* FIXME: check if SIGCHLD must be unset before call. */
+ res = grantpt (master);
+ if (res < 0)
+ error ("Error setting up terminal emulator: grantpt: %s",
+ safe_strerror (errno));
+
+ res = unlockpt (master);
+ if (res < 0)
+ error ("Error setting up terminal emulator: unlockpt: %s",
+ safe_strerror (errno));
+
+ /* FIXME: change to point to more permanent string? */
+ inferior_thisrun_terminal = ptsname (master);
+
+#if defined (CANT_FORK) || (!defined (HAVE_WORKING_VFORK) && \
+ !defined (HAVE_WORKING_FORK))
+ /* FIXME: provide alternative to CANT_FORK case. */
+ internal_error (__FILE__, __LINE__, "Can't fork out terminal emulator.");
+#else
+ /* fire up the terminal emulator */
+ if (vfork () == 0)
+ {
+ execlp ("urxvt", "urxvt", "--hold", "-pty-fd", pty_fd, (char *) NULL);
+
+ _exit (EXIT_FAILURE);
+ }
+#endif /* CANT_FORK etc. */
+
+ free (pty_fd);
+
+ sleep (5);
+ }
+ else
+ /* Save the name for later, for determining whether we and the child
+ are sharing a tty. */
+ inferior_thisrun_terminal = ttyname;
}
void