Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Pipe question
@ 2002-12-04  5:39 a2782
  2002-12-04  8:18 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: a2782 @ 2002-12-04  5:39 UTC (permalink / raw)
  To: gdb

Hi to all!

First, I want to thank Eli Zaretskii, Jim Blandy, Kris Warkentin, Keith 
Seitz and Joel Brobecker for their advices about communication with GDB.

Now, a question. I\'m doing this:

    pipe(togdb); pipe(fromgdb);
    if (fork() != 0)
    {
        close(togdb[0]);
        close(fromgdb[1]);
    }
    else
    {
        /* This is necessary for my GUI */
        int Max = sysconf(_SC_OPEN_MAX);
        for (int i=STDERR_FILENO+1;i<Max;i++)
            fcntl(i, F_SETFD, FD_CLOEXEC);

        close(togdb[1]);
        dup2(togdb[0],0);
        close(fromgdb[0]);
        dup2(fromgdb[1],1);
        system(strcat(\"gdb --quiet -f \",executable));
    }

When I want to give GDB a command, I write in togdb[1]; when I want to 
parse GDB output, I read from fromgdb[0]. All is working. (Note: system
() is exec()).

But when I close the program, I only write \"quit\\n\" to togdb[1]. This 
causes that the program doesn\'t end properly (GDB, which is the child 
process, ends well). I have to go and type \"kill\" in a console. Could 
anybody tell me what instructions I have to put in the end of the 
program in order to finish it succesfully (without kill)? I suppose 
it\'s something related with the pipes...

Thanks in advance.


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

* Re: Pipe question
  2002-12-04  5:39 Pipe question a2782
@ 2002-12-04  8:18 ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2002-12-04  8:18 UTC (permalink / raw)
  To: a2782; +Cc: gdb

> Date: Wed, 4 Dec 2002 14:36:36 GMT
> From: a2782@dis.ulpgc.es
> 
>         system(strcat(\"gdb --quiet -f \",executable));

I hope this is not your actual code: you cannot strcat onto a
constant string.  It's a bug.

> But when I close the program, I only write \"quit\\n\" to togdb[1]. This 
> causes that the program doesn\'t end properly (GDB, which is the child 
> process, ends well). I have to go and type \"kill\" in a console. Could 
> anybody tell me what instructions I have to put in the end of the 
> program in order to finish it succesfully (without kill)?

When you give GDB the `quit' command, it asks whether to kill the
program being debugged; you need to respond with "yes".  So something
like "quit\nyes\n" should do the trick (but I didn't actually try
this, so I might miss something).


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

* Re: Pipe question
@ 2002-12-04  8:45 Michael Elizabeth Chastain
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Elizabeth Chastain @ 2002-12-04  8:45 UTC (permalink / raw)
  To: a2782; +Cc: gdb

Good morning,

> But when I close the program, I only write \"quit\\n\" to togdb[1]. This 
> causes that the program doesn\'t end properly (GDB, which is the child 
> process, ends well). I have to go and type \"kill\" in a console.

Try running gdb directly and starting up an inferior process (child process).
Then type "quit <CR>" on the command line and you will see what is happening:

  (gdb) quit
  The program is running.  Exit anyway? (y or n)

At this point gdb is still running and the inferior process still exists.
Your program is probably closing the pipe and killing gdb at this point
and that leaves the inferior process.

> Could anybody tell me what instructions I have to put in the end of the 
> program in order to finish it succesfully (without kill)?

Write a "y\n" down the pipe.  Then gdb will take care of killing the
inferior process.

Note that gdb will ask the question only if it has an inferior process running,
so your program has to parse gdb's output to see if it is asking the
question.  Or you may know for sure that there is always an inferior process.
Or you could just slam a "y\n" down the pipe unconditionally; if gdb does not
ask the question, it won't be alive to read the "y\n".  But that would
be crude.

Hope this helps,

Michael C


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

end of thread, other threads:[~2002-12-04 16:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-04  5:39 Pipe question a2782
2002-12-04  8:18 ` Eli Zaretskii
2002-12-04  8:45 Michael Elizabeth Chastain

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