Subject: 23.1.91; Nextstep port: M-x gdb hangs in tab completion of symbols
From: Steve Revilak <[email-masked]>
To: [email-masked]
Date: Sun, 17 Jan 2010 09:25:34 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

This bug report will be sent to the Free Software Foundation,
not to your local site managers!
Please write in English if possible, because the Emacs maintainers
usually do not have translators to read other languages for them.

Your bug report will be posted to the [email-masked] mailing list,
and to the gnu.emacs.bug news group.

Please describe exactly what actions triggered the bug
and the precise symptoms of the bug.  If you can, give
a recipe starting from `emacs -Q':

I'd like to report a problem with M-x gdb in the Nextstep port of
emacs 23.1.91.  When gud mode is started with M-x gdb, tab completion
of symbols (i.e., gud-gdb-complete-command) causes emacs to hang.

The release announcement for emacs 23.1.91 noted a major change in M-x
gdb (<http://lists.gnu.org/archive/html/emacs-devel/2009-12/msg01109.html>)
and this seems to be new behavior in 23.1.91.

Steps To Reproduce
------------------

  1) Start with foo.c

---------------------------------
#include <stdio.h>

static int add_one(int x) {
   return (x + 1);
}

int main(void) {
   int y = add_one(3);
   printf("%d\n", y);
   return 0;
}
---------------------------------

  2) Compile foo.c

     $ make CFLAGS="-g -Wall" foo  
     cc -g -Wall    foo.c   -o foo

  3) Start emacs with the command line

     /Applications/Emacs.app/Contents/MacOS/Emacs -Q -nw foo.c

     Above, "-nw" isn't necessary for reproducing this behavior.  -nw
     just makes it easier to capture what emacs is displaying.

  4) Type M-x gdb RET

     Emacs responds with "Run gdb (like this): gdb --annotate=3 foo".

     Press RET to accept the gdb command line.

  5) Emacs creates a *gud-foo* buffer, whose initial contents are

---------------------------------
Current directory is ~/
GNU gdb 6.3.50-20050815 (Apple version gdb-696) (Sat Oct 20 18:20:28 GMT 2007)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc-apple-darwin"...
warning: --arch option not supported in this gdb.
Reading symbols for shared libraries .. done
(gdb) 
---------------------------------

  6) At the (gdb) prompt, type "b add_", then TAB

  7) After pressing TAB, emacs becomes unresponsive.

     Emacs stays unresponsive until Ctrl-G is pressed.

Observations from edebug
------------------------

I've used M-x edebug-defun to instrument different functions in
gud.el, so that I could step through them with emacs debugger.  

Emacs seems to hang when evaluating the expression

   (get-buffer-process gud-comint-buffer)

in line 981 of gud.el.  This line is part of defun
gud-gdb-run-command-fetch-lines.

Observations from gdb
---------------------

While emacs was hung (i.e., after completing step 7, above), I
attached a debugger to emacs.  Here is a backtrace:

(0:0)spud:srevilak$ gdb /Applications/Emacs.app/Contents/MacOS/Emacs
GNU gdb 6.3.50-20050815 (Apple version gdb-696) (Sat Oct 20 18:20:28 GMT 2007)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc-apple-darwin"...
warning: --arch option not supported in this gdb.
Reading symbols for shared libraries .... done

(gdb) attach 606
Attaching to program: `/Applications/Emacs.app/Contents/MacOS/Emacs', process 606.
Reading symbols for shared libraries ................................................................... done
0x9001f488 in select ()
(gdb) info threads
* 1 process 606 thread 0xd03  0x9001f488 in select ()

