all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Richard Copley <rcopley@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 19868@debbugs.gnu.org
Subject: bug#19868: 25.0.50; Compilation eats buffers
Date: Tue, 17 Feb 2015 00:25:41 +0000	[thread overview]
Message-ID: <CAPM58oiOa8_wBO=R8q+yESmjX3bUgEam3ujA59D35iBv4xaDFg@mail.gmail.com> (raw)
In-Reply-To: <83k2zjukmr.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 5005 bytes --]

On 15 February 2015 at 17:53, Eli Zaretskii <eliz@gnu.org> wrote:
>>
>> On Windows, with MinGW gcc.exe installed and on the path, save a file
>> "c:\temp\bug.c" containing these two lines:
>>
>> #include <windows.h>
>> int main () { Sleep (5000); }
>>
>> Compile with "M-x compile RET", supplying this compile-command:
>> gcc -mwindows -o bug.exe bug.c && bug.exe
>>
>> Within 5 seconds, execute "M-x compile" again and answer "yes" to kill
>> the existing process. The process doesn't respond to the signal,
>
> There are no signals on Windows.  Emacs simulates SIGINT and SIGKILL
> by other means, see sys_kill.
>
>> and Emacs hangs inside the call to `delete-process' in
>> `compilation-start'.
>>
>> When the process does eventually die and the `delete-process' call
>> returns, the current buffer has changed from *compilation* to the buffer
>> from which the compilation was launched (which will often be a source
>> code buffer).
>>
>> `compilation-start' then proceeds to erase the buffer and discard its
>> undo history. This is potentially very bad news for the user's source
>> code.
>
> I cannot reproduce this: for me, Emacs doesn't hang at all.  As soon
> as I answer YES to the kill process question, I see in Process
> Explorer that cmdproxy, cmd.exe, and the program that sleeps are all
> terminated, and the new compilation begins.  Like I'd expect.
>
> If I instrument the sys_kill function, I see that we first send a
> simulated Ctrl-C keystroke to the process, and a second afterwards
> terminate it forcefully, which is consistent with the calls to
> interrupt-process and delete-process in compilation-start.
>
> I tried this on Windows 7 and XP, and both show the same correct
> behavior.
>
> It could be that what you see is specific to Windows 8, or to 64-bit
> programs, or to how MinGW64 sets up the process in its startup code (I
> used MinGW32).

I see my problem no matter what compiler I use to build "bug.exe"
(old-fashioned MinGW32, and both the 32- and 64-bit MinGW-W64
GCC 4.9.2 toolchains). I'll try on Windows 7, and if I get time,
with 32-bit Emacs.

when building "bug.exe" with good old MinGW and with
both the 32- and 64-bit toolchains from MinGW-W64. I haven't tried it
with a 32-bit Emacs. I will try that, and on Windows 7, when I have time.

> You say above that Emacs hangs inside the delete-process call -- can
> you show a backtrace in that state, preferably from an unoptimized
> build?  I'd like to see where exactly it hangs.

I tried to work out how to control the optimization level when building
Emacs but I'm stumped. How do you do that? (If there are configure
flags, can they be mentioned in "configure --help"?)

FWIW, attached is the result of "thread apply all bt full" after typing
Ctrl-C in GDB while debugging an optimized Emacs that was hanging.
Looks like I'm doing something horribly wrong. Sorry about that.

> Also, is the -mwindows compiler switch a factor here, i.e. does the
> problem happen with a console application that sleeps?

Yes, -mwindows is needed. Console applications die as expected.

> (I'm not sure it should matter, because the process that we are
> killing is cmdproxy, not the program you compiled.)

Then I don't understand why a GUI program would ever die in response
to that. (Would runemacs.exe?) Really I didn't expect it to; that's
not the bug I was reporting (though I'm happy to help fix it if it is
a bug).

> In addition, can you look at the relevant processes in Process
> Explorer and seed if any of them are killed when you answer YES?

"cmdproxy.exe" and its descendants "cmd.exe" and "conhost.exe"
are killed, leaving just the orphaned "bug.exe".

>> I'm not sure where the buffer gets changed (presumably in a sentinel,
>> but `compilation-sentinel' looks OK to me).
>
> Run all this under GDB, put a breakpoint on a low-level function that
> switches buffers (e.g., in set_buffer_internal), and you will see in
> the backtrace which Lisp function triggers that.  It is advisable to
> manually load compile.el in advance, so that xbacktrace shows more
> details.

I'm sorry to say that, mysteriously, I can no longer reproduce the
effect where the current buffer changes during the `delete-process'
call and causes work to be lost. I can't see what I'm doing differently.
I might have to get back to you another time.

>> In GNU Emacs 25.0.50.1 (x86_64-w64-mingw32)
>>  of 2015-02-09 on MACHINE
>> Repository revision: 21d1f8b85eec8fc1f87bb30398e449f6b20b6ecc
>> Windowing system distributor `Microsoft Corp.', version 6.3.9600
>> Configured using:
>>  `configure --prefix /c/emacs/emacs-20150209-192633
>>  --disable-dependency-tracking
>>  --enable-locallisppath=%emacs_dir%/../site-lisp --with-wide-int
>>  --build=x86_64-w64-mingw32 'CPPFLAGS=-I G:/usr/include -I
>>  C:/GnuWin32/include' 'LDFLAGS=-L G:/usr/lib -L C:/GnuWin32/lib''
>
> Any idea why you are building --with-wide-int?  It's supposed to be a
> no-op in a 64-bit build.  (This is not related to the bug.)

I'll remove it, thanks.

