public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/gdb] gdb-17.2-rebase-f44: Defer printing "rpm module not found" message until after GDB startup
Date: Sun, 28 Jun 2026 00:01:45 GMT	[thread overview]
Message-ID: <178260490529.1.7896373840083635196.rpms-gdb-62add5755cb4@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : rpms/gdb
            Branch : gdb-17.2-rebase-f44
            Commit : 62add5755cb45ee829c4505073c02acf7b6316e1
            Author : Kevin Buettner <kevinb@redhat.com>
            Date   : 2024-06-27T20:00:16-07:00
            Stats  : +26/-5 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/gdb/c/62add5755cb45ee829c4505073c02acf7b6316e1?branch=gdb-17.2-rebase-f44

            Log:
            Defer printing "rpm module not found" message until after GDB startup

The "RPM suggestions" mechanism will not work without the (python) rpm
module.  Inform the user of this, but wait to do so until just prior
to printing the GDB prompt.  If we do it right away, the message
typically appears before the version and copyright info, which is
easily missed by many users.  Additionally, it seems that several
other packages which parse GDB version info are confused by an early
error message regarding a missing python3-rpm package, so waiting to
print the error allows those applications to work as they used to.

I've tested this using a mock chroot which is missing the python3-rpm
package.  This is what is printed when I start GDB:

    <mock-chroot> sh-5.2# /usr/libexec/gdb
    GNU gdb (Fedora Linux) 14.2-12.fc41
    Copyright (C) 2023 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "x86_64-redhat-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <https://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
	<http://www.gnu.org/software/gdb/documentation/>.

    For help, type "help".
    Type "apropos word" to search for commands related to "word".

    Unable to load the Python 'rpm' module.  Lack of this module disables
    the RPM suggestions mechanism which recommends shell commands for
    installing missing debuginfo packages.  To enable this functionality,
    please install the python3-rpm package.
    (gdb)

Note that the version is printed first, instead of a more cryptic
message about a missing rpm module.  I've also expanded the error
message, explaining the implications of the missing rpm module.
That text is also separated from the standard introductory blurb
by a newline.

The error message will not be quieted by GDB's -q switch.  I.e...

    <mock-chroot> sh-5.2# /usr/libexec/gdb -q

    Unable to load the Python 'rpm' module.  Lack of this module disables
    the RPM suggestions mechanism which recommends shell commands for
    installing missing debuginfo packages.  To enable this functionality,
    please install the python3-rpm package.
    (gdb)

However, since the printing of the message is hooked into the
'before_prompt' event, it won't be printed when using GDB's
--batch switch:

    <mock-chroot> sh-5.2# /usr/libexec/gdb -q --batch -ex 'print 6*7'
    $1 = 42

Thus, the error message will no longer be output when running
the gdb-add-index script.

---
diff --git a/gdb-add-rpm-suggestion-script.patch b/gdb-add-rpm-suggestion-script.patch
index f8d72fe..94a4745 100644
--- a/gdb-add-rpm-suggestion-script.patch
+++ b/gdb-add-rpm-suggestion-script.patch
@@ -26,7 +26,7 @@ diff --git a/gdb/python/lib/gdb/command/rpm-suggestions.py b/gdb/python/lib/gdb/
 new file mode 100644
 --- /dev/null
 +++ b/gdb/python/lib/gdb/command/rpm-suggestions.py
-@@ -0,0 +1,118 @@
+@@ -0,0 +1,134 @@
 +# Copyright 2023 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
@@ -48,10 +48,26 @@ new file mode 100644
 +try:
 +    import rpm
 +except ModuleNotFoundError:
-+    print(
-+        "Unable to load 'rpm' module.  Please install the python3-rpm package.",
-+	file=sys.stderr
-+    )
++    # The "RPM suggestions" mechanism will not work without the (python)
++    # rpm module.  Inform the user of this, but wait to do so until
++    # just prior to printing the GDB prompt.  If we do it right away,
++    # the message typically appears before the version and copyright
++    # info, which is easily missed by many users.  Additionally, it
++    # seems that several other packages which parse GDB version info
++    # are confused by an early error message regarding a missing
++    # python3-rpm package, so waiting to print the error allows those
++    # applications to work as they used to.
++    def before_prompt():
++        print(
++            ("\nUnable to load the Python 'rpm' module.  Lack of this module disables\n"
++             "the RPM suggestions mechanism which recommends shell commands for\n"
++             "installing missing debuginfo packages.  To enable this functionality,\n"
++             "please install the python3-rpm package."),
++            file=sys.stderr
++        )
++        gdb.events.before_prompt.disconnect(before_prompt)
++
++    gdb.events.before_prompt.connect(before_prompt)
 +else:
 +    # Track all the RPMs suggested during a single debug session so we
 +    # don't suggest the same RPM twice.  This is only cleared when the

diff --git a/gdb.spec b/gdb.spec
index ea10716..39801a6 100644
--- a/gdb.spec
+++ b/gdb.spec
@@ -926,6 +926,11 @@ fi
 # endif scl
 
 %changelog
+* Thu Jun 27 2024 Kevin Buettner <kevinb@redhat.com>
+- Revise rpm-suggestions.py script so that message regarding
+  a not-found 'rpm' module is deferred until just prior to
+  printing the GDB prompt.  (RHBZ 2275274)
+
 * Wed Jun 19 2024 Guinevere Larsen <blarsen@redhat.com>
 - Drop gdb-glibc-strstr-workaround.patch
 

                 reply	other threads:[~2026-06-28  0:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178260490529.1.7896373840083635196.rpms-gdb-62add5755cb4@fedoraproject.org \
    --to=kevinb@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox