From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ryan Johnson Newsgroups: gmane.emacs.bugs Subject: bug#7117: 23.2.2 mangles terminal escape sequences Date: Thu, 30 Sep 2010 16:39:07 +0200 Message-ID: <4CA4A10B.8050201@ece.cmu.edu> References: <4CA089B5.80601@ece.cmu.edu> <4CA174DA.701@ece.cmu.edu> <4CA47684.5020806@ece.cmu.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1285857705 24763 80.91.229.12 (30 Sep 2010 14:41:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 30 Sep 2010 14:41:45 +0000 (UTC) Cc: 7117@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Sep 30 16:41:43 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1P1KKL-00086W-8D for geb-bug-gnu-emacs@m.gmane.org; Thu, 30 Sep 2010 16:41:41 +0200 Original-Received: from localhost ([127.0.0.1]:33165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P1KKK-0004y7-4m for geb-bug-gnu-emacs@m.gmane.org; Thu, 30 Sep 2010 10:41:40 -0400 Original-Received: from [140.186.70.92] (port=51893 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P1KK9-0004xz-KB for bug-gnu-emacs@gnu.org; Thu, 30 Sep 2010 10:41:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1P1KK6-00047j-Rh for bug-gnu-emacs@gnu.org; Thu, 30 Sep 2010 10:41:29 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36582) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1P1KK6-00047e-Jw for bug-gnu-emacs@gnu.org; Thu, 30 Sep 2010 10:41:26 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1P1KFq-00014F-2o; Thu, 30 Sep 2010 10:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ryan Johnson Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 30 Sep 2010 14:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 7117 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 7117-submit@debbugs.gnu.org id=B7117.12858573814093 (code B ref 7117); Thu, 30 Sep 2010 14:37:01 +0000 Original-Received: (at 7117) by debbugs.gnu.org; 30 Sep 2010 14:36:21 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1P1KFA-00013y-Td for submit@debbugs.gnu.org; Thu, 30 Sep 2010 10:36:21 -0400 Original-Received: from bache.ece.cmu.edu ([128.2.129.23]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1P1KF7-00013r-Du for 7117@debbugs.gnu.org; Thu, 30 Sep 2010 10:36:18 -0400 Original-Received: from [128.178.77.144] (diaspc12.epfl.ch [128.178.77.144]) by bache.ece.cmu.edu (Postfix) with ESMTP id 5E987192; Thu, 30 Sep 2010 10:39:09 -0400 (EDT) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 In-Reply-To: <4CA47684.5020806@ece.cmu.edu> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 30 Sep 2010 10:37:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:40574 Archived-At: On 9/30/2010 1:37 PM, Ryan Johnson wrote: > On 9/28/2010 6:53 AM, Ryan Johnson wrote: >> On 9/27/2010 10:52 PM, Stefan Monnier wrote: >>>> Steps to reproduce: >>>> 1. ssh to a machine with emacs-23 installed (I suspect slower >>>> networks would expose this more, but the bug bites me even over >>>> intranet) >>>> 2. compile tee-input.c (see below) into a shared library (on >>>> solaris: >>>> `cc -g -G -xcode=pic13 -ldl -hlibtee-input.so tee-input.c -g -o >>>> libtee-input.so') >>>> 3. invoke `LD_PRELOAD=libtee-input.so emacs -nw -Q 2>input.txt' >>>> 4. M-x xterm-mouse-mode >>>> 5. flick the mouse scroll wheel hard, so it generates many ticks in >>>> quick succession (note the garbage that results) >>>> 6. M-x show-lossage (note the mangled escape sequences) >>>> 7. C-x C-c >>>> 8. Examine input.txt (note the intact escape sequences) >>> Does (set-keyboard-coding-system 'binary) circumvent the problem? >> No. In fact, the solaris machine which I ran the example on defaults >> to `no-conversion' (an alias of binary iirc) for some reason. Sorry, >> I forgot to mention before. >> >> This matches my expectations, since bug #6920 arises before any >> coding system touches the input. > Any hints on where the problem might lurk? I poked around a little but > without luck -- the functions that power read-char are many hundreds > of lines long and seem to weave between lisp and C at regular > intervals. I'm willing to go source diving but it's a bit daunting to > wade into the C code again without a starting reference. OK, I bit the bullet and fired up a debugger. I've narrowed down the problem some. In keyboard.c, all keyboard input is buffered in kbd_buffer, which is a circular buffer with tail kbd_fetch_ptr. In all cases, when a control sequence gets mangled it's because kbd_fetch_ptr was incremented by more than one slot between iterations of the command loop (often by several dozen). However, it turns out that incrementing by more than one slot happens quite often and only sometimes exhibits the bug. More digging shows that multiple increments are due to Fdiscard_input being called with the following stack trace: =>[1] Fdiscard_input(), line 10947 in "keyboard.c" [2] cmd_error_internal(data = -1059860928, context = 0xffbfee40 ""), line 1301 in "keyboard.c" [3] cmd_error(data = -1059860928), line 1234 in "keyboard.c" [4] internal_condition_case(bfun = 0x111578 = &command_loop_1(), handlers = 1077839640, hfun = 0x109b8c = &cmd_error(register Lisp_Object data)), line 1480 in "eval.c" [5] command_loop_2(), line 1360 in "keyboard.c" [6] internal_catch(tag = 1077836792, func = 0x10283c = &command_loop_2(), arg = 1077782856), line 1226 in "eval.c" [7] command_loop(), line 1339 in "keyboard.c" [8] recursive_edit_1(), line 954 in "keyboard.c" [9] Frecursive_edit(), line 1016 in "keyboard.c" [10] main(argc = 3, argv = 0xffbff374), line 1833 in "emacs.c" At this point the symptom is easy enough to understand: sometimes discard-input gets unlucky and chops the front off of a partly-arrived escape sequence. The real question is, why would the command loop encounter errors and need to discard input at all? [1] _longjmp() =>[2] unwind_to_catch() [3] Fsignal() [4] xsignal() [5] xsignal0() [6] window_scroll() [7] scroll_command() [8] Fscroll_down() [9] Ffuncall() [10] Feval() [11] internal_lisp_condition_case() [12] Fbyte_code() [13] funcall_lambda() [14] Ffuncall() [15] Fapply() [16] apply1() [17] Fcall_interactively() [18] Ffuncall() [19] call3() [20] Fcommand_execute() [21] command_loop_1() [22] internal_condition_case() [23] command_loop_2() [24] internal_catch() [25] command_loop() [26] recursive_edit_1() [27] Frecursive_edit() [28] main() From the above, it seems that scrolling past beginning or end of buffer triggers an error, which I guess is somewhat justifiable. However, on a very slow connection this morning mouse-clicking between or even within buffers caused problems. Unfortunately, setting debug-on-error doesn't seem to catch errors generated from C code. I could try to break on longjmp over another slow connection, but with the number of times it gets called for other reasons this would be slow going... Ideas? Ryan