public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: gdb arbitrarily starting threads
Date: Sat, 20 Jun 2015 18:47:00 -0000	[thread overview]
Message-ID: <20150620184715.GA17350@calimero.vinschen.de> (raw)
In-Reply-To: <CAH5rLZVsTzSVTRzG_Aucw=_i-o5M-G0_ddPu0gPaqQM-Nn3iJg@mail.gmail.com>

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

On Jun 20 09:29, William M. (Mike) Miller wrote:
> I have a single-threaded executable that has a number of debug-print
> routines that can be called interactively in the debugger to display
> data structures to stderr.  Something has changed in gdb/gcc/Cygwin
> during the last year or so (I don't update my installation very often)
> so that when I call one of these functions, _sometimes_ gdb will start
> a new thread and put my current thread into "running" status, so that
> I can't step, etc. (although the thread isn't actually running).
> Here's the scenario:
> 
> 1) I say "gdb xxx.exe", set a breakpoint, and run.  When I hit the
> breakpoint, "info threads" shows me two threads, one for my executable
> and one with some _cygtls/cygthread/ntdll frames; both are stopped.
> 
> 2) I say "up" a couple of times, then "p db_foo(p)" (where db_foo is
> one of these debug-print routines that displays to stderr the data
> structure pointed to by "p").  Sometimes, but not always, gdb will
> respond with
> 
>     [New Thread 1436.0x1f00]

You don't have this under control.  Nor does Cygwin, most of the time.

E.g, a debugged Windows executable has always at least two threads, one
is your process thread, one is the thread created by the OS when the
debugger attaches to a process.

Every Cygwin process has at least two threads, your process thread, as
well as a so-called "signal thread", the thread handling POSIX signals,
created at every process startup by the Cygwin DLL.

Certain Windows system calls create threads in your process to perform
tasks "under the hood".

Cygwin is doing the same, for instance to implement interruptible system
calls where the underlying OS call is non-interuptible.  select(2) may
start multiple threads at once.  Etc.

There's no way around that.  Windows process handling is centered around
cheap thread creation and termination.  Have a look into the "Details"
view in Windows Task Manager.  Activate the "Threads" column.  Note that
almost all processes are running with more than one thread.  Just don't
worry about it, it's kind of system inherent.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-06-20 18:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-20 13:29 William M. (Mike) Miller
2015-06-20 18:47 ` Corinna Vinschen [this message]
2015-06-20 20:02   ` William M. (Mike) Miller
2015-06-20 20:42     ` Ken Brown
2015-06-20 20:51       ` William M. (Mike) Miller
2015-06-21 19:29         ` Ken Brown
2015-06-22  0:28           ` William M. (Mike) Miller
2015-06-24 14:33             ` Eli Zaretskii
2015-09-05 17:16               ` William M. (Mike) Miller
2015-09-13 15:21               ` William M. (Mike) Miller

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=20150620184715.GA17350@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.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.
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).