Subject: bin/30143: gdb does not work with threaded programs
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <armihu@utu.fi>
List: netbsd-bugs
Date: 05/05/2005 15:30:00
>Number:         30143
>Category:       bin
>Synopsis:       gdb does not work with threaded programs
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 05 15:30:00 +0000 2005
>Originator:     Arto Huusko
>Release:        NetBSD-current 3.99.3
>Organization:
>Environment:
NetBSD lady 3.99.3 NetBSD 3.99.3 (LADY) #4: Thu May  5 10:27:52 EEST 2005  root@lady:/local/netbsd/current/i386/obj/sys/arch/i386/compile/LADY i386
>Description:
gdb does not work with threaded programs. At least trying to get a
stack trace from a core dump does not work, but fails with something
like this:

#0  0x080486fe in test (x=Cannot access memory at address 0xbfbfe810

>How-To-Repeat:
A tiny example program:

int
test(int *x)
{
        return *x;
}

int
main(int argc, char **argv)
{
        return test(0);
}

Compile with "gcc -O0 -g -lpthread test.c -o test"

Running the program yields:

Memory fault 

And "gdb test test.core":

This GDB was configured as "i386--netbsdelf"...
Core was generated by `test'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/libexec/ld.elf_so...done.
Loaded symbols for /usr/libexec/ld.elf_so
Reading symbols from /usr/lib/libpthread.so.0...done.
Loaded symbols for /usr/lib/libpthread.so.0
Reading symbols from /usr/lib/libc.so.12...done.
Loaded symbols for /usr/lib/libc.so.12
#0  0x080486fe in test (x=Cannot access memory at address 0xbfbfe810
) at test.c:4
4               return *x;
(gdb) where
#0  0x080486fe in test (x=Cannot access memory at address 0xbfbfe810
) at test.c:4
Cannot access memory at address 0xbfbfe808


If the program is compiled like so: "gcc -O0 -g test.c -o test",
and then run, the output is:

Memory fault (core dumped) 

Note that the threaded program did not say "(core dumped)" even though
it did. And gdb is happy with this core:

This GDB was configured as "i386--netbsdelf"...
Core was generated by `test'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/libexec/ld.elf_so...done.
Loaded symbols for /usr/libexec/ld.elf_so
Reading symbols from /usr/lib/libc.so.12...done.
Loaded symbols for /usr/lib/libc.so.12
#0  0x080486ee in test (x=0x0) at test.c:4
4               return *x;
(gdb) where
#0  0x080486ee in test (x=0x0) at test.c:4
#1  0x0804870c in main (argc=1, argv=0xbfbfe88c) at test.c:10
#2  0x08048526 in ___start ()


>Fix:
Unknown, and I guess this might not necessarily be a gdb bug. Could be
a pthread bug, too.