-if test -f "$index"; then
- $OBJCOPY --add-section .gdb_index="$index" \
- --set-section-flags .gdb_index=readonly "$file" "$file"
- status=$?
-else
- echo "$myname: No index was created for $file" 1>&2
- echo "$myname: [Was there no debuginfo? Was there already an index?]" 1>&2
+handle_file ()
+{
+ fpath="$1"
+
+ set_files "$fpath"
+
+ if test -f "$index4" -a -f "$index5"; then
+ echo "$myname: Both index types were created for $fpath" 1>&2
+ status=1
+ elif test -f "$index4" -o -f "$index5"; then
+ if test -f "$index4"; then
+ index="$index4"
+ section=".gdb_index"
+ else
+ index="$index5"
+ section=".debug_names"
+ fi
+ debugstradd=false
+ debugstrupdate=false
+ if test -s "$debugstr"; then
+ if ! $OBJCOPY --dump-section .debug_str="$debugstrmerge" "$fpath" \
+ /dev/null 2>$debugstrerr; then
+ cat >&2 $debugstrerr
+ exit 1
+ fi
+ if grep -q "can't dump section '.debug_str' - it does not exist" \
+ $debugstrerr; then
+ debugstradd=true
+ else
+ debugstrupdate=true
+ cat >&2 $debugstrerr
+ fi
+ cat "$debugstr" >>"$debugstrmerge"
+ fi
+
+ $OBJCOPY --add-section $section="$index" \
+ --set-section-flags $section=readonly \
+ $(if $debugstradd; then \
+ echo --add-section .debug_str="$debugstrmerge"; \
+ echo --set-section-flags .debug_str=readonly; \
+ fi; \
+ if $debugstrupdate; then \
+ echo --update-section .debug_str="$debugstrmerge"; \
+ fi) \
+ "$fpath" "$fpath"
+
+ status=$?
+ else
+ echo "$myname: No index was created for $fpath" 1>&2
+ echo "$myname: [Was there no debuginfo? Was there already an index?]" \
+ 1>&2
+ fi
+}
+
+handle_file "$file"
+if [ "$dwz_file" != "" ]; then
+ handle_file "$dwz_file"