This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Open file descriptors before running gdb


Hi there.  I have what is hopefully a quick question about how gdb handles
file descriptors.  Normally, when you fork / exec a process, any open file
descriptors are inherited by the child process.  This works fine normally,
but when we try to fork and exec gdb, the file descriptors that should have
been inherited in the program we're debugging can't be written to.  I
hunted through the docs but maybe not hard enough since I didn't find an
answer as to how gdb handles file descriptors in the manner.  One note is
that we're getting an EBADF errno (errno = 9) from the 'write' command
which is trying to tell us we have a bad file descriptor when our program
is under gdb (which was exec'd from our main program that opened the file
descriptor).

Any tips or leads to some documentation would be greatly appreciated!!

Example:

//  **** This works ****
// program 1
main()
{
    open file descriptor
    fork process
    in child process, call execvp(program 2)
}

// program 2
main()
{
    Successfully writes to file descriptor opened in program 1
}



// **** This doesn't work ****
// program 1
main()
{
    open file descriptor
    fork process
    in child process, call execvp(gdb program 2)
}

// program 2
main()
{
    Fails to write to file descriptor opened in program 1 when under gdb
}


Thanx for any time you have!

****************************************
Brian Preston - bpreston@us.ibm.com

- Sanity is the playground for the unimaginative



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]