ubsan: bpf: left shift cannot be represented in type 'DI' (aka 'long')
[deliverable/binutils-gdb.git] / gdb / contrib / cc-with-tweaks.sh
index e8e8ff007452b1ac4693e2f2f666eeb973266630..98c4f89afc9be60f45b44045802a9b9589bc6ca0 100755 (executable)
@@ -1,8 +1,8 @@
-#! /bin/sh
+#!/usr/bin/env bash
 # Wrapper around gcc to tweak the output in various ways when running
 # the testsuite.
 
-# Copyright (C) 2010-2013 Free Software Foundation, Inc.
+# Copyright (C) 2010-2019 Free Software Foundation, Inc.
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 #
 # bash$ cd $objdir/gdb/testsuite
 # bash$ runtest \
-#   CC_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS gcc" \
-#   CXX_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS g++"
+#   CC_FOR_TARGET="/bin/bash $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS gcc" \
+#   CXX_FOR_TARGET="/bin/bash $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS g++"
 #
+# For documentation on Fission and dwp files:
+#     http://gcc.gnu.org/wiki/DebugFission
+#     http://gcc.gnu.org/wiki/DebugFissionDWP
 # For documentation on index files: info -f gdb.info -n "Index Files"
 # For information about 'dwz', see the announcement:
 #     http://gcc.gnu.org/ml/gcc/2012-04/msg00686.html
 # -Z invoke objcopy --compress-debug-sections
 # -z compress using dwz
 # -m compress using dwz -m
-# -i make an index
+# -i make an index (.gdb_index)
+# -n make a dwarf5 index (.debug_names)
+# -p create .dwp files (Fission), you need to also use gcc option -gsplit-dwarf
 # If nothing is given, no changes are made
 
 myname=cc-with-tweaks.sh
+mydir=`dirname "$0"`
 
 if [ -z "$GDB" ]
 then
@@ -72,6 +78,7 @@ next_is_output_file=no
 output_file=a.out
 
 want_index=false
+index_options=""
 want_dwz=false
 want_multi=false
 want_dwp=false
@@ -82,6 +89,7 @@ while [ $# -gt 0 ]; do
        -Z) want_objcopy_compress=true ;;
        -z) want_dwz=true ;;
        -i) want_index=true ;;
+       -n) want_index=true; index_options=-dwarf-5;;
        -m) want_multi=true ;;
        -p) want_dwp=true ;;
        *) break ;;
@@ -89,6 +97,20 @@ while [ $# -gt 0 ]; do
     shift
 done
 
+if [ "$want_index" = true ]
+then
+    if [ -z "$GDB_ADD_INDEX" ]
+    then
+       if [ -f $mydir/gdb-add-index.sh ]
+       then
+           GDB_ADD_INDEX="$mydir/gdb-add-index.sh"
+       else
+           echo "$myname: unable to find usable contrib/gdb-add-index.sh" >&2
+           exit 1
+       fi
+    fi
+fi
+
 for arg in "$@"
 do
     if [ "$next_is_output_file" = "yes" ]
@@ -141,6 +163,12 @@ then
     exit 1
 fi
 
+get_tmpdir ()
+{
+    tmpdir=$(dirname "$output_file")/.tmp
+    mkdir -p "$tmpdir"
+}
+
 if [ "$want_objcopy_compress" = true ]; then
     $OBJCOPY --compress-debug-sections "$output_file"
     rc=$?
@@ -148,35 +176,65 @@ if [ "$want_objcopy_compress" = true ]; then
 fi
 
 if [ "$want_index" = true ]; then
-    $GDB --batch-silent -nx -ex "set auto-load no" -ex "file $output_file" -ex "save gdb-index $output_dir"
-    rc=$?
-    [ $rc != 0 ] && exit $rc
-
-    # GDB might not always create an index.  Cope.
-    if [ -f "$index_file" ]
-    then
-       $OBJCOPY --add-section .gdb_index="$index_file" \
-           --set-section-flags .gdb_index=readonly \
-           "$output_file" "$output_file"
-       rc=$?
-    else
-       rc=0
-    fi
+    # Filter out these messages which would stop dejagnu testcase run:
+    # echo "$myname: No index was created for $file" 1>&2
+    # echo "$myname: [Was there no debuginfo? Was there already an index?]" 1>&2
+    GDB=$GDB $GDB_ADD_INDEX $index_options "$output_file" 2>&1 \
+       | grep -v "^${GDB_ADD_INDEX##*/}: " >&2
+    rc=${PIPESTATUS[0]}
     [ $rc != 0 ] && exit $rc
 fi
 
 if [ "$want_dwz" = true ]; then
-    $DWZ "$output_file" > /dev/null 2>&1
+    # Validate dwz's result by checking if the executable was modified.
+    cp "$output_file" "${output_file}.copy"
+    $DWZ "$output_file" > /dev/null
+    cmp "$output_file" "$output_file.copy" > /dev/null
+    cmp_rc=$?
+    rm -f "${output_file}.copy"
+
+    case $cmp_rc in
+    0)
+       echo "$myname: dwz did not modify ${output_file}."
+        exit 1
+       ;;
+    1)
+       # File was modified, great.
+       ;;
+    *)
+       # Other cmp error, it presumably has already printed something on
+       # stderr.
+       exit 1
+       ;;
+    esac
 elif [ "$want_multi" = true ]; then
+    get_tmpdir
+    dwz_file=$tmpdir/$(basename "$output_file").dwz
+    # Remove the dwz output file if it exists, so we don't mistake it for a
+    # new file in case dwz fails.
+    rm -f "$dwz_file"
+
     cp $output_file ${output_file}.alt
-    $DWZ -m ${output_file}.dwz "$output_file" ${output_file}.alt > /dev/null 2>&1
+    $DWZ -m "$dwz_file" "$output_file" ${output_file}.alt > /dev/null
+    rm -f ${output_file}.alt
+
+    # Validate dwz's work by checking if the expected output file exists.
+    if [ ! -f "$dwz_file" ]; then
+       echo "$myname: dwz file $dwz_file missing."
+       exit 1
+    fi
 fi
 
 if [ "$want_dwp" = true ]; then
     dwo_files=$($READELF -wi "${output_file}" | grep _dwo_name | \
        sed -e 's/^.*: //' | sort | uniq)
-    $DWP -o "${output_file}.dwp" ${dwo_files} > /dev/null
-    rm -f ${dwo_files}
+    rc=0
+    if [ -n "$dwo_files" ]; then
+       $DWP -o "${output_file}.dwp" ${dwo_files} > /dev/null
+       rc=$?
+       [ $rc != 0 ] && exit $rc
+       rm -f ${dwo_files}
+    fi
 fi
 
 rm -f "$index_file"
This page took 0.027811 seconds and 4 git commands to generate.