Subject: gdb versus threads?
To: None <netbsd-users@netbsd.org>
From: Ben Collver <collver@peak.org>
List: netbsd-users
Date: 05/29/2006 08:06:42
I am having trouble printing some variables in GDB on NetBSD/i386 3.0.
A friendly bird told me that it may be related to threads, and that the
-current gdb6 (not pkgsrc) sources may help.  I tried building gdb6 on
NetBSD 3.0 from -current sources, but it did not help.

I first noticed it while debugging csound4, so I will show an example
from csound4.  Unfortunately, I did not log the original case.  At that
time, gdb was printing bogus values instead of having trouble accessing
memory.

Included in this email is a log of my session in both gdb5 and gdb6.

Any recommendations?

Thank you,

Ben


environment
-----------
NetBSD/i386 3.0 and pkgsrc-current
cd audio/csound4
patch Makefile for non-optimized debug build
  -CFLAGS+=               -g
  +CFLAGS=                -g -O0
make
cd work/csound-4.23f13gbs.0/csound
ftp http://terrorpin.net/~ben/docs/alt/music/csound/work/8-loscil-loop.csd
ftp http://terrorpin.net/~ben/docs/alt/music/csound/work/aif.aifc

First, I single-step 13 times to show how the gdb flow looks.  Then, I
show that I am unable to print a long variable, and what gdb thinks that
variable's address is.


gdb 5 session
-------------
$ /usr/bin/gdb ./csound
GNU gdb 5.3nb1
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) b aifc.c:275
Breakpoint 1 at 0x80f384d: file aifc.c, line 275.
(gdb) set args -W -o test.wav 8-loscil-loop.csd
(gdb) r
Starting program: /home/ben/src/netbsd/current/pkgsrc/audio/csound4/work/csound-4.23f13gbs.0/csound/csound -W -o test.wav 8-loscil-loop.csd
Using csound.xmg
0dBFS level = 32767.0
Csound Version 4.23f13 (May 27 2006)
UnifiedCSD:  8-loscil-loop.csd
STARTING FILE
Creating options
Creating orchestra
Creating /var/tmp/tmp.0.00010315aa.orc (0xbd708790)
Creating score
orchname:  /var/tmp/tmp.0.00010315aa.orc
scorename: /var/tmp/tmp.1.00010315ab.sco
orch compiler:
9 lines read
sorting score ...
        ... done
Csound Version 4.23f13 (May 27 2006)
0dBFS level = 32767.0
orch now loaded
audio buffered in 1024 sample-frame blocks
SFDIR undefined.  using current directory
writing 2048-byte blks of shorts to test.wav (WAV)
SECTION 1:
ftable 1:
deferred alloc
[Switching to LWP 1]

Breakpoint 1, aifcReadHeader (fd=???, fname=???, hdr=???, firstlong=???, p=???)
    at aifc.c:275
