>From de7c4824c7d839ff4deacf0772c27de46a753b56 Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Wed, 11 Jan 2012 14:45:09 +0000 Subject: [PATCH] Add the ability to preseve debug information in a separate debuginfo archive based on a patch by Reini Urban http://cygwin.com/ml/cygwin/2009-08/msg00124.html If _CYGPORT_RESTRICT_debug_ is defined, instead of stripping executable files, split the debug info into .dbg files placed into /usr/lib/debug, and then assemble those files into a debuginfo archive. Signed-off-by: Jon TURNEY --- bin/cygport.in | 5 ++++- lib/pkg_pkg.cygpart | 14 +++++++++++++- lib/src_postinst.cygpart | 29 +++++++++++++++++++++++++++-- lib/src_prep.cygpart | 2 +- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/bin/cygport.in b/bin/cygport.in index a3625bb..2b754a5 100755 --- a/bin/cygport.in +++ b/bin/cygport.in @@ -460,6 +460,7 @@ declare -r logdir="${workdir}/log"; declare -r patchdir="${workdir}/patch"; declare -r spkgdir="${workdir}/spkg"; declare -r distdir="${workdir}/dist"; +declare -r dbgdir="${workdir}/dbg"; SRC_DIR=${SRC_DIR:-${ORIG_PN:-${PN}}-${PV}}; if [ "x${SRC_DIR}" = "x." ] @@ -530,6 +531,8 @@ declare -r src_patchfile=${PF}.src.patch; declare -ar pkg_name=(${PKG_NAMES:-${PN}}); declare -r pkg_count=${#pkg_name[*]}; +declare -r dbgpath=/usr/lib/debug + ################################################################################ # # Command processing @@ -593,7 +596,7 @@ do package|pkg) __stage Packaging; __log_init ${pkglog}; - (__pkg_binpkg && __pkg_pkgcheck && __pkg_srcpkg && __pkg_dist) 2>&1 | tee -a ${pkglog}; + (__pkg_binpkg && __pkg_pkgcheck && __pkg_srcpkg && __pkg_dbgpkg && __pkg_dist) 2>&1 | tee -a ${pkglog}; _status=$?; ;; diff|mkdiff|mkpatch) diff --git a/lib/pkg_pkg.cygpart b/lib/pkg_pkg.cygpart index e4df744..1cac55c 100644 --- a/lib/pkg_pkg.cygpart +++ b/lib/pkg_pkg.cygpart @@ -399,5 +399,17 @@ __pkg_dist() { fi } +__pkg_dbgpkg() { + if defined _CYGPORT_RESTRICT_debug_ + then + + echo; + __step "Creating debuginfo package"; + + cd ${dbgdir}; + tar jcvf ${top}/${PF}-debuginfo.tar.bz2 * || error "Debuginfo package creation failed" + fi +} + # protect functions -readonly -f __pkg_binpkg __pkg_diff __gpg_sign __pkg_srcpkg __pkg_dist +readonly -f __pkg_dbgpkg __pkg_binpkg __pkg_diff __gpg_sign __pkg_srcpkg __pkg_dist diff --git a/lib/src_postinst.cygpart b/lib/src_postinst.cygpart index afc97b6..0582985 100644 --- a/lib/src_postinst.cygpart +++ b/lib/src_postinst.cygpart @@ -542,7 +542,13 @@ __prepstrip() { cd ${D}; - echo "Stripping executables:"; + if defined _CYGPORT_RESTRICT_debug_ + then + echo "Creating debug files, stripping executables and adding debuglink:"; + rm -fr ${dbgdir}/*; + else + echo "Stripping executables:"; + fi # *.so: Apache2 modules, OCaml stublibs, Ruby modules # *.oct: Octave modules @@ -609,7 +615,26 @@ __prepstrip() { echo " ${exe}"; chmod 0755 ${exe}; - ${strip} ${exe}; + + # ensure this is actually a PE-COFF object + if ${OBJDUMP} -f ${exe} &>/dev/null + then + if defined _CYGPORT_RESTRICT_debug_ + then + pathname=$(dirname ${exe}) + dbg=$(basename ${exe%.*}).dbg + mkdir -p ${dbgdir}${dbgpath}/${pathname} + # objcopy requires the file we are debuglinking with exists, so make it here and then move it under ${dbgdir} + # gdb has the intelligence to look in ${dbgpath}/${pathname}/ for the .dbg file, so we don't need to give the full path + objcopy --only-keep-debug ${exe} ${dbg} + objcopy --strip-debug ${exe} + objcopy --add-gnu-debuglink=${dbg} ${exe} + mv ${dbg} ${dbgdir}${dbgpath}/${pathname}/ + else + ${strip} ${exe}; + fi + fi + done } diff --git a/lib/src_prep.cygpart b/lib/src_prep.cygpart index 5d64408..59d4f24 100644 --- a/lib/src_prep.cygpart +++ b/lib/src_prep.cygpart @@ -198,7 +198,7 @@ __gpg_verify() { __mkdirs() { cd ${top}; - mkdir -p ${srcdir} ${origsrcdir} ${B} ${D} ${T} ${configdir} ${logdir} ${distdir} ${patchdir} ${spkgdir}; + mkdir -p ${srcdir} ${origsrcdir} ${B} ${D} ${T} ${configdir} ${logdir} ${distdir} ${patchdir} ${spkgdir} ${dbgdir}; } cygpatch() { -- 1.7.5.1