How to compile libstdc+ with debug symbols? (WITH_DEBUG doesn't work)

Status
Not open for further replies.
What's the proper way to compile i.e. libstdc+ library from /usr/src with debug symbols.
Tried:
Code:
cd /usr/src/gnu/lib/libstdc++
sudo make WITH_DEBUG=1
But it compiling with -O2 flag;/
 
:)
Workaround:
Code:
> sudo make CFLAGS="-g3 -pipe -march=nocona -DIN_GLIBCPP_V3 -DHAVE_CONFIG_H -I/usr/src/gnu/lib/libstdc++ -
I/usr/src/gnu/lib/libstdc++/../../../contrib/libstdc++/libsupc++ -I/usr/src/gnu/lib/libstdc++/../../../contrib/gcc -
I/usr/src/gnu/lib/libstdc++/../../../contrib/libstdc++/include -I/usr/src/gnu/lib/libstdc++/../../../contrib/gcclibs/include -
I/usr/src/gnu/lib/libstdc++/../../../contrib/libstdc++/include -I. -frandom-seed=RepeatabilityConsideredGood -fstack-protector"

But still doesn't generate a lot.
Code:
(gdb) bt full
#0  0x00000008092c05b7 in strlen () from /lib/libc.so.7
No symbol table info available.
#1  0x0000000808dca275 in std::distance<char const*> () from /usr/lib/libstdc++.so.6
No symbol table info available.
#2  0x0000000808dcc4c9 in std::string::assign () from /usr/lib/libstdc++.so.6
No symbol table info available.
#3  0x0000000808dcc4f9 in std::string::operator= () from /usr/lib/libstdc++.so.6
No symbol table info available.
Tried as well with:
Code:
LFLAGS="/usr/src/gnu/lib/libstdc++"
No symbols:
Code:
> objdump -g /usr/lib/libstdc++.so.6
/usr/lib/libstdc++.so.6:     file format elf64-x86-64
objdump: /usr/lib/libstdc++.so.6: no recognized debugging information
> nm /usr/lib/libstdc++.so.6
nm: /usr/lib/libstdc++.so.6: no symbols
Why?
 
WITH_DEBUG is not respected under /usr/src, only DEBUG_FLAGS. Try
$ make all install DEBUG_FLAGS='-O0 -ggdb3' -C gnu/lib/libstdc++
it should install unstripped library.
 
eye said:
WITH_DEBUG is not respected under /usr/src, only DEBUG_FLAGS. Try
$ make all install DEBUG_FLAGS='-O0 -ggdb3' -C/usr/src/gnu/lib/libstdc++
it should install unstripped library.

LOL, almost:)

Compiling with command above, generated flags are:
Code:
c++ -O2 -pipe -march=nocona -DIN_GLIBCPP_V3 -DHAVE_CONFIG_H
-I/usr/src/gnu/lib/libstdc++ (.more.-I..) -I.
-frandom-seed=RepeatabilityConsideredGood
-O0 -ggdb3 -fstack-protector
-fno-implicit-templates -ffunction-sections -fdata-sections  -Wno-deprecated 
-c /usr/src/gnu/lib/libstdc++/../../../contrib/libstdc++/src/bitmap_allocator.cc
Additional -O2 is added, how to get rid of it?
Following this, it says: -lm and -L should be provided?
When I added -lm into DEBUG_FLAGS and -L into LFLAGS as follows:
Code:
LFLAGS="-L /usr/src/gnu/lib/libstdc++ -L/usr/src/contrib/libstdc++/src"
, it says:
Code:
c++: -lm: linker input file unused because linking not done
 
Tried as well something with obj and depend from here:
Code:
> sudo make obj depend all install DEBUG_FLAGS='-O0 -ggdb3' -C/usr/src/gnu/lib/libstdc++
Still no symbols.
Tried as well this and this.

Man src.conf.
 
Success!:)

Code:
> sudo make CFLAGS="-Wall -lm -pipe -march=nocona -DIN_GLIBCPP_V3 -DHAVE_CONFIG_H -I/usr/src/gnu/lib/libstdc++ -
I/usr/src/gnu/lib/libstdc++/../../../contrib/libstdc++/libsupc++ -I/usr/src/gnu/lib/libstdc++/../../../contrib/gcc -
I/usr/src/gnu/lib/libstdc++/../../../contrib/libstdc++/include -I/usr/src/gnu/lib/libstdc++/../../../contrib/gcclibs/include -
I/usr/src/gnu/lib/libstdc++/../../../contrib/libstdc++/include -I. -frandom-seed=RepeatabilityConsideredGood -fstack-protector -
L/usr/src/gnu/lib/libstdc++ -L/usr/src/contrib/libstdc++/src -L. -L/usr/src/contrib/libstdc++" DEBUG_FLAGS='-O0 -ggdb3' -C 
/usr/src/gnu/lib/libstdc++ && nm /usr/lib/libstdc++.so.6 | wc -l
    4251
Basically I've replaced CFLAGS to not have additional -O2 and added -lm (now linking works correctly).
 
-O0 is enough to cancel effect of -O2 (which is added from sys.mk) but it is not required to produce useful backtraces. If it doesn't compile with above DEBUG_FLAGS it's probably because of your broken environment. Also, specifying CFLAGS/LDFLAGS on command line overrides them in makefiles, i.e. asking for things to break.
 
This topic is better suited for the FreeBSD developer mailing lists.
 
Status
Not open for further replies.
Back
Top