diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 2b6f732d..2598d606 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -35,9 +35,51 @@ build_id() { LANG=C readelf -n "$1" | sed -n '/Build ID/ { s/.*: //p; q; }' } +_source_files_sedscript='1 { a \ +declare -A COMPDIR +} +/^Contents of the .debug_info section:$/,/^[^[:space:]]/ { +/^ <0>.*\(DW_TAG_compile_unit\)$/,/^ {0,3}[^[:space:]]/{ + /^ <0>.*\(DW_TAG_compile_unit\)$/{h;d} + /^ {0,3}[^[:space:]]/{ + x + s/(.*)/\n&\n/ + s/.*DW_AT_comp_dir[^\n]*: ([^\n]*)\n.*/'\''\1'\''&/ + s/.*DW_AT_stmt_list[^\n]*: ([^\n]*)\n.*/COMPDIR\[\1\]=&/ + P;d + } + H + d +} +} +/^Raw dump of debug contents of section .debug_line:$/,/^[^[:space:]]/ { +/^ Offset:/,/^ Line Number Statements:$/ { + /^ Offset:/ { + a \ +unset DIRTABLE\ +unset FILETABLE + + s/.*(0x[[:xdigit:]]+)$/OFFSET=\1/; p; d } + /^ The Directory Table/,/^$/ { + /^ [[:digit:]]+\t[^/.]/ { + s/^ ([[:digit:]]+)\t(.*)/DIRTABLE[\1]=\$\{COMPDIR\[\$OFFSET]\}\/\2/ + p; d + } + d + } + /^ The File Name Table/,/^$/ { + /^ [[:digit:]]+\t[1-9]/ { + s/^ [[:digit:]]+\t([[:digit:]]+)\t.*\t(.*)$/\[\[ -v DIRTABLE\[\1\] \]\] \&\& echo \$\{DIRTABLE\[\1\]\}\/\2/ + p; d + } + d + } +} +}' + source_files() { LANG=C readelf "$1" --debug-dump | \ - awk '/DW_AT_name +:/{name=$8}/DW_AT_comp_dir +:/{{if (name == "") next}{if (name !~ /^[<\/]/) {printf "%s/", $8}}{print name}}' + sed -n -E -e "${_source_files_sedscript}" | /bin/bash } strip_file() { @@ -60,7 +102,7 @@ strip_file() { while IFS= read -r t; do f=${t/${dbgsrcdir}/"$srcdir"} mkdir -p "${dbgsrc/"$dbgsrcdir"/}${t%/*}" - cp -- "$f" "${dbgsrc/"$dbgsrcdir"/}$t" + cp -n -- "$f" "${dbgsrc/"$dbgsrcdir"/}$t" done < <(source_files "$binary") # copy debug symbols to debug directory