Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Carlos Eduardo Rodrigues de Almeida <eduardo.almeida@gmail.com>
To: gdb@sources.redhat.com
Subject: Sending signal to inferior
Date: Fri, 30 Dec 2005 03:37:00 -0000	[thread overview]
Message-ID: <214135380512291937q58cd9ebajc40590fdc3936be4@mail.gmail.com> (raw)

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);
      }
    }
  }
}


             reply	other threads:[~2005-12-30  3:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-30  3:37 Carlos Eduardo Rodrigues de Almeida [this message]
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
2006-01-03 13:11 Sanborn, Ed
2006-01-03 22:54 ` Jim Blandy

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=214135380512291937q58cd9ebajc40590fdc3936be4@mail.gmail.com \
    --to=eduardo.almeida@gmail.com \
    --cc=gdb@sources.redhat.com \
    /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