public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/gdb] gdb-17.2-rebase-f44: Catch ModuleNotFoundError in rpm-suggestions.py
@ 2026-06-28  0:01 Kevin Buettner
  0 siblings, 0 replies; only message in thread
From: Kevin Buettner @ 2026-06-28  0:01 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : rpms/gdb
            Branch : gdb-17.2-rebase-f44
            Commit : 16722914d913c6e7475cba5cef63a5e7bd33f29b
            Author : Kevin Buettner <kevinb@redhat.com>
            Date   : 2024-05-23T17:37:53-07:00
            Stats  : +107/-96 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/gdb/c/16722914d913c6e7475cba5cef63a5e7bd33f29b?branch=gdb-17.2-rebase-f44

            Log:
            Catch ModuleNotFoundError in rpm-suggestions.py

Revise rpm-suggestions.py script so that a message is printed when the
'rpm' module (found in the python3-rpm package) isn't found.  In
particular, the ModuleNotFoundError will be caught, avoiding a
potential python import error.  (RHBZ 2275274)

---
diff --git a/gdb-add-rpm-suggestion-script.patch b/gdb-add-rpm-suggestion-script.patch
index 660bc58..1efb387 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,111 @@
+@@ -0,0 +1,116 @@
 +# Copyright 2023 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
@@ -44,100 +44,105 @@ new file mode 100644
 +
 +import gdb
 +import gdb.missing_debug
-+import rpm
-+
-+# 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
-+# main executable is changed.
-+__missing_rpms = {}
-+
-+# Track any missing RPMs that have been discovered since the last time
-+# the prompt was displayed.  RPMs in here are also present in the
-+# __MISSING_RPMS dictionary, but this dictionary is cleared each time
-+# the prompt is shown.
-+__suggest_rpms = {}
-+
-+
-+# Lookup RPMs that might provide the debug information for FILENAME,
-+# which is a string containing the path to an object file GDB could
-+# not find any debug information for.
-+#
-+# If a possible RPM is found then this is added to the globals
-+# __MISSING_RPMS and __SUGGEST_RPMS, which are used elsewhere in this
-+# script.
-+def find_suggestions(filename):
-+    ts = rpm.TransactionSet()
-+
-+    mi = ts.dbMatch(rpm.RPMDBI_BASENAMES, filename)
-+    for h in mi:
-+        # Build the debuginfo package name.
-+        obj = h.format("%{name}-debuginfo-%{version}-%{release}.%{arch}")
-+
-+        # Check to see if the package is installed.
-+        mi2 = ts.dbMatch(rpm.RPMDBI_LABEL, str(obj))
-+        if len(mi2) > 0:
-+            continue
-+
-+        # Now build the name of the package FILENAME came from.
-+        obj = h.format("%{name}-%{version}-%{release}.%{arch}")
-+        rpm_name = str(obj)
-+        if not rpm_name in __missing_rpms:
-+            __suggest_rpms[rpm_name] = True
-+            __missing_rpms[rpm_name] = True
-+
-+
-+# A missing debug handler class.  Just forwards the name of the
-+# objfile for which we are missing debug information to
-+# find_suggestions.
-+class RPMSuggestionHandler(gdb.missing_debug.MissingDebugHandler):
-+    def __init__(self):
-+        super().__init__("rpm-suggestions")
-+
-+    def __call__(self, objfile):
-+        # Traditionally the 'build-id-verbose' parameter is what
-+        # controlled all RPM suggestion.  Maybe once all the RPM
-+        # suggestion is performed via Python extensions then we might
-+        # consider renaming this parameter to something else, but for
-+        # now, for backward compatibility, I've retained this name.
-+        if gdb.parameter("build-id-verbose") > 0:
-+            find_suggestions(objfile.filename)
-+            return False
-+        return None
-+
-+
-+# Called before GDB displays its prompt.  If the global __SUGGEST_RPMS
-+# dictionary is not empty, then this hook prints treats the keys of
-+# this dictionary as strings which are the names of RPMs.  This hook
-+# formats each RPM name into a suggested debuginfo-install command and
-+# suggests this to the user.
-+def before_prompt():
-+    global __suggest_rpms
-+
-+    if len(__suggest_rpms) > 0:
-+        for p in __suggest_rpms.keys():
-+            print("Missing debuginfo, try: dnf debuginfo-install " + p)
-+        __suggest_rpms = {}
-+
-+
-+# Called when the executable within a progrm space is changed.  Clear
-+# the lists of RPM suggestions.  We only clear the previous suggestion
-+# list when the executable really changes.  If the user simply
-+# recompiles the executable, then we don't both clearing this list.
-+def executable_changed_handler(event):
-+    global __missing_rpms
-+    global __suggest_rpms
-+
-+    if not event.reload:
-+        __missing_rpms = {}
-+        __suggest_rpms = {}
-+
-+
-+# Attach to the required GDB events.
-+gdb.events.executable_changed.connect(executable_changed_handler)
-+gdb.events.before_prompt.connect(before_prompt)
-+
-+# Register the missing debug handler with GDB.
-+gdb.missing_debug.register_handler(None, RPMSuggestionHandler())
++try:
++    import rpm
++except ModuleNotFoundError:
++    print(
++        "Unable to load 'rpm' module.  Please install the python3-rpm package."
++    )
++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
++    # main executable is changed.
++    __missing_rpms = {}
++
++    # Track any missing RPMs that have been discovered since the last time
++    # the prompt was displayed.  RPMs in here are also present in the
++    # __MISSING_RPMS dictionary, but this dictionary is cleared each time
++    # the prompt is shown.
++    __suggest_rpms = {}
++
++
++    # Lookup RPMs that might provide the debug information for FILENAME,
++    # which is a string containing the path to an object file GDB could
++    # not find any debug information for.
++    #
++    # If a possible RPM is found then this is added to the globals
++    # __MISSING_RPMS and __SUGGEST_RPMS, which are used elsewhere in this
++    # script.
++    def find_suggestions(filename):
++        ts = rpm.TransactionSet()
++
++        mi = ts.dbMatch(rpm.RPMDBI_BASENAMES, filename)
++        for h in mi:
++            # Build the debuginfo package name.
++            obj = h.format("%{name}-debuginfo-%{version}-%{release}.%{arch}")
++
++            # Check to see if the package is installed.
++            mi2 = ts.dbMatch(rpm.RPMDBI_LABEL, str(obj))
++            if len(mi2) > 0:
++                continue
++
++            # Now build the name of the package FILENAME came from.
++            obj = h.format("%{name}-%{version}-%{release}.%{arch}")
++            rpm_name = str(obj)
++            if not rpm_name in __missing_rpms:
++                __suggest_rpms[rpm_name] = True
++                __missing_rpms[rpm_name] = True
++
++
++    # A missing debug handler class.  Just forwards the name of the
++    # objfile for which we are missing debug information to
++    # find_suggestions.
++    class RPMSuggestionHandler(gdb.missing_debug.MissingDebugHandler):
++        def __init__(self):
++            super().__init__("rpm-suggestions")
++
++        def __call__(self, objfile):
++            # Traditionally the 'build-id-verbose' parameter is what
++            # controlled all RPM suggestion.  Maybe once all the RPM
++            # suggestion is performed via Python extensions then we might
++            # consider renaming this parameter to something else, but for
++            # now, for backward compatibility, I've retained this name.
++            if gdb.parameter("build-id-verbose") > 0:
++                find_suggestions(objfile.filename)
++                return False
++            return None
++
++
++    # Called before GDB displays its prompt.  If the global __SUGGEST_RPMS
++    # dictionary is not empty, then this hook prints treats the keys of
++    # this dictionary as strings which are the names of RPMs.  This hook
++    # formats each RPM name into a suggested debuginfo-install command and
++    # suggests this to the user.
++    def before_prompt():
++        global __suggest_rpms
++
++        if len(__suggest_rpms) > 0:
++            for p in __suggest_rpms.keys():
++                print("Missing debuginfo, try: dnf debuginfo-install " + p)
++            __suggest_rpms = {}
++
++
++    # Called when the executable within a progrm space is changed.  Clear
++    # the lists of RPM suggestions.  We only clear the previous suggestion
++    # list when the executable really changes.  If the user simply
++    # recompiles the executable, then we don't both clearing this list.
++    def executable_changed_handler(event):
++        global __missing_rpms
++        global __suggest_rpms
++
++        if not event.reload:
++            __missing_rpms = {}
++            __suggest_rpms = {}
++
++
++    # Attach to the required GDB events.
++    gdb.events.executable_changed.connect(executable_changed_handler)
++    gdb.events.before_prompt.connect(before_prompt)
++
++    # Register the missing debug handler with GDB.
++    gdb.missing_debug.register_handler(None, RPMSuggestionHandler())
 diff --git a/gdb/testsuite/gdb.python/py-missing-debug.py b/gdb/testsuite/gdb.python/py-missing-debug.py
 --- a/gdb/testsuite/gdb.python/py-missing-debug.py
 +++ b/gdb/testsuite/gdb.python/py-missing-debug.py

diff --git a/gdb.spec b/gdb.spec
index 68a993b..4a1c38a 100644
--- a/gdb.spec
+++ b/gdb.spec
@@ -45,7 +45,7 @@ Version: 14.2
 
 # 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: 8%{?dist}
+Release: 9%{?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
 # Do not provide URL for snapshots as the file lasts there only for 2 days.
@@ -926,6 +926,12 @@ fi
 # endif scl
 
 %changelog
+* Thu May 23 2024 Kevin Buettner <kevinb@redhat.com> - 14.2-9
+- Revise rpm-suggestions.py script so that a message is printed when
+  the 'rpm' module (found in the python3-rpm package) isn't found.
+  In particular, the ModuleNotFoundError will be caught, avoiding
+  a potential python import error.  (RHBZ 2275274)
+
 * Wed May 22 2024 Guinevere Larsen <blarsen@redhat.com>
 - Remove gdb-fedora-libncursesw.patch, this workaround isn't needed
   anymore.

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-28  0:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-28  0:01 [rpms/gdb] gdb-17.2-rebase-f44: Catch ModuleNotFoundError in rpm-suggestions.py Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox