[binutils-gdb] gdb: remove complaint_interceptor::g_complaint_interceptor

Simon Marchi via Gdb-cvs <[email protected]> Thu, 21 May 2026 17:50:15 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1500a5d93a2ae02ee227d6b227acfeda9f6d4f6a

commit 1500a5d93a2ae02ee227d6b227acfeda9f6d4f6a
Author: Simon Marchi <[email protected]>
Date:   Thu May 21 00:00:49 2026 -0400

    gdb: remove complaint_interceptor::g_complaint_interceptor
    
    The thread_local g_complaint_interceptor pointer is unnecessary.  The
    complaint_interceptor constructor registers itself as the warning hook
    via m_saved_warning_hook (this), so when complaint_internal dispatches
    through the warning hook, it lands in complaint_interceptor::warn with
    'this' already pointing at the registered interceptor.  Inside warn,
    g_complaint_interceptor and 'this' always refer to the same object.
    
    Replace g_complaint_interceptor->m_complaints with m_complaints in
    complaint_interceptor::warn and remove g_complaint_interceptor.
    
    Change-Id: I75565a5f2c0e51363f36be0e3544210c10bb5491
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 gdb/complaints.c | 9 ++-------
 gdb/complaints.h | 7 -------
 2 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/gdb/complaints.c b/gdb/complaints.c
index ab6e2049685..e3d68a869c9 100644
--- a/gdb/complaints.c
+++ b/gdb/complaints.c
@@ -77,13 +77,8 @@ clear_complaints ()
 
 /* See complaints.h.  */
 
-thread_local complaint_interceptor *complaint_interceptor::g_complaint_interceptor;
-
-/* See complaints.h.  */
-
 complaint_interceptor::complaint_interceptor ()
-  : m_saved_complaint_interceptor (&g_complaint_interceptor, this),
-    m_saved_warning_hook (this)
+  : m_saved_warning_hook (this)
 {
 }
 
@@ -122,7 +117,7 @@ void
 complaint_interceptor::warn (const char *fmt, va_list args)
 {
   gdb::lock_guard<gdb::mutex> guard (complaint_mutex);
-  g_complaint_interceptor->m_complaints.insert (string_vprintf (fmt, args));
+  m_complaints.insert (string_vprintf (fmt, args));
 }
 
 static void
diff --git a/gdb/complaints.h b/gdb/complaints.h
index c607194e265..8f5cf24c1c9 100644
--- a/gdb/complaints.h
+++ b/gdb/complaints.h
@@ -20,7 +20,6 @@
 #ifndef GDB_COMPLAINTS_H
 #define GDB_COMPLAINTS_H
 
-#include "gdbsupport/scoped_restore.h"
 #include "gdbsupport/unordered_set.h"
 
 /* Helper for complaint.  */
@@ -89,17 +88,11 @@ private:
   /* The issued complaints.  */
   complaint_collection m_complaints;
 
-  /* The saved value of g_complaint_interceptor.  */
-  scoped_restore_tmpl<complaint_interceptor *> m_saved_complaint_interceptor;
-
   /* A helper function that is used by the 'complaint' implementation
      to issue a complaint.  */
   void warn (const char *, va_list) override
     ATTRIBUTE_PRINTF (2, 0);
 
-  /* This object.  Used by the static callback function.  */
-  static thread_local complaint_interceptor *g_complaint_interceptor;
-
   /* Object to initialise the warning hook.  */
   scoped_restore_warning_hook m_saved_warning_hook;
 };