Subject: gdb backtrace
To: None <port-macppc@netbsd.org, tech-toolchain@netbsd.org>
From: Christian Groessler <cpg@aladdin.de>
List: tech-toolchain
Date: 07/04/2002 01:28:04
Hi,

the gdb backtrace doesn't work if linked w/ shared libs.

Assume the following program:

----------------
#include <stdio.h>

void runtz(void)
{
        sleep(1);
        printf("runtz\n");
}

int main(void)
{

        int i;

        for (i=0; i<100; i++) runtz();

        return(0);
}
----------------

After "cc -g loopy.c -o loopy", try

----------------
[power:~/tmp]$ gdb loopy
GNU gdb 5.0nb1
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc--netbsd"...
(gdb) r
Starting program: /home/chris/tmp/loopy 
runtz
^C
Program received signal SIGINT, Interrupt.
0x418865f4 in ?? () from /usr/lib/libc.so.12
(gdb) bt
#0  0x418865f4 in ?? () from /usr/lib/libc.so.12
(gdb)
----------------

It does not work.
Trying the same statically linked "cc -g -static loopy.c -o loopy", it
works:

----------------
[power:~/tmp]$ gdb loopy
GNU gdb 5.0nb1
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc--netbsd"...
(gdb) r
Starting program: /home/chris/tmp/loopy 
runtz
^C
Program received signal SIGINT, Interrupt.
0x18007a4 in nanosleep ()
(gdb) bt
#0  0x18007a4 in nanosleep ()
#1  0x1800788 in sleep ()
#2  0x1800638 in runtz () at loopy.c:6
#3  0x1800694 in main () at loopy.c:15
#4  0x180030c in _start ()
(gdb) 
----------------

On i386, even with "cc -g loopy.c -o loopy" (using shared libs) it
works:

----------------
[tann:~/tmp]$ gdb loopy
GNU gdb 5.0nb1
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386--netbsdelf"...
(gdb) r
Starting program: /home/chris/tmp/loopy 
runtz
^C
Program received signal SIGINT, Interrupt.
0x480a87c7 in nanosleep () from /usr/lib/libc.so.12
(gdb) bt
#0  0x480a87c7 in nanosleep () from /usr/lib/libc.so.12
#1  0x480a87a0 in sleep () from /usr/lib/libc.so.12
#2  0x8048944 in runtz () at loopy.c:6
#3  0x8048979 in main () at loopy.c:15
#4  0x8048740 in ___start ()
(gdb) 
----------------


Should I send-pr this?

regards,
chris