From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ken Raeburn Newsgroups: gmane.emacs.devel Subject: Re: Debugging Emacs with threads Date: Sun, 11 Dec 2016 22:18:16 -0500 Message-ID: <99B23C4A-3861-4995-BE61-317359FB2214@raeburn.org> References: <83inqqe8kb.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1481512850 20218 195.159.176.226 (12 Dec 2016 03:20:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 12 Dec 2016 03:20:50 +0000 (UTC) Cc: Tom Tromey , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 12 04:20:46 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGHAU-0004ii-5d for ged-emacs-devel@m.gmane.org; Mon, 12 Dec 2016 04:20:46 +0100 Original-Received: from localhost ([::1]:58370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGHAY-0002jg-8B for ged-emacs-devel@m.gmane.org; Sun, 11 Dec 2016 22:20:50 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGH97-0002i7-S6 for emacs-devel@gnu.org; Sun, 11 Dec 2016 22:19:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cGH94-0005il-P8 for emacs-devel@gnu.org; Sun, 11 Dec 2016 22:19:21 -0500 Original-Received: from mail-qt0-f196.google.com ([209.85.216.196]:32864) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cGH94-0005iT-Lq for emacs-devel@gnu.org; Sun, 11 Dec 2016 22:19:18 -0500 Original-Received: by mail-qt0-f196.google.com with SMTP id n6so8370656qtd.0 for ; Sun, 11 Dec 2016 19:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raeburn-org.20150623.gappssmtp.com; s=20150623; h=subject:mime-version:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VyS8mYBlkYuKIpiK7C0YIU1SGG1TgzvUXOPQbmWflxo=; b=WuVQqwp2swi4UxPtWEjFR3I3zKKAyvaddx0vgaOjKhD7UnRcs8Qe4pIQzGX0jG4sJf WyMMb7GWmwEGIyb69OT67Smtrp+4wlSPOBP7golHHfq8wkajLTnUFqwjK8y4mJzF8NGa aSPuxloj/XDONJx5c8WXNSUURhjXqYvomBaytjw8k7R1+hVAM1dQTT5bDTN4oFOLFZjE 5b7pwbfN1r4vq+UA4WXvCYTbbWKJZXRoNKTPIG5kH0FDQJYtqMkEN5dELVE48Ose7K1z BGViRQcP3C02bkO9DQmrMggxg2EpgwjClIhwn8iVvsvXVreKaKh/39manmdwQh3Fmg8X 8xaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:mime-version:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VyS8mYBlkYuKIpiK7C0YIU1SGG1TgzvUXOPQbmWflxo=; b=STiVL8N7otCDY+HaKIFvKK2GeFtV+qfTSC7gUG29lsbL3EcqfZBogi0zawerh+Qti8 JgBqrWBEQhx4y/9H/+s80710vLGouoKY164pLEadq9EyYOeOrUiHyvGspp7IlZhbhW5A IiN25cITZN2XD3WHz86Vdy0UEroUwz6XG68M4fUQfFfCtAxrwlwaqxNO3jzl0HWcKCzF +QivzbchJsJ54mlCVqNhIn8OjCJlgyQUZ9XL1WvmD3HUnbd0EMsnR0QWhiowcM/3tKLr qZTF6Qdx1epOgXIKtClTsfsi4L9wmvZriQ+BisgIIfvvgIcJ7N3fZ4lZ/NANxt3UsUXe qsmA== X-Gm-Message-State: AKaTC0053BbsbLsfeRcZpY+SqqutRLspz3EbM0WzqCLnjWK7+xmJj3J1wnsoWm9XwxY4Og== X-Received: by 10.200.37.221 with SMTP id f29mr87561279qtf.123.1481512697973; Sun, 11 Dec 2016 19:18:17 -0800 (PST) Original-Received: from [192.168.23.52] (c-50-138-183-136.hsd1.ma.comcast.net. [50.138.183.136]) by smtp.gmail.com with ESMTPSA id s41sm25444192qtc.39.2016.12.11.19.18.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 Dec 2016 19:18:17 -0800 (PST) In-Reply-To: <83inqqe8kb.fsf@gnu.org> X-Mailer: Apple Mail (2.3124) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.216.196 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:210324 Archived-At: On Dec 11, 2016, at 11:26, Eli Zaretskii wrote: > There's a nasty issue that people who debug Emacs with threads need to > be aware of. >=20 > When Emacs stops due to a breakpoint, the thread that is the current > one is in sync between GDB and Emacs. IOW, the current_thread > variable describes the same thread on which GDB commands will act. > But as soon as you say something like "thread 1" at the GDB prompt, > this synchronization is lost: GDB acts on the thread you specified, > while current_thread is still pointing at the thread which was the > current one when Emacs stopped. >=20 > The result of this is that invoking functions in Emacs will likely > crash, because thread-specific variables used by Emacs are incorrect > for the thread whose stack GDB will use to create the call-stack frame > for the function it calls. In particular, xbacktrace will definitely > crash. And since src/.gdbinit automatically invokes xbacktrace when > you type "bt", any "bt" issued when the threads mismatch will ruin the > debugging session. >=20 > It would be good to protect xbacktrace from this, and avoid calling > functions in Emacs in this situation. Unfortunately, I couldn't find > any way of gleaning the OS thread ID from the GDB thread number. > Maybe Tom, who knows a lot about GDB, could help, or someone else > might have an idea that we then could implement in .gdbinit? Perhaps a new thread-local variable which has the value of = current_thread when the thread is the current Lisp thread. Or we could = invoke sys_thread_self() to compare against current_thread->thread_id; = it=E2=80=99s not like xbacktrace works on a core file anyway. (I=E2=80=99= m assuming GDB will invoke a function or look at TLS in the context of = the current OS thread, or the appropriate OS thread when invoked via = something like =E2=80=9Cthread apply all bt=E2=80=9D.) Ken=