scripts/build/debug/300-gdb.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jul 24 20:30:52 2011 +0200 (2011-07-24)
changeset 2570 2651341cc084
parent 2508 9e2761e59a75
child 2575 b0cc1bf3e851
permissions -rw-r--r--
debug/gdb: install gdbinit sample file

gdb needs to know where to find the libstdc++ helper python script
to do, well, whatever it has to do with it...

We can't install that in the user's ~/.gdbinit, it's too complex to
handle all the cases. Moreover, if the user is using more than one
toolchain, we can't put all that stuff in there...

Just provide a sample config file the user can adapt to his/her
own needs.

Thanks go to Khem RAJ for providing such a hint:
http://sourceware.org/ml/crossgcc/2011-07/msg00026.html

Reported-by: ANDY KENNEDY <ANDY.KENNEDY@adtran.com>
CC: Khem Raj <raj.khem@gmail.com>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
     1 # Build script for the gdb debug facility
     2 
     3 # The version of ncurses to use. Yes, it's hard-coded.
     4 # It's used only internally by crosstool-NG, and is
     5 # not exposed outside, so we don't care about providing
     6 # config options for this.
     7 CT_DEBUG_GDB_NCURSES_VERSION="5.7"
     8 
     9 # Ditto for the expat library
    10 CT_DEBUG_GDB_EXPAT_VERSION="2.0.1"
    11 
    12 do_debug_gdb_parts() {
    13     do_gdb=
    14     do_ncurses=
    15     do_expat=
    16 
    17     if [ "${CT_GDB_CROSS}" = y ]; then
    18         do_gdb=y
    19     fi
    20 
    21     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
    22         do_gdb=y
    23     fi
    24 
    25     if [ "${CT_GDB_NATIVE}" = "y" ]; then
    26         do_gdb=y
    27         # GDB on Mingw depends on PDcurses, not ncurses
    28         if [ "${CT_MINGW32}" != "y" ]; then
    29             do_ncurses=y
    30         fi
    31         do_expat=y
    32     fi
    33 }
    34 
    35 do_debug_gdb_get() {
    36     local linaro_version
    37     local linaro_series
    38     local linaro_base_url="http://launchpad.net/gdb-linaro"
    39 
    40     # Account for the Linaro versioning
    41     linaro_version="$( echo "${CT_GDB_VERSION}"      \
    42                        |sed -r -e 's/^linaro-//;'   \
    43                      )"
    44     linaro_series="$( echo "${linaro_version}"      \
    45                       |sed -r -e 's/-.*//;'         \
    46                     )"
    47 
    48     do_debug_gdb_parts
    49 
    50     if [ "${do_gdb}" = "y" ]; then
    51         CT_GetFile "gdb-${CT_GDB_VERSION}"                          \
    52                    {ftp,http}://ftp.gnu.org/pub/gnu/gdb             \
    53                    ftp://sources.redhat.com/pub/gdb/{,old-}releases \
    54                    "${linaro_base_url}/${linaro_series}/${linaro_version}/+download"
    55     fi
    56 
    57     if [ "${do_ncurses}" = "y" ]; then
    58         CT_GetFile "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}" .tar.gz  \
    59                    {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
    60                    ftp://invisible-island.net/ncurses
    61     fi
    62 
    63     if [ "${do_expat}" = "y" ]; then
    64         CT_GetFile "expat-${CT_DEBUG_GDB_EXPAT_VERSION}" .tar.gz    \
    65                    http://mesh.dl.sourceforge.net/sourceforge/expat/expat/${CT_DEBUG_GDB_EXPAT_VERSION}
    66     fi
    67 }
    68 
    69 do_debug_gdb_extract() {
    70     do_debug_gdb_parts
    71 
    72     if [ "${do_gdb}" = "y" ]; then
    73         CT_Extract "gdb-${CT_GDB_VERSION}"
    74         CT_Patch "gdb" "${CT_GDB_VERSION}"
    75     fi
    76 
    77     if [ "${do_ncurses}" = "y" ]; then
    78         CT_Extract "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
    79         CT_DoExecLog ALL chmod -R u+w "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
    80         CT_Patch "ncurses" "${CT_DEBUG_GDB_NCURSES_VERSION}"
    81     fi
    82 
    83     if [ "${do_expat}" = "y" ]; then
    84         CT_Extract "expat-${CT_DEBUG_GDB_EXPAT_VERSION}"
    85         CT_Patch "expat" "${CT_DEBUG_GDB_EXPAT_VERSION}"
    86     fi
    87 }
    88 
    89 do_debug_gdb_build() {
    90     local -a extra_config
    91 
    92     do_debug_gdb_parts
    93 
    94     gdb_src_dir="${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}"
    95 
    96     # Version 6.3 and below behave badly with gdbmi
    97     case "${CT_GDB_VERSION}" in
    98         6.2*|6.3)   extra_config+=("--disable-gdbmi");;
    99     esac
   100 
   101     if [ "${CT_GDB_HAS_PKGVERSION_BUGURL}" = "y" ]; then
   102         extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
   103         [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
   104     fi
   105 
   106     if [ "${CT_GDB_CROSS}" = "y" ]; then
   107         local -a cross_extra_config
   108         local gcc_version
   109 
   110         CT_DoStep INFO "Installing cross-gdb"
   111         CT_DoLog EXTRA "Configuring cross-gdb"
   112 
   113         mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
   114         cd "${CT_BUILD_DIR}/build-gdb-cross"
   115 
   116         cross_extra_config=("${extra_config[@]}")
   117         case "${CT_THREADS}" in
   118             none)   cross_extra_config+=("--disable-threads");;
   119             *)      cross_extra_config+=("--enable-threads");;
   120         esac
   121 
   122         CC_for_gdb=
   123         LD_for_gdb=
   124         if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
   125             CC_for_gdb="gcc -static"
   126             LD_for_gdb="ld -static"
   127         fi
   128 
   129         gdb_cross_configure="${gdb_src_dir}/configure"
   130 
   131         CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
   132 
   133         CT_DoExecLog CFG                                \
   134         CC="${CC_for_gdb}"                              \
   135         LD="${LD_for_gdb}"                              \
   136         "${gdb_cross_configure}"                        \
   137             --build=${CT_BUILD}                         \
   138             --host=${CT_HOST}                           \
   139             --target=${CT_TARGET}                       \
   140             --prefix="${CT_PREFIX_DIR}"                 \
   141             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   142             --with-sysroot="${CT_SYSROOT_DIR}"          \
   143             --with-expat=yes                            \
   144             --disable-werror                            \
   145             "${cross_extra_config[@]}"
   146 
   147         CT_DoLog EXTRA "Building cross-gdb"
   148         CT_DoExecLog ALL make ${JOBSFLAGS}
   149 
   150         CT_DoLog EXTRA "Installing cross-gdb"
   151         CT_DoExecLog ALL make install
   152 
   153         CT_DoLog EXTRA "Install '.gdbinit' template"
   154         # See in scripts/build/internals.sh for why we do this
   155         if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
   156             gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" )
   157         else
   158             gcc_version=$( sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
   159                                "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/version.c"   \
   160                          )
   161         fi
   162         ${sed} -r                                               \
   163                -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;"             \
   164                -e "s:@@VERSION@@:${gcc_version}:;"              \
   165                "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in"   \
   166                >"${CT_PREFIX_DIR}/share/gdb/gdbinit"
   167 
   168         CT_EndStep
   169     fi
   170 
   171     if [ "${CT_GDB_NATIVE}" = "y" ]; then
   172         local -a native_extra_config
   173         local -a ncurses_opt
   174         local -a gdb_native_CFLAGS
   175 
   176         CT_DoStep INFO "Installing native gdb"
   177 
   178         native_extra_config=("${extra_config[@]}")
   179 
   180         # GDB on Mingw depends on PDcurses, not ncurses
   181         if [ "${do_ncurses}" = "y" ]; then
   182             CT_DoLog EXTRA "Building static target ncurses"
   183 
   184             [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
   185             [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
   186 
   187             mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
   188             cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
   189 
   190             # Use build = CT_REAL_BUILD so that configure thinks it is
   191             # cross-compiling, and thus will use the ${CT_BUILD}-*
   192             # tools instead of searching for the native ones...
   193             CT_DoExecLog CFG                                                    \
   194             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   195                 --build=${CT_BUILD}                                             \
   196                 --host=${CT_BUILD}                                              \
   197                 --prefix=/usr                                                   \
   198                 --without-shared                                                \
   199                 --enable-symlinks                                               \
   200                 --with-build-cc=${CT_REAL_BUILD}-gcc                            \
   201                 --with-build-cpp=${CT_REAL_BUILD}-gcc                           \
   202                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   203                 "${ncurses_opts[@]}"
   204 
   205             # Under some operating systems (eg. Winblows), there is an
   206             # extension appended to executables. Find that.
   207             tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
   208 
   209             CT_DoExecLog ALL make ${JOBSFLAGS} -C include
   210             CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
   211 
   212             CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
   213             CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
   214 
   215             mkdir -p "${CT_BUILD_DIR}/build-ncurses"
   216             cd "${CT_BUILD_DIR}/build-ncurses"
   217 
   218             CT_DoExecLog CFG                                                    \
   219             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   220                 --build=${CT_BUILD}                                             \
   221                 --host=${CT_TARGET}                                             \
   222                 --with-build-cc=${CT_BUILD}-gcc                                 \
   223                 --with-build-cpp=${CT_BUILD}-gcc                                \
   224                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   225                 --prefix="${CT_BUILD_DIR}/static-target"                        \
   226                 --without-shared                                                \
   227                 --without-sysmouse                                              \
   228                 --without-progs                                                 \
   229                 --enable-termcap                                                \
   230                 "${ncurses_opts[@]}"
   231 
   232             CT_DoExecLog ALL make ${JOBSFLAGS}
   233 
   234             CT_DoExecLog ALL make install
   235 
   236             # We no longer need the temporary tic. Remove it
   237             CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/buildtools/tic${tic_ext}"
   238 
   239             native_extra_config+=("--with-curses")
   240             # There's no better way to tell gdb where to find -lcurses... :-(
   241             gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
   242             gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
   243         fi # do_ncurses
   244 
   245         if [ "${do_expat}" = "y" ]; then
   246             CT_DoLog EXTRA "Building static target expat"
   247 
   248             mkdir -p "${CT_BUILD_DIR}/expat-build"
   249             cd "${CT_BUILD_DIR}/expat-build"
   250 
   251             CT_DoExecLog CFG                                                \
   252             "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure"   \
   253                 --build=${CT_BUILD}                                         \
   254                 --host=${CT_TARGET}                                         \
   255                 --prefix="${CT_BUILD_DIR}/static-target"                    \
   256                 --enable-static                                             \
   257                 --disable-shared
   258 
   259             CT_DoExecLog ALL make ${JOBSFLAGS}
   260             CT_DoExecLog ALL make install
   261 
   262             native_extra_config+=("--with-expat")
   263             native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
   264         fi # do_expat
   265 
   266         CT_DoLog EXTRA "Configuring native gdb"
   267 
   268         mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
   269         cd "${CT_BUILD_DIR}/build-gdb-native"
   270 
   271         case "${CT_THREADS}" in
   272             none)   native_extra_config+=("--disable-threads");;
   273             *)      native_extra_config+=("--enable-threads");;
   274         esac
   275 
   276         if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
   277             CC_for_gdb="${CT_TARGET}-gcc -static"
   278             LD_for_gdb="${CT_TARGET}-ld -static"
   279         else
   280             CC_for_gdb="${CT_TARGET}-gcc"
   281             LD_for_gdb="${CT_TARGET}-ld"
   282         fi
   283 
   284         export ac_cv_func_strncmp_works=yes
   285 
   286         CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
   287 
   288         CT_DoExecLog CFG                                \
   289         CC="${CC_for_gdb}"                              \
   290         LD="${LD_for_gdb}"                              \
   291         CFLAGS="${gdb_native_CFLAGS[*]}"                \
   292         "${gdb_src_dir}/configure"                      \
   293             --build=${CT_BUILD}                         \
   294             --host=${CT_TARGET}                         \
   295             --target=${CT_TARGET}                       \
   296             --prefix=/usr                               \
   297             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   298             --without-uiout                             \
   299             --disable-tui                               \
   300             --disable-gdbtk                             \
   301             --without-x                                 \
   302             --disable-sim                               \
   303             --disable-werror                            \
   304             --without-included-gettext                  \
   305             --without-develop                           \
   306             "${native_extra_config[@]}"
   307 
   308         CT_DoLog EXTRA "Building native gdb"
   309         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   310 
   311         CT_DoLog EXTRA "Installing native gdb"
   312         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   313 
   314         # Building a native gdb also builds a gdbserver
   315         find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
   316 
   317         unset ac_cv_func_strncmp_works
   318 
   319         # GDB on Mingw depends on PDcurses, not ncurses
   320         if [ "${CT_MINGW32}" != "y" ]; then
   321             CT_DoLog EXTRA "Cleaning up ncurses"
   322             cd "${CT_BUILD_DIR}/build-ncurses"
   323             CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
   324 
   325             CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
   326         fi
   327 
   328         CT_EndStep # native gdb build
   329     fi
   330 
   331     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
   332         local -a gdbserver_extra_config
   333 
   334         CT_DoStep INFO "Installing gdbserver"
   335         CT_DoLog EXTRA "Configuring gdbserver"
   336 
   337         mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
   338         cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
   339 
   340         # Workaround for bad versions, where the configure
   341         # script for gdbserver is not executable...
   342         # Bah, GNU folks strike again... :-(
   343         chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
   344 
   345         gdbserver_LDFLAGS=
   346         if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
   347             gdbserver_LDFLAGS=-static
   348         fi
   349 
   350         gdbserver_extra_config=("${extra_config[@]}")
   351 
   352         CT_DoExecLog CFG                                \
   353         LDFLAGS="${gdbserver_LDFLAGS}"                  \
   354         "${gdb_src_dir}/gdb/gdbserver/configure"        \
   355             --build=${CT_BUILD}                         \
   356             --host=${CT_TARGET}                         \
   357             --target=${CT_TARGET}                       \
   358             --prefix=/usr                               \
   359             --sysconfdir=/etc                           \
   360             --localstatedir=/var                        \
   361             --includedir="${CT_HEADERS_DIR}"            \
   362             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   363             --program-prefix=                           \
   364             --without-uiout                             \
   365             --disable-tui                               \
   366             --disable-gdbtk                             \
   367             --without-x                                 \
   368             --without-included-gettext                  \
   369             --without-develop                           \
   370             --disable-werror                            \
   371             "${gdbserver_extra_config[@]}"
   372 
   373         CT_DoLog EXTRA "Building gdbserver"
   374         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   375 
   376         CT_DoLog EXTRA "Installing gdbserver"
   377         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   378 
   379         CT_EndStep
   380     fi
   381 }