From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12042 invoked by alias); 13 Apr 2006 07:55:35 -0000 Received: (qmail 12033 invoked by uid 22791); 13 Apr 2006 07:55:34 -0000 X-Spam-Check-By: sourceware.org Received: from romy.inter.net.il (HELO romy.inter.net.il) (192.114.186.66) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 13 Apr 2006 07:55:33 +0000 Received: from HOME-C4E4A596F7 (IGLD-83-130-205-75.inter.net.il [83.130.205.75]) by romy.inter.net.il (MOS 3.7.3-GA) with ESMTP id DYZ36997 (AUTH halo1); Thu, 13 Apr 2006 10:55:28 +0300 (IDT) Date: Thu, 13 Apr 2006 08:10:00 -0000 Message-Id: From: Eli Zaretskii To: Vladimir Prus CC: gdb@sources.redhat.com In-reply-to: (message from Vladimir Prus on Thu, 13 Apr 2006 11:02:23 +0400) Subject: Re: printfs output in wrong order in MI Reply-to: Eli Zaretskii References: X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2006-04/txt/msg00151.txt.bz2 > From: Vladimir Prus > 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.