From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Madhu Newsgroups: gmane.emacs.bugs Subject: bug#36648: emacs signals under gdb - [Re: connecting to a lost server process Date: Thu, 18 Jul 2019 20:28:21 +0530 (IST) Message-ID: <20190718.202821.1196946470014157934.enometh@meer.net> References: <8336j3zz07.fsf@gnu.org> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Thu_Jul_18_20_28_21_2019_951)--" Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="22505"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 36648@debbugs.gnu.org To: eliz@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 18 17:05:13 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ho7y4-0005ia-FJ for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 Jul 2019 17:05:12 +0200 Original-Received: from localhost ([::1]:38938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1ho7y3-0004c8-8X for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 Jul 2019 11:05:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40586) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1ho7xz-0004bi-HU for bug-gnu-emacs@gnu.org; Thu, 18 Jul 2019 11:05:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ho7xx-0003Ao-Ok for bug-gnu-emacs@gnu.org; Thu, 18 Jul 2019 11:05:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45685) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ho7xx-0003AS-Gv for bug-gnu-emacs@gnu.org; Thu, 18 Jul 2019 11:05:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ho7xv-0005HX-9e for bug-gnu-emacs@gnu.org; Thu, 18 Jul 2019 11:05:05 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Madhu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 18 Jul 2019 15:05:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36648 X-GNU-PR-Package: emacs Original-Received: via spool by 36648-submit@debbugs.gnu.org id=B36648.156346224620227 (code B ref 36648); Thu, 18 Jul 2019 15:05:03 +0000 Original-Received: (at 36648) by debbugs.gnu.org; 18 Jul 2019 15:04:06 +0000 Original-Received: from localhost ([127.0.0.1]:54506 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ho7wz-0005GA-GS for submit@debbugs.gnu.org; Thu, 18 Jul 2019 11:04:06 -0400 Original-Received: from smtp6.ctinetworks.com ([205.166.61.199]:53054) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ho7rt-0002xH-AO for 36648@debbugs.gnu.org; Thu, 18 Jul 2019 10:58:50 -0400 Original-Received: from localhost (unknown [117.193.12.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: enometh@meer.net) by smtp6.ctinetworks.com (Postfix) with ESMTPSA id 005F683B8C; Thu, 18 Jul 2019 10:58:44 -0400 (EDT) In-Reply-To: <8336j3zz07.fsf@gnu.org> X-Mailer: Mew version 6.8 on Emacs 27.0 X-ctinetworks-Information: Please contact the ISP for more information X-ctinetworks-MailScanner-ID: 005F683B8C.A87B5 X-ctinetworks-VirusCheck: Found to be clean X-ctinetworks-Watermark: 1564325928.33599@sbG5+Kvfg0s0B7Ak2i9Kkw X-Mailman-Approved-At: Thu, 18 Jul 2019 11:04:04 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:163308 Archived-At: ----Next_Part(Thu_Jul_18_20_28_21_2019_951)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit * Eli Zaretskii <8336j3zz07.fsf@gnu.org> Wrote on Thu, 18 Jul 2019 08:35:04 +0300 >> From: Madhu >> Date: Sun, 14 Jul 2019 17:30:52 +0530 >> >> #5 report_file_errno (string=, name=name@entry=XIL(0xdd55f3), >> errorno=) >> at /var/tmp/portage/app-editors/emacs-27.0.50-r3/work/emacs-27.0.50/src/fileio.c:222 >> #6 0x000000000041a663 in connect_network_socket (proc=XIL(0xd7f415), >> addrinfos=, use_external_socket_p=) >> at /var/tmp/portage/app-editors/emacs-27.0.50-r3/work/emacs-27.0.50/src/process.c:3633 >> #7 0x00000000005a2cc6 in Fmake_network_process (nargs=, >> args=) >> at /var/tmp/portage/app-editors/emacs-27.0.50-r3/work/emacs-27.0.50/src/process.c:4246 > > See the call to report_file_errno in frame #5? Signaling an error > while waiting for input is fatal in Emacs, so it aborts. > >> Lisp Backtrace: >> "make-network-process" (0xffffc2a0) >> "server-running-p" (0xffffc690) >> "server-start" (0xffffcbc0) >> >> (gdb) up 5 >> #5 report_file_errno (string=, name=name@entry=XIL(0xdd55f3), >> errorno=) >> at /var/tmp/portage/app-editors/emacs-27.0.50-r3/work/emacs-27.0.50/src/fileio.c:222 >> 222 xsignal (Fcar (data), Fcdr (data)); >> >> (gdb) pp data >> (file-missing "make client process failed" "No such file or directory" :name "server-client-test" :family local :server nil :noquery t :service "/dev/shm/madhu/emacs/emacs-test") > > So here's the reason for the problem: the way you try to restart the > server fails because the socket no longer exists. > >> Additional notes: >> - make-network-process signals a (file-missing "make client process failed" "No such file or directory" :name "server-client-test" :family local :server nil :noquery t :service "/dev/shm/madhu/emacs/emacs-test") >> which is not supposed to happen since the file would be created by the >> system call to socket. I suspect a wrong error is being reported >> because of some problem with pselect (which is interrupted when we >> enter gdb) > > I don't think the error is wrong. Look at the function > server-running-p: it attempts to determine whether the server is > already running by creating a client process of the server. This > happens _before_ restarting the server. IOW, Emacs attempts to clean > up if the server is already running. In your case, the socket > doesn't exist, so this method of restarting the server can no longer > be used safely, because when you attach GDB to Emacs, Emacs will > almost always be waiting for input, where every error is fatal. server-running-p tries to start a server, and if it fails with a file error, then the condition-case is expected to catch it and the function is supposed to return nil. If I modify this function (see patch [1]) to test for the file instead of trying to catch an error from make-network-process, then this particular example (of restarting the server from gdb) works. >From the point of view of elisp, no error should be signalled - it should be caught by the condition-case. If I'm running an emacs compiled without X, when I suspend emacs and enter gdb on the same terminal, then no error is signalled (presumably because emacs is not waiting for input). > Instead, I suggest to restart the server by binding a function to the > sigusr1 or sigusr2 event. These events can be triggered by the > corresponding signals. Thank you, I will take up this suggestion. The default SIGUSR is very useful to unwedge emacs. However there seems to be room for improvement around the "abort when awaiting for input behaviour" - as there are other situations within gdb which are not "really" error situations which unnecessarily abort emacs. >> - another unrelated emacs-bug. M-x gud-gdb -- emacs .. with the above >> arg line fails to pass the quoted arguments to gdb. > > Sorry, I don't think I understand what exactly do you mean by "with > the above arg line". Can you please show a full sequence of commands > that produce this problem? M-x gud-gdb RET gdb --args emacs --arg -Q --eval '(progn (load-library "custom") (load-library "server") (setq server-name "emacs-test"))' RET => |Reading symbols from emacs... (gdb) show args Argument list to give program being debugged when it is started is "--arg -Q --eval \'\(progn \(load-library custom \) \(load-library server \) \(setq server-name emacs-test \)\)\'". (gdb) i.e. the arguments are not correctly quoted when passed to gdb. [1] ----Next_Part(Thu_Jul_18_20_28_21_2019_951)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="avoid-condition-case-in-server-running-p.patch" diff --git a/lisp/server.el b/lisp/server.el index 436a44a7e9..2bd512f52c 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -763,6 +763,9 @@ server-running-p Emacs process. To check from a Lisp program whether a server was started by the current Emacs process, use the `server-process' variable." (unless name (setq name server-name)) + (if (and (not server-use-tcp) + (not (file-exists-p (expand-file-name name server-socket-dir)))) + nil (condition-case nil (if server-use-tcp (with-temp-buffer @@ -778,7 +781,7 @@ server-running-p :name "server-client-test" :family 'local :server nil :noquery t :service (expand-file-name name server-socket-dir))) t) - (file-error nil))) + (file-error nil)))) ;;;###autoload (define-minor-mode server-mode ----Next_Part(Thu_Jul_18_20_28_21_2019_951)----