unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ken Raeburn <raeburn@raeburn.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Tom Tromey <tom@tromey.com>, emacs-devel@gnu.org
Subject: Re: Debugging Emacs with threads
Date: Sun, 11 Dec 2016 22:18:16 -0500	[thread overview]
Message-ID: <99B23C4A-3861-4995-BE61-317359FB2214@raeburn.org> (raw)
In-Reply-To: <83inqqe8kb.fsf@gnu.org>


On Dec 11, 2016, at 11:26, Eli Zaretskii <eliz@gnu.org> wrote:

> There's a nasty issue that people who debug Emacs with threads need to
> be aware of.
> 
> 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.
> 
> 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.
> 
> 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’s not like xbacktrace works on a core file anyway.  (I’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 “thread apply all bt”.)

Ken


  parent reply	other threads:[~2016-12-12  3:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-11 16:26 Debugging Emacs with threads Eli Zaretskii
2016-12-11 16:43 ` Andreas Schwab
2016-12-11 17:37   ` Eli Zaretskii
2016-12-11 18:04     ` Andreas Schwab
2016-12-11 18:12       ` Eli Zaretskii
2016-12-12  3:07   ` Ken Raeburn
2016-12-12  3:18 ` Ken Raeburn [this message]
2016-12-12 17:38   ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=99B23C4A-3861-4995-BE61-317359FB2214@raeburn.org \
    --to=raeburn@raeburn.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=tom@tromey.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).