how to get a well debuggable busybox binary ?

whenever i try to debug busybox, gdb (7.6.2) is completely clueless, especially upon entering applet_main. for example in ping.c, after breaking on ping_main, gdb lists the BSD copyright header at the end of the file as the actual sourceline. stepping with "n" just makes the program run through.

so in the end i end up extracting all the needed code and stuff it into a standalone C file so i can manage to build it with my own debug CFLAGS, without -fomit-framepointer, FAST_FUNC, MAIN_EXTERNALLY_VISIBLE, and all the weird microoptimization c/ldflags/macros that are hardcoded everywhere, as well as the multiple levels of main() indirection. the trylink script is also completely useless for debugging as it uses dozens of exotic and untested ld flags to shave off a byte or 2.

i use the following to build busybox in "debug mode"

if [ ! -z "$DEBUGBUILD" ] ; then
        debugcflags="-O0 -g"
        sed -i 's/# CONFIG_DEBUG is not set/CONFIG_DEBUG=y/' .config
sed -i 's/# CONFIG_DEBUG_PESSIMIZE is not set/CONFIG_DEBUG_PESSIMIZE=y/' .config sed -i 's/CONFIG_NO_DEBUG_LIB=y/# CONFIG_NO_DEBUG_LIB is not set/' .config
fi

make V=1 LDFLAGS=-static HOSTLDFLAGS=-static \
CFLAGS_busybox="$debugcflags -Wl,-z,muldefs -Werror-implicit-function-declaration" \
HOSTCC="$CC -static" CC="$CC -static" HOSTCFLAGS=-D_GNU_SOURCE

and then use busybox_unstripped.

i'm pretty sure there must be a better way as i cant imagine anyone debugging busybox copy/pasting for hours. any tips are welcome.
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to