Discussion:
<value optimized out> even with gcc -g -O0
Chuck Anderson
2010-02-01 06:18:26 UTC
Permalink
I'm trying to debug an issue for the upstream author of ocp and am
running into an issue where gdb is showing "<value optimized out>" for
variables even though I've compiled the program with gcc -g -O0. Are
there any gcc/gdb gurus who can help?

Compiler excerpts:

gcc -g -O0 -fPIC -Wall -I.././ -I.././gnulib kickload.c -o kickload.o -c
gcc -g -O0 -fPIC -Wall -I.././ -I.././gnulib compdate.c -o compdate.o -c
...
gcc -g -O0 -fPIC -Wall -I./ -I./gnulib -o ocp boot/kickload.o -pthread -ldl goodies/helpc/ocphhc doc/opencp.dox ocp.hlp

gdb output:

Program received signal SIGSEGV, Segmentation fault.
playmonoi16 (dst=0x76ddc0, len=<value optimized out>,
ch=<value optimized out>) at mixasm.c:1746
1746 *(dst++)+=voltabs[0]
(gdb) p dst
$1 = (int32_t *) 0x76ddc0
(gdb) p len
$2 = <value optimized out>
(gdb) p ch
$3 = <value optimized out>
(gdb) p *ch
Cannot access memory at address 0x0
(gdb) up
#1 0x00007ffff5948257 in mixPlayChannel (dst=<value optimized out>,
len=<value optimized out>, ch=0x779df0, stereo=<value optimized
out>)
at mixasm.c:2022
2022 playrout(dst, mylen, ch);
(gdb) p stereo
$4 = <value optimized out>


Thanks!
Gianluca Sforna
2010-02-01 08:34:19 UTC
Permalink
Post by Chuck Anderson
Program received signal SIGSEGV, Segmentation fault.
playmonoi16 (dst=0x76ddc0, len=<value optimized out>,
? ?ch=<value optimized out>) at mixasm.c:1746
Sorry for asking the obvious, but this hit me several times... is this
mixasm.c file part of the sources you are compiling with -g -O0? if
it's in a library your code is using, you also need to recompile that
one with -O0.
--
Gianluca Sforna

http://morefedora.blogspot.com
http://www.linkedin.com/in/gianlucasforna
Chuck Anderson
2010-02-01 13:14:24 UTC
Permalink
Post by Gianluca Sforna
Post by Chuck Anderson
Program received signal SIGSEGV, Segmentation fault.
playmonoi16 (dst=0x76ddc0, len=<value optimized out>,
? ?ch=<value optimized out>) at mixasm.c:1746
Sorry for asking the obvious, but this hit me several times... is this
mixasm.c file part of the sources you are compiling with -g -O0? if
it's in a library your code is using, you also need to recompile that
one with -O0.
Yup, it is part of the source. Many/most of the files are actually
compiled as shared objects, but everything is using -g -O0. Someone
on #gdb thinks this is a gcc bug.
Roberto Ragusa
2010-02-01 15:44:17 UTC
Permalink
Post by Chuck Anderson
Post by Gianluca Sforna
Post by Chuck Anderson
Program received signal SIGSEGV, Segmentation fault.
playmonoi16 (dst=0x76ddc0, len=<value optimized out>,
ch=<value optimized out>) at mixasm.c:1746
Sorry for asking the obvious, but this hit me several times... is this
mixasm.c file part of the sources you are compiling with -g -O0? if
it's in a library your code is using, you also need to recompile that
one with -O0.
Yup, it is part of the source. Many/most of the files are actually
compiled as shared objects, but everything is using -g -O0. Someone
on #gdb thinks this is a gcc bug.
One thing I would try is adding a

int *lenp=&len;

somewhere, just to make optimization a little more difficult for gcc.
Maybe you avoid the bug, if there is one.
--
Roberto Ragusa mail at robertoragusa.it
David Malcolm
2010-02-01 15:34:51 UTC
Permalink
Post by Chuck Anderson
I'm trying to debug an issue for the upstream author of ocp and am
running into an issue where gdb is showing "<value optimized out>" for
variables even though I've compiled the program with gcc -g -O0. Are
there any gcc/gdb gurus who can help?
gcc -g -O0 -fPIC -Wall -I.././ -I.././gnulib kickload.c -o kickload.o -c
gcc -g -O0 -fPIC -Wall -I.././ -I.././gnulib compdate.c -o compdate.o -c
...
gcc -g -O0 -fPIC -Wall -I./ -I./gnulib -o ocp boot/kickload.o -pthread -ldl goodies/helpc/ocphhc doc/opencp.dox ocp.hlp
Program received signal SIGSEGV, Segmentation fault.
playmonoi16 (dst=0x76ddc0, len=<value optimized out>,
ch=<value optimized out>) at mixasm.c:1746
1746 *(dst++)+=voltabs[0]
(gdb) p dst
$1 = (int32_t *) 0x76ddc0
(gdb) p len
$2 = <value optimized out>
(gdb) p ch
$3 = <value optimized out>
(gdb) p *ch
Cannot access memory at address 0x0
(gdb) up
#1 0x00007ffff5948257 in mixPlayChannel (dst=<value optimized out>,
len=<value optimized out>, ch=0x779df0, stereo=<value optimized
out>)
at mixasm.c:2022
2022 playrout(dst, mylen, ch);
(gdb) p stereo
$4 = <value optimized out>
Not sure if it's the same bug, but I ran into similar issue when trying
to debug Python; see:
https://bugzilla.redhat.com/show_bug.cgi?id=556975
"Variables optimized out (python)"

