Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* RE: Sending signal to inferior
@ 2006-01-03 13:11 Sanborn, Ed
  2006-01-03 22:54 ` Jim Blandy
  0 siblings, 1 reply; 12+ messages in thread
From: Sanborn, Ed @ 2006-01-03 13:11 UTC (permalink / raw)
  To: gdb

 Please delete me from this list.

-----Original Message-----
From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On
Behalf Of Bob Rossi
Sent: Friday, December 30, 2005 5:58 PM
To: Carlos Eduardo Rodrigues de Almeida; gdb@sources.redhat.com
Subject: Re: Sending signal to inferior

On Fri, Dec 30, 2005 at 11:48:02AM -0500, Daniel Jacobowitz wrote:
> On Fri, Dec 30, 2005 at 11:43:00AM -0500, Bob Rossi wrote:
> > On Fri, Dec 30, 2005 at 04:57:38AM +0000, Carlos Eduardo Rodrigues
de Almeida wrote:
> > > Thank you.. I'm trying to solve this for days..
> > 
> > Wow, that took me a long time to figure out, and I wrote libtgdb.
> > 
> > It's the tty command that is allowing libtgdb to interrupt GDB when 
> > the inferior is running. Apparently, if you don't move the 
> > inferior's terminal via the GDB tty command, then you can't 
> > interrupt the inferior when it's running.
> > 
> > Basically, I'm assuming that the SIGINT to GDB is ignored if the 
> > inferior has control of the terminal. However, if you put the 
> > inferior on a different terminal, then GDB must handle the SIGINT. 
> > This explanation is just a guess though.
> 
> It shouldn't be.  Check whether GDB is reaching handle_sigint() and 
> whether it is going through the event loop properly?

This is a tough one. For some reason, if I start debugging GDB, it
doesn't reach the handle_sigint line. However, with fprintf there, I'm
seeing output. Could I be doing something wrong or is this expected?

I configured && compiled like this:
  cvs -d ':ext:bobbybrasko@sources.redhat.com:/cvs/src' co gdb
  CFLAGS=-g ../src/configure
  make

I was wondering if any of the -W compile options stop me from debuging
GDB in this case.

Thanks,
Bob Rossi



^ permalink raw reply	[flat|nested] 12+ messages in thread
* Sending signal to inferior
@ 2005-12-30  3:37 Carlos Eduardo Rodrigues de Almeida
  2005-12-30  4:11 ` Bob Rossi
  0 siblings, 1 reply; 12+ messages in thread
From: Carlos Eduardo Rodrigues de Almeida @ 2005-12-30  3:37 UTC (permalink / raw)
  To: gdb

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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>


#include <termio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>


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[] = "file /home/eduardo/lab3/Debug/lab3\n";
char cmd2[] = "run\n";
char cmd3[] = "quit\n";
char cmd4[] = "\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) != 0) || (pipe(stdout_pipe) != 0) ||
pipe(stderr_pipe) != 0) {
    printf("Error creating pipes");
    exit(1);
  }

  fork_status = fork();

  if(fork_status == -1){
    printf("Error forking");
    exit(1);
  }
  /* Chield process */
  else if(fork_status == 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 = (0 > stdout_pipe[0]) ? 0 : stdout_pipe[0];
    max = (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 = select(max + 1, &rdSet, NULL, NULL, NULL);

      if(selectRet == -1)
	return;

      if(FD_ISSET(0, &rdSet)) {
	nRead = read(0, buf, 2048);
	write(stdin_pipe[1], buf, nRead);
      }

      if(FD_ISSET(stdout_pipe[0], &rdSet)) {
	nRead = read(stdout_pipe[0], buf, 2048);
	if(nRead == 0)
	  return;
	write(1, buf, nRead);
      }

      if(FD_ISSET(stderr_pipe[0], &rdSet)) {
	nRead = read(stderr_pipe[0], buf, 2048);
	if(nRead == 0)
	  return;

	write(2, buf, nRead);
      }
    }
  }
}


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2006-01-03 22:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-03 13:11 Sending signal to inferior Sanborn, Ed
2006-01-03 22:54 ` Jim Blandy
  -- strict thread matches above, loose matches on Subject: below --
2005-12-30  3:37 Carlos Eduardo Rodrigues de Almeida
2005-12-30  4:11 ` Bob Rossi
2005-12-30  4:29   ` Carlos Eduardo Rodrigues de Almeida
2005-12-30  4:42     ` Bob Rossi
2005-12-30  4:57       ` Carlos Eduardo Rodrigues de Almeida
2005-12-30 16:43         ` Bob Rossi
2005-12-30 16:48           ` Daniel Jacobowitz
2005-12-30 17:04             ` Bob Rossi
2005-12-30 22:58             ` Bob Rossi
2005-12-30 23:14               ` Bob Rossi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox