gdb/gdb_mbuild.sh - gdb

Functions defined

Source code

  1. #!/bin/sh

  2. #  Multi-build script for testing compilation of all maintained
  3. #  configs of GDB.

  4. #  Copyright (C) 2002-2015 Free Software Foundation, Inc.

  5. #  Contributed by Richard Earnshaw  (rearnsha@arm.com)

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

  18. # Make certain that the script is not running in an internationalized
  19. # environment.
  20. LANG=c ; export LANG
  21. LC_ALL=c ; export LC_ALL

  22. usage()
  23. {
  24.     cat <<EOF
  25. Usage: gdb_mbuild.sh [ <options> ... ] <srcdir> <builddir>
  26. Options:
  27.    -j <makejobs>  Run <makejobs> in parallel.  Passed to make.
  28.                   On a single cpu machine, 2 is recommended.
  29.    -k             Keep going.  Do not stop after the first build fails.
  30.    --keep         Keep builds.  Do not remove each build when finished.
  31.    -e <regexp>    Regular expression for selecting the targets to build.
  32.    -f             Force rebuild.  Even rebuild previously built directories.
  33.    -v             Be more (and more, and more) verbose.
  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. cat <<NOTYET
  42.   -b <maxbuilds> Run <maxbuild> builds in parallel.
  43.                  On a single cpu machine, 1 is recommended.
  44. NOTYET
  45. }

  46. ### COMMAND LINE OPTIONS

  47. makejobs=
  48. maxbuilds=1
  49. keepgoing=
  50. force=false
  51. targexp=""
  52. verbose=0
  53. keep=false
  54. while test $# -gt 0
  55. do
  56.     case "$1" in
  57.     -j )
  58.         # Number of parallel make jobs.
  59.         shift
  60.         test $# -ge 1 || usage
  61.         makejobs="-j $1"
  62.         ;;
  63.     -b | -c )
  64.         # Number of builds to fire off in parallel.
  65.         shift
  66.         test $# -ge 1 || usage
  67.         maxbuilds=$1
  68.         ;;
  69.     -k )
  70.         # Should we soldier on after the first build fails?
  71.         keepgoing=-k
  72.         ;;
  73.     --keep )
  74.         keep=true
  75.         ;;
  76.     -e )
  77.         # A regular expression for selecting targets
  78.         shift
  79.         test $# -ge 1 || usage
  80.         targexp="${targexp} -e ${1}"
  81.         ;;
  82.     -f )
  83.         # Force a rebuild
  84.         force=true ;
  85.         ;;
  86.     -v )
  87.         # Be more, and more, and more, verbose
  88.         verbose=`expr ${verbose} + 1`
  89.         ;;
  90.     -* ) usage ;;
  91.     *) break ;;
  92.     esac
  93.     shift
  94. done


  95. ### COMMAND LINE PARAMETERS

  96. if test $# -ne 2
  97. then
  98.     usage
  99. fi

  100. # Convert these to absolute directory paths.

  101. # Where the sources live
  102. srcdir=`cd $1 && /bin/pwd` || exit 1

  103. # Where the builds occur
  104. builddir=`cd $2 && /bin/pwd` || exit 1

  105. ### ENVIRONMENT PARAMETERS

  106. # Version of make to use
  107. make=${MAKE:-make}
  108. MAKE=${make}
  109. export MAKE


  110. # Where to look for the list of targets to test
  111. maintainers=${srcdir}/gdb/MAINTAINERS
  112. if [ ! -r ${maintainers} ]
  113. then
  114.     echo Maintainers file ${maintainers} not found
  115.     exit 1
  116. fi

  117. # Get the list of targets and the build options
  118. alltarg=`cat ${maintainers} | tr -s '[\t]' '[ ]' | sed -n '
  119. /^[ ]*[-a-z0-9\.]*[ ]*[(]*--target=.*/ !d
  120. s/^.*--target=//
  121. s/).*$//
  122. h
  123. :loop
  124.   g
  125.   /^[^ ]*,/ !b end
  126.   s/,[^ ]*//
  127.   p
  128.   g
  129.   s/^[^,]*,//
  130.   h
  131. b loop
  132. :end
  133. p
  134. ' | if test "${targexp}" = ""
  135. then
  136.     grep -v -e broken -e OBSOLETE
  137. else
  138.     grep ${targexp}
  139. fi`


  140. # Usage: fail <message> <test-that-should-succeed>.  Should the build
  141. # fail?  If the test is true, and we don't want to keep going, print
  142. # the message and shoot everything in sight and abort the build.

  143. fail ()
  144. {
  145.     msg="$1" ; shift
  146.     if test "$@"
  147.     then
  148.         echo "${target}: ${msg}"
  149.         if test "${keepgoing}" != ""
  150.         then
  151.             #exit 1
  152.             continue
  153.         else
  154.             kill $$
  155.             exit 1
  156.         fi
  157.     fi
  158. }


  159. # Usage: log <level> <logfile>.  Write standard input to <logfile> and
  160. # stdout (if verbose >= level).

  161. log ()
  162. {
  163.     if test ${verbose} -ge $1
  164.     then
  165.         tee $2
  166.     else
  167.         cat > $2
  168.     fi
  169. }



  170. # Warn the user of what is comming, print the list of targets

  171. echo "$alltarg"
  172. echo ""


  173. # For each target, configure, build and test it.

  174. echo "$alltarg" | while read target gdbopts simopts
  175. do

  176.     trap "exit 1"  1 2 15
  177.     dir=${builddir}/${target}

  178.     # Should a scratch rebuild be forced, for perhaps the entire
  179.     # build be skipped?

  180.     if ${force}
  181.     then
  182.         echo forcing ${target} ...
  183.         rm -rf ${dir}
  184.     elif test -f ${dir}
  185.     then
  186.         echo "${target}"
  187.         continue
  188.     else
  189.         echo ${target} ...
  190.     fi

  191.     # Did the previous configure attempt fail?  If it did
  192.     # restart from scratch.

  193.     if test -d ${dir} -a ! -r ${dir}/Makefile
  194.     then
  195.         echo ... removing partially configured ${target}
  196.         rm -rf ${dir}
  197.         if test -d ${dir}
  198.         then
  199.             echo "${target}: unable to remove directory ${dir}"
  200.             exit 1
  201.         fi
  202.     fi

  203.     # From now on, we're in this target's build directory

  204.     mkdir -p ${dir}
  205.     cd ${dir} || exit 1

  206.     # Configure, if not already.  Should this go back to being
  207.     # separate and done in parallel?

  208.     if test ! -r Makefile
  209.     then
  210.         # Default SIMOPTS to GDBOPTS.
  211.         test -z "${simopts}" && simopts="${gdbopts}"
  212.         # The config options
  213.         __target="--target=${target}"
  214.         __enable_gdb_build_warnings=`test -z "${gdbopts}" \
  215.             || echo "--enable-gdb-build-warnings=${gdbopts}"`
  216.         __enable_sim_build_warnings=`test -z "${simopts}" \
  217.             || echo "--enable-sim-build-warnings=${simopts}"`
  218.         __configure="${srcdir}/configure \
  219.             ${__target} \
  220.             ${__enable_gdb_build_warnings} \
  221.             ${__enable_sim_build_warnings}"
  222.         echo ... ${__configure}
  223.         trap "echo Removing partially configured ${dir} directory ...; rm -rf ${dir}; exit 1" 1 2 15
  224.         ${__configure} 2>&1 | log 2 Config.log
  225.         trap "exit 1"  1 2 15
  226.     fi
  227.     fail "configure failed" ! -r Makefile

  228.     # Build, if not built.

  229.     if test ! -x gdb/gdb -a ! -x gdb/gdb.exe
  230.     then
  231.         # Iff the build fails remove the final build target so that
  232.         # the follow-on code knows things failed.  Stops the follow-on
  233.         # code thinking that a failed rebuild succedded (executable
  234.         # left around from previous build).
  235.         echo ... ${make} ${keepgoing} ${makejobs} ${target}
  236.         ( ${make} ${keepgoing} ${makejobs} all-gdb || rm -f gdb/gdb gdb/gdb.exe
  237.         ) 2>&1 | log 1 Build.log
  238.     fi
  239.     fail "compile failed" ! -x gdb/gdb -a ! -x gdb/gdb.exe

  240.     # Check that the built GDB can at least print it's architecture.

  241.     echo ... run ${target}
  242.     rm -f core gdb.core ${dir}/gdb/x
  243.     cat <<EOF > x
  244. maint print architecture
  245. quit
  246. EOF
  247.     ./gdb/gdb -batch -nx -x x 2>&1 | log 1 Gdb.log
  248.     fail "gdb dumped core" -r core -o -r gdb.core
  249.     fail "gdb printed no output" ! -s Gdb.log
  250.     grep -e internal-error Gdb.log && fail "gdb panic" 1

  251.     echo ... cleanup ${target}

  252.     # Create a sed script that cleans up the output from GDB.
  253.     rm -f mbuild.sed
  254.     touch mbuild.sed || exit 1
  255.     # Rules to replace <0xNNNN> with the corresponding function's
  256.     # name.
  257.     sed -n -e '/<0x0*>/d' -e 's/^.*<0x\([0-9a-f]*\)>.*$/0x\1/p' Gdb.log \
  258.     | sort -u \
  259.     | while read addr
  260.     do
  261.         func="`addr2line -f -e ./gdb/gdb -s ${addr} | sed -n -e 1p`"
  262.         test ${verbose} -gt 0 && echo "${addr} ${func}" 1>&2
  263.         echo "s/<${addr}>/<${func}>/g"
  264.     done >> mbuild.sed
  265.     # Rules to strip the leading paths off of file names.
  266.     echo 's/"\/.*\/gdb\//"gdb\//g' >> mbuild.sed
  267.     # Run the script
  268.     sed -f mbuild.sed Gdb.log > Mbuild.log

  269.     # Replace the build directory with a file as semaphore that stops
  270.     # a rebuild. (should the logs be saved?)

  271.     cd ${builddir}

  272.     if ${keep}
  273.     then
  274.         :
  275.     else
  276.         rm -f ${target}.tmp
  277.         mv ${target}/Mbuild.log ${target}.tmp
  278.         rm -rf ${target}
  279.         mv ${target}.tmp ${target}
  280.     fi

  281.     # Success!
  282.     echo ... ${target} built

  283. done

  284. exit 0