Static Library Debug Symbols

Static library debug symbols

If you use /ZI or /Zi (C/C++ -> General -> Debug Information Format), then the vc$(PlatformToolsetVersion).pdb is created, which contains the debug info for all of the .obj files created. If alternately you use /Z7, the debug info will be embedded into the .obj file, and then embedded into the .lib. This is probably the easiest way to distribute the debug info for a static library.

I wouldn't advise distributing a static library, however, since it's generally tied to a specific version of the compiler.

How to separate debug symbols from a C static library and later load it in GDB

Don't do this:

objcopy --only-keep-debug lib_mylib.o lib_mylib.o.debug

(It only works for shared libraries.)

Do this instead:

cp lib_mylib.o lib_mylib.o.debug

Even easier may be to keep lib_mylib.o untouched, and strip debug symbols from the executable at link time:

gcc -g driver.c -o driver -L. -l_mylib -Wl,-s

And easier still: link the binary with debug info and keep it for debugging, but use stripped executable where you need it to be stripped:

gcc -g driver.c -o driver-dbg -L. -l_mylib &&
strip -g -o driver driver-dbg

With above, you wouldn't need to add-symbol-file, just point GDB to driver-dbg and it will do everything automatically.

Strip/Remove debug symbols and archive names from a static library

This script implements Sigismondo's suggestion (unpacks the archive, strips each object file individually, renames them 1000.o, 1001.o, etc., and repacks). The parameters for ar crus may vary depending on your version of ar.

#!/bin/bash
# usage: repack.sh file.a

if [ -z "$1" ]; then
echo "usage: repack file.a"
exit 1
fi

if [ -d tmprepack ]; then
/bin/rm -rf tmprepack
fi

mkdir tmprepack
cp $1 tmprepack
pushd tmprepack

basename=${1##*/}

ar xv $basename
/bin/rm -f $basename
i=1000
for p in *.o ; do
strip -d $p
mv $p ${i}.o
((i++))
done

ar crus $basename *.o
mv $basename ..

popd
/bin/rm -rf tmprepack
exit 0


Related Topics



Leave a reply



Submit