[-- Attachment #2: bt.txt --]
[-- Type: text/plain, Size: 6183 bytes --]

Program received signal SIGINT, Interrupt.
[Switching to Thread 8568.0x1518]
0x00007ff9c5cc3233 in RegLoadMUIStringA ()
   from C:\WINDOWS\system32\KernelBase.dll
(gdb) thread apply all bt full

Thread 7 (Thread 8568.0x1518):
#0  0x00007ff9c5cc3233 in RegLoadMUIStringA ()
   from C:\WINDOWS\system32\KernelBase.dll
No symbol table info available.
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 6 (Thread 8568.0x450):
#0  0x00007ff9c8aa28ca in ntdll!ZwWaitForWorkViaWorkerFactory ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ff9c8a44d26 in ntdll!RtlFreeUnicodeString ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#2  0x00007ff9c88213d2 in KERNEL32!BaseThreadInitThunk ()
   from C:\WINDOWS\system32\kernel32.dll
No symbol table info available.
#3  0x00007ff9c8a7eb64 in ntdll!RtlUserThreadStart ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#4  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 5 (Thread 8568.0x1814):
#0  0x00007ff9c8aa28ca in ntdll!ZwWaitForWorkViaWorkerFactory ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ff9c8a44d26 in ntdll!RtlFreeUnicodeString ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#2  0x00007ff9c88213d2 in KERNEL32!BaseThreadInitThunk ()
   from C:\WINDOWS\system32\kernel32.dll
No symbol table info available.
#3  0x00007ff9c8a7eb64 in ntdll!RtlUserThreadStart ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#4  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 4 (Thread 8568.0x1930):
#0  0x00007ff9c8aa0e3a in ntdll!ZwReadFile ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ff9c5c183a8 in ReadFile () from C:\WINDOWS\system32\KernelBase.dll
No symbol table info available.
#2  0x00007ff9c8981b59 in msvcrt!__crtGetStringTypeW ()
   from C:\WINDOWS\system32\msvcrt.dll
No symbol table info available.
#3  0x00007ff9c8981c79 in msvcrt!_read () from C:\WINDOWS\system32\msvcrt.dll
No symbol table info available.
#4  0x0000000400196135 in _sys_read_ahead (fd=<optimized out>)
    at g:/emacs/repo/emacs/src/w32.c:7990
        cp = 0x100000000
        rc = 0
#5  0x000000040019b815 in reader_thread (arg=0x4017a5940 <child_procs>)
    at g:/emacs/repo/emacs/src/w32proc.c:1017
        rc = <optimized out>
        cp = 0x4017a5940 <child_procs>
#6  0x00007ff9c88213d2 in KERNEL32!BaseThreadInitThunk ()
   from C:\WINDOWS\system32\kernel32.dll
No symbol table info available.
#7  0x00007ff9c8a7eb64 in ntdll!RtlUserThreadStart ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#8  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 3 (Thread 8568.0x2258):
#0  0x00007ff9c60726ca in USER32!GetMessageW ()
   from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#1  0x00007ff9c6072695 in USER32!GetMessageW ()
   from C:\WINDOWS\system32\user32.dll
No symbol table info available.
#2  0x0000000400170068 in w32_msg_pump (msg_buf=0x2ecfef0)
    at g:/emacs/repo/emacs/src/w32fns.c:2526
        msg = {hwnd = 0x1906d0, message = 275, wParam = 1, lParam = 0,
          time = 452290093, pt = {x = 273, y = 1075}}
        focus_window = <optimized out>
#3  0x00000004001705c0 in w32_msg_worker (arg=<optimized out>)
---Type <return> to continue, or q <return> to quit---
    at g:/emacs/repo/emacs/src/w32fns.c:2747
        msg = {hwnd = 0x0, message = 0, wParam = 0, lParam = 0, time = 0,
          pt = {x = 0, y = 0}}
        dummy_buf = {next = 0x0, w32msg = {msg = {hwnd = 0x0, message = 0,
              wParam = 0, lParam = 0, time = 0, pt = {x = 0, y = 0}},
            dwModifiers = 0, rect = {left = 0, top = 0, right = 0,
              bottom = 0}}, result = 0, completed = 0}
#4  0x00007ff9c88213d2 in KERNEL32!BaseThreadInitThunk ()
   from C:\WINDOWS\system32\kernel32.dll
No symbol table info available.
#5  0x00007ff9c8a7eb64 in ntdll!RtlUserThreadStart ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#6  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 2 (Thread 8568.0x15a4):
#0  0x00007ff9c8aa111a in ntdll!ZwDelayExecution ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ff9c5c1121a in SleepEx () from C:\WINDOWS\system32\KernelBase.dll
No symbol table info available.
#2  0x000000040019bdab in timer_loop (arg=0x0)
    at g:/emacs/repo/emacs/src/w32proc.c:381
        sleep_time = <optimized out>
        handler = <optimized out>
        now = <optimized out>
        expire = <optimized out>
        reload = <optimized out>
        itimer = 0x0
        which = <optimized out>
        sig = <optimized out>
        crit = <optimized out>
        max_sleep = <optimized out>
        hth = 0x0
#3  0x00007ff9c88213d2 in KERNEL32!BaseThreadInitThunk ()
   from C:\WINDOWS\system32\kernel32.dll
No symbol table info available.
#4  0x00007ff9c8a7eb64 in ntdll!RtlUserThreadStart ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#5  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 1 (Thread 8568.0x10c8):
#0  0x00007ff9c8aa0e1a in ntdll!ZwWaitForSingleObject ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ff9c8a49a85 in ntdll!RtlImageNtHeaderEx ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
#2  0x00007ff9c8a47f44 in ntdll!RtlEnterCriticalSection ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)

  reply	other threads:[~2015-02-17  0:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-14 19:30 bug#19868: 25.0.50; Compilation eats buffers Richard Copley
2015-02-15 17:53 ` Eli Zaretskii
2015-02-17  0:25   ` Richard Copley [this message]
2016-08-12 20:47 ` bug#19868: #19868 " Noam Postavsky
2016-08-13  6:44   ` Eli Zaretskii
2016-08-15 22:19     ` Noam Postavsky
2016-08-16 14:18       ` Eli Zaretskii
2016-08-16 21:17         ` Noam Postavsky
2016-08-17 15:15           ` Eli Zaretskii
2016-08-29 21:48             ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPM58oiOa8_wBO=R8q+yESmjX3bUgEam3ujA59D35iBv4xaDFg@mail.gmail.com' \
    --to=rcopley@gmail.com \
    --cc=19868@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.