Set distro name using --with-pkgconfig configure option

Instead of placing the distro name (e.g. 'Fedora Linux') into the
version.in file, use the --with-pkgconfig configure option to set the
disto name.

This does change GDB's version output slightly.   Prior to this commit
we might expect to see something like this:

  $ gdb --version
  GNU gdb (GDB) Fedora Linux 13.1-1-fc38
  ...

Now we'll see this:

  $ gdb --version
  GNU gdb (Fedora Linux) 13.1-1-fc38
  ...

Notice that 'Fedora Linux' moved inside the parenthesis.

There are other benefits to this change, the Python gdb.VERSION
string will now contain '13.1-1-fc38' instead of 'Fedora Linux
13.1-1-fc38', this was reported as an issue in this bug:

  https://bugzilla.redhat.com/show_bug.cgi?id=2179554

I've also removed the change to gdb.gdb/selftest.exp as I don't
believe that this was ever being used -- when this test was run we
should have hit an earlier case.

I have added a brand new test that checks our version string.  I've
placed this new test into a separate file, so we should (hopefully)
not have any issues maintaining this as an out of tree test.

For implementation, by default we make use of the %dist_name macro,
however, this is not defined on RHEL 9 or earlier, so to support
reusing this commit on RHEL systems, I also detect the %rhel macro,
and in that case use a hard-coded string.
This commit is contained in:
Andrew Burgess 2023-03-20 16:32:26 +00:00
parent 7403afbaf9
commit 240ac8eb89
2 changed files with 88 additions and 35 deletions

View File

@ -1,38 +1,34 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Elena Zannoni <ezannoni@redhat.com>
From: Andrew Burgess <aburgess@redhat.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.3-rh-testversion-20041202.patch
;; Match the Fedora's version info.
;;=fedora
;; Check distro name is included in the version output.
2003-02-24 Elena Zannoni <ezannoni@redhat.com>
* gdb.gdb/selftest.exp: Add matching on specific Red Hat only version
string.
diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
--- a/gdb/testsuite/gdb.gdb/selftest.exp
+++ b/gdb/testsuite/gdb.gdb/selftest.exp
@@ -53,6 +53,9 @@ proc test_with_self { } {
-re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
pass "printed version with cast"
}
+ -re ".\[0-9\]+ = .(Fedora Linux|Red Hat Enterprise Linux) \[\\(\\)0-9.a-z\\-\]+.*$gdb_prompt $" {
+ pass "printed version Fedora or Red Hat Enterprise Linux only"
+ }
}
# start the "xgdb" process
diff --git a/gdb/top.c b/gdb/top.c
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2382,7 +2382,7 @@ The second argument is the terminal the UI runs on."), &cmdlist);
struct internalvar *major_version_var = create_internalvar ("_gdb_major");
struct internalvar *minor_version_var = create_internalvar ("_gdb_minor");
int vmajor = 0, vminor = 0, vrevision = 0;
- sscanf (version, "%d.%d.%d", &vmajor, &vminor, &vrevision);
+ sscanf (version, "%*[^0123456789]%d.%d.%d", &vmajor, &vminor, &vrevision);
set_internalvar_integer (major_version_var, vmajor);
set_internalvar_integer (minor_version_var, vminor + (vrevision > 0));
}
diff --git a/gdb/testsuite/gdb.base/fedora-version.exp b/gdb/testsuite/gdb.base/fedora-version.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/fedora-version.exp
@@ -0,0 +1,22 @@
+# Copyright 2023 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/>.
+
+# Start with a fresh gdb
+clean_restart
+
+# Check the version string contains either the Fedora or RHEL distro
+# name, and that the version number looks roughly correct in format.
+gdb_test "show version" \
+ "GNU gdb \\((Fedora Linux|Red Hat Enterprise Linux)\\) \[0-9\]+\\.\[0-9\]+-\[0-9\]+.*"

View File

