Subject: gdb, or is it ld, mis-behaves on 1.6.1_STABLE/i386 with i386 binaries....
To: NetBSD Toolchain Technical Discussion List <tech-toolchain@NetBSD.ORG>
From: Greg A. Woods <woods@weird.com>
List: port-i386
Date: 10/29/2003 18:08:44
I'm having a bit of a problem with gdb, both the 5.0nb1 version included
in the base OS, as well as 5.3 fom pkgsrc.

On most base-OS programs it works just fine.

However on most X11 programs it seems unable to find the right debugging
symbols for all but the bottom (first?) frame and it claims all the
other frames are calls from inside lib/csu/common_elf/crtbegin.c.

In this case "xclock" is a static-linked binary produced with "cc -g" > 

$ file xclock
xclock: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for NetBSD, statically linked, not stripped
$ /usr/pkg/bin/gdb ./xclock                                              
GNU gdb 5.3
Copyright 2002 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) run
Starting program: /build/woods/proven/NetBSD-1.6.x-i386-i386-obj/xsrc/xfree/xc/programs/xclock/xclock 
Xlib:  extension "RENDER" missing on display "very.weird.com:0.0".
Warning: Cannot convert string "" to type XftFont
^?
Program received signal SIGINT, Interrupt.
0x08179223 in poll ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
167     }
(gdb) where
#0  0x08179223 in poll ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#1  0x080ec018 in IoWait ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#2  0x080ec25f in _XtWaitForSomething ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#3  0x080ecd8c in XtAppNextEvent ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#4  0x080e5bc2 in XtAppMainLoop ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#5  0x0804874c in main ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#6  0x0804825c in ___start (argc=1, argv=0xbfbfcd9c, envp=0xbfbfcda4, 
    cleanup=0, obj=0x0, ps_strings=0xbfbfdff0)
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/crt0.c:94
(gdb)


Objdump also has a complaint about the binary:

$ objdump -g xclock 

xclock:     file format elf32-i386

Bad stab: __mbstate8:(8,3)=ar(0,1);0;127;(0,2),0,1024;?
Last stabs entries before error:
n_type n_desc n_value  string
LSYM   50     00000000 __uint16_t:t(7,4)=(0,9)
LSYM   51     00000000 __int32_t:t(7,5)=(0,1)
LSYM   52     00000000 __uint32_t:t(7,6)=(0,4)
LSYM   58     00000000 __int64_t:t(7,7)=(0,6)
LSYM   60     00000000 __uint64_t:t(7,8)=(0,7)
LSYM   67     00000000 __intptr_t:t(7,9)=(0,3)
LSYM   68     00000000 __uintptr_t:t(7,10)=(0,5)
EINCL  0      00000000 
LSYM   52     00000000 paddr_t:t(3,1)=(0,5)
LSYM   53     00000000 psize_t:t(3,2)=(0,5)
LSYM   54     00000000 vaddr_t:t(3,3)=(0,5)
LSYM   55     00000000 vsize_t:t(3,4)=(0,5)
LSYM   58     00000000 register_t:t(3,5)=(0,1)
EINCL  0      00000000 
BINCL  0      000018e7 /home/proven/woods/NetBSD-1.6.x-i386-destdir/usr/include/machine/ansi.h
LSYM   0      00000000 __mbstate_t:t(8,1)=(8,2)=u128__mbstate8:(8,3)=ar(0,1);0;127;(0,2),0,1024;?


On the other hand objdump also complains about other binaries that gdb
is happy with:

$ file /build/woods/proven/NetBSD-1.6.x-i386-destdir/bin/sh 
/build/woods/proven/NetBSD-1.6.x-i386-destdir/bin/sh: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for NetBSD, statically linked, not stripped
$ objdump -g /build/woods/proven/NetBSD-1.6.x-i386-destdir/bin/sh   

/build/woods/proven/NetBSD-1.6.x-i386-destdir/bin/sh:     file format elf32-i386

Bad stab: __mbstate8:(8,3)=ar(0,1);0;127;(0,2),0,1024;?
Last stabs entries before error:
n_type n_desc n_value  string
LSYM   50     00000000 __uint16_t:t(7,4)=(0,9)
LSYM   51     00000000 __int32_t:t(7,5)=(0,1)
LSYM   52     00000000 __uint32_t:t(7,6)=(0,4)
LSYM   58     00000000 __int64_t:t(7,7)=(0,6)
LSYM   60     00000000 __uint64_t:t(7,8)=(0,7)
LSYM   67     00000000 __intptr_t:t(7,9)=(0,3)
LSYM   68     00000000 __uintptr_t:t(7,10)=(0,5)
EINCL  0      00000000 
LSYM   52     00000000 paddr_t:t(3,1)=(0,5)
LSYM   53     00000000 psize_t:t(3,2)=(0,5)
LSYM   54     00000000 vaddr_t:t(3,3)=(0,5)
LSYM   55     00000000 vsize_t:t(3,4)=(0,5)
LSYM   58     00000000 register_t:t(3,5)=(0,1)
EINCL  0      00000000 
BINCL  0      000018e7 /build/woods/proven/NetBSD-1.6.x-i386-destdir/usr/include/machine/ansi.h
LSYM   0      00000000 __mbstate_t:t(8,1)=(8,2)=u128__mbstate8:(8,3)=ar(0,1);0;127;(0,2),0,1024;?


Does anyone have any ideas as to what might be going on here?


FYI, I'm trying to debug xclock where it fails when I try to run it in
"-digital" mode:

$ gdb ./xclock
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) run -digital
Starting program: /build/woods/proven/NetBSD-1.6.x-i386-i386-obj/xsrc/xfree/xc/programs/xclock/./xclock -digital
Xlib:  extension "RENDER" missing on display "very.weird.com:0.0".
Warning: Cannot convert string "" to type XftFont

Program received signal SIGSEGV, Segmentation fault.
0x805013b in XftCharIndex ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
167     }
(gdb) where
#0  0x805013b in XftCharIndex ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#1  0x804cbb0 in XftTextExtents8 ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#2  0x8048d7f in Initialize ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#3  0x80e19fd in CallInitialize ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#4  0x80e1da2 in xtCreate ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#5  0x80e218d in _XtCreateWidget ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#6  0x80e21de in XtCreateManagedWidget ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#7  0x80486eb in main ()
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/../common_elf/crtbegin.c:167
#8  0x804825c in ___start (argc=2, argv=0xbfbfcd88, envp=0xbfbfcd94, 
    cleanup=0, obj=0x0, ps_strings=0xbfbfdff0)
    at /work/woods/m-NetBSD-1.6/lib/csu/i386_elf/crt0.c:94
(gdb) 

So far it's the only X program from XF4.3.0/i386 that I've had problems
with, though I've not run a whole lot of the other programs I've built
this way yet (I have run XFree86, xterm, xdpyinfo, xload, xman, twm,
ico, x11perf, sxpm, and maybe a few others).

-- 
						Greg A. Woods

+1 416 218-0098                  VE3TCP            RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>          Secrets of the Weird <woods@weird.com>