public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "ppluzhnikov at google dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug threads/10227] New: GDB resumes inferior unexpectedly when receiving ignored signal; step/next behave as continue
Date: Tue, 02 Jun 2009 06:15:00 -0000	[thread overview]
Message-ID: <20090602061531.10227.ppluzhnikov@google.com> (raw)

Reproduces in 32 and 64-bit mode using CVS Head.

The test case below generates endless stream of SIGPIPEs, which are
SIG_IGNored.

When "handle SIGPIPE nostop noprint pass" is in effect, everything works
as expected.

But when "handle SIGPIPE nostop print pass", then executing "next" turns
into "continue" instead, as can be seen in this log:

$ gdb64-cvs ./a.out
GNU gdb (GDB) 6.8.50.20090601-cvs
...
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
(gdb) b foo
Breakpoint 1 at 0x40070d: file sigpipe.c, line 22.
(gdb) handle SIGPIPE nostop print pass
(gdb) run
[Thread debugging using libthread_db enabled]
[New Thread 0x40800950 (LWP 29291)]

Breakpoint 1, foo () at sigpipe.c:22
22	  return 42;
(gdb) finish
0x00000000004007a7 in main () at sigpipe.c:53
53	    int x = foo();
Value returned is $1 = 42
(gdb) next
54	    bar(x);
(gdb) next

Program received signal SIGPIPE, Broken pipe.

Breakpoint 1, foo () at sigpipe.c:22    <<< How did we end up inside foo() ???
22	  return 42;                    <<< We should have stopped on line 53.

--- cut ---
/* compile with "gcc -pthread -g t.c"
 * Test program generates an endless stream of SIGPIPE in second thread.  */

#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>

void *fn(void *p)
{
  int fd = *(int*)p;
  while (1) {
    int x = 1;
    x++;
    x++;
    write(fd, &x, sizeof(x));
  }
}

int foo()
{
  return 42;
}

int bar(int x)
{
  return x - 1;
}

int main()
{
  int fd[2];
  pthread_t tid;

  signal(SIGPIPE, SIG_IGN);

  if (pipe(fd) == -1)
    return 1;

  switch (fork()) {
  case 0:
    /* child */
    exit(0);
  case -1:
    return 1;
  default:
    /* parent */
    close(fd[0]);
    pthread_create(&tid, 0, fn, &fd[1]);
  }

  while (1) {
    int x = foo();
    bar(x);
  }
  return 0;
}
--- cut ---

-- 
           Summary: GDB resumes inferior unexpectedly when receiving ignored
                    signal; step/next behave as continue
           Product: gdb
           Version: 6.8
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: threads
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: ppluzhnikov at google dot com
                CC: gdb-prs at sourceware dot org
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=10227

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


             reply	other threads:[~2009-06-02  6:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02  6:15 ppluzhnikov at google dot com [this message]
2009-06-02  6:36 ` [Bug threads/10227] " ppluzhnikov at google dot com

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=20090602061531.10227.ppluzhnikov@google.com \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.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.
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).