Hope this is helpful
Dave
Jan Kratochvil
2010-02-02 20:18:07 UTC
Permalink
Post by Chuck Anderson
I'm trying to debug an issue for the upstream author of ocp and am
running into an issue where gdb is showing "<value optimized out>" for
variables even though I've compiled the program with gcc -g -O0.
[...]
Post by Chuck Anderson
gcc -g -O0 -fPIC -Wall -I.././ -I.././gnulib kickload.c -o kickload.o -c
gcc -g -O0 -fPIC -Wall -I.././ -I.././gnulib compdate.c -o compdate.o -c
...
gcc -g -O0 -fPIC -Wall -I./ -I./gnulib -o ocp boot/kickload.o -pthread -ldl goodies/helpc/ocphhc doc/opencp.dox ocp.hlp
If you list also the mixasm.c compilation line you would find:
gcc -g -O0 -fpic -Wall -I.././ -O mixasm.c -o mixasm.o -c

as there is explicit -O in dev/Makefile there. After removing it getting
a valid dump with no <value optimized out>.

For the -O build found one <value optimized out> as correct and one <value
optimized out> as some bug in either gdb or gcc but that is out of the scope
of this mail thread. -O0 -g works, NOTABUG.


Thanks,
Jan

#0 playmonoi16 (dst=0x71ff90, len=384, ch=0x72bfc0) at mixasm.c:1738
#1 0x00007ffff5d57cc7 in mixPlayChannel (dst=0x71ff90, len=384, ch=0x72bfc0, stereo=0) at mixasm.c:2022
#2 0x00007ffff5d55ba8 in putchn (chn=0x72bfc0, len=384, opt=0) at mix.c:129
#3 0x00007ffff5d55f14 in mixMixChanSamples (ch=0x7fffffffcc00, n=1, s=0x7ffff5d3fcc0, len=384, rate=22050, opt=0) at mix.c:180
#4 0x00007ffff405f312 in getchansample (this=0x7ffff4268a80, ch=9, buf=0x7ffff5d3fcc0, len=384, rate=22050, opt=0) at itplay.c:1817
#5 0x00007ffff4061fcd in itpGetLChanSample (ch=9, buf=0x7ffff5d3fcc0, len=384, rate=22050, opt=0) at itpplay.c:534
#6 0x00007ffff599375a in plDrawScopes () at cpiscope.c:365
#7 0x00007ffff5993fd0 in scoDraw () at cpiscope.c:464
#8 0x00007ffff598add2 in plmpDrawScreen () at cpiface.c:772
#9 0x00007ffff598ae30 in plmpCallBack () at cpiface.c:789
#10 0x00007ffff697be9e in _fsMain (argc=2, argv=0x7fffffffd088) at pfsmain.c:266
#11 0x00007ffff7dcc332 in init_modules (argc=2, argv=0x7fffffffd088) at pmain.c:207
#12 0x00007ffff7dcc472 in _bootup (argc=2, argv=0x7fffffffd088) at pmain.c:237
#13 0x00000000004022e0 in runocp (handle=0x6040d0, argc=2, argv=0x7fffffffd088) at kickload.c:518
#14 0x000000000040243a in main (argc=2, argv=0x7fffffffd088) at kickload.c:568
Chuck Anderson
2010-02-02 20:35:48 UTC
Permalink
Post by Jan Kratochvil
Post by Chuck Anderson
I'm trying to debug an issue for the upstream author of ocp and am
running into an issue where gdb is showing "<value optimized out>" for
variables even though I've compiled the program with gcc -g -O0.
[...]
Post by Chuck Anderson
gcc -g -O0 -fPIC -Wall -I.././ -I.././gnulib kickload.c -o kickload.o -c
gcc -g -O0 -fPIC -Wall -I.././ -I.././gnulib compdate.c -o compdate.o -c
...
gcc -g -O0 -fPIC -Wall -I./ -I./gnulib -o ocp boot/kickload.o -pthread -ldl goodies/helpc/ocphhc doc/opencp.dox ocp.hlp
gcc -g -O0 -fpic -Wall -I.././ -O mixasm.c -o mixasm.o -c
as there is explicit -O in dev/Makefile there. After removing it getting
a valid dump with no <value optimized out>.
For the -O build found one <value optimized out> as correct and one <value
optimized out> as some bug in either gdb or gcc but that is out of the scope
of this mail thread. -O0 -g works, NOTABUG.
Thanks a bunch for this!

Continue reading on narkive:
Loading...