From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11069 invoked by alias); 20 May 2009 00:18:17 -0000 Received: (qmail 11057 invoked by uid 22791); 20 May 2009 00:18:16 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from e24smtp03.br.ibm.com (HELO e24smtp03.br.ibm.com) (32.104.18.24) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 May 2009 00:18:05 +0000 Received: from mailhub3.br.ibm.com (mailhub3.br.ibm.com [9.18.232.110]) by e24smtp03.br.ibm.com (8.13.1/8.13.1) with ESMTP id n4K0H6EM031280 for ; Tue, 19 May 2009 21:17:06 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.18.232.46]) by mailhub3.br.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n4K0IRmc1953994 for ; Tue, 19 May 2009 21:18:27 -0300 Received: from d24av01.br.ibm.com (loopback [127.0.0.1]) by d24av01.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n4K0I2hV014839 for ; Tue, 19 May 2009 21:18:02 -0300 Received: from [9.8.2.226] ([9.8.2.226]) by d24av01.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n4K0I2iS014835 for ; Tue, 19 May 2009 21:18:02 -0300 Subject: [RFC] patch to make GDB open a new terminal window for the inferior From: Thiago Jung Bauermann To: gdb-patches ml Content-Type: text/plain Date: Wed, 20 May 2009 00:18:00 -0000 Message-Id: <1242778681.6232.19.camel@hactar> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-05/txt/msg00409.txt.bz2 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 * 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