From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#12163: 24.1; Can not input anything or showing none output when debugging c/c++ application. Date: Fri, 10 Aug 2012 20:57:14 +0300 Message-ID: <83628qeikl.fsf@gnu.org> References: <83obmkdoli.fsf@gnu.org> <83ehnfdzgw.fsf@gnu.org> <837gt7dqjm.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1344621473 26351 80.91.229.3 (10 Aug 2012 17:57:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Aug 2012 17:57:53 +0000 (UTC) Cc: 12163@debbugs.gnu.org To: qq510371827 Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 10 19:57:53 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SztT6-0006Ap-Ua for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Aug 2012 19:57:53 +0200 Original-Received: from localhost ([::1]:34039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SztT6-0000je-71 for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Aug 2012 13:57:52 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:35923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SztT3-0000jT-DV for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 13:57:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SztT0-0006QQ-Qj for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 13:57:49 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37787) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SztT0-0006QM-Mi for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 13:57:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Sztb0-0003U6-FW for bug-gnu-emacs@gnu.org; Fri, 10 Aug 2012 14:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Aug 2012 18:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12163 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 12163-submit@debbugs.gnu.org id=B12163.134462192813354 (code B ref 12163); Fri, 10 Aug 2012 18:06:02 +0000 Original-Received: (at 12163) by debbugs.gnu.org; 10 Aug 2012 18:05:28 +0000 Original-Received: from localhost ([127.0.0.1]:47333 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SztaS-0003TK-DM for submit@debbugs.gnu.org; Fri, 10 Aug 2012 14:05:28 -0400 Original-Received: from mtaout23.012.net.il ([80.179.55.175]:62907) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SztaP-0003TB-J9 for 12163@debbugs.gnu.org; Fri, 10 Aug 2012 14:05:27 -0400 Original-Received: from conversion-daemon.a-mtaout23.012.net.il by a-mtaout23.012.net.il (HyperSendmail v2007.08) id <0M8J00800WBBO300@a-mtaout23.012.net.il> for 12163@debbugs.gnu.org; Fri, 10 Aug 2012 20:57:07 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout23.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0M8J0089IWJ6O220@a-mtaout23.012.net.il>; Fri, 10 Aug 2012 20:57:07 +0300 (IDT) In-reply-to: X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:63016 Archived-At: > From: qq510371827 > Date: Fri, 10 Aug 2012 18:18:44 +0800 > > Ok,source code is as follows: > #include "stdio.h" > #include "ctype.h" > #include "string.h" > > void Reverse(char* p,int n) > { > if(--n > 0) Reverse(p+1,n); > printf("%c",*p); > fflush(stdout); > } > int main() > { > //setbuf(stdin,NULL); > //setbuf(stdout,NULL); > // setvbuf(stdin,NULL,_IONBF,0); > // setvbuf(stdout,NULL,_IONBF,0); > //freopen("input.txt","r",stdin); > char s[255],*p,*q; > int i=0,n; > fgets(s,255,stdin); > s[strlen(s)-1] = ' '; > p = q = s; // set breakpoint at this line. > while(*p != '\0') > { > i++; > p++; > if(isspace(*p)) > { > n = i; > i = 0; > Reverse(q,n); > q = p+1; > } > } > n = i; > Reverse(q,n); > printf("\n"); > return 0; > } > Thanks in advance. I looked into this. The problem seems to be that gdb-mi.el is confused wrt which text typed by the user to send to GDB and which to the program being debugged. Here's the session on Windows: Reading symbols from d:/usr/eli/data/rev.exe...done. (gdb) break 22 Breakpoint 1 at 0x4013ae: file rev.c, line 22. (gdb) start Temporary breakpoint 2 at 0x40136f: file rev.c, line 19. Starting program: d:/usr/eli/data/rev.exe [New Thread 2120.0x165c] Temporary breakpoint 2, main () at rev.c:19 19 int i=0,n; At this point, I see the source in another window with the arrow at line 19 and the breakpoint I set at line 22. Now: (gdb) continue Continuing. Breakpoint 1, main () at rev.c:22 22 p = q = s; // set breakpoint at this line. (gdb) print s $1 = "23-thread-info --thread 1 \000 ..." That "23-thread-info --thread 1" thing is a command sent by gdb-mi.el to GDB. But since the debbuggee is reading stdin with fgets, the command ends up in the buffer read by fgets. Which explains why the program doesn't stop when fgets is called: the call to fgets returns immediately with the above command as its input. I tried to work around this by commenting out the "-thread-info" command sent here: (defun gdb-starting (_output-field) ;; CLI commands don't emit ^running at the moment so use gdb-running too. (setq gdb-inferior-status "running") (gdb-force-mode-line-update (propertize gdb-inferior-status 'face font-lock-type-face)) (setq gdb-active-process t) (setq gud-running t) ;; GDB doesn't seem to respond to -thread-info before first stop or ;; thread exit (even in non-stop mode), so this is useless. ;; Behavior may change in the future. (gdb-emit-signal gdb-buf-publisher 'update-threads)) <<<<<<<<<<<<< Then I do get a chance to type some text when the debuggee is stuck in fgets. But what winds up in the buffer read by fgets is -interpreter-exec console "TEXT" where TEXT is what I typed. Evidently, gdb-mi thinks that what I typed is a GDB command, so it wraps it with -interpreter-exec. The above was on MS-Windows. On GNU/Linux, I see a slightly different manifestation of what seems to be the same problem: there, I cannot get the debuggee to continue after I type some text that is supposed to be read by fgets. Sounds like the input never gets to the debuggee, or maybe the debuggee's stdin is not line-buffered for some reason. In any case, the call to fgets never returns. So I no longer think this is a Windows-specific problem, and my original assertion that it has to do with different buffering on Windows seems to be incorrect. Perhaps someone who knows more about GUD and comint in general could chime in and find out what is wrong here. Or at least explain what should be done in gdb-mi to treat separately GDB commands and input to the debuggee. Evidently, the old gud-gdb way of running GDB did that correctly.