From ab2e98d96a846747c02eba9067bda2397b00cc3b Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Tue, 22 Jul 2025 15:31:08 +0900 Subject: [PATCH 1/7] Revert "gdb: Build additional Python scripting-capable variant" This reverts commit 35934f2cfb285b4197c2ef2a900bf315beff108d because it was ported with screwed up indentation ... Signed-off-by: Stephanos Ioannidis --- config/debug/gdb.in.cross | 11 ------- scripts/build/debug/300-gdb.sh | 59 +++++++++------------------------- 2 files changed, 15 insertions(+), 55 deletions(-) diff --git a/config/debug/gdb.in.cross b/config/debug/gdb.in.cross index d2fbf5104f..7ecc2e3bab 100644 --- a/config/debug/gdb.in.cross +++ b/config/debug/gdb.in.cross @@ -49,17 +49,6 @@ config GDB_CROSS_PYTHON have been reports of problems when linking gdb to the static libpython.a. This should be fixed in gdb >=7.3. YMMV. -config GDB_CROSS_PYTHON_VARIANT - bool - prompt "Build additional Python-capable gdb variant (gdb-py)" - depends on GDB_CROSS_PYTHON - help - Build an additional gdb variant (gdb-py) that supports Python scripting. - - When this option is enabled, the default gdb variant (gdb) does not link - against libpython; instead, an additional Python-capable gdb variant - executable (gdb-py) that links against libpython is built. - config GDB_CROSS_PYTHON_BINARY string "Python binary to use" depends on GDB_CROSS_PYTHON diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index feabdca900..8702cc49ed 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -12,43 +12,25 @@ do_debug_gdb_extract() do_debug_gdb_build_cross() { - local progprefix progsuffix usepython local gcc_version p _p local -a cross_extra_config - for arg in "$@"; do - case "$arg" in - *) - eval "${arg// /\\ }" - ;; - esac - done - - CT_DoStep INFO "Installing cross-${progprefix}gdb${progsuffix}" - CT_mkdir_pushd "${CT_BUILD_DIR}/build-${progprefix}gdb${progsuffix}-cross" + CT_DoStep INFO "Installing cross-gdb" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-gdb-cross" cross_extra_config=( "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}" ) - - if [ -n "${progprefix}" ]; then - cross_extra_config+=("--program-prefix=${progprefix}") - fi - - if [ -n "${progsuffix}" ]; then - cross_extra_config+=("--program-suffix=${progsuffix}") - fi - - if [ "${usepython}" = "y" ]; then - if [ -z "${CT_GDB_CROSS_PYTHON_BINARY}" ]; then - if [ "${CT_CANADIAN}" = "y" -o "${CT_CROSS_NATIVE}" = "y" ]; then - CT_Abort "For canadian build, Python wrapper runnable on the build machine must be provided. Set CT_GDB_CROSS_PYTHON_BINARY." - elif [ "${CT_CONFIGURE_has_python}" = "y" ]; then - cross_extra_config+=("--with-python=${python}") - else - CT_Abort "Python support requested in GDB, but Python not found. Set CT_GDB_CROSS_PYTHON_BINARY." - fi - else - cross_extra_config+=("--with-python=${CT_GDB_CROSS_PYTHON_BINARY}") - fi + if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then + if [ -z "${CT_GDB_CROSS_PYTHON_BINARY}" ]; then + if [ "${CT_CANADIAN}" = "y" -o "${CT_CROSS_NATIVE}" = "y" ]; then + CT_Abort "For canadian build, Python wrapper runnable on the build machine must be provided. Set CT_GDB_CROSS_PYTHON_BINARY." + elif [ "${CT_CONFIGURE_has_python}" = "y" ]; then + cross_extra_config+=("--with-python=${python}") + else + CT_Abort "Python support requested in GDB, but Python not found. Set CT_GDB_CROSS_PYTHON_BINARY." + fi + else + cross_extra_config+=("--with-python=${CT_GDB_CROSS_PYTHON_BINARY}") + fi else cross_extra_config+=("--with-python=no") fi @@ -133,18 +115,7 @@ do_debug_gdb_build_cross() do_debug_gdb_build() { if [ "${CT_GDB_CROSS}" = "y" ]; then - if [ "${CT_GDB_CROSS_PYTHON_VARIANT}" = "y" ]; then - do_debug_gdb_build_cross \ - usepython=n - - do_debug_gdb_build_cross \ - usepython=y \ - progprefix="${CT_TARGET}-" \ - progsuffix="-py" - else - do_debug_gdb_build_cross \ - usepython="${CT_GDB_CROSS_PYTHON}" - fi + do_debug_gdb_build_cross fi if [ "${CT_GDB_NATIVE}" = "y" ]; then From 5f648c12bb872f9d46e63deee706bb62aaa50155 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Tue, 22 Jul 2025 15:31:37 +0900 Subject: [PATCH 2/7] Revert "gdb: Refactor cross GDB build step" This reverts commit e20c3feb9aac28f28e90e561c2fe2069044a6ca8 because it was ported with screwed up indentation ... Signed-off-by: Stephanos Ioannidis --- scripts/build/debug/300-gdb.sh | 195 ++++++++++++++++----------------- 1 file changed, 95 insertions(+), 100 deletions(-) diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index 8702cc49ed..508ba25f41 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -10,112 +10,107 @@ do_debug_gdb_extract() CT_ExtractPatch GDB } -do_debug_gdb_build_cross() +do_debug_gdb_build() { - local gcc_version p _p - local -a cross_extra_config - - CT_DoStep INFO "Installing cross-gdb" - CT_mkdir_pushd "${CT_BUILD_DIR}/build-gdb-cross" - - cross_extra_config=( "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}" ) - if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then - if [ -z "${CT_GDB_CROSS_PYTHON_BINARY}" ]; then - if [ "${CT_CANADIAN}" = "y" -o "${CT_CROSS_NATIVE}" = "y" ]; then - CT_Abort "For canadian build, Python wrapper runnable on the build machine must be provided. Set CT_GDB_CROSS_PYTHON_BINARY." - elif [ "${CT_CONFIGURE_has_python}" = "y" ]; then - cross_extra_config+=("--with-python=${python}") - else - CT_Abort "Python support requested in GDB, but Python not found. Set CT_GDB_CROSS_PYTHON_BINARY." - fi - else - cross_extra_config+=("--with-python=${CT_GDB_CROSS_PYTHON_BINARY}") - fi - else - cross_extra_config+=("--with-python=no") - fi + if [ "${CT_GDB_CROSS}" = "y" ]; then + local gcc_version p _p + local -a cross_extra_config + + CT_DoStep INFO "Installing cross-gdb" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-gdb-cross" + + cross_extra_config=( "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}" ) + if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then + if [ -z "${CT_GDB_CROSS_PYTHON_BINARY}" ]; then + if [ "${CT_CANADIAN}" = "y" -o "${CT_CROSS_NATIVE}" = "y" ]; then + CT_Abort "For canadian build, Python wrapper runnable on the build machine must be provided. Set CT_GDB_CROSS_PYTHON_BINARY." + elif [ "${CT_CONFIGURE_has_python}" = "y" ]; then + cross_extra_config+=("--with-python=${python}") + else + CT_Abort "Python support requested in GDB, but Python not found. Set CT_GDB_CROSS_PYTHON_BINARY." + fi + else + cross_extra_config+=("--with-python=${CT_GDB_CROSS_PYTHON_BINARY}") + fi + else + cross_extra_config+=("--with-python=no") + fi - if [ "${CT_GDB_CROSS_SIM}" = "y" ]; then - cross_extra_config+=("--enable-sim") - else - cross_extra_config+=("--disable-sim") - fi + if [ "${CT_GDB_CROSS_SIM}" = "y" ]; then + cross_extra_config+=("--enable-sim") + else + cross_extra_config+=("--disable-sim") + fi - if ${CT_HOST}-gcc --version 2>&1 | grep clang; then - # clang detects the line from gettext's _ macro as format string - # not being a string literal and produces a lot of warnings - which - # ct-ng's logger faithfully relays to user if this happens in the - # error() function. Suppress them. - cross_extra_config+=("--enable-build-warnings=,-Wno-format-nonliteral,-Wno-format-security") - fi + if ${CT_HOST}-gcc --version 2>&1 | grep clang; then + # clang detects the line from gettext's _ macro as format string + # not being a string literal and produces a lot of warnings - which + # ct-ng's logger faithfully relays to user if this happens in the + # error() function. Suppress them. + cross_extra_config+=("--enable-build-warnings=,-Wno-format-nonliteral,-Wno-format-security") + fi - # Target libexpat resides in sysroot and does not have - # any dependencies, so just passing '-lexpat' to gcc is enough. - # - # By default gdb configure looks for expat in '$prefix/lib' - # directory. In our case '$prefix/lib' resolves to '/usr/lib' - # where libexpat for build platform lives, which is - # unacceptable for cross-compiling. - # - # To prevent this '--without-libexpat-prefix' flag must be passed. - # Thus configure falls back to '-lexpat', which is exactly what we want. - # - # NOTE: DO NOT USE --with-libexpat-prefix (until GDB configure is smarter)!!! - # It conflicts with a static build: GDB's configure script will find the shared - # version of expat and will attempt to link that, despite the -static flag. - # The link will fail, and configure will abort with "expat missing or unusable" - # message. - cross_extra_config+=("--with-expat") - cross_extra_config+=("--without-libexpat-prefix") - - # ct-ng always builds ncurses in cross mode as a static library. - # Starting from the patchset 20200718 ncurses defines a special macro - # NCURSES_STATIC for a static library. This is critical for mingw host - # platform. - # - # The problem is that the macro must be defined in a user program too, - # not just in ncurses. It won't hurt if we define it here. - do_gdb_backend \ - buildtype=cross \ - host="${CT_HOST}" \ - cflags="${CT_CFLAGS_FOR_HOST} -DNCURSES_STATIC" \ - ldflags="${CT_LDFLAGS_FOR_HOST}" \ - prefix="${CT_PREFIX_DIR}" \ - static="${CT_GDB_CROSS_STATIC}" \ - static_libstdcxx="${CT_GDB_CROSS_STATIC}" \ - --with-sysroot="${CT_SYSROOT_DIR}" \ - "${cross_extra_config[@]}" - - if [ "${CT_BUILD_MANUALS}" = "y" ]; then - CT_DoLog EXTRA "Building and installing the cross-GDB manuals" - CT_DoExecLog ALL make ${CT_JOBSFLAGS} pdf html - CT_DoExecLog ALL make install-{pdf,html}-gdb - fi + # Target libexpat resides in sysroot and does not have + # any dependencies, so just passing '-lexpat' to gcc is enough. + # + # By default gdb configure looks for expat in '$prefix/lib' + # directory. In our case '$prefix/lib' resolves to '/usr/lib' + # where libexpat for build platform lives, which is + # unacceptable for cross-compiling. + # + # To prevent this '--without-libexpat-prefix' flag must be passed. + # Thus configure falls back to '-lexpat', which is exactly what we want. + # + # NOTE: DO NOT USE --with-libexpat-prefix (until GDB configure is smarter)!!! + # It conflicts with a static build: GDB's configure script will find the shared + # version of expat and will attempt to link that, despite the -static flag. + # The link will fail, and configure will abort with "expat missing or unusable" + # message. + cross_extra_config+=("--with-expat") + cross_extra_config+=("--without-libexpat-prefix") + + # ct-ng always builds ncurses in cross mode as a static library. + # Starting from the patchset 20200718 ncurses defines a special macro + # NCURSES_STATIC for a static library. This is critical for mingw host + # platform. + # + # The problem is that the macro must be defined in a user program too, + # not just in ncurses. It won't hurt if we define it here. + do_gdb_backend \ + buildtype=cross \ + host="${CT_HOST}" \ + cflags="${CT_CFLAGS_FOR_HOST} -DNCURSES_STATIC" \ + ldflags="${CT_LDFLAGS_FOR_HOST}" \ + prefix="${CT_PREFIX_DIR}" \ + static="${CT_GDB_CROSS_STATIC}" \ + static_libstdcxx="${CT_GDB_CROSS_STATIC}" \ + --with-sysroot="${CT_SYSROOT_DIR}" \ + "${cross_extra_config[@]}" + + if [ "${CT_BUILD_MANUALS}" = "y" ]; then + CT_DoLog EXTRA "Building and installing the cross-GDB manuals" + CT_DoExecLog ALL make ${CT_JOBSFLAGS} pdf html + CT_DoExecLog ALL make install-{pdf,html}-gdb + fi - CT_DoLog EXTRA "Installing '.gdbinit' template" - # See in scripts/build/internals.sh for why we do this - # TBD GCC 3.x and older not supported - if [ -f "${CT_SRC_DIR}/gcc/gcc/BASE-VER" ]; then - gcc_version=$(cat "${CT_SRC_DIR}/gcc/gcc/BASE-VER") - else - gcc_version=$(sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \ - "${CT_SRC_DIR}/gcc/gcc/version.c" \ - ) - fi - sed -r \ - -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;" \ - -e "s:@@VERSION@@:${gcc_version}:;" \ - "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in" \ - >"${CT_PREFIX_DIR}/share/gdb/gdbinit" - - CT_Popd - CT_EndStep -} + CT_DoLog EXTRA "Installing '.gdbinit' template" + # See in scripts/build/internals.sh for why we do this + # TBD GCC 3.x and older not supported + if [ -f "${CT_SRC_DIR}/gcc/gcc/BASE-VER" ]; then + gcc_version=$(cat "${CT_SRC_DIR}/gcc/gcc/BASE-VER") + else + gcc_version=$(sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \ + "${CT_SRC_DIR}/gcc/gcc/version.c" \ + ) + fi + sed -r \ + -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;" \ + -e "s:@@VERSION@@:${gcc_version}:;" \ + "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in" \ + >"${CT_PREFIX_DIR}/share/gdb/gdbinit" -do_debug_gdb_build() -{ - if [ "${CT_GDB_CROSS}" = "y" ]; then - do_debug_gdb_build_cross + CT_Popd + CT_EndStep fi if [ "${CT_GDB_NATIVE}" = "y" ]; then From 796b4fde7d6462d1af3e66f3efe2cba21476b82b Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Wed, 9 Mar 2022 18:05:37 +0900 Subject: [PATCH 3/7] gdb: Add CT_GDB_CROSS_STATIC_LIBSTDCXX configuration This commit adds a new configuration `CT_GDB_CROSS_STATIC_LIBSTDCXX`, which enables static linking of libstdc++ and libgcc for the cross-gdb running on the host. This configuration is enabled by default because using shared "standard libraries" can often cause compatibility problems when distributing toolchain binaries and it is therefore highly desirable to always static-link them. Note that this behaviour aligns with other similar symbols such as `CT_CC_GCC_STATIC_LIBSTDCXX` and `CT_GDB_NATIVE_STATIC_LIBSTDCXX`. For macOS, GDB is built using the Clang compiler, which is the default compiler for the macOS hosts, and `libstdc++` and `libgcc` are not applicable for obvious reasons. Since macOS provides a fairly well known and controlled execution environment, there is little point in static linking the C++ runtime library. Signed-off-by: Stephanos Ioannidis --- config/debug/gdb.in.cross | 9 +++++++++ scripts/build/debug/300-gdb.sh | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/config/debug/gdb.in.cross b/config/debug/gdb.in.cross index 7ecc2e3bab..35c1258d2c 100644 --- a/config/debug/gdb.in.cross +++ b/config/debug/gdb.in.cross @@ -26,6 +26,15 @@ config GDB_CROSS_STATIC That way, you can share the cross-gdb without installing a toolchain on every machine that will be used to debug target programs. +config GDB_CROSS_STATIC_LIBSTDCXX + bool + prompt "Link against static libstdc+++" + depends on !GDB_CROSS_STATIC + default y + help + Say 'y' if you do not want gdb to require libstdc++ and libgcc shared + libraries on the host. + config GDB_CROSS_SIM bool prompt "Enable 'sim'" diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index 508ba25f41..c3621a83c4 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -83,7 +83,7 @@ do_debug_gdb_build() ldflags="${CT_LDFLAGS_FOR_HOST}" \ prefix="${CT_PREFIX_DIR}" \ static="${CT_GDB_CROSS_STATIC}" \ - static_libstdcxx="${CT_GDB_CROSS_STATIC}" \ + static_libstdcxx="${CT_GDB_CROSS_STATIC_LIBSTDCXX}" \ --with-sysroot="${CT_SYSROOT_DIR}" \ "${cross_extra_config[@]}" @@ -296,8 +296,18 @@ do_gdb_backend() extra_config+=("--disable-source-highlight") fi if [ "${static_libstdcxx}" = "y" ]; then - ldflags+=" -static-libgcc" - ldflags+=" -static-libstdc++" + case "$CT_HOST" in + *darwin*) + # macOS builds with clang and provides a well known execution + # environment, so there is little point in static linking the + # C++ runtime library -- ignore this option for now. + ;; + *) + ldflags+=" -static-libgcc" + ldflags+=" -static-libstdc++" + ;; + esac + # libsource-highlight is a dynamic library that uses exception # exceptions are handled by libstdc++ # this combination is very buggy, so configure don't use it and abort From 02141175fb6bf3c6937c28d90bb7dd96aa10c57c Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Mon, 13 Jun 2022 02:00:32 +0900 Subject: [PATCH 4/7] gdb: Refactor cross GDB build step This commit moves the cross GDB build step out to a separate function so that it can be invoked more than once. When porting this patch in the future, run `git diff --histogram` to more clearly see what this commit does. Signed-off-by: Stephanos Ioannidis --- scripts/build/debug/300-gdb.sh | 187 +++++++++++++++++---------------- 1 file changed, 96 insertions(+), 91 deletions(-) diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index c3621a83c4..aa8d13441f 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -10,107 +10,112 @@ do_debug_gdb_extract() CT_ExtractPatch GDB } -do_debug_gdb_build() +do_debug_gdb_build_cross() { - if [ "${CT_GDB_CROSS}" = "y" ]; then - local gcc_version p _p - local -a cross_extra_config - - CT_DoStep INFO "Installing cross-gdb" - CT_mkdir_pushd "${CT_BUILD_DIR}/build-gdb-cross" - - cross_extra_config=( "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}" ) - if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then - if [ -z "${CT_GDB_CROSS_PYTHON_BINARY}" ]; then - if [ "${CT_CANADIAN}" = "y" -o "${CT_CROSS_NATIVE}" = "y" ]; then - CT_Abort "For canadian build, Python wrapper runnable on the build machine must be provided. Set CT_GDB_CROSS_PYTHON_BINARY." - elif [ "${CT_CONFIGURE_has_python}" = "y" ]; then - cross_extra_config+=("--with-python=${python}") - else - CT_Abort "Python support requested in GDB, but Python not found. Set CT_GDB_CROSS_PYTHON_BINARY." - fi + local gcc_version p _p + local -a cross_extra_config + + CT_DoStep INFO "Installing cross-gdb" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-gdb-cross" + + cross_extra_config=( "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}" ) + if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then + if [ -z "${CT_GDB_CROSS_PYTHON_BINARY}" ]; then + if [ "${CT_CANADIAN}" = "y" -o "${CT_CROSS_NATIVE}" = "y" ]; then + CT_Abort "For canadian build, Python wrapper runnable on the build machine must be provided. Set CT_GDB_CROSS_PYTHON_BINARY." + elif [ "${CT_CONFIGURE_has_python}" = "y" ]; then + cross_extra_config+=("--with-python=${python}") else - cross_extra_config+=("--with-python=${CT_GDB_CROSS_PYTHON_BINARY}") + CT_Abort "Python support requested in GDB, but Python not found. Set CT_GDB_CROSS_PYTHON_BINARY." fi else - cross_extra_config+=("--with-python=no") + cross_extra_config+=("--with-python=${CT_GDB_CROSS_PYTHON_BINARY}") fi + else + cross_extra_config+=("--with-python=no") + fi - if [ "${CT_GDB_CROSS_SIM}" = "y" ]; then - cross_extra_config+=("--enable-sim") - else - cross_extra_config+=("--disable-sim") - fi + if [ "${CT_GDB_CROSS_SIM}" = "y" ]; then + cross_extra_config+=("--enable-sim") + else + cross_extra_config+=("--disable-sim") + fi - if ${CT_HOST}-gcc --version 2>&1 | grep clang; then - # clang detects the line from gettext's _ macro as format string - # not being a string literal and produces a lot of warnings - which - # ct-ng's logger faithfully relays to user if this happens in the - # error() function. Suppress them. - cross_extra_config+=("--enable-build-warnings=,-Wno-format-nonliteral,-Wno-format-security") - fi + if ${CT_HOST}-gcc --version 2>&1 | grep clang; then + # clang detects the line from gettext's _ macro as format string + # not being a string literal and produces a lot of warnings - which + # ct-ng's logger faithfully relays to user if this happens in the + # error() function. Suppress them. + cross_extra_config+=("--enable-build-warnings=,-Wno-format-nonliteral,-Wno-format-security") + fi - # Target libexpat resides in sysroot and does not have - # any dependencies, so just passing '-lexpat' to gcc is enough. - # - # By default gdb configure looks for expat in '$prefix/lib' - # directory. In our case '$prefix/lib' resolves to '/usr/lib' - # where libexpat for build platform lives, which is - # unacceptable for cross-compiling. - # - # To prevent this '--without-libexpat-prefix' flag must be passed. - # Thus configure falls back to '-lexpat', which is exactly what we want. - # - # NOTE: DO NOT USE --with-libexpat-prefix (until GDB configure is smarter)!!! - # It conflicts with a static build: GDB's configure script will find the shared - # version of expat and will attempt to link that, despite the -static flag. - # The link will fail, and configure will abort with "expat missing or unusable" - # message. - cross_extra_config+=("--with-expat") - cross_extra_config+=("--without-libexpat-prefix") - - # ct-ng always builds ncurses in cross mode as a static library. - # Starting from the patchset 20200718 ncurses defines a special macro - # NCURSES_STATIC for a static library. This is critical for mingw host - # platform. - # - # The problem is that the macro must be defined in a user program too, - # not just in ncurses. It won't hurt if we define it here. - do_gdb_backend \ - buildtype=cross \ - host="${CT_HOST}" \ - cflags="${CT_CFLAGS_FOR_HOST} -DNCURSES_STATIC" \ - ldflags="${CT_LDFLAGS_FOR_HOST}" \ - prefix="${CT_PREFIX_DIR}" \ - static="${CT_GDB_CROSS_STATIC}" \ - static_libstdcxx="${CT_GDB_CROSS_STATIC_LIBSTDCXX}" \ - --with-sysroot="${CT_SYSROOT_DIR}" \ - "${cross_extra_config[@]}" - - if [ "${CT_BUILD_MANUALS}" = "y" ]; then - CT_DoLog EXTRA "Building and installing the cross-GDB manuals" - CT_DoExecLog ALL make ${CT_JOBSFLAGS} pdf html - CT_DoExecLog ALL make install-{pdf,html}-gdb - fi + # Target libexpat resides in sysroot and does not have + # any dependencies, so just passing '-lexpat' to gcc is enough. + # + # By default gdb configure looks for expat in '$prefix/lib' + # directory. In our case '$prefix/lib' resolves to '/usr/lib' + # where libexpat for build platform lives, which is + # unacceptable for cross-compiling. + # + # To prevent this '--without-libexpat-prefix' flag must be passed. + # Thus configure falls back to '-lexpat', which is exactly what we want. + # + # NOTE: DO NOT USE --with-libexpat-prefix (until GDB configure is smarter)!!! + # It conflicts with a static build: GDB's configure script will find the shared + # version of expat and will attempt to link that, despite the -static flag. + # The link will fail, and configure will abort with "expat missing or unusable" + # message. + cross_extra_config+=("--with-expat") + cross_extra_config+=("--without-libexpat-prefix") + + # ct-ng always builds ncurses in cross mode as a static library. + # Starting from the patchset 20200718 ncurses defines a special macro + # NCURSES_STATIC for a static library. This is critical for mingw host + # platform. + # + # The problem is that the macro must be defined in a user program too, + # not just in ncurses. It won't hurt if we define it here. + do_gdb_backend \ + buildtype=cross \ + host="${CT_HOST}" \ + cflags="${CT_CFLAGS_FOR_HOST} -DNCURSES_STATIC" \ + ldflags="${CT_LDFLAGS_FOR_HOST}" \ + prefix="${CT_PREFIX_DIR}" \ + static="${CT_GDB_CROSS_STATIC}" \ + static_libstdcxx="${CT_GDB_CROSS_STATIC_LIBSTDCXX}" \ + --with-sysroot="${CT_SYSROOT_DIR}" \ + "${cross_extra_config[@]}" + + if [ "${CT_BUILD_MANUALS}" = "y" ]; then + CT_DoLog EXTRA "Building and installing the cross-GDB manuals" + CT_DoExecLog ALL make ${CT_JOBSFLAGS} pdf html + CT_DoExecLog ALL make install-{pdf,html}-gdb + fi - CT_DoLog EXTRA "Installing '.gdbinit' template" - # See in scripts/build/internals.sh for why we do this - # TBD GCC 3.x and older not supported - if [ -f "${CT_SRC_DIR}/gcc/gcc/BASE-VER" ]; then - gcc_version=$(cat "${CT_SRC_DIR}/gcc/gcc/BASE-VER") - else - gcc_version=$(sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \ - "${CT_SRC_DIR}/gcc/gcc/version.c" \ - ) - fi - sed -r \ - -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;" \ - -e "s:@@VERSION@@:${gcc_version}:;" \ - "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in" \ - >"${CT_PREFIX_DIR}/share/gdb/gdbinit" + CT_DoLog EXTRA "Installing '.gdbinit' template" + # See in scripts/build/internals.sh for why we do this + # TBD GCC 3.x and older not supported + if [ -f "${CT_SRC_DIR}/gcc/gcc/BASE-VER" ]; then + gcc_version=$(cat "${CT_SRC_DIR}/gcc/gcc/BASE-VER") + else + gcc_version=$(sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \ + "${CT_SRC_DIR}/gcc/gcc/version.c" \ + ) + fi + sed -r \ + -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;" \ + -e "s:@@VERSION@@:${gcc_version}:;" \ + "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in" \ + >"${CT_PREFIX_DIR}/share/gdb/gdbinit" + + CT_Popd + CT_EndStep +} - CT_Popd - CT_EndStep +do_debug_gdb_build() +{ + if [ "${CT_GDB_CROSS}" = "y" ]; then + do_debug_gdb_build_cross fi if [ "${CT_GDB_NATIVE}" = "y" ]; then From e1d175f0982f16901eab1531367d594635b0c0e7 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Mon, 13 Jun 2022 02:09:08 +0900 Subject: [PATCH 5/7] gdb: Build additional Python scripting-capable variant This commit adds an option to build an additional gdb variant (gdb-py) that supports Python scripting. When this option is enabled, the default gdb variant (gdb) does not link against libpython; instead, an additional Python-capable gdb variant executable (gdb-py) that links against libpython is built. Signed-off-by: Stephanos Ioannidis --- config/debug/gdb.in.cross | 11 ++++++++++ scripts/build/debug/300-gdb.sh | 37 ++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/config/debug/gdb.in.cross b/config/debug/gdb.in.cross index 35c1258d2c..2fa8db2612 100644 --- a/config/debug/gdb.in.cross +++ b/config/debug/gdb.in.cross @@ -58,6 +58,17 @@ config GDB_CROSS_PYTHON have been reports of problems when linking gdb to the static libpython.a. This should be fixed in gdb >=7.3. YMMV. +config GDB_CROSS_PYTHON_VARIANT + bool + prompt "Build additional Python-capable gdb variant (gdb-py)" + depends on GDB_CROSS_PYTHON + help + Build an additional gdb variant (gdb-py) that supports Python scripting. + + When this option is enabled, the default gdb variant (gdb) does not link + against libpython; instead, an additional Python-capable gdb variant + executable (gdb-py) that links against libpython is built. + config GDB_CROSS_PYTHON_BINARY string "Python binary to use" depends on GDB_CROSS_PYTHON diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index aa8d13441f..8331b34de7 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -12,14 +12,32 @@ do_debug_gdb_extract() do_debug_gdb_build_cross() { + local progprefix progsuffix usepython local gcc_version p _p local -a cross_extra_config - CT_DoStep INFO "Installing cross-gdb" - CT_mkdir_pushd "${CT_BUILD_DIR}/build-gdb-cross" + for arg in "$@"; do + case "$arg" in + *) + eval "${arg// /\\ }" + ;; + esac + done + + CT_DoStep INFO "Installing cross-${progprefix}gdb${progsuffix}" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-${progprefix}gdb${progsuffix}-cross" cross_extra_config=( "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}" ) - if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then + + if [ -n "${progprefix}" ]; then + cross_extra_config+=("--program-prefix=${progprefix}") + fi + + if [ -n "${progsuffix}" ]; then + cross_extra_config+=("--program-suffix=${progsuffix}") + fi + + if [ "${usepython}" = "y" ]; then if [ -z "${CT_GDB_CROSS_PYTHON_BINARY}" ]; then if [ "${CT_CANADIAN}" = "y" -o "${CT_CROSS_NATIVE}" = "y" ]; then CT_Abort "For canadian build, Python wrapper runnable on the build machine must be provided. Set CT_GDB_CROSS_PYTHON_BINARY." @@ -115,7 +133,18 @@ do_debug_gdb_build_cross() do_debug_gdb_build() { if [ "${CT_GDB_CROSS}" = "y" ]; then - do_debug_gdb_build_cross + if [ "${CT_GDB_CROSS_PYTHON_VARIANT}" = "y" ]; then + do_debug_gdb_build_cross \ + usepython=n + + do_debug_gdb_build_cross \ + usepython=y \ + progprefix="${CT_TARGET}-" \ + progsuffix="-py" + else + do_debug_gdb_build_cross \ + usepython="${CT_GDB_CROSS_PYTHON}" + fi fi if [ "${CT_GDB_NATIVE}" = "y" ]; then From e8f84c7827dcb8bd88ce9a1c00e3964ac8098399 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Mon, 4 Jul 2022 20:12:30 +0900 Subject: [PATCH 6/7] cross-gdb: Add LZMA support configuration This commit adds a new configuration for enabling the LZMA compression support through the liblzma, which is required by the GDB's "mini debuginfo" feature. Note that this configuration is not enabled by default because it is a niche feature and requires the liblzma, which is currently not built by the crosstool-ng for the host (gdb also keeps this feature disabled by default unless liblzma is available for the host). Signed-off-by: Stephanos Ioannidis --- config/debug/gdb.in.cross | 11 +++++++++++ scripts/build/debug/300-gdb.sh | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/config/debug/gdb.in.cross b/config/debug/gdb.in.cross index 2fa8db2612..0adff4f660 100644 --- a/config/debug/gdb.in.cross +++ b/config/debug/gdb.in.cross @@ -85,6 +85,17 @@ config GDB_CROSS_PYTHON_BINARY help message in gdb's configure script for the --with-python option for further guidance. +config GDB_CROSS_LZMA + bool + prompt "Build GDB with LZMA" + help + Build GDB with liblzma, a compression library supporting the LZMA + algorithm. LZMA is used by the GDB's "mini debuginfo" feature, which is + only useful on the platforms using the ELF object file format. + + Note that crosstool-ng does not build liblzma for the host and you are + responsible for providing this library on the build system. + config GDB_CROSS_EXTRA_CONFIG_ARRAY string prompt "Cross-gdb extra config" diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index 8331b34de7..ef7bb826b9 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -59,6 +59,12 @@ do_debug_gdb_build_cross() cross_extra_config+=("--disable-sim") fi + if [ "${CT_GDB_CROSS_LZMA}" = "y" ]; then + cross_extra_config+=("--with-lzma") + else + cross_extra_config+=("--without-lzma") + fi + if ${CT_HOST}-gcc --version 2>&1 | grep clang; then # clang detects the line from gettext's _ macro as format string # not being a string literal and produces a lot of warnings - which From 998ad4de23a1cfab0da6ce77e36d288cc9dd60c6 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Mon, 4 Jul 2022 20:17:47 +0900 Subject: [PATCH 7/7] cross-gdb: Add Guile scripting support configuration This commit adds a new configuration for enabling the GNU Guile scripting support through the libguile. Note that this configuration is not enabled by default because it is a niche feature and requires the libguile, which is currently not built by the crosstool-ng for the host (gdb also keeps this feature disabled by default unless libguile is available for the host). Signed-off-by: Stephanos Ioannidis --- config/debug/gdb.in.cross | 10 ++++++++++ scripts/build/debug/300-gdb.sh | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/config/debug/gdb.in.cross b/config/debug/gdb.in.cross index 0adff4f660..0c1df4f12d 100644 --- a/config/debug/gdb.in.cross +++ b/config/debug/gdb.in.cross @@ -96,6 +96,16 @@ config GDB_CROSS_LZMA Note that crosstool-ng does not build liblzma for the host and you are responsible for providing this library on the build system. +config GDB_CROSS_GUILE + bool + prompt "Build GDB with GNU Guile scripting support" + help + Build GDB with libguile, a library implementing the GNU Guile scripting + feature. + + Note that crosstool-ng does not build libguile for the host and you are + responsible for providing this library on the build system. + config GDB_CROSS_EXTRA_CONFIG_ARRAY string prompt "Cross-gdb extra config" diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index ef7bb826b9..ac4a0b0b49 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -65,6 +65,12 @@ do_debug_gdb_build_cross() cross_extra_config+=("--without-lzma") fi + if [ "${CT_GDB_CROSS_GUILE}" = "y" ]; then + cross_extra_config+=("--with-guile") + else + cross_extra_config+=("--without-guile") + fi + if ${CT_HOST}-gcc --version 2>&1 | grep clang; then # clang detects the line from gettext's _ macro as format string # not being a string literal and produces a lot of warnings - which