public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@cygnus.com>
To: Jiva DeVoe <jiva@opnix.com>, gdb@sources.redhat.com
Subject: Re: GDB and threads...
Date: Mon, 30 Apr 2001 18:32:00 -0000	[thread overview]
Message-ID: <1010501013206.ZM31835@ocotillo.lan> (raw)
In-Reply-To: <20010426174305.B19540@opnix.com>

On Apr 26,  5:43pm, Jiva DeVoe wrote:

> Does anyone have any tips on debugging multithreaded apps using gdb?
> I have been trying for a couple of months now, and IMO gdb is REALLY
> not very effective at it (at least in my experience.)  I've used
> windows debuggers to do this, and when I would have a fault in a
> subthread, the debugger would actually break *in* that thread.  With
> gdb, it breaks, but it still breaks in the main thread.  I can't even
> get the thread info commands to work.

Jiva,

I constructed a small program with three threads (counting the main
thread) to see if I could reproduce the problem that you describe.
Here's the program:

--- threads-segv.c ---
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void *
worker (void *args)
{
  int i;
  char **a = args;

  for (i = 0; i < 5; i++)
    {
      printf ("%c\n", a[i][0]);
      sleep (1);
    }
  return NULL;
}

int
main(void)
{
  pthread_t tid1, tid2;
  char *a1[] = { "a", "b", "c", "d", "e" };
  char *a2[] = { "A", "B", "C", 0, "E" };

  pthread_create (&tid1, NULL, worker, a1);
  pthread_create (&tid2, NULL, worker, a2);


  pthread_join (tid1, NULL);
  pthread_join (tid2, NULL);
  return 0;
}
--- end threads-segv.c ---

I compile it (on my Red Hat 7.0 machine) as follows:

    gcc -Wall -o threads-segv -g threads-segv.c -lpthread

When I run it (without GDB), it terminates (as intended) with a
SIGSEGV.  When I debug it with GDB (using current development
sources), I see the following:

    (gdb) r
    Starting program: /home/kev/ctests/threads-segv 
    [New Thread 1024 (LWP 5462)]
    [New Thread 2049 (LWP 5463)]
    Delayed SIGSTOP caught for LWP 5463.
    [New Thread 1026 (LWP 5464)]
    Delayed SIGSTOP caught for LWP 5464.
    [New Thread 2051 (LWP 5465)]
    Delayed SIGSTOP caught for LWP 5465.
    a
    A
    b
    B
    C
    c
    d

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 2051 (LWP 5465)]
    0x08048577 in worker (args=0xbffff968) at threads-segv.c:13
    warning: Source file is more recent than executable.

    13            printf ("%c\n", a[i][0]);
    (gdb) print i
    $1 = 3
    (gdb) print a[i]
    $2 = 0x0
    (gdb) info thread
    * 4 Thread 2051 (LWP 5465)  0x08048577 in worker (args=0xbffff968)
	at threads-segv.c:13
      3 Thread 1026 (LWP 5464)  0x400f3241 in __libc_nanosleep ()
       from /lib/libc.so.6
      2 Thread 2049 (LWP 5463)  0x40113b97 in __poll (fds=0x804b684, nfds=1, 
	timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63
      1 Thread 1024 (LWP 5462)  0x40067e75 in __sigsuspend (set=0xbffff7c8)
	at ../sysdeps/unix/sysv/linux/sigsuspend.c:45
    (gdb) bt
    #0  0x08048577 in worker (args=0xbffff968) at threads-segv.c:13
    #1  0x4002bc8e in pthread_start_thread_event (arg=0xbf5ffc00) at manager.c:274
    (gdb) 

So, with my admittedly simple test case, I've been unable to reproduce
the problems that you've described.

Have you tried the current development sources?  If not, see

    http://sources.redhat.com/gdb/#download

and read the section about downloading the development version.

Also, it would be useful if you'd send us your own testcase(s) which
illustrate the problems that you're seeing.

Kevin

  parent reply	other threads:[~2001-04-30 18:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-26 17:39 Jiva DeVoe
2001-04-26 21:00 ` Jeffrey W. Baker
2001-04-30 18:32 ` Kevin Buettner [this message]
2001-04-30 18:46   ` Jiva DeVoe
2001-04-30 18:54   ` Jiva DeVoe
2012-04-12  9:44 gdb " Folkert van Heusden
2012-04-13 13:07 ` Jan Kratochvil

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=1010501013206.ZM31835@ocotillo.lan \
    --to=kevinb@cygnus.com \
    --cc=gdb@sources.redhat.com \
    --cc=jiva@opnix.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).