Introduce a new config symbol EXTRACT_DEBUGINFO to extract debuginfo from all binaries. This depends on USE_STRIP and DEBUG.
The debuginfo of all packages will be extracted from the binary and copied into "bin/$platform/debuginfo". This allows better debugging of coredumps by loading the debuginfo into gdb. Signed-off-by: Helmut Schaa <helmut.sc...@googlemail.com> --- Any comments? Helmut config/Config-build.in | 10 ++++++++++ include/package-ipkg.mk | 5 ++++- rules.mk | 9 +++++++++ scripts/extract-debug.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 scripts/extract-debug.sh diff --git a/config/Config-build.in b/config/Config-build.in index 371ae76..60b0975 100644 --- a/config/Config-build.in +++ b/config/Config-build.in @@ -165,6 +165,16 @@ menu "Global build settings" This will install binaries stripped using sstrip endchoice + config EXTRACT_DEBUGINFO + bool + prompt "Extract debug info from binaries" + depends on USE_STRIP + depends on DEBUG + default n + help + Extract debuginfo from binaries for better cross debugging without + wasting space on the target device. + config STRIP_ARGS string prompt "Strip arguments" diff --git a/include/package-ipkg.mk b/include/package-ipkg.mk index 9783a63..b64775e 100644 --- a/include/package-ipkg.mk +++ b/include/package-ipkg.mk @@ -76,6 +76,7 @@ ifeq ($(DUMP),) define BuildTarget/ipkg IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1) + DDIR_$(1):=$(PKG_BUILD_DIR)/debuginfo-$(PKGARCH) KEEP_$(1):=$(strip $(call Package/$(1)/conffiles)) ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT))) @@ -134,7 +135,7 @@ ifeq ($(DUMP),) $(PKG_INFO_DIR)/$(1).provides: $$(IPKG_$(1)) $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk @rm -rf $(PACKAGE_DIR)/$(1)_* $$(IDIR_$(1)) - mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR) + mkdir -p $(PACKAGE_DIR) $(DEBUGINFO_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR) $$(DDIR_$(1)) $(call Package/$(1)/install,$$(IDIR_$(1))) -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf @( \ @@ -148,6 +149,7 @@ ifeq ($(DUMP),) $(if $(PROVIDES),@for pkg in $(PROVIDES); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done) $(CheckDependencies) + $(EXTRACT_DEBUG) $$(DDIR_$(1)) $$(IDIR_$(1)) $(RSTRIP) $$(IDIR_$(1)) ( \ echo "Package: $(1)"; \ @@ -187,6 +189,7 @@ ifeq ($(DUMP),) ) endif + if [ -e $$(DDIR_$(1))/* ]; then cp -r $$(DDIR_$(1))/* $(DEBUGINFO_DIR)/ ; fi $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR) @[ -f $$(IPKG_$(1)) ] diff --git a/rules.mk b/rules.mk index a84636a..6d01c76 100644 --- a/rules.mk +++ b/rules.mk @@ -98,6 +98,7 @@ else endif PACKAGE_DIR:=$(BIN_DIR)/packages +DEBUGINFO_DIR:=$(BIN_DIR)/debuginfo BUILD_DIR:=$(BUILD_DIR_BASE)/$(TARGET_DIR_NAME) STAGING_DIR:=$(TOPDIR)/staging_dir/$(TARGET_DIR_NAME) BUILD_DIR_TOOLCHAIN:=$(BUILD_DIR_BASE)/$(TOOLCHAIN_DIR_NAME) @@ -257,6 +258,14 @@ else $(SCRIPT_DIR)/rstrip.sh endif +ifeq ($(CONFIG_EXTRACT_DEBUGINFO),y) + EXTRACT_DEBUG:= \ + OBJCOPY=$(TARGET_CROSS)objcopy \ + $(SCRIPT_DIR)/extract-debug.sh +else + EXTRACT_DEBUG:=: +endif + ifeq ($(CONFIG_IPV6),y) DISABLE_IPV6:= else diff --git a/scripts/extract-debug.sh b/scripts/extract-debug.sh new file mode 100644 index 0000000..188be2d --- /dev/null +++ b/scripts/extract-debug.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2014 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +SELF=${0##*/} + +[ -z "$OBJCOPY" ] && { + echo "$SELF: objcopy command not defined (OBJCOPY variable not set)" + exit 1 +} + +DESTDIR=$1 + +[ -z "$DESTDIR" ] && { + echo "$SELF: no destdir specified" + exit 1 +} + +TARGET=$2 + +[ -z "$TARGET" ] && { + echo "$SELF: no directories / files specified" + echo "usage: $SELF [PATH...]" + exit 1 +} + +find $TARGET -type f -a -exec file {} \; | \ + sed -n -e 's/^\(.*\):.*ELF.*\(executable\|shared object\).*,.* stripped/\1:\2/p' | \ +( + IFS=":" + while read F S; do + echo "$SELF: $F:$S" + eval "mkdir -p $DESTDIR/`echo ${F%/*} | sed s#$TARGET##`" + eval "$OBJCOPY --only-keep-debug $F $DESTDIR/`echo $F | sed s#$TARGET##`.debug" + eval "$OBJCOPY --add-gnu-debuglink=$DESTDIR/`echo $F | sed s#$TARGET##`.debug $F" + done + true +) -- 1.8.4.5 _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel