This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: printfs output in wrong order in MI
- From: Eli Zaretskii <eliz at gnu dot org>
- To: Vladimir Prus <ghost at cs dot msu dot su>
- Cc: gdb at sources dot redhat dot com
- Date: Thu, 13 Apr 2006 10:55:35 +0300
- Subject: Re: printfs output in wrong order in MI
- References: <e1j893$lse$1@sea.gmane.org> <e1kt1v$ssc$1@sea.gmane.org>
- Reply-to: Eli Zaretskii <eliz at gnu dot org>
> From: Vladimir Prus <ghost@cs.msu.su>
> Date: Thu, 13 Apr 2006 11:02:23 +0400
>
> Vladimir Prus wrote:
>
> >
> > Hi,
> > I'm seing strange behaviour of the "printf" command if used in MI:
> >
> > (gdb)
> > print &i
> > &"print &i\n"
> > ~"$1 = (int *) 0xbfc5f484\n"
> > ^done
> > (gdb)
> > printf "%x", &i
> > &"printf \"%x\", &i\n"
> > ^done
> > (gdb)
> > ~"bfc5f484"
> > -interpreter-exec console "printf \"%x\", &i"
> > ^done
> > (gdb)
> > ~"bfc5f484"
> >
> > The output of 'print' appears before "^done", but the output of "printf"
> > appears *after* both "^done", and the prompt, which makes it impossible to
> > reliably catch the output.
> ....
> > Any ideas why "printf" is so special?
>
> I turns out that using
>
> printf "%x\n", &i
>
> (that is, adding "\n"), fixes the problem. Still looks like a bug to me,
> though.
I think it's expected behavior: printf uses buffered output, so if you
don't finish the line with a newline, the buffer is not flushed.
Similar ``bugs'' can be seen in any C program that displays characters
via printf without \n or fflush.