@ -520,9 +520,55 @@ find -name "*.info*"|xargs rm -f
find -name "*.orig" | xargs rm -f
! find -name "*.rej" # Should not happen.
# Change the version that gets printed at GDB startup, so it is distro-specific.
# In the past a distro name prefix was added to the version string in
# version.in.
#
# However, placing text at the start of version.in can cause problems;
# GDB will have a version string that starts with text rather than a
# number as is the case with upstream GDB, and for most (all?) other
# distros.
#
# GDB's version string is exposed to users as part of the Python API,
# and it is not uncommon for users to try and grok the version number
# from this string. Having Fedora/RHEL GDB not start with the major
# version number can be unexpected, and might cause tools/script that
# work for other builds of GDB to fail with Fedora/RHEL GDB.
#
# So, we switched to use the more standard --with-pkgversion configure
# option. This ensures the distro name is still included in the 'gdb
# --version' output, but the text is no longer part of the string
# exposed in the Python API.
#
# Unfortunately, for RHEL the dist_name macro is not defined. At
# least not on RHEL 9 or earlier. So, if dist_name is not defined,
# but the rhel macro is, then we use a hard-coded RHEL appropriate
# string.
#
# FIXME: It would be nice to rewrite this using %elif, but this is not
# supported on older (pre 9) RHEL systems.
%if 0%{?dist_name:1}
%global pkgversion_configure_flag --with-pkgversion=%{dist_name}
%else
%if 0%{?fedora:1}
%global pkgversion_configure_flag --with-pkgversion=Fedora Linux
%endif
%if 0%{?rhel:1}
%global pkgversion_configure_flag --with-pkgversion=Red Hat Enterprise Linux
%endif
%endif
# Change the version that gets printed by GDB. The 'version' here is
# usually the same as the original upstream version on which we are
# based. The 'release' is new information we're adding and identifies
# the modifications we've made to upstream.
cat > gdb/version.in << _FOO
%{?dist_name} %{version}-%{release}
%{?version_prefix:%version_prefix }%{version}-%{release}
_FOO
# Remove the info and other generated files added by the FSF release
@ -644,6 +690,9 @@ export PKG_CONFIG_PATH=%{_libdir}/pkgconfig
../configure \
${COMMON_GDB_CONFIGURE_FLAGS} \
${GDB_MINIMAL_CONFIGURE_FLAGS} \
%if 0%{?pkgversion_configure_flag:1}
"%{pkgversion_configure_flag}" \
%endif
--with-auto-load-dir='$debugdir:$datadir/auto-load%{?scl::%{_root_datadir}/gdb/auto-load}' \
--with-auto-load-safe-path='$debugdir:$datadir/auto-load%{?scl::%{_root_datadir}/gdb/auto-load}' \
%ifarch sparc sparcv9
@ -744,6 +793,9 @@ $(: ppc64 host build crashes on ppc variant of libexpat.so ) \
../configure \
${COMMON_GDB_CONFIGURE_FLAGS} \
${GDB_FULL_CONFIGURE_FLAGS} \
%if 0%{?pkgversion_configure_flag:1}
"%{pkgversion_configure_flag}" \
%endif
--with-auto-load-dir='$debugdir:$datadir/auto-load%{?scl::%{_root_datadir}/gdb/auto-load}' \
--with-auto-load-safe-path='$debugdir:$datadir/auto-load%{?scl::%{_root_datadir}/gdb/auto-load}' \
%ifarch sparc sparcv9
@ -1192,6 +1244,11 @@ fi
%endif
%changelog
* Wed Mar 29 2023 Andrew Burgess <aburgess@redhat.com>
- Used --with-pkgversion to place the distribution name in the version
string rather than placing the string directly into the version.in
file.
* Fri Mar 24 2023 Kevin Buettner <kevinb@redhat.com> - 13.1-2
- Backport fix for RHBZ 2177655. (Luis Machado)