(gdb) bt
#0  0x9001f488 in select ()
#1  0x0015a2d8 in wait_reading_process_output (time_limit=0, microsecs=0, read_kbd=0, do_display=0, wait_for_cell=41944074, wait_proc=0xa8f320, just_wait_proc=0) at process.c:4941
#2  0x0015c00c in Faccept_process_output (process=11072293, seconds=4, millisec=-1073750304, just_this_one=41944074) at process.c:4323
#3  0x00112eac in Ffuncall (nargs=4, args=0xbfffe250) at eval.c:3025
#4  0x001505bc in Fbyte_code (bytestr=48, vector=-1073749248, maxdepth=40) at bytecode.c:679
#5  0x00112a5c in funcall_lambda (fun=10653413, nargs=3, arg_vector=0xbfffe504) at eval.c:3202
#6  0x00112ffc in Ffuncall (nargs=4, args=0x48c17ca) at eval.c:3072
#7  0x001505bc in Fbyte_code (bytestr=48, vector=-1073748736, maxdepth=20) at bytecode.c:679
#8  0x00112a5c in funcall_lambda (fun=10652229, nargs=0, arg_vector=0xbfffe72c) at eval.c:3202
#9  0x00112ffc in Ffuncall (nargs=4, args=0x48c176a) at eval.c:3072
#10 0x00113b90 in apply1 (fn=76289898, arg=3906012) at eval.c:2756
#11 0x0010ddbc in Fcall_interactively (function=76289898, record_flag=41944074, keys=22028253) at callint.c:396
#12 0x00112e88 in Ffuncall (nargs=4, args=0xbfffe91c) at eval.c:3021
#13 0x00113188 in call3 (fn=4, arg1=-1073750304, arg2=0, arg3=0) at eval.c:2841
#14 0x000ab524 in command_loop_1 () at keyboard.c:1904
#15 0x0010ff68 in internal_condition_case (bfun=0xaa160 <command_loop_1>, handlers=41978570, hfun=0xa1fd0 <cmd_error>) at eval.c:1490
#16 0x0009a8a0 in command_loop_2 () at keyboard.c:1360
#17 0x0010fdf0 in internal_catch (tag=4, func=0x9a860 <command_loop_2>, arg=41944074) at eval.c:1226
#18 0x0009a550 in command_loop () at keyboard.c:1339
#19 0x0009a678 in recursive_edit_1 () at keyboard.c:954
#20 0x0009a804 in Frecursive_edit () at keyboard.c:1016
#21 0x00099e44 in main (argc=400, argv=0xbffff560) at emacs.c:1833

(gdb) up 1
#1  0x0015a2d8 in wait_reading_process_output (time_limit=0, microsecs=0, read_kbd=0, do_display=0, wait_for_cell=41944074, wait_proc=0xa8f320, just_wait_proc=0) at process.c:4941
4941              nfds = ns_select
(gdb) info locals
timeout_reduced_for_timers = 0
channel = 22035053
nfds = 0
Available = {
   fds_bits = {64, 0 <repeats 31 times>}
}
Connecting = {
   fds_bits = {0 <repeats 32 times>}
}
check_connect = 0
check_delay = 0
no_avail = 0
xerrno = 0
proc = -1
timeout = {
   tv_sec = 100000, 
   tv_usec = 0
}
end_time = {
   tv_sec = 1462952, 
   tv_usec = 3680068
}
wait_channel = 6
got_some_input = 0
count = 17
(gdb) l
4936                }
4937    #endif
4938    #if defined (USE_GTK) || defined (HAVE_GCONF)
4939              nfds = xg_select
4940    #elif defined (HAVE_NS)
4941              nfds = ns_select
4942    #else
4943              nfds = select
4944    #endif
4945                            (max (max (max_process_desc, max_keyboard_desc),
(gdb)

Systems where this behavior occurs
----------------------------------

I've observed this behavior on two systems

  (a) Mac OS X 10.4.11

      GNU Emacs 23.1.91.2 (powerpc-apple-darwin8.11.0, NS apple-appkit-824.48) 
      of 2010-01-13

$ gdb --version
GNU gdb 6.3.50-20050815 (Apple version gdb-696) (Sat Oct 20 18:20:28 GMT 2007)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc-apple-darwin".

$ gcc --version
powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5370)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  (b) Mac OS X 10.6.2

      GNU Emacs 23.1.91.2 (x86_64-apple-darwin10.2.0, NS apple-appkit-1038.25) 
      of 2010-01-11

$ gdb --version
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".

$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646) (dot 1)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

                                 * * *

