From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 111513858C83; Sun, 27 Mar 2022 09:48:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 111513858C83 From: "eliz at gnu dot org" To: gdb-prs@sourceware.org Subject: [Bug mi/29002] Console input broken in MI mode Date: Sun, 27 Mar 2022 09:48:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: mi X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: eliz at gnu dot org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: 12.1 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Mar 2022 09:48:45 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29002 --- Comment #3 from Eli Zaretskii --- But this is not the whole story. That commit also causes the Emacs gdb-mi front-end to GDB to become broken, at least on MS-Windows. What happens is that gdb-mi sends, via the GDB/MI interface, several comman= ds in a sequence when the debugging session begins. Those commands are: 1-gdb-set new-console off 2-gdb-set interactive-mode on 3-gdb-set height 0 4-enable-pretty-printing 5-enable-frame-filters 6-file-list-exec-source-file 7-gdb-show prompt 8-stack-info-frame 9-thread-info 10-break-list 11-thread-info 12-break-list But when GDB responds to those commands, some of the responses have the fir= st character of the TOKEN part stripped. Here's what Emacs receives in respon= se (this is a single string sent to Emacs in one go): 1^done (gdb)=20 2^done (gdb)=20 3^done (gdb)=20 ^done (gdb)=20 5^done (gdb)=20 ^done,line=3D\"1189\",file=3D\"emacs.c\",fullname=3D\"d:\\\\gnu\\\\git\\\\e= macs\\\\branch\\\\src\\\\emacs.c\",macro-info=3D\"1\" (gdb)=20 7^done,value=3D\"(gdb) \" (gdb)=20 8^error,msg=3D\"No registers.\" (gdb)=20 ^done,threads=3D[] (gdb)=20 0^done,BreakpointTable=3D{nr_rows=3D\"1\",nr_cols=3D\"6\",hdr=3D[{width=3D\= "7\",alignment=3D\"-1\",col_name=3D\"number\",colhdr=3D\"Num\"},{width=3D\"= 14\",alignment=3D\"-1\",col_name=3D\"type\",colhdr=3D\"Type\"},{width=3D\"4= \",alignment=3D\"-1\",col_name=3D\"disp\",colhdr=3D\"Disp\"},{width=3D\"3\"= ,alignment=3D\"-1\",col_name=3D\"enabled\",colhdr=3D\"Enb\"},{width=3D\"10\= ",alignment=3D\"-1\",col_name=3D\"addr\",colhdr=3D\"Address\"},{width=3D\"4= 0\",alignment=3D\"2\",col_name=3D\"what\",colhdr=3D\"What\"}],body=3D[bkpt= =3D{number=3D\"1\",type=3D\"breakpoint\",disp=3D\"keep\",enabled=3D\"y\",ad= dr=3D\"0x0115dc0c\",func=3D\"terminate_due_to_signal\",file=3D\"emacs.c\",f= ullname=3D\"d:\\\\gnu\\\\git\\\\emacs\\\\branch\\\\src\\\\emacs.c\",line=3D= \"400\",thread-groups=3D[\"i1\"],times=3D\"0\",original-location=3D\"termin= ate_due_to_signal\"}]} (gdb)=20 1^done,threads=3D[] (gdb)=20 12^done,BreakpointTable=3D{nr_rows=3D\"1\",nr_cols=3D\"6\",hdr=3D[{width=3D= \"7\",alignment=3D\"-1\",col_name=3D\"number\",colhdr=3D\"Num\"},{width=3D\= "14\",alignment=3D\"-1\",col_name=3D\"type\",colhdr=3D\"Type\"},{width=3D\"= 4\",alignment=3D\"-1\",col_name=3D\"disp\",colhdr=3D\"Disp\"},{width=3D\"3\= ",alignment=3D\"-1\",col_name=3D\"enabled\",colhdr=3D\"Enb\"},{width=3D\"10= \",alignment=3D\"-1\",col_name=3D\"addr\",colhdr=3D\"Address\"},{width=3D\"= 40\",alignment=3D\"2\",col_name=3D\"what\",colhdr=3D\"What\"}],body=3D[bkpt= =3D{number=3D\"1\",type=3D\"breakpoint\",disp=3D\"keep\",enabled=3D\"y\",ad= dr=3D\"0x0115dc0c\",func=3D\"terminate_due_to_signal\",file=3D\"emacs.c\",f= ullname=3D\"d:\\\\gnu\\\\git\\\\emacs\\\\branch\\\\src\\\\emacs.c\",line=3D= \"400\",thread-groups=3D[\"i1\"],times=3D\"0\",original-location=3D\"termin= ate_due_to_signal\"}]} Note that responses to 4, 6, and 9 don't have the TOKEN part, and responses= to 10 and 11 have the first digit, 1, removed from TOKEN, so they appear as if= the TOKEN were 0 (which is invalid) and 1 (which was already received, and so is not expected at this time). It turns out that restoring the "done_once" part of the offending commit fi= xes this problem as well. I'm guessing that the repeated calls to `setbuf` cau= se those characters to be lost, perhaps because `setbuf` flushes the stream, w= hich for an input stream means it empties the buffer. And we do call `setbuf` in this scenario, because interaction between Emacs and GDB in this case is via pipes. In general, AFAIK the C standard allows to call `setvbuf` (and thus `setbuf= `) only once, before any I/O operation was done for a given stream. But after= the commit mentioned above, we call `setbuf` multiple times. So the proposed patch now changes to an almost full revert of the offending commit, see the attachment. --=20 You are receiving this mail because: You are on the CC list for the bug.=