diff --git a/_gdb.spec.Patch.include b/_gdb.spec.Patch.include index 9b964ed..f7ee2f4 100644 --- a/_gdb.spec.Patch.include +++ b/_gdb.spec.Patch.include @@ -187,3 +187,15 @@ Patch042: gdb-rhbz-2232086-generate-gdb-index-consistently.patch # non-deterministic gdb-index generation (RH BZ 2232086). Patch043: gdb-rhbz-2232086-generate-dwarf-5-index-consistently.patch + +Patch044: gdb-rhbz2250652-gdbpy_gil.patch + + +Patch045: gdb-rhbz2250652-avoid-PyOS_ReadlineTState.patch + +# Backport potential fix for RH BZ 2257562. +Patch046: gdb-rhbz2257562-cp-namespace-null-ptr-check.patch + + +Patch047: gdb-ftbs-swapped-calloc-args.patch + diff --git a/_gdb.spec.patch.include b/_gdb.spec.patch.include index abd8ca2..8258dc9 100644 --- a/_gdb.spec.patch.include +++ b/_gdb.spec.patch.include @@ -41,3 +41,7 @@ %patch -p1 -P041 %patch -p1 -P042 %patch -p1 -P043 +%patch -p1 -P044 +%patch -p1 -P045 +%patch -p1 -P046 +%patch -p1 -P047 diff --git a/_patch_order b/_patch_order index aee01ee..ea078f3 100644 --- a/_patch_order +++ b/_patch_order @@ -41,3 +41,7 @@ gdb-rhbz-2232086-reduce-size-of-gdb-index.patch gdb-rhbz-2232086-cpp-ify-mapped-symtab.patch gdb-rhbz-2232086-generate-gdb-index-consistently.patch gdb-rhbz-2232086-generate-dwarf-5-index-consistently.patch +gdb-rhbz2250652-gdbpy_gil.patch +gdb-rhbz2250652-avoid-PyOS_ReadlineTState.patch +gdb-rhbz2257562-cp-namespace-null-ptr-check.patch +gdb-ftbs-swapped-calloc-args.patch diff --git a/gdb-ftbs-swapped-calloc-args.patch b/gdb-ftbs-swapped-calloc-args.patch new file mode 100644 index 0000000..3486c8e --- /dev/null +++ b/gdb-ftbs-swapped-calloc-args.patch @@ -0,0 +1,42 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: Kevin Buettner +Date: Wed, 17 Jan 2024 12:53:53 -0700 +Subject: gdb-ftbs-swapped-calloc-args.patch + +Backport upstream commit 54195469c18ec9873cc5ba6907f768509473fa9b +which fixes a build problem in which arguments to calloc were swapped. + +[opcodes] ARC + PPC: Fix -Walloc-size warnings + +Recently, -Walloc-size warnings started to kick in. Fix these two +calloc() calls to match the intended usage pattern. + +opcodes/ChangeLog: + + * arc-dis.c (init_arc_disasm_info): Fix calloc() call. + * ppc-dis.c (powerpc_init_dialect): Ditto. + +diff --git a/opcodes/arc-dis.c b/opcodes/arc-dis.c +--- a/opcodes/arc-dis.c ++++ b/opcodes/arc-dis.c +@@ -147,7 +147,7 @@ static bool + init_arc_disasm_info (struct disassemble_info *info) + { + struct arc_disassemble_info *arc_infop +- = calloc (sizeof (*arc_infop), 1); ++ = calloc (1, sizeof (*arc_infop)); + + if (arc_infop == NULL) + return false; +diff --git a/opcodes/ppc-dis.c b/opcodes/ppc-dis.c +--- a/opcodes/ppc-dis.c ++++ b/opcodes/ppc-dis.c +@@ -348,7 +348,7 @@ powerpc_init_dialect (struct disassemble_info *info) + { + ppc_cpu_t dialect = 0; + ppc_cpu_t sticky = 0; +- struct dis_private *priv = calloc (sizeof (*priv), 1); ++ struct dis_private *priv = calloc (1, sizeof (*priv)); + + if (priv == NULL) + return; diff --git a/gdb-rhbz2250652-avoid-PyOS_ReadlineTState.patch b/gdb-rhbz2250652-avoid-PyOS_ReadlineTState.patch new file mode 100644 index 0000000..1997ef9 --- /dev/null +++ b/gdb-rhbz2250652-avoid-PyOS_ReadlineTState.patch @@ -0,0 +1,48 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= +Date: Mon, 8 Jan 2024 13:24:05 +0100 +Subject: gdb-rhbz2250652-avoid-PyOS_ReadlineTState.patch + +gdb/python: avoid use of _PyOS_ReadlineTState + +In python/py-gdb-readline.c we make use of _PyOS_ReadlineTState, +however, this variable is no longer public in Python 3.13, and so GDB +no longer builds. + +We are making use of _PyOS_ReadlineTState in order to re-acquire the +Python Global Interpreter Lock (GIL). The _PyOS_ReadlineTState +variable is set in Python's outer readline code prior to calling the +user (GDB) supplied readline callback function, which for us is +gdbpy_readline_wrapper. The gdbpy_readline_wrapper function is called +without the GIL held. + +Instead of using _PyOS_ReadlineTState, I propose that we switch to +calling PyGILState_Ensure() and PyGILState_Release(). These functions +will acquire the GIL based on the current thread. I think this should +be sufficient; I can't imagine why we'd be running +gdbpy_readline_wrapper on one thread on behalf of a different Python +thread.... that would be unexpected I think. + +Approved-By: Tom Tromey + +diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c +--- a/gdb/python/py-gdb-readline.c ++++ b/gdb/python/py-gdb-readline.c +@@ -56,13 +56,11 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout, + if (except.reason == RETURN_QUIT) + return NULL; + +- /* The thread state is nulled during gdbpy_readline_wrapper, +- with the original value saved in the following undocumented +- variable (see Python's Parser/myreadline.c and +- Modules/readline.c). */ +- PyEval_RestoreThread (_PyOS_ReadlineTState); ++ ++ /* This readline callback is called without the GIL held. */ ++ gdbpy_gil gil; ++ + gdbpy_convert_exception (except); +- PyEval_SaveThread (); + return NULL; + } + diff --git a/gdb-rhbz2250652-gdbpy_gil.patch b/gdb-rhbz2250652-gdbpy_gil.patch new file mode 100644 index 0000000..a72c350 --- /dev/null +++ b/gdb-rhbz2250652-gdbpy_gil.patch @@ -0,0 +1,81 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= +Date: Mon, 8 Jan 2024 13:12:15 +0100 +Subject: gdb-rhbz2250652-gdbpy_gil.patch + +gdb: move gdbpy_gil into python-internal.h + +Move gdbpy_gil class into python-internal.h, the next +commit wants to make use of this class from a file other +than python.c. + +Approved-By: Tom Tromey + +diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h +--- a/gdb/python/python-internal.h ++++ b/gdb/python/python-internal.h +@@ -754,6 +754,30 @@ class gdbpy_allow_threads + PyThreadState *m_save; + }; + ++/* A helper class to save and restore the GIL, but without touching ++ the other globals that are handled by gdbpy_enter. */ ++ ++class gdbpy_gil ++{ ++public: ++ ++ gdbpy_gil () ++ : m_state (PyGILState_Ensure ()) ++ { ++ } ++ ++ ~gdbpy_gil () ++ { ++ PyGILState_Release (m_state); ++ } ++ ++ DISABLE_COPY_AND_ASSIGN (gdbpy_gil); ++ ++private: ++ ++ PyGILState_STATE m_state; ++}; ++ + /* Use this after a TRY_EXCEPT to throw the appropriate Python + exception. */ + #define GDB_PY_HANDLE_EXCEPTION(Exception) \ +diff --git a/gdb/python/python.c b/gdb/python/python.c +--- a/gdb/python/python.c ++++ b/gdb/python/python.c +@@ -257,30 +257,6 @@ gdbpy_enter::finalize () + python_gdbarch = target_gdbarch (); + } + +-/* A helper class to save and restore the GIL, but without touching +- the other globals that are handled by gdbpy_enter. */ +- +-class gdbpy_gil +-{ +-public: +- +- gdbpy_gil () +- : m_state (PyGILState_Ensure ()) +- { +- } +- +- ~gdbpy_gil () +- { +- PyGILState_Release (m_state); +- } +- +- DISABLE_COPY_AND_ASSIGN (gdbpy_gil); +- +-private: +- +- PyGILState_STATE m_state; +-}; +- + /* Set the quit flag. */ + + static void diff --git a/gdb-rhbz2257562-cp-namespace-null-ptr-check.patch b/gdb-rhbz2257562-cp-namespace-null-ptr-check.patch new file mode 100644 index 0000000..f868e6f --- /dev/null +++ b/gdb-rhbz2257562-cp-namespace-null-ptr-check.patch @@ -0,0 +1,113 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: Kevin Buettner +Date: Tue, 16 Jan 2024 20:07:53 -0700 +Subject: gdb-rhbz2257562-cp-namespace-null-ptr-check.patch + +;; Backport potential fix for RH BZ 2257562. + +Fix printing of global variable stubs if no inferior is running + +Since 3c45e9f915ae4aeab7312d6fc55a947859057572 gdb crashes when trying +to print a global variable stub without a running inferior, because of +a missing nullptr-check (the block_scope function took care of that +check before it was converted to a method). + +With this check it works again: +``` +(gdb) print s +$1 = +``` + +Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31128 +Approved-By: Tom Tromey +(cherry picked from commit 576745e26c0ec76a53ba45b20af464628a50b3e4) + +diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c +--- a/gdb/cp-namespace.c ++++ b/gdb/cp-namespace.c +@@ -1026,7 +1026,11 @@ cp_lookup_transparent_type (const char *name) + + /* If that doesn't work and we're within a namespace, look there + instead. */ +- scope = get_selected_block (0)->scope (); ++ const block *block = get_selected_block (0); ++ if (block == nullptr) ++ return nullptr; ++ ++ scope = block->scope (); + + if (scope[0] == '\0') + return NULL; +diff --git a/gdb/testsuite/gdb.cp/print-global-stub.cc b/gdb/testsuite/gdb.cp/print-global-stub.cc +new file mode 100644 +--- /dev/null ++++ b/gdb/testsuite/gdb.cp/print-global-stub.cc +@@ -0,0 +1,31 @@ ++/* This testcase is part of GDB, the GNU debugger. ++ ++ 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 . */ ++ ++struct S ++{ ++ S (int); ++ virtual ~S (); ++ ++ int m_i; ++}; ++ ++S s (5); ++ ++int main () ++{ ++ return 0; ++} +diff --git a/gdb/testsuite/gdb.cp/print-global-stub.exp b/gdb/testsuite/gdb.cp/print-global-stub.exp +new file mode 100644 +--- /dev/null ++++ b/gdb/testsuite/gdb.cp/print-global-stub.exp +@@ -0,0 +1,32 @@ ++# Copyright (C) 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 . ++ ++# This file is part of the GDB testsuite. ++# It tests printing of a global stub without inferior. ++ ++require allow_cplus_tests ++ ++standard_testfile .cc ++set objfile [standard_output_file ${testfile}.o] ++ ++if { [gdb_compile $srcdir/$subdir/$srcfile $objfile object \ ++ {c++ debug}] != "" } { ++ untested "failed to compile" ++ return -1 ++} ++ ++clean_restart $objfile ++ ++gdb_test "print s" " = " diff --git a/gdb.spec b/gdb.spec index 8c7040a..2514679 100644 --- a/gdb.spec +++ b/gdb.spec @@ -57,9 +57,9 @@ Version: 14.1 # The release always contains a leading reserved number, start it at 1. # `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing. -Release: 1.0.riscv64%{?dist} +Release: 4.0.riscv64%{?dist} -License: GPL-3.0-or-later AND BSD-3-clause AND FSFAP AND LGPL-2.1-or-later AND GPL-2.0-or-later AND LGPL-2.0-or-later AND LicenseRef-Fedora-Public-Domain AND GFDL-1.3-or-later AND LGPL-2.0-or-later WITH GCC-exception-2.0 AND GPL-3.0-or-later WITH GCC-exception-3.1 AND GPL-2.0-or-later WITH GNU-compiler-exception +License: GPL-3.0-or-later AND BSD-3-Clause AND FSFAP AND LGPL-2.1-or-later AND GPL-2.0-or-later AND LGPL-2.0-or-later AND LicenseRef-Fedora-Public-Domain AND GFDL-1.3-or-later AND LGPL-2.0-or-later WITH GCC-exception-2.0 AND GPL-3.0-or-later WITH GCC-exception-3.1 AND GPL-2.0-or-later WITH GNU-compiler-exception # Do not provide URL for snapshots as the file lasts there only for 2 days. # ftp://sourceware.org/pub/gdb/releases/FIXME{tarname}.tar.xz #Source: %{tarname}.tar.xz @@ -1250,9 +1250,20 @@ fi %endif %changelog -* Thu Dec 14 2023 David Abdurachmanov - 14.1-1.0.riscv64 +* Tue Jan 23 2024 David Abdurachmanov - 14.1-4.0.riscv64 - Add riscv64 support +* Tue Jan 16 2024 Kevin Buettner - 14.1-4 +- Backport upstream commit bc23ea51f8a83e9524dfb553baa8baacb29e68a9, + potentially fixing RHBZ 2257562. + +* Thu Jan 11 2024 Alexandra Hájková - 14.1-3 +- Fix typo in gdb.spec. + +* Mon Jan 8 2024 Alexandra Hájková - 14.1-2 +- Backport upstream commits 7ae9ecfd801 and 8170efad364 to avoid + using _PyOS_ReadlineTState (RHBZ 2250652). + * Fri Dec 8 2023 Kevin Buettner - 14.1-1 - Rebase to FSF GDB 14.1. - Update local patches: