123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #! /bin/sh
- GDB=${GDB:=gdb}
- OBJCOPY=${OBJCOPY:=objcopy}
- READELF=${READELF:=readelf}
- myname="${0##*/}"
- dwarf5=""
- if [ "$1" = "-dwarf-5" ]; then
- dwarf5="$1"
- shift
- fi
- if test $# != 1; then
- echo "usage: $myname [-dwarf-5] FILE" 1>&2
- exit 1
- fi
- file="$1"
- if test ! -r "$file"; then
- echo "$myname: unable to access: $file" 1>&2
- exit 1
- fi
- dir="${file%/*}"
- test "$dir" = "$file" && dir="."
- dwz_file=""
- if $READELF -S "$file" | grep -q " \.gnu_debugaltlink "; then
- dwz_file=$($READELF --string-dump=.gnu_debugaltlink "$file" \
- | grep -A1 "'\.gnu_debugaltlink':" \
- | tail -n +2 \
- | sed 's/.*]//')
- dwz_file=$(echo $dwz_file)
- if $READELF -S "$dwz_file" | grep -E -q " \.(gdb_index|debug_names) "; then
-
- dwz_file=""
- fi
- fi
- set_files ()
- {
- local file="$1"
- index4="${file}.gdb-index"
- index5="${file}.debug_names"
- debugstr="${file}.debug_str"
- debugstrmerge="${file}.debug_str.merge"
- debugstrerr="${file}.debug_str.err"
- }
- tmp_files=
- for f in "$file" "$dwz_file"; do
- if [ "$f" = "" ]; then
- continue
- fi
- set_files "$f"
- tmp_files="$tmp_files $index4 $index5 $debugstr $debugstrmerge $debugstrerr"
- done
- rm -f $tmp_files
- trap "rm -f $tmp_files" 0
- $GDB --batch -nx -iex 'set auto-load no' \
- -ex "file $file" -ex "save gdb-index $dwarf5 $dir" || {
-
- status=$?
- echo "$myname: gdb error generating index for $file" 1>&2
- exit $status
- }
- status=0
- handle_file ()
- {
- local file
- file="$1"
- set_files "$file"
- if test -f "$index4" -a -f "$index5"; then
- echo "$myname: Both index types were created for $file" 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" "$file" \
- /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) \
- "$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
- fi
- }
- handle_file "$file"
- if [ "$dwz_file" != "" ]; then
- handle_file "$dwz_file"
- fi
- exit $status
|