Subject: bug#21965: 24.5; Emacs freezes when canceling at open file

From: Maneesh Yadav <[email-masked]>
Date: Tue, 24 Nov 2015 14:58:11 -0800

lldb "thread continue" runs after, but emacs remains unresponsive

'thread step-in" does increment the instruction counter (output
below)...but not really sure what that implies.

(lldb) thread step-in

Process 25251 stopped

* thread #1: tid = 0x746f0, 0x00007fff8a861168
libsystem_kernel.dylib`__psynch_mutexwait + 12, queue =
'com.apple.main-thread', stop reason = instruction step into

    frame #0: 0x00007fff8a861168 libsystem_kernel.dylib`__psynch_mutexwait + 12

libsystem_kernel.dylib`__psynch_mutexwait:

->  0x7fff8a861168 <+12>: movq   %rax, %rdi

    0x7fff8a86116b <+15>: jmp    0x7fff8a85cc53            ; cerror_nocancel

    0x7fff8a861170 <+20>: retq

    0x7fff8a861171 <+21>: nop

(lldb) thread step-in

Process 25251 stopped

* thread #1: tid = 0x746f0, 0x00007fff8a86116b
libsystem_kernel.dylib`__psynch_mutexwait + 15, queue =
'com.apple.main-thread', stop reason = instruction step into

    frame #0: 0x00007fff8a86116b libsystem_kernel.dylib`__psynch_mutexwait + 15

libsystem_kernel.dylib`__psynch_mutexwait:

->  0x7fff8a86116b <+15>: jmp    0x7fff8a85cc53            ; cerror_nocancel

    0x7fff8a861170 <+20>: retq

    0x7fff8a861171 <+21>: nop

    0x7fff8a861172 <+22>: nop

(lldb) thread step-in

Process 25251 stopped

* thread #1: tid = 0x746f0, 0x00007fff8a85cc53
libsystem_kernel.dylib`cerror_nocancel, queue =
'com.apple.main-thread', stop reason = instruction step into

    frame #0: 0x00007fff8a85cc53 libsystem_kernel.dylib`cerror_nocancel

libsystem_kernel.dylib`cerror_nocancel:

->  0x7fff8a85cc53 <+0>:  movl   %edi, -0x14ad19d9(%rip)   ; errno

    0x7fff8a85cc59 <+6>:  movq   %gs:0x8, %rax

    0x7fff8a85cc62 <+15>: testq  %rax, %rax

    0x7fff8a85cc65 <+18>: je     0x7fff8a85cc69            ; <+22>

On Tue, Nov 24, 2015 at 2:51 PM, Maneesh Yadav <[email-masked]> wrote:
> FWIW I just triggered the condition 3 times in a row (I seem to be
> getting better at triggering it), attached with lldb output
> (backtraces looks the same as before as well).  Looks like the same
> instruction?
>
>
> #1
>
>
>
> Process 25176 stopped
>
> * thread #1: tid = 0x7369a, 0x00007fff8a861166
> libsystem_kernel.dylib`__psynch_mutexwait + 10, queue =
> 'com.apple.main-thread', stop reason = signal SIGSTOP
>
>     frame #0: 0x00007fff8a861166 libsystem_kernel.dylib`__psynch_mutexwait + 10
>
> libsystem_kernel.dylib`__psynch_mutexwait:
>
> ->  0x7fff8a861166 <+10>: jae    0x7fff8a861170            ; <+20>
>
>     0x7fff8a861168 <+12>: movq   %rax, %rdi
>
>     0x7fff8a86116b <+15>: jmp    0x7fff8a85cc53            ; cerror_nocancel
>
>     0x7fff8a861170 <+20>: retq
>
>
> (lldb) thread backtrace
>
> * thread #1: tid = 0x7369a, 0x00007fff8a861166
> libsystem_kernel.dylib`__psynch_mutexwait + 10, queue =
> 'com.apple.main-thread', stop reason = signal SIGSTOP
>
>   * frame #0: 0x00007fff8a861166 libsystem_kernel.dylib`__psynch_mutexwait + 10
>
>     frame #1: 0x00007fff853b5696
> libsystem_pthread.dylib`_pthread_mutex_lock + 480
>
>     frame #2: 0x0000000100a17ba1 libglib-2.0.0.dylib`g_mutex_lock + 26
>
>     frame #3: 0x00000001009db284 libglib-2.0.0.dylib`g_main_context_acquire + 42
>
>     frame #4: 0x000000010024fc47 emacs`xg_select + 231
> ...
>
>
>
> #2
>
> Process 25238 stopped
>
> * thread #1: tid = 0x742be, 0x00007fff8a861166
> libsystem_kernel.dylib`__psynch_mutexwait + 10, queue =
> 'com.apple.main-thread', stop reason = signal SIGSTOP
>
>     frame #0: 0x00007fff8a861166 libsystem_kernel.dylib`__psynch_mutexwait + 10
>
> libsystem_kernel.dylib`__psynch_mutexwait:
>
> ->  0x7fff8a861166 <+10>: jae    0x7fff8a861170            ; <+20>
>
>     0x7fff8a861168 <+12>: movq   %rax, %rdi
>
>     0x7fff8a86116b <+15>: jmp    0x7fff8a85cc53            ; cerror_nocancel
>
>     0x7fff8a861170 <+20>: retq
>
>
>
> #3
>
> Process 25251 stopped
>
> * thread #1: tid = 0x746f0, 0x00007fff8a861166
> libsystem_kernel.dylib`__psynch_mutexwait + 10, queue =
> 'com.apple.main-thread', stop reason = signal SIGSTOP
>
>     frame #0: 0x00007fff8a861166 libsystem_kernel.dylib`__psynch_mutexwait + 10
>
> libsystem_kernel.dylib`__psynch_mutexwait:
>
> ->  0x7fff8a861166 <+10>: jae    0x7fff8a861170            ; <+20>
>
>     0x7fff8a861168 <+12>: movq   %rax, %rdi
>
>     0x7fff8a86116b <+15>: jmp    0x7fff8a85cc53            ; cerror_nocancel
>     0x7fff8a861170 <+20>: retq
>
>
> On Mon, Nov 23, 2015 at 7:39 PM, John Wiegley <[email-masked]> wrote:
>>>>>>> Eli Zaretskii <[email-masked]> writes:
>>
>>> No. And I'm not even convinced that's where we are blocked. It could be that
>>> this is part of a loop that Emacs is waiting in. To prove that we are
>>> blocked there, one needs to attach the debugger many times and see that the
>>> debugger finds Emacs at _exactly_ the same instruction. Or, after attaching,
>>> step Emacs and see that it cannot move even a single instructions.
>>
>> Fair enough.  The docs for g_main_context_acquire do say that it should return
>> immediately, if no other thread is holding the lock.
>>
>> John