From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10155 invoked by alias); 30 Dec 2005 03:37:03 -0000 Received: (qmail 10147 invoked by uid 22791); 30 Dec 2005 03:37:03 -0000 X-Spam-Check-By: sourceware.org Received: from zproxy.gmail.com (HELO zproxy.gmail.com) (64.233.162.204) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 30 Dec 2005 03:37:02 +0000 Received: by zproxy.gmail.com with SMTP id 40so1810064nzk for ; Thu, 29 Dec 2005 19:37:00 -0800 (PST) Received: by 10.65.148.3 with SMTP id a3mr1723308qbo; Thu, 29 Dec 2005 19:37:00 -0800 (PST) Received: by 10.65.222.12 with HTTP; Thu, 29 Dec 2005 19:37:00 -0800 (PST) Message-ID: <214135380512291937q58cd9ebajc40590fdc3936be4@mail.gmail.com> Date: Fri, 30 Dec 2005 03:37:00 -0000 From: Carlos Eduardo Rodrigues de Almeida To: gdb@sources.redhat.com Subject: Sending signal to inferior MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2005-12/txt/msg00212.txt.bz2 Hi all, I'm trying to write a front-end to GDB. For the first experiment I wrote a small program just to control gdb.. The program is at the end of the message I run some program and I can't stop it sending a SIGINT to GDB if I kill -2 GDBPID nothing happens the only way to stop the inferior is to ps, get its pid and kill -2 INFERIORPID someone had this problem in the list but I couldn't find the solution.. someone pointed to tgdb http://cgdb.sourceforge.net/ I noticed something: tgdb has a tgdb_driver that is exactly what I'm trying to do but using tgdb.. a little program that controls gdb.. Running some program with tgdb_driver I get 3 process: tgdb_driver gdb (created by tgdb_driver) inferior (created by gdb) if I send a SIGINT to gdb it stops the inferior. with my program I get: echo gdb inferior if I send a SIGINT to gdb, it DOES not stop the inferior... I looked at the source code and it mentions the setsid() funcition: /* If this is not called, when user types ^c SIGINT gets sent to gdb */ setsid(); but if I comment out this line it keeps working... I couldn't find what tgdb does to stop the inferior when I send gdb the SIGINT.. does someone can point me a solution? Thank you! Eduardo The program I wrote: #include #include #include #include #include #include #include #include #include #include typedef struct _ARG { int fd_read; int fd_write; }ARG; char buf[2048]; int nRead; int treatfd(void *arg); int treatSTDIN(void *arg); pid_t fork_status; char cmd1[] =3D "file /home/eduardo/lab3/Debug/lab3\n"; char cmd2[] =3D "run\n"; char cmd3[] =3D "quit\n"; char cmd4[] =3D "\002"; int main(void) { int stdin_pipe[2], stdout_pipe[2], stderr_pipe[2]; pthread_t tstdin, tstdout, tstderr; ARG argstdin, argstdout, argstderr; struct termio Termio; int bwritten; if( (pipe(stdin_pipe) !=3D 0) || (pipe(stdout_pipe) !=3D 0) || pipe(stderr_pipe) !=3D 0) { printf("Error creating pipes"); exit(1); } fork_status =3D fork(); if(fork_status =3D=3D -1){ printf("Error forking"); exit(1); } /* Chield process */ else if(fork_status =3D=3D 0) { setsid(); close(0); dup(stdin_pipe[0]); close(stdin_pipe[0]); close(stdin_pipe[1]); close(1); dup(stdout_pipe[1]); close(stdout_pipe[0]); close(stdout_pipe[1]); close(2); dup(stderr_pipe[1]); close(stderr_pipe[0]); close(stderr_pipe[1]); // printf("executando gdb"); execlp("gdb", "gdb", (char *)0); // printf("Error with execl"); exit(1); } /* Parent process */ else { close(stdin_pipe[0]); close(stdout_pipe[1]); close(stderr_pipe[1]); fd_set rdSet; int max; int selectRet; max =3D (0 > stdout_pipe[0]) ? 0 : stdout_pipe[0]; max =3D (max > stderr_pipe[0]) ? max : stderr_pipe[0]; while(1) { FD_ZERO(&rdSet); FD_SET(0, &rdSet); FD_SET(stdout_pipe[0], &rdSet); FD_SET(stderr_pipe[0], &rdSet); selectRet =3D select(max + 1, &rdSet, NULL, NULL, NULL); if(selectRet =3D=3D -1) return; if(FD_ISSET(0, &rdSet)) { nRead =3D read(0, buf, 2048); write(stdin_pipe[1], buf, nRead); } if(FD_ISSET(stdout_pipe[0], &rdSet)) { nRead =3D read(stdout_pipe[0], buf, 2048); if(nRead =3D=3D 0) return; write(1, buf, nRead); } if(FD_ISSET(stderr_pipe[0], &rdSet)) { nRead =3D read(stderr_pipe[0], buf, 2048); if(nRead =3D=3D 0) return; write(2, buf, nRead); } } } }