[pacman-dev] [PATCH 1/2] Build a single debug package for all packages from a PKGBUILD
We want to provide source files with debug symbol packages to allow easy stepping through the program. This becomes difficult with split packages due to the binaries in many of these sharing source files across packages. There are (at least) two solutions to this problem. #1: ensure common source files are located in the debug package for the package lowest in the dependency chain and add dependencies to the debug packages so all require source files are present, or #2: create one debug package for all split packages in a PKGBUILD. The second is a more robust approach despite potentially creating very large debug packages. This patch creates a single $pkgbase-debug package and adds provides such that installing $pkgname-debug will always work. Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/libmakepkg/tidy/strip.sh.in | 2 +- scripts/makepkg.sh.in | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 1c7aacf..9baed9f 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -88,7 +88,7 @@ tidy_strip() { [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S" if check_option "debug" "y"; then - dbgdir="$pkgdir-@DEBUGSUFFIX@/usr/lib/debug" + dbgdir="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@/usr/lib/debug" mkdir -p "$dbgdir" fi diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 2000451..de709ba 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -787,18 +787,24 @@ create_debug_package() { return fi - pkgdir="${pkgdir}-@DEBUGSUFFIX@" + pkgdir="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@" # check if we have any debug symbols to package if dir_is_empty "$pkgdir/usr/lib/debug"; then return fi - depends=("$pkgname=$(get_full_version)") - pkgdesc="Detached debugging symbols for $pkgname" - pkgname=$pkgname-@DEBUGSUFFIX@ + unset groups depends optdepends provides conflicts replaces backup install changelog - unset groups optdepends provides conflicts replaces backup install changelog + local pkg + for pkg in ${pkgname[@]}; do + if [[ $pkg != $pkgbase ]]; then + provides+=("$pkg-@DEBUGSUFFIX@") + fi + done + + pkgdesc="Detached debugging symbols for $pkgname" + pkgname=$pkgbase-@DEBUGSUFFIX@ create_package } @@ -1169,10 +1175,10 @@ run_split_packaging() { tidy_install lint_package || exit 1 create_package - create_debug_package restore_package_variables done pkgname=("${pkgname_backup[@]}") + create_debug_package } usage() { -- 2.10.2
Debug packages are fairly useless currently because the soucre files needed for stepping through code etc are not packaged with them. This patch adds the needed source files to the debug package and adjusts the debug info to look at the /usr/src/debug/ directory for them rather than the build location. This requires using the "debugedit" program which is provided as part of the RPM sources. Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/libmakepkg/tidy/strip.sh.in | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 9baed9f..ff75cb4 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -35,6 +35,11 @@ build_id() { LANG=C readelf -n $1 | sed -n '/Build ID/ { s/.*: //p; q; }' } +source_files() { + LANG=C readelf $1 --debug-dump | \ + awk '/DW_AT_name +:/{name=$8}/DW_AT_comp_dir +:/{print $8 "/" name}' +} + strip_file() { local binary=$1; shift @@ -50,6 +55,18 @@ strip_file() { return fi + # copy source files to debug directory + local f t + for f in $(source_files "$binary"); do + t=${f/$srcdir/$dbgsrc} + mkdir -p "${t%/*}" + cp "$f" "$t" + done + + # adjust debug symbols to point at sources + debugedit -b "${srcdir}" -d /usr/src/debug/ -i "$binary" &> /dev/null + + # copy debug symbols to debug directory mkdir -p "$dbgdir/${binary%/*}" objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug" objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary" @@ -88,8 +105,10 @@ tidy_strip() { [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S" if check_option "debug" "y"; then + dbgdir="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@/usr/lib/debug" - mkdir -p "$dbgdir" + dbgsrc="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@/usr/src/debug" + mkdir -p "$dbgdir" "$dbgsrc" fi local binary strip_flags -- 2.10.2
On Mon, Dec 05, 2016 at 03:02:10PM +1000, Allan McRae wrote:
Debug packages are fairly useless currently because the soucre files needed for stepping through code etc are not packaged with them. This patch adds the needed source files to the debug package and adjusts the debug info to look at the /usr/src/debug/ directory for them rather than the build location. This requires using the "debugedit" program which is provided as part of the RPM sources.
...will pacman provide a copy of debugedit?
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/libmakepkg/tidy/strip.sh.in | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 9baed9f..ff75cb4 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -35,6 +35,11 @@ build_id() { LANG=C readelf -n $1 | sed -n '/Build ID/ { s/.*: //p; q; }' }
+source_files() { + LANG=C readelf $1 --debug-dump | \
"$1"
+ awk '/DW_AT_name +:/{name=$8}/DW_AT_comp_dir +:/{print $8 "/" name}' +} + strip_file() { local binary=$1; shift
@@ -50,6 +55,18 @@ strip_file() { return fi
+ # copy source files to debug directory + local f t + for f in $(source_files "$binary"); do
http://mywiki.wooledge.org/DontReadLinesWithFor while read -r f; do ... done < <(source_files "$binary")
+ t=${f/$srcdir/$dbgsrc}
t=${f/"$srcdir"/$dbgsrc}
+ mkdir -p "${t%/*}" + cp "$f" "$t"
cp -- "$f" "$t"
+ done + + # adjust debug symbols to point at sources + debugedit -b "${srcdir}" -d /usr/src/debug/ -i "$binary" &> /dev/null + + # copy debug symbols to debug directory mkdir -p "$dbgdir/${binary%/*}" objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug" objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary" @@ -88,8 +105,10 @@ tidy_strip() { [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
if check_option "debug" "y"; then + dbgdir="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@/usr/lib/debug" - mkdir -p "$dbgdir" + dbgsrc="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@/usr/src/debug" + mkdir -p "$dbgdir" "$dbgsrc" fi
local binary strip_flags -- 2.10.2
On 07/12/16 06:17, Dave Reisner wrote:
This
requires using the "debugedit" program which is provided as part of the RPM sources. ...will pacman provide a copy of debugedit?
I did not intend to. I have packaged it for the Arch repos, but it requires librpmio meaning we would need to pull in a large chunk of the RPM sources...
participants (2)
-
Allan McRae
-
Dave Reisner