[pacman-dev] [PATCH] makepkg: Include more source files in debug packages.

Austin Lund austin.lund at gmail.com
Thu Feb 20 01:51:43 UTC 2020


Currently only the file pointed to by the DW_AT_name is included as a source
file in debug packages.  This means many files that are useful for debugging are
not included.  For example, no header files are included but yet these may by
referenced in the .debug_line section.

This sed script converts into shell variables the debug dump information from
readelf about compilation units, directory tables and file tables.  This can be
used to get the full path of all the source files from within the package being
compiled that are referenced in the debugging information.  Also, placeholder
symbols (e.g. <builtin>) and paths outside the current source (e.g. linked
libraries) will be more consistently ignored from inclusion in the debug
packages.

Signed-off-by: Austin Lund <austin.lund at gmail.com>
---
 scripts/libmakepkg/tidy/strip.sh.in | 46 +++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

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 == "<artificial>") 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
-- 
2.25.0


More information about the pacman-dev mailing list