Subject: bug#16737: 24.3.50; Yank causes hang

From: Nicolas Richard <[email-masked]>
Date: Wed, 05 Mar 2014 12:01:06 +0100

Le 04/03/2014 17:59, Eli Zaretskii a écrit :
> Since you say that Emacs hangs for several seconds, would it be
> possible for you to attach GDB right after you type C-x C-e to eval
> (x-get-selection)?  You could prepare the "gdb -p PID" command line in
> the shell window in advance, so all you'd need to type is RET.

I didn't quite do that and unfortunately killed the process at the end,
so can't try your suggestion anymore. FWIW, here's what I did, although
I doubt it's very useful. I'll try to do better next time.

(gdb) break Fx_get_selection_internal 
Breakpoint 4 at 0x813c820: file xselect.c, line 1998.
(gdb) c
Continuing.

## Here I go to emacs and hit C-x C-e to evaluate (x-get-selection 'secondary)

Breakpoint 4, Fx_get_selection_internal (selection_symbol=149985546, target_type=139439426, time_stamp=139286466, terminal=139286466) at xselect.c:1998
1998	  Lisp_Object val = Qnil;
(gdb) info  locals 
val = 135564854
gcpro1 = {
  next = 0xbf39428, 
  var = 0xc, 
  nvars = 0
}
gcpro2 = {
  next = 0xf, 
  var = 0xbfffd7d8, 
  nvars = 135564854
}
f = 0xbfffd7f8
(gdb) n
2000	  struct frame *f = frame_for_x_selection (terminal);
(gdb) 
2003	  CHECK_SYMBOL (selection_symbol);
(gdb) 
2004	  CHECK_SYMBOL (target_type);
(gdb) 
2005	  if (EQ (target_type, QMULTIPLE))
(gdb) 
2007	  if (!f)
(gdb) 
2011				       FRAME_DISPLAY_INFO (f));
(gdb) 
2010	  val = x_get_local_selection (selection_symbol, target_type, 1,
(gdb) 
2013	  if (NILP (val) && FRAME_LIVE_P (f))
(gdb) 
2016	      XSETFRAME (frame, f);
(gdb) 
2017	      RETURN_UNGCPRO (x_get_foreign_selection (selection_symbol, target_type,
(gdb) 
Warning:
Cannot insert breakpoint 0.
Error accessing memory address 0xe4d00845: Erreur d'entrée/sortie.

## At this point my emacs entered the debugger with (error "Timed out waiting for reply from selection owner")
## Hitting 'c' in emacs returns to gdb :

0xb6cb07e1 in __libc_siglongjmp (env=0x8899758, val=1) at longjmp.c:29
29	longjmp.c: Aucun fichier ou dossier de ce type.
(gdb) 


Let's try another recipe:
## Here I go to emacs and hit C-x C-e after (x-get-selection 'secondary)
       
Breakpoint 4, Fx_get_selection_internal (selection_symbol=149985546, target_type=139439426, time_stamp=139286466, terminal=139286466) at xselect.c:1998
1998	  Lisp_Object val = Qnil;
(gdb) n
2000	  struct frame *f = frame_for_x_selection (terminal);
(gdb) 
2003	  CHECK_SYMBOL (selection_symbol);
(gdb) 
2004	  CHECK_SYMBOL (target_type);
(gdb) 
2005	  if (EQ (target_type, QMULTIPLE))
(gdb) 
2007	  if (!f)
(gdb) 
2011				       FRAME_DISPLAY_INFO (f));
(gdb) 
2010	  val = x_get_local_selection (selection_symbol, target_type, 1,
(gdb) 
2013	  if (NILP (val) && FRAME_LIVE_P (f))
(gdb) 
2016	      XSETFRAME (frame, f);
(gdb) 
2017	      RETURN_UNGCPRO (x_get_foreign_selection (selection_symbol, target_type,
(gdb) s
x_get_foreign_selection (selection_symbol=149985546, target_type=139439426, time_stamp=139286466, frame=142123853) at xselect.c:1186
1186	  struct frame *f = XFRAME (frame);
(gdb) n
1187	  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
(gdb) 
1188	  Display *display = dpyinfo->display;
(gdb) 
1189	  Window requestor_window = FRAME_X_WINDOW (f);
(gdb) 
1190	  Time requestor_time = dpyinfo->last_user_time;
(gdb) 
1191	  Atom target_property = dpyinfo->Xatom_EMACS_TMP;
(gdb) 
1192	  Atom selection_atom = symbol_to_x_atom (dpyinfo, selection_symbol);
(gdb) 
1193	  Atom type_atom = (CONSP (target_type)
(gdb) 
1195			    : symbol_to_x_atom (dpyinfo, target_type));
(gdb) 
1193	  Atom type_atom = (CONSP (target_type)
(gdb) 
1199	  if (!FRAME_LIVE_P (f))
(gdb) 
1202	  if (! NILP (time_stamp))
(gdb) 
1205	  block_input ();
(gdb) 
1210	  x_catch_errors (display);
(gdb) 
1211	  XConvertSelection (display, selection_atom, type_atom, target_property,
(gdb) 
1213	  x_check_errors (display, "Can't convert selection: %s");
(gdb) 
1214	  x_uncatch_errors ();
(gdb) 
1217	  reading_selection_window = requestor_window;
(gdb) 
1218	  reading_which_selection = selection_atom;
(gdb) 
1219	  XSETCAR (reading_selection_reply, Qnil);
(gdb) 
1230	  unblock_input ();
(gdb) 
1233	  timeout = max (0, x_selection_timeout);
(gdb) 
1234	  secs = timeout / 1000;
(gdb) 
1235	  nsecs = (timeout % 1000) * 1000000;
(gdb) 
1237	  wait_reading_process_output (secs, nsecs, 0, 0,

## At this point, it indeed waited for a few seconds

(gdb) 
1241	  if (NILP (XCAR (reading_selection_reply)))
(gdb) 
1242	    error ("Timed out waiting for reply from selection owner");
(gdb) 
Warning:
Cannot insert breakpoint 0.
Error accessing memory address 0xe4d9da45: Erreur d'entrée/sortie.

deliver_profiler_signal (signal=27) at profiler.c:250
250	{
(gdb) n
251	  deliver_process_signal (signal, handle_profiler_signal);
(gdb) 

Program received signal SIGTRAP, Trace/breakpoint trap.
0x08168cbd in deliver_process_signal (sig=27, handler=0x8229d01 <handle_profiler_signal>) at sysdep.c:1550
1550	{
(gdb) 
1553	  int old_errno = errno;
(gdb) 

Program received signal SIGTRAP, Trace/breakpoint trap.
__errno_location () at ../csu/errno-loc.c:25
25	../csu/errno-loc.c: Aucun fichier ou dossier de ce type.
(gdb) 

Program received signal SIGTRAP, Trace/breakpoint trap.
0xb6e43baa in __i686.get_pc_thunk.cx () from /lib/libpthread.so.0
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0xb6e4eae5 in __errno_location () at ../csu/errno-loc.c:25
25	in ../csu/errno-loc.c
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
__errno_location () at ../csu/errno-loc.c:26
26	in ../csu/errno-loc.c
(gdb) 
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0xb6e4eaf1 in __errno_location () at ../csu/errno-loc.c:26
26	in ../csu/errno-loc.c
(gdb) 
Continuing.

## After hitting RET a few more times, I got bored and did :

(gdb) handle SIGTRAP pass
SIGTRAP is used by the debugger.
Are you sure you want to change it? (y or n) y 
Signal        Stop	Print	Pass to program	Description
SIGTRAP       Yes	Yes	Yes		Trace/breakpoint trap
(gdb) c
Continuing.
[Thread 0xb1435b40 (LWP 5760) exited]
[Thread 0xb1c36b40 (LWP 5759) exited]
[Thread 0xb4f11b40 (LWP 22285) exited]
[Thread 0xb596eb40 (LWP 22284) exited]
[Thread 0xb639bb40 (LWP 22283) exited]

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
(gdb) 

## Perhaps this wasn't exactly the right thing to do -- sorry about
## that.

-- 
Nico.