dev-debug/gdb: backport 2 fixes to 17.2

* Fix build on sparc
* Don't enable emoji in MI output, which breaks e.g. kdevelop

Closes: https://bugs.gentoo.org/981378
Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sam James
2026-08-25 05:03:03 +01:00
parent b08ee78d45
commit 3cb63a7d2a
3 changed files with 587 additions and 0 deletions

View File

@@ -0,0 +1,156 @@
https://sourceware.org/PR34501
https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/915
From 615449b7e8d92ed8b9025b3591853b2517b79fa5 Mon Sep 17 00:00:00 2001
Message-ID: <615449b7e8d92ed8b9025b3591853b2517b79fa5.1787629806.git.sam@gentoo.org>
From: Tom de Vries <tdevries@suse.de>
Date: Thu, 13 Aug 2026 03:59:17 +0200
Subject: [PATCH] [gdb/cli] Don't emit emojis in MI
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
PR mi/34501 reports the following:
...
$ gdb -q \
-ex 'set charset UTF-8' \
-ex 'interpreter-exec mi2 "-break-insert -f foo' \
-ex quit
&"<22>\235\214<31>\217 No symbol table is loaded. Use the \"file\" command.\n"
...
$
...
The output is a bit odd, but that gets better if we use
'set print sevenbit-strings on':
...
&"\342\235\214\357\270\217 No symbol table is loaded. Use the \"file\" command.\n"
...
The output we see there is the error emoji:
...
$ gdb
(gdb) b foo
❌️ No symbol table is loaded. Use the "file" command.
...
More specifically, two utf-8 encoded unicode characters:
- Cross Mark [1]: 0xE2 0x9D 0x8C
- Variation Selector-16 (VS16) [2]: 0xEF 0xB8 0x8F
Now the question: is GDB doing something wrong?
I think we probably should encode unicode characters in MI error strings as
octal escapes, independent of the sevenbit-strings setting. This patch does
not address this part.
Then there's the question whether we should emit emojis in MI error strings in
the first place [3]. In principle they're unicode characters encoded in UTF-8,
and we can expect other such unicode characters in translated error strings.
But, given that MI has can_emit_style_escape () == false, and already filters
out ANSI escape sequences, I think it's reasonable to also disable emojis.
As for implementation, I introduced a function emoji_allowed alongside
can_emit_style_escape, which defaults to the value of can_emit_style_escape.
Tested on x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34501
[1] https://www.compart.com/en/unicode/U+274C
[2] https://www.compart.com/en/unicode/U+FE0F
[3] https://sourceware.org/bugzilla/show_bug.cgi?id=33920#c1
(cherry picked from commit dbf19e0f878eb592011c25c1dbbfc35eee330ec2)
---
gdb/cli/cli-style.c | 4 +--
gdb/testsuite/gdb.base/style-mi-no-emoji.exp | 30 ++++++++++++++++++++
gdb/ui-file.h | 8 ++++++
3 files changed, 40 insertions(+), 2 deletions(-)
create mode 100644 gdb/testsuite/gdb.base/style-mi-no-emoji.exp
diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c
index d6829f01095..7379f9a55bc 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -468,7 +468,7 @@ show_warning_prefix (struct ui_file *file, int from_tty,
void
print_warning_prefix (ui_file *file)
{
- if (emojis_ok ())
+ if (file->emoji_allowed () && emojis_ok ())
gdb_puts (warning_prefix.c_str (), file);
}
@@ -490,7 +490,7 @@ show_error_prefix (struct ui_file *file, int from_tty,
void
print_error_prefix (ui_file *file)
{
- if (emojis_ok ())
+ if (file->emoji_allowed () && emojis_ok ())
gdb_puts (error_prefix.c_str (), file);
}
diff --git a/gdb/testsuite/gdb.base/style-mi-no-emoji.exp b/gdb/testsuite/gdb.base/style-mi-no-emoji.exp
new file mode 100644
index 00000000000..c46c35b04a6
--- /dev/null
+++ b/gdb/testsuite/gdb.base/style-mi-no-emoji.exp
@@ -0,0 +1,30 @@
+# Copyright (C) 2026 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
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check that emojis are not printed in MI error messages.
+
+with_ansi_styling_terminal {
+ clean_restart
+
+ gdb_test "set style emoji on"
+
+ # Check that there is no emoji printed before the error. Regression test
+ # for PR34501.
+ set re_line \
+ [string_to_regexp \
+ {&"No symbol table is loaded. Use the \"file\" command.\n"}]
+ gdb_test {interpreter-exec mi2 "-break-insert -f foo"} \
+ "\r\n${re_line}(?=\r\n).*"
+}
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 1219bde0a75..bf44389d652 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -93,6 +93,14 @@ class ui_file
virtual bool can_emit_style_escape ()
{ return false; }
+ /* True if emojis are allowed on STREAM. */
+ bool emoji_allowed ()
+ {
+ /* By default, assume that emojis are not allowed on streams that don't
+ support ANSI escapes. */
+ return can_emit_style_escape ();
+ }
+
virtual void flush ()
{}
base-commit: 2636da31af44fab38c22cee0fe771761173ea64b
--
2.55.0

View File

@@ -0,0 +1,75 @@
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=2636da31af44fab38c22cee0fe771761173ea64b
From 2636da31af44fab38c22cee0fe771761173ea64b Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@efficios.com>
Date: Mon, 17 Nov 2025 16:25:18 -0500
Subject: [PATCH] gdb/ser-unix: work around conflicting types for tcflag_t
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit
When trying to cross-compile GDB to sparc-buildroot-linux-uclibc, I get:
CXX ser-unix.o
In file included from /data1/smarchi/many-buildroots/toolchains/sparc/sparc-buildroot-linux-uclibc/sysroot/usr/include/termios.h:39,
from /home/smarchi/src/binutils-gdb/gdb/ser-unix.c:51:
/data1/smarchi/many-buildroots/toolchains/sparc/sparc-buildroot-linux-uclibc/sysroot/usr/include/bits/termios.h:26:22: error: conflicting declaration ‘typedef unsigned int tcflag_t’
26 | typedef unsigned int tcflag_t;
| ^~~~~~~~
In file included from /home/smarchi/src/binutils-gdb/gdb/ser-unix.c:46:
/data1/smarchi/many-buildroots/toolchains/sparc/sparc-buildroot-linux-uclibc/sysroot/usr/include/asm/termbits.h:13:25: note: previous declaration as ‘typedef long unsigned int tcflag_t’
13 | typedef unsigned long tcflag_t;
| ^~~~~~~~
uClibc and the kernel don't agree on the definition of tcflag_t for this
architecture. Here' uClibc [1]:
typedef unsigned int tcflag_t;
And here's the kernel [2]:
#if defined(__sparc__) && defined(__arch64__)
typedef unsigned int tcflag_t;
#else
typedef unsigned long tcflag_t; <--- that branch is take
#endif
glibc [3] has the same definition as uClibc, so we would get the same
problem.
I propose to work around this the same way as we handle differences in
the termios structure, by renaming the version from the kernel.
I opened a bug on the glibc bugzilla [4] to ask if this is something
that would need to be fixed on the libc side, but in the mean time we
need to work around it.
[1] https://github.com/kraj/uClibc/blob/ca1c74d67dd115d059a875150e10b8560a9c35a8/libc/sysdeps/linux/sparc/bits/termios.h#L26
[2] https://github.com/torvalds/linux/blob/e7c375b181600caf135cfd03eadbc45eb530f2cb/arch/sparc/include/uapi/asm/termbits.h#L7-L11
[3] https://gitlab.com/gnutools/glibc/-/blob/efc8642051e6c4fe5165e8986c1338ba2c180de6/bits/termios.h#L104
[4] https://sourceware.org/bugzilla/show_bug.cgi?id=33643
Change-Id: I71c6e0df5ac8e2ff3db3233a2220faaf70c3df6d
Approved-By: Tom Tromey <tom@tromey.com>
(cherry picked from commit 6b84377e146794446f21371f8455b870a029cc8e)
---
gdb/ser-unix.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 5ec664df1f3..50c0fdddf6d 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -43,8 +43,10 @@
/* Workaround to resolve conflicting declarations of termios
in <asm/termbits.h> and <termios.h>. */
# define termios asmtermios
+# define tcflag_t asmtcflag_t
# include <asm/termbits.h>
# undef termios
+# undef tcflag_t
#endif
#ifdef HAVE_TERMIOS_H
--
2.43.7

View File

@@ -0,0 +1,356 @@
# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
# See https://sourceware.org/gdb/wiki/DistroAdvice for general packaging
# tips & notes.
GUILE_COMPAT=( 2-2 3-0 )
PYTHON_COMPAT=( python3_{11..14} )
inherit flag-o-matic guile-single linux-info python-single-r1 strip-linguas toolchain-funcs
export CTARGET=${CTARGET:-${CHOST}}
if [[ ${CTARGET} == ${CHOST} ]] ; then
if [[ ${CATEGORY} == cross-* ]] ; then
export CTARGET=${CATEGORY#cross-}
fi
fi
is_cross() { [[ ${CHOST} != ${CTARGET} ]] ; }
case ${PV} in
9999*)
# live git tree
EGIT_REPO_URI="
https://sourceware.org/git/binutils-gdb.git
https://git.sr.ht/~sourceware/binutils-gdb
https://gitlab.com/x86-binutils/binutils-gdb.git
"
inherit git-r3
SRC_URI=""
;;
*.*.50_p2???????|*.*.90_p2???????)
# Weekly snapshots
MY_PV="${PV/_p/.}"
SRC_URI="
https://sourceware.org/pub/gdb/snapshots/branch/gdb-weekly-${MY_PV}.tar.xz
https://sourceware.org/pub/gdb/snapshots/current/gdb-weekly-${MY_PV}.tar.xz
https://distfiles.gentoo.org/pub/proj/toolchain/gdb/snapshots/gdb-weekly-${MY_PV}.tar.xz
"
S="${WORKDIR}/${PN}-${MY_PV}"
# e.g. 13.1.90_p20230325 is a snapshot on the stable branch, so it's fine
if [[ ${PV} == *.[123456789].9?_p2??????? ]] ; then
REGULAR_RELEASE=1
fi
;;
*.*.9?)
# Prereleases
MY_PV="${PV/_p/.}"
SRC_URI="
https://sourceware.org/pub/gdb/snapshots/branch/gdb-${MY_PV}.tar.xz
https://distfiles.gentoo.org/pub/proj/toolchain/gdb/snapshots/gdb-${MY_PV}.tar.xz
"
S="${WORKDIR}/${PN}-${MY_PV}"
;;
*)
# Normal upstream release
SRC_URI="
mirror://gnu/gdb/${P}.tar.xz
https://sourceware.org/pub/gdb/releases/${P}.tar.xz
"
REGULAR_RELEASE=1
esac
PATCH_DEV=""
PATCH_VER=""
DESCRIPTION="GNU debugger"
HOMEPAGE="https://sourceware.org/gdb/"
SRC_URI="
${SRC_URI}
${PATCH_DEV:+https://distfiles.gentoo.org/pub/proj/toolchain/gdb/patches/${P}-patches-${PATCH_VER}.tar.xz}
"
LICENSE="GPL-3+ LGPL-2.1+"
SLOT="0"
IUSE="babeltrace cet +debuginfod guile lzma multitarget nls +python rocm +server sim source-highlight test vanilla +xml xxhash zstd"
if [[ -n ${REGULAR_RELEASE} ]] ; then
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~x64-macos ~x64-solaris"
fi
REQUIRED_USE="
guile? ( ${GUILE_REQUIRED_USE} )
python? ( ${PYTHON_REQUIRED_USE} )
rocm? ( multitarget )
"
RESTRICT="!test? ( test )"
# <babeltrace-2: bug #951652
RDEPEND="
dev-libs/mpfr:=
dev-libs/gmp:=
>=sys-libs/ncurses-5.2-r2:=
>=sys-libs/readline-7:=
virtual/zlib:=
babeltrace? ( dev-util/babeltrace:0/1 )
debuginfod? (
dev-libs/elfutils[debuginfod(-)]
)
lzma? ( app-arch/xz-utils )
python? ( ${PYTHON_DEPS} )
guile? ( ${GUILE_DEPS} )
xml? ( dev-libs/expat )
rocm? ( >=dev-libs/rocdbgapi-6.3 )
source-highlight? (
dev-util/source-highlight
)
xxhash? (
dev-libs/xxhash
)
zstd? ( app-arch/zstd:= )
"
DEPEND="${RDEPEND}"
BDEPEND="
app-arch/xz-utils
sys-apps/texinfo
app-alternatives/yacc
nls? ( sys-devel/gettext )
source-highlight? ( virtual/pkgconfig )
test? ( dev-util/dejagnu )
"
QA_CONFIG_IMPL_DECL_SKIP=(
MIN # gnulib FP (bug #898688)
)
QA_PREBUILT="usr/share/gdb/guile/*"
PATCHES=(
"${FILESDIR}"/${PN}-8.3.1-verbose-build.patch
"${FILESDIR}"/${P}-sparc-termios.patch
"${FILESDIR}"/${PN}-17.2-gdb-cli-Don-t-emit-emojis-in-MI.patch
)
pkg_setup() {
local CONFIG_CHECK
if [[ ${CHOST} == *-linux-* ]] ; then
if kernel_is -ge 6.11.3 ; then
# https://forums.gentoo.org/viewtopic-p-8846891.html
# See also PR31520.
#
# Either CONFIG_PROC_MEM_ALWAYS_FORCE or CONFIG_PROC_MEM_FORCE_PTRACE
# should be okay, but not CONFIG_PROC_MEM_NO_FORCE.
CONFIG_CHECK+="
~!PROC_MEM_NO_FORCE
"
fi
fi
linux-info_pkg_setup
use guile && guile-single_pkg_setup
use python && python-single-r1_pkg_setup
}
src_prepare() {
default
use guile && guile_bump_sources
strip-linguas -u bfd/po opcodes/po
# Avoid using ancient termcap from host on Prefix systems
sed -i -e 's/termcap tinfow/tinfow/g' \
gdb/configure{.ac,} || die
}
gdb_branding() {
printf "Gentoo ${PV} "
if ! use vanilla && [[ -n ${PATCH_VER} ]] ; then
printf "p${PATCH_VER}"
else
printf "vanilla"
fi
[[ -n ${EGIT_COMMIT} ]] && printf " ${EGIT_COMMIT}"
}
src_configure() {
strip-unsupported-flags
# See https://www.gnu.org/software/make/manual/html_node/Parallel-Output.html
# Avoid really confusing logs from subconfigure spam, makes logs far
# more legible.
MAKEOPTS="--output-sync=line ${MAKEOPTS}"
local myconf=(
# portage's econf() does not detect presence of --d-d-t
# because it greps only top-level ./configure. But not
# libiberty's or gdb's configure.
--disable-dependency-tracking
--disable-silent-rules
--with-pkgversion="$(gdb_branding)"
--with-bugurl='https://bugs.gentoo.org/'
--disable-werror
# Disable modules that are in a combined binutils/gdb tree. bug #490566
--disable-{binutils,etc,gas,gold,gprof,gprofng,ld}
$(use_with babeltrace)
$(use_with debuginfod)
$(use_enable test unit-tests)
# Allow user to opt into CET for host libraries.
# Ideally we would like automagic-or-disabled here.
# But the check does not quite work on i686: bug #760926.
$(use_enable cet)
# Helps when cross-compiling. Not to be confused with --with-sysroot.
--with-build-sysroot="${ESYSROOT}"
)
is_cross && myconf+=(
--with-sysroot="\${prefix}/${CTARGET}"
--includedir="\${prefix}/include/${CTARGET}"
--with-gdb-datadir="\${datadir}/gdb/${CTARGET}"
)
# gdbserver only works for native targets (CHOST==CTARGET).
# it also doesn't support all targets, so rather than duplicate
# the target list (which changes between versions), use the
# "auto" value when things are turned on, which is triggered
# whenever no --enable or --disable is given
if is_cross || use !server ; then
myconf+=( --disable-gdbserver )
fi
myconf+=(
--enable-64-bit-bfd
--disable-install-libbfd
--disable-install-libiberty
--enable-obsolete
# This only disables building in the readline subdir.
# For gdb itself, it'll use the system version.
--disable-readline
--with-system-readline
# This only disables building in the zlib subdir.
# For gdb itself, it'll use the system version.
--without-zlib
--with-system-zlib
--with-separate-debug-dir="${EPREFIX}"/usr/lib/debug
--with-amd-dbgapi=$(usex rocm)
$(use_with xml expat)
$(use_with lzma)
$(use_enable nls)
$(use_enable sim)
$(use_enable source-highlight)
$(use multitarget && echo --enable-targets=all)
$(use_with python python "${EPYTHON}")
$(use_with xxhash)
$(use_with guile)
$(use_with zstd)
# Find libraries using the toolchain sysroot rather than the configured
# prefix. Needed when cross-compiling.
#
# Check which libraries to apply this to with:
# "${S}"/gdb/configure --help | grep without-lib | sort
--without-lib{babeltrace,expat,gmp,iconv,ipt,lzma,mpfr,xxhash}-prefix
)
# source-highlight is detected with pkg-config: bug #716558
export ac_cv_path_pkg_config_prog_path="$(tc-getPKG_CONFIG)"
export CC_FOR_BUILD="$(tc-getBUILD_CC)"
# ensure proper compiler is detected for Clang builds: bug #831202
export GCC_FOR_TARGET="${CC_FOR_TARGET:-$(tc-getCC)}"
econf "${myconf[@]}"
}
src_test() {
# Run the unittests (nabbed invocation from Fedora's spec file) at least
emake -k -C gdb run GDBFLAGS='-batch -ex "maintenance selftest"'
# Too many failures
# In fact, gdb's test suite needs some work to get passing.
# See e.g. https://sourceware.org/gdb/wiki/TestingGDB.
# As of 11.2, on amd64: "# of unexpected failures 8600"
# Also, ia64 kernel crashes when gdb testsuite is running.
#emake -k check
}
src_install() {
emake DESTDIR="${D}" install
find "${ED}"/usr -name libiberty.a -delete || die
# Delete translations that conflict with binutils-libs. bug #528088
# Note: Should figure out how to store these in an internal gdb dir.
if use nls ; then
find "${ED}" \
-regextype posix-extended -regex '.*/(bfd|opcodes)[.]g?mo$' \
-delete || die
fi
# Don't install docs when building a cross-gdb
if [[ ${CTARGET} != ${CHOST} ]] ; then
rm -rf "${ED}"/usr/share/{doc,info,locale} || die
local f
for f in "${ED}"/usr/share/man/*/* ; do
if [[ ${f##*/} != ${CTARGET}-* ]] ; then
mv "${f}" "${f%/*}/${CTARGET}-${f##*/}" || die
fi
done
return 0
fi
# Install it by hand for now:
# https://sourceware.org/ml/gdb-patches/2011-12/msg00915.html
# Only install if it exists due to the twisted behavior (see
# notes in src_configure above).
[[ -e gdbserver/gdbreplay ]] && dobin gdbserver/gdbreplay
docinto gdb
dodoc gdb/CONTRIBUTE gdb/README gdb/MAINTAINERS \
gdb/NEWS gdb/PROBLEMS
docinto sim
dodoc sim/{MAINTAINERS,README-HACKING}
if use server ; then
docinto gdbserver
dodoc gdbserver/README
fi
# Remove shared info pages
rm -f "${ED}"/usr/share/info/{annotate,bfd,configure,ctf-spec,standards}.info*
use guile && guile_unstrip_ccache
if use python ; then
python_optimize "${ED}"/usr/share/gdb/python/gdb
fi
if use kernel_Hurd ; then
mv "${ED}"/usr/bin/gcore "${ED}"/usr/bin/gcore.gdb || die
fi
}
pkg_postinst() {
# Portage doesn't unmerge files in /etc
rm -vf "${EROOT}"/etc/skel/.gdbinit
if use prefix && [[ ${CHOST} == *-darwin* ]] ; then
ewarn "gdb is unable to get a mach task port when installed by Prefix"
ewarn "Portage, unprivileged. To make gdb fully functional you'll"
ewarn "have to perform the following steps:"
ewarn " % sudo chgrp procmod ${EPREFIX}/usr/bin/gdb"
ewarn " % sudo chmod g+s ${EPREFIX}/usr/bin/gdb"
fi
}