[ale] OT: Sending Commands to GDB
Michael Potter
michael at potter.name
Thu Jan 20 11:30:02 EST 2011
Here is how I was determining that gdb was terminating immediately
after the stat on the named pipe:
strace gdb -batch -x <(/bin/echo pwd) /bin/true
By way <(cmd) syntax leaves a named pipe laying around in your /tmp directory.
strace dumps out the system calls that happened while gdb was running.
--
Michael Potter
On Thu, Jan 20, 2011 at 9:10 AM, Ed Cashin <ecashin at noserose.net> wrote:
>
> Sometimes it's easier to use "expect" than to figure out
> what's going wrong.
>
> On Wed, Jan 19, 2011 at 11:51 AM, Brian Pitts <brian at polibyte.com> wrote:
> > On 01/19/2011 09:25 AM, Tim Watts wrote:
> >> More progress. Try this:
> >>
> >> #!/bin/bash
> >> sleep 0.5
> >> cat
> >> echo quit
> >> sleep 0.5
> >>
> >> and this:
> >>
> >> $ echo pwd |./gdbin|gdb /bin/true
> >
> > This is interesting Tim, thanks for your help. You too Michael. You put
> > me on the write track to play around with Python's subprocess module.
> > The communicate() method
> >
> > 1. (optionally) sends data to stdin
> > 2. reads data from stdout and stderr, until end-of-file is reached.
> > 3. Waits for process to terminate.
> >
> > g = subprocess.Popen('gdb /bin/true', shell=True, stdin=subprocess.PIPE,
> > stdout=subprocess.PIPE)
> >
> > g.communicate('pwd\n')
> >
> > Not surprisingly based on our experiences, the pwd command was not
> > executed. The only output after the missing debuginfo warnings is
> >
> > (gdb) Hangup detected on fd 0\nerror detected on stdin\n
> >
> > But what if I write to stdin before calling communicate?
> >
> > g = subprocess.Popen('gdb /bin/true', shell=True, stdin=subprocess.PIPE,
> > stdout=subprocess.PIPE)
> >
> > g.stdin.write('pwd\n')
> >
> > g.communicate()
> >
> > Like your experiments suggested, this works. The last of the output is
> >
> > (gdb) Working directory /home/brian.\n(gdb) Hangup detected on fd
> > 0\nerror detected on stdin\n
> >
> > If I throw in a
> >
> > g.stdin.write('quit\n')
> >
> > I can avoid the final hangup and error messages.
> >
> >> [BTW, how is this OT?]
> >
> > I don't remember why I thought the post would be OT when I started
> > writing it last night. It didn't end up that way.
> >
> > --
> > All the best,
> > Brian Pitts
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://mail.ale.org/mailman/listinfo/ale
> > See JOBS, ANNOUNCE and SCHOOLS lists at
> > http://mail.ale.org/mailman/listinfo
> >
>
>
>
> --
> Ed Cashin <ecashin at noserose.net>
> http://noserose.net/e/
> http://www.coraid.com/
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
More information about the Ale
mailing list