gdb/gdb_buildall.sh - gdb

Functions defined

Source code

  1. #!/bin/sh

  2. # Build script to build GDB with all targets enabled.

  3. # Copyright (C) 2008-2015 Free Software Foundation, Inc.
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program.  If not, see <http://www.gnu.org/licenses/>.

  16. # Make certain that the script is not running in an internationalized
  17. # environment. The script is grepping for GDB's output.

  18. # Contributed by Markus Deuling <deuling@de.ibm.com>.
  19. # Based on gdb_mbuild.sh from Richard Earnshaw.


  20. LANG=c ; export LANG
  21. LC_ALL=c ; export LC_ALL

  22. # Prints a usage message.
  23. usage()
  24. {
  25.   cat <<EOF
  26. Usage: gdb_buildall.sh [ <options> ... ] <srcdir> <builddir>

  27. Options:

  28.   --bfd64        Enable 64-bit BFD.
  29.   --clean        Delete build directory after check.
  30.   -e <regexp>    Regular expression for selecting the targets to build.
  31.   --force        Force rebuild.
  32.   -j <makejobs>  Run <makejobs> in parallel.  Passed to make.
  33.                  On a single cpu machine, 2 is recommended.
  34. Arguments:
  35.    <srcdir>       Source code directory.
  36.    <builddir>     Build directory.

  37. Environment variables examined (with default if not defined):
  38.    MAKE (make)"
  39. EOF
  40.   exit 1
  41. }

  42. ### Command line options.
  43. makejobs=
  44. force=false
  45. targexp=""
  46. bfd_flag=""
  47. clean=false
  48. while test $# -gt 0
  49. do
  50.   case "$1" in
  51.   -j )
  52.       # Number of parallel make jobs.
  53.       shift
  54.       test $# -ge 1 || usage
  55.       makejobs="-j $1"
  56.       ;;
  57.       --clean )
  58.         # Shall the build directory be deleted after processing?
  59.         clean=true
  60.         ;;
  61.     -e )
  62.       # A regular expression for selecting targets
  63.       shift
  64.       test $# -ge 1 || usage
  65.       targexp="${targexp} -e ${1}"
  66.       ;;
  67.     --force )
  68.       # Force a rebuild
  69.       force=true ;
  70.       ;;
  71.     --bfd64)
  72.       # Enable 64-bit BFD
  73.       bfd_flag="--enable-64-bit-bfd"
  74.       ;;
  75.     -* ) usage ;;
  76.     *) break ;;
  77.   esac
  78.   shift
  79. done

  80. if test $# -ne 2
  81. then
  82.   usage
  83. fi

  84. ### Environment.

  85. # Convert these to absolute directory paths.
  86. srcdir=`cd $1 && /bin/pwd` || exit 1
  87. builddir=`cd $2 && /bin/pwd` || exit 1
  88. # Version of make to use
  89. make=${MAKE:-make}
  90. MAKE=${make}
  91. export MAKE
  92. # We dont want GDB do dump cores.
  93. ulimit -c 0

  94. # Just make sure we're in the right directory.
  95. maintainers=${srcdir}/gdb/MAINTAINERS
  96. if [ ! -r ${maintainers} ]
  97. then
  98.     echo Maintainers file ${maintainers} not found
  99.     exit 1
  100. fi


  101. # Build GDB with all targets enabled.
  102. echo "Starting gdb_buildall.sh ..."

  103. trap "exit 1"  1 2 15
  104. dir=${builddir}/ALL

  105. # Should a scratch rebuild be forced, for perhaps the entire build be skipped?
  106. if ${force}
  107. then
  108.   echo ... forcing rebuild
  109.   rm -rf ${dir}
  110. fi

  111. # Did the previous configure attempt fail?  If it did restart from scratch
  112. if test -d ${dir} -a ! -r ${dir}/Makefile
  113. then
  114.   echo ... removing partially configured
  115.   rm -rf ${dir}
  116.   if test -d ${dir}
  117.   then
  118.     echo "... ERROR: Unable to remove directory ${dir}"
  119.     exit 1
  120.   fi
  121. fi

  122. # Create build directory.
  123. mkdir -p ${dir}
  124. cd ${dir} || exit 1

  125. # Configure GDB.
  126. if test ! -r Makefile
  127. then
  128.   # Default SIMOPTS to GDBOPTS.
  129.   test -z "${simopts}" && simopts="${gdbopts}"

  130.   # The config options.
  131.   __build="--enable-targets=all"
  132.   __enable_gdb_build_warnings=`test -z "${gdbopts}" \
  133.     || echo "--enable-gdb-build-warnings=${gdbopts}"`
  134.   __enable_sim_build_warnings=`test -z "${simopts}" \
  135.     || echo "--enable-sim-build-warnings=${simopts}"`
  136.   __configure="${srcdir}/configure \
  137.     ${__build} ${bfd_flag}\
  138.     ${__enable_gdb_build_warnings} \
  139.     ${__enable_sim_build_warnings}"
  140.   echo ... ${__configure}
  141.   trap "echo Removing partially configured ${dir} directory ...; rm -rf ${dir}; exit 1" 1 2 15
  142.   ${__configure} > Config.log 2>&1
  143.   trap "exit 1"  1 2 15

  144.   # Without Makefile GDB won't build.
  145.   if test ! -r Makefile
  146.   then
  147.     echo "... CONFIG ERROR: GDB couldn't be configured " | tee -a Config.log
  148.     echo "... CONFIG ERROR: see Config.log for details "
  149.     exit 1
  150.   fi
  151. fi

  152. # Build GDB, if not built.
  153. gdb_bin="gdb/gdb"
  154. if test ! -x gdb/gdb -a ! -x gdb/gdb.exe
  155. then
  156.   echo ... ${make} ${makejobs}
  157.   ( ${make} ${makejobs} all-gdb || rm -f gdb/gdb gdb/gdb.exe
  158.   ) > Build.log 2>&1

  159.   # If the build fails, exit.
  160.   if test ! -x gdb/gdb -a ! -x gdb/gdb.exe
  161.   then
  162.     echo "... BUILD ERROR: GDB couldn't be compiled " | tee -a Build.log
  163.     echo "... BUILD ERROR: see Build.log for details "
  164.     exit 1
  165.   fi
  166.   if test -x gdb/gdb.exe
  167.   then
  168.     gdb_bin="gdb/gdb.exe"
  169.   fi
  170. fi


  171. # Retrieve a list of settable architectures by invoking "set architecture"
  172. # without parameters.
  173. cat <<EOF > arch
  174. set architecture
  175. quit
  176. EOF
  177. ./gdb/gdb --batch -nx -x arch 2>&1 | cat > gdb_archs
  178. tail -n 1 gdb_archs | sed 's/auto./\n/g' | sed 's/,/\n/g'sed 's/Requires an argument. Valid arguments are/\n/g' | sed '/^[ ]*$/d' > arch
  179. mv arch gdb_archs

  180. if test "${targexp}" != ""
  181. then
  182.   alltarg=`cat gdb_archs | grep ${targexp}`
  183. else
  184.   alltarg=`cat gdb_archs`
  185. fi
  186. rm -f gdb_archs

  187. # Test all architectures available in ALLTARG
  188. echo "maint print architecture for"
  189. echo "$alltarg" | while read target
  190. do
  191.   cat <<EOF > x
  192. set architecture ${target}
  193. maint print architecture
  194. quit
  195. EOF
  196.   log_file=$target.log
  197.   log_file=${log_file//:/_}
  198.   echo -n "... ${target}"
  199.   ./gdb/gdb -batch -nx -x x 2>&1 | cat > $log_file
  200.   # Check GDBs results
  201.   if test ! -s $log_file
  202.   then
  203.     echo " ERR: gdb printed no output" | tee -a $log_file
  204.   elif test `grep -o internal-error $log_file | tail -n 1`
  205.   then
  206.     echo " ERR: gdb panic" | tee -a $log_file
  207.   else
  208.     echo " OK"
  209.   fi

  210.   # Create a sed script that cleans up the output from GDB.
  211.   rm -f mbuild.sed
  212.   # Rules to replace <0xNNNN> with the corresponding function's name.
  213.   sed -n -e '/<0x0*>/d' -e 's/^.*<0x\([0-9a-f]*\)>.*$/0x\1/p' $log_file \
  214.   | sort -u \
  215.   | while read addr
  216.   do
  217.     func="`addr2line -f -e ./$gdb_bin -s ${addr} | sed -n -e 1p`"
  218.     echo "s/<${addr}>/<${func}>/g"
  219.   done >> mbuild.sed
  220.   # Rules to strip the leading paths off of file names.
  221.   echo 's/"\/.*\/gdb\//"gdb\//g' >> mbuild.sed
  222.   # Run the script.
  223.   sed -f mbuild.sed $log_file > Mbuild.log

  224.   mv Mbuild.log ${builddir}/$log_file
  225.   rm -rf $log_file x mbuild.sed
  226. done
  227. echo "done."

  228. # Clean up build directory if necessary.
  229. if ${clean}
  230. then
  231.   echo "cleanning up $dir"
  232.   rm -rf ${dir}
  233. fi

  234. exit 0