275         hdr->readlong = FALSE;
Current language:  auto; currently c
(gdb) n
277           if (sreadin(fd,(char *)&ckHdr,sizeof(CkHdr),p) < sizeof(CkHdr))
(gdb) n
279           pos = lseek(fd,(off_t)0L,SEEK_CUR);
(gdb) n
0x0804c6ac in Fl_Window::hide() ()
(gdb) n
Single stepping until exit from function _ZN9Fl_Window4hideEv,
which has no line number information.
aifcReadHeader (fd=???, fname=???, hdr=???, firstlong=???, p=???) at aifc.c:281
281           if (ckHdr.ckID == *(long *) FVER_ID) {
(gdb) n
282             sreadin(fd,(char *) &fver_version,sizeof(long),p);
(gdb) n
284             fver_read =1;
(gdb) n
458           if (hdr->hdrsize + hdr->audsize - sizeof(ckHdr) ==
(gdb) n
463             ckSize = natlong(ckHdr.ckSize); /* else seek past this chunk to nxt */
(gdb) n
464             if (ckSize & 1)  ckSize++;      /*      rnded up to even byte bndry */
(gdb) n
465             if (lseek(fd, (off_t)(pos + ckSize), 0) != pos + ckSize)
(gdb) n
0x0804c6ac in Fl_Window::hide() ()
(gdb) n
Single stepping until exit from function _ZN9Fl_Window4hideEv,
which has no line number information.
aifcReadHeader (fd=???, fname=???, hdr=???, firstlong=???, p=???) at aifc.c:277
277           if (sreadin(fd,(char *)&ckHdr,sizeof(CkHdr),p) < sizeof(CkHdr))
(gdb) n
279           pos = lseek(fd,(off_t)0L,SEEK_CUR);
(gdb) p pos
Error accessing memory address 0x24: Invalid argument.
(gdb) info address pos
Symbol "pos" is a local variable at frame offset 36.


gdb6 session
------------
$ gdb ./csound
GNU gdb 6.4
Copyright 2005 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-unknown-netbsdelf3.0"...
(gdb) b aifc.c:275
Breakpoint 1 at 0x80f384d: file aifc.c, line 275.
(gdb) set args -W -o test.wav 8-loscil-loop.csd
(gdb) r
Starting program: /home/ben/src/netbsd/current/pkgsrc/audio/csound4/work/csound-4.23f13gbs.0/csound/csound -W -o test.wav 8-loscil-loop.csd
Using csound.xmg
0dBFS level = 32767.0
Csound Version 4.23f13 (May 27 2006)
UnifiedCSD:  8-loscil-loop.csd
STARTING FILE
Creating options
Creating orchestra
Creating /var/tmp/tmp.0.00011024aa.orc (0xbd708790)
Creating score
orchname:  /var/tmp/tmp.0.00011024aa.orc
scorename: /var/tmp/tmp.1.00011024ab.sco
orch compiler:
9 lines read
sorting score ...
        ... done
Csound Version 4.23f13 (May 27 2006)
0dBFS level = 32767.0
orch now loaded
audio buffered in 1024 sample-frame blocks
SFDIR undefined.  using current directory
writing 2048-byte blks of shorts to test.wav (WAV)
SECTION 1:
ftable 1:
deferred alloc

Breakpoint 1, aifcReadHeader (fd=???, fname=???, hdr=???, firstlong=???, p=???)
    at aifc.c:275
275         hdr->readlong = FALSE;
Current language:  auto; currently c
(gdb) n
aifcReadHeader (fd=???, fname=???, hdr=???, firstlong=???, p=???) at aifc.c:277
277           if (sreadin(fd,(char *)&ckHdr,sizeof(CkHdr),p) < sizeof(CkHdr))
(gdb) n
sreadin (infd=???, inbuf=???, nbytes=???, p=???) at soundin.c:147
147     {                               /* on POST-HEADER reads of audio samples */
(gdb) n
sreadin (infd=-1077947664, inbuf=0x0, nbytes=-1077948072, p=0x0)
    at soundin.c:148
148             int    n, ntot=0;
(gdb) n
150             do if ((n = read(infd, inbuf+ntot, nbytes-ntot)) < 0)
(gdb)
0x0804c9bc in read@plt ()
(gdb) n
Single stepping until exit from function read@plt,
which has no line number information.
0xbd742f98 in read () from /usr/lib/libpthread.so.0
(gdb) n
Single stepping until exit from function read,
which has no line number information.
sreadin (infd=-1077947664, inbuf=0x0, nbytes=-1077948072, p=0x0)
    at soundin.c:153
153             if (p->filetyp) {                           /* for AIFF and WAV samples */
(gdb) n
177     }
(gdb) n
aifcReadHeader (fd=???, fname=???, hdr=???, firstlong=???, p=???) at aifc.c:279
279           pos = lseek(fd,(off_t)0L,SEEK_CUR);
(gdb) n
0x0804c6ac in lseek@plt ()
(gdb) n
Single stepping until exit from function lseek@plt,
which has no line number information.
0xbd6eda98 in lseek () from /usr/lib/libc.so.12
(gdb) n
Single stepping until exit from function lseek,
which has no line number information.
0xbd66800c in __syscall@plt () from /usr/lib/libc.so.12
(gdb) n
Single stepping until exit from function __syscall@plt,
which has no line number information.
0xbd6edacc in __syscall () from /usr/lib/libc.so.12
(gdb) n
Single stepping until exit from function __syscall,
which has no line number information.
0xbd6edac5 in lseek () from /usr/lib/libc.so.12
(gdb) n
Single stepping until exit from function lseek,
which has no line number information.
aifcReadHeader (fd=???, fname=???, hdr=???, firstlong=???, p=???) at aifc.c:281
281           if (ckHdr.ckID == *(long *) FVER_ID) {
(gdb) p pos
Cannot access memory at address 0x24
(gdb) info address pos
Symbol "pos" is a local variable at frame offset 36.