Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: gdb-patches ml <gdb-patches@sourceware.org>
Subject: [RFC] patch to make GDB open a new terminal window for the inferior
Date: Wed, 20 May 2009 00:18:00 -0000	[thread overview]
Message-ID: <1242778681.6232.19.camel@hactar> (raw)

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



             reply	other threads:[~2009-05-20  0:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-20  0:18 Thiago Jung Bauermann [this message]
2009-05-20 17:48 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1242778681.6232.19.camel@hactar \
    --to=bauerman@br.ibm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox