[11/11,gdb/testsuite] Don't use readelf in gdb/contrib/cc-with-tweaks.sh

Message ID 20240521154415.9543-11-tdevries@suse.de
State New
Headers
Series [01/11,gdb/testsuite] Add gdb.base/fission-macro.exp |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom de Vries May 21, 2024, 3:44 p.m. UTC
  Readelf is used in gdb/contrib/cc-with-tweaks.sh to find the .dwo files to put
into a .dwp package.

Usage a more basic method for this: assume a .dwo file for each .o file in the
link line.

Verified using shellcheck.

PR/testsuite 31754
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31754
---
 gdb/contrib/cc-with-tweaks.sh | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
  

Patch

diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh
index f760bd7c0a1..036f3e9d394 100755
--- a/gdb/contrib/cc-with-tweaks.sh
+++ b/gdb/contrib/cc-with-tweaks.sh
@@ -70,7 +70,6 @@  then
 fi
 
 OBJCOPY=${OBJCOPY:-objcopy}
-READELF=${READELF:-readelf}
 
 DWZ=${DWZ:-dwz}
 DWP=${DWP:-dwp}
@@ -280,14 +279,18 @@  elif [ "$want_multi" = true ]; then
 fi
 
 if [ "$want_dwp" = true ]; then
-    dwo_files=$($READELF -wi "${output_file}" | grep _dwo_name | \
-	sed -e 's/^.*: //' | sort | uniq)
+    dwo_files=()
+    for arg in "$@"; do
+	if echo "$arg" | grep -Eq "\.o$"; then
+	    dwo_files=("${dwo_files[@]}" "${arg/.o/.dwo}")
+	fi
+    done
     rc=0
-    if [ -n "$dwo_files" ]; then
-	$DWP -o "${output_file}.dwp" ${dwo_files} > /dev/null
+    if [ ${#dwo_files[@]} -ne 0 ]; then
+	$DWP -o "${output_file}.dwp" "${dwo_files[@]}" > /dev/null
 	rc=$?
 	[ $rc != 0 ] && exit $rc
-	rm -f ${dwo_files}
+	rm -f "${dwo_files[@]}"
     fi
 fi