If Emacs crashed, and you have the Emacs process in the gdb debugger,
please include the output from the following gdb commands:
     `bt full' and `xbacktrace'.
For information about debugging Emacs, please read the file
/Applications/Emacs.app/Contents/Resources/etc/DEBUG.

In GNU Emacs 23.1.91.2 (powerpc-apple-darwin8.11.0, NS apple-appkit-824.48)
  of 2010-01-13 on spud.local
Windowing system distributor `Apple', version 10.3.824
configured using `configure  '--with-ns''

Important settings:
   value of $LC_ALL: nil
   value of $LC_COLLATE: C
   value of $LC_CTYPE: nil
   value of $LC_MESSAGES: nil
   value of $LC_MONETARY: nil
   value of $LC_NUMERIC: nil
   value of $LC_TIME: nil
   value of $LANG: en_US.UTF-8
   value of $XMODIFIERS: nil
   locale-coding-system: utf-8-unix
   default enable-multibyte-characters: t

Major mode: Debugger

Minor modes in effect:
   shell-dirtrack-mode: t
   display-time-mode: t
   tooltip-mode: t
   mouse-wheel-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   global-auto-composition-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   column-number-mode: t
   line-number-mode: t

Recent input:
<left> <return> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <up> <up> 
<up> <right> <right> <right> <right> <left> <right> 
M-x <up> <up> C-g C-g C-h f <return> C-x o <down> <right> 
<return> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> M-x e d b u 
<tab> <backspace> <backspace> e <tab> d e <tab> <return> 
C-x b <return> b _ <backspace> SPC a d d <tab> SPC 
SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC 
SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC 
SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC C-g C-x 
o C-g C-g C-g <return> <return> C-g C-g <return> C-x 
b C-g C-g C-x C-b C-x k <return> M-x g d b <return> 
<return> b SPC a d d _ <tab> SPC C-x o C-g C-x o q 
<return> b <backspace> n <return> b SPC a d d _ <tab> 
SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC 
SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC 
SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC C-g 
<left> <left> <left> <left> <left> <left> <left> <left> 
<left> <left> <left> <left> <left> <left> <left> <left> 
<left> <left> <left> <left> <left> <left> <left> <left> 
<left> <left> <left> <left> <left> <left> <left> <left> 
<left> <left> <left> <left> <left> C-x o C-g C-g M-x 
r e p o r t - e m <tab> <return>

Recent messages:

Result: nil
  [2 times]
Result: t
  [3 times]
Result: #<buffer *gud-foo*>

Result: #<process gud-foo>

Quit [3 times]
Quit

Load-path shadows:
None found.

Features:
(shadow sort mail-extr message ecomplete rfc822 mml mml-sec
password-cache mm-decode mm-bodies mm-encode mailcap mail-parse rfc2231
rfc2047 rfc2045 qp ietf-drums mailabbrev nnheader gnus-util netrc
time-date mm-util mail-prsvr gmm-utils wid-edit mailheader canlock sha1
hex-util hashcash mail-utils emacsbug debug mule-util edebug jka-compr
find-func help-mode view log-edit pcvs-util add-log gdb-ui byte-opt
bytecomp byte-compile advice help-fns advice-preload bindat json gud
ansi-color cc-mode cc-fonts cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs multi-isearch skeleton reftex-parse reftex-ref
vc vc-dispatcher supercite easy-mmode sendmail regi reftex-vcr
reftex-dcr reftex reftex-vars tex-mode shell latexenc vc-rcs conf-mode
newcomment grep compile comint ring dired bbdb-autoloads bbdb regexp-opt
timezone server paren time tooltip ediff-hook vc-hooks lisp-float-type
mwheel ns-win easymenu tool-bar dnd fontset image fringe lisp-mode
register page menu-bar rfn-eshadow timer select scroll-bar mldrag mouse
jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
loaddefs button minibuffer faces cus-face files text-properties overlay
md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process ns multi-tty
emacs)