From patchwork Tue May 7 16:13:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 32595 Received: (qmail 9048 invoked by alias); 7 May 2019 16:13:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 8741 invoked by uid 89); 7 May 2019 16:13:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=HTo:U*palves X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 May 2019 16:13:52 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 8491CAC8A; Tue, 7 May 2019 16:13:50 +0000 (UTC) Subject: [RFC, gdb/contrib] Fix gdb/contrib/gdb-add-index.sh for dwz-m-ed execs From: Tom de Vries To: gdb-patches@sourceware.org, Simon Marchi , Pedro Alves References: <20190507144207.GA17626@delia> Message-ID: Date: Tue, 7 May 2019 18:13:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190507144207.GA17626@delia> X-IsSubscribed: yes [ was: Re: [PATCH][gdb] Write index for dwz -m file ] Hi, This is a follow-up patch for "[gdb] Write index for dwz -m file". Any comments on the updated gdb/contrib/gdb-add-index.sh script? In particular, I'd like some advice on whether I should add shell variables (as I've done for readelf) for grep, tail and sed. Thanks, - Tom [gdb/contrib] Fix gdb/contrib/gdb-add-index.sh for dwz-m-ed execs Atm gdb-add-index.exp fails with target board cc-with-dwz-m. Fix this by updating gdb/contrib/gdb-add-index.sh to handle a dwz-m-ed executable. Tested on x86_64-linux. gdb/ChangeLog: 2019-05-07 Tom de Vries PR gdb/24445 * contrib/gdb-add-index.sh: Update to handle dwz-m-ed executable. --- gdb/contrib/gdb-add-index.sh | 134 +++++++++++++++++++++++++++---------------- 1 file changed, 86 insertions(+), 48 deletions(-) diff --git a/gdb/contrib/gdb-add-index.sh b/gdb/contrib/gdb-add-index.sh index efaad1dce7..afedce0c84 100755 --- a/gdb/contrib/gdb-add-index.sh +++ b/gdb/contrib/gdb-add-index.sh @@ -20,6 +20,7 @@ # If not, or you want others, pass the following in the environment GDB=${GDB:=gdb} OBJCOPY=${OBJCOPY:=objcopy} +READELF=${READELF:=readelf} myname="${0##*/}" @@ -43,15 +44,40 @@ fi dir="${file%/*}" test "$dir" = "$file" && dir="." -index4="${file}.gdb-index" -index5="${file}.debug_names" -debugstr="${file}.debug_str" -debugstrmerge="${file}.debug_str.merge" -debugstrerr="${file}.debug_str.err" -rm -f $index4 $index5 $debugstr $debugstrmerge $debugstrerr +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) +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 "$file" + tmp_files="$tmp_files $index4 $index5 $debugstr $debugstrmerge $debugstrerr" +done + +rm -f $tmp_files + # Ensure intermediate index file is removed when we exit. -trap "rm -f $index4 $index5 $debugstr $debugstrmerge $debugstrerr" 0 +trap "rm -f $tmp_files" 0 $GDB --batch -nx -iex 'set auto-load no' \ -ex "file $file" -ex "save gdb-index $dwarf5 $dir" || { @@ -67,50 +93,62 @@ $GDB --batch -nx -iex 'set auto-load no' \ # already stripped binary, it's a no-op. status=0 -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 +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 - debugstrupdate=true - cat >&2 $debugstrerr + 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 - 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" + $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 +} - 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" +handle_file "$dwz_file" exit $status