From patchwork Wed Mar 18 10:44:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 131897 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id D93FB4C3181C for ; Wed, 18 Mar 2026 10:46:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D93FB4C3181C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TeIa53KM X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id BFCCC4BBCDE1 for ; Wed, 18 Mar 2026 10:44:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFCCC4BBCDE1 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BFCCC4BBCDE1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773830660; cv=none; b=llb8d/+M7aWBEpLl2+5nwB6CFpx5wc4HMBtkG7/9PCaa0xnjUcfGHXBQ+Zaqaok99FkFU6/wrb82qIdiO9rOqe9Aoo+jQE1E8mC9fAO8v8GcG6DBjv0EtsjNWpjG7jzh6BFB+k0u6upPgGHrjy8TsT+BcvAUJVXmky13BnoEh+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773830660; c=relaxed/simple; bh=lXjvfwKO0hkh1Si2HaozCA1gAJhBhPRv94olW3J5zOw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=vxZb9VtyA7narb9hYXyYq7EiKazOJVMwg3Xcofwcm28Z/f0i7GmGbzbQiBSH6HHd9nLw2kik3XwnT41WM9icCdpejd1QO/mbOXlzevv2+RDiVSkknMb5vH9aPnw9tIQ7bKumtnX8tCk4GBVGL+cxz4ipxbg9hXv0bXjIkmXjjNQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFCCC4BBCDE1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773830655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/G5KmXqxqcAsub9haB2rPeEgQxc6Ce2PVHuA5soDqjo=; b=TeIa53KMD4TWD6Edxm7bdkhhosQ/E0M/TvjGwHqPUk64WmGx1LV1oi3Rgf6YnpEvoxElvw 3X1mhG60imv14mwNeeM+e7f2gA68vmMwffK6GCz+2+VzG+b/FlNHQVOvZ8Sga6d7gTBQLl pOeDo48JT0N6qdWB6OzMaUkXeaAqWts= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-tgk3KwcTPtiZS-aC7CmvaQ-1; Wed, 18 Mar 2026 06:44:14 -0400 X-MC-Unique: tgk3KwcTPtiZS-aC7CmvaQ-1 X-Mimecast-MFC-AGG-ID: tgk3KwcTPtiZS-aC7CmvaQ_1773830653 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-439c112b1a4so4288669f8f.3 for ; Wed, 18 Mar 2026 03:44:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773830653; x=1774435453; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/G5KmXqxqcAsub9haB2rPeEgQxc6Ce2PVHuA5soDqjo=; b=IduKElxVg72YNy7NlD1BYkfCu5oQpmCeS42dgnnfWPxsgpKd30DOCUseYF1DJGp1DU Jmtrp1hCrAmDdzHVAxS7yOTPpJDYE6iWr5ByNPaD//pQAkWXYhtdXptSaj7YP1hbe+rW p8LoXXxZ9lRUjmXgWEBS+Fg4hrNYPpY+Dv8nDqfEvEB4Epmql/1dZ5Ab+BpWT1eQT5T8 39hgK5wiyUnvCXc3FA7oetbRe14aGV3BWYKyCvccOx9KdsDJShfnuxBsZw2b9i5GEPZB aeoX479F/1nYJiRQZvnu27YVV+3TwZXZDHjMVxOCcFIlB5iYoFOY82RbuK5g2oO5AzNB zOIw== X-Gm-Message-State: AOJu0YwpKxEm0wGMrWQPnMVNIZz+tk+pRDWm9Pep3X7WMfu0nlMkWrQx TTGB9q+eTKD0wVKJlV9YxeOsFPfohson1/cjTm6U3+U1kElauMzMbO6iLV4BCVMd/STZKQqx7z/ jv8vk6CJvr/WRxK8SlG3RNW5pS7YRXdGKOvSdwOrNbGVsUHfFjjpWnQTsMifRb4NrYsLtFhXj+N 1JLKp3i28DMGKkfU41GeFOQMWstOoEofJmVscGaY9zvVt7S98= X-Gm-Gg: ATEYQzwMXPTXvKfrmt3LqijFlk+NvrtYAVG31cbmIbPKjphaV88u37JoWG0aaJFl5V2 ydphgs42O4N+KW4dmPvDA7+tVkHul6fzeOh9nk2iQdqzlXbnaDyvWiOnkhopQIeFjKfuMdCPup0 usDjSWJgrV17cxlY2l9Q2JVgS7laGl8JHSQ45NwU36WSH0pGG3YdgRbcboPm3gpLZkbaVfYwjBP zB0xiTlxK9ZYfAibnppgZS4j3gGkGQhP/LrJ9ducYjtP1623OgKAKK0bpnoT9jHQ7a1bplY5zcN YzL643IBIqad0lZ9bZwxn62Gx10JdKeSDbFKhl3haVB9lU8tTsZP5juwkvRSpeQw6bwxtoaCdqd JKMN9hq9CjyXzXlQp X-Received: by 2002:a05:6000:2890:b0:43b:4349:acb3 with SMTP id ffacd0b85a97d-43b527ada93mr4852813f8f.24.1773830652483; Wed, 18 Mar 2026 03:44:12 -0700 (PDT) X-Received: by 2002:a05:6000:2890:b0:43b:4349:acb3 with SMTP id ffacd0b85a97d-43b527ada93mr4852755f8f.24.1773830651833; Wed, 18 Mar 2026 03:44:11 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b518495aasm6928716f8f.3.2026.03.18.03.44.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 03:44:11 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb: new_objfile observer, update some comments, add some asserts Date: Wed, 18 Mar 2026 10:44:08 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5ARP2o3FKBlrZqx4py_hxdJjRULpTDojGzLGeKajVdo_1773830653 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org I was looking at the new_objfile observer and noticed a comment in reread_symbols (symfile.c) that seemed out of date, it talked about calling the new objfile observer with a NULL objfile argument. A little digging indicates that the comment is indeed out of date, and that we never call the new_objfile observer with a NULL argument any more. So in this commit I have: 1. Updated the out of date comment in reread_symbols. 2. Updated the comment in observable.h to indicate that the objfile argument should never be NULL. 3. Gone through the existing new_objfile observers, and, where the objfile argument is used, added a gdb_assert that the argument is not NULL. These observers are not called that often, so adding these asserts will have minimal performance impact. There should be no user visible changes after this commit. --- gdb/ada-lang.c | 1 + gdb/ada-tasks.c | 1 + gdb/agent.c | 2 ++ gdb/arm-tdep.c | 2 ++ gdb/auto-load.c | 2 ++ gdb/linux-thread-db.c | 2 ++ gdb/observable.h | 3 ++- gdb/python/py-inferior.c | 6 +++--- gdb/remote.c | 1 + gdb/symfile.c | 4 ++-- gdb/symtab.c | 1 + 11 files changed, 19 insertions(+), 6 deletions(-) base-commit: e4fe38115fea0a9f357527959893f18ca8d51a03 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index eb4cd6d2f60..309d0210071 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -14061,6 +14061,7 @@ static struct cmd_list_element *show_ada_list; static void ada_new_objfile_observer (struct objfile *objfile) { + gdb_assert (objfile != nullptr); ada_clear_symbol_cache (objfile->pspace ()); } diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index 0e124e1a2a2..ecf08bc144c 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -1468,6 +1468,7 @@ ada_tasks_clear_pspace_data (program_space *pspace) static void ada_tasks_new_objfile_observer (objfile *objfile) { + gdb_assert (objfile != nullptr); ada_tasks_clear_pspace_data (objfile->pspace ()); } diff --git a/gdb/agent.c b/gdb/agent.c index beeaf62b552..533f9aaf657 100644 --- a/gdb/agent.c +++ b/gdb/agent.c @@ -70,6 +70,8 @@ agent_new_objfile (struct objfile *objfile) if (can_use_agent == can_use_agent_off) return; + gdb_assert (objfile != nullptr); + agent_look_up_symbols (objfile); } diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index d7a9b469ef8..7fd512a8ca8 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -2537,6 +2537,8 @@ arm_exidx_new_objfile (struct objfile *objfile) bfd_vma exidx_vma = 0, extab_vma = 0; LONGEST i; + gdb_assert (objfile != nullptr); + /* If we've already touched this file, do nothing. */ if (arm_exidx_data_key.get (objfile->obfd.get ()) != nullptr) return; diff --git a/gdb/auto-load.c b/gdb/auto-load.c index b5fec13743c..8e0812f1c50 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -1201,6 +1201,8 @@ auto_load_section_scripts (struct objfile *objfile, const char *section_name) void load_auto_scripts_for_objfile (struct objfile *objfile) { + gdb_assert (objfile != nullptr); + /* Return immediately if auto-loading has been globally disabled. This is to handle sequencing of operations during gdb startup. Also return immediately if OBJFILE was not created from a file diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index bd45a2f2978..654263081e6 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1274,6 +1274,8 @@ thread_db_new_objfile (struct objfile *objfile) /* This observer must always be called with inferior_ptid set correctly. */ + gdb_assert (objfile != nullptr); + if (/* libpthread with separate debug info has its debug info file already loaded (and notified without successful thread_db initialization) the time gdb::observers::new_objfile.notify is called for the library itself. diff --git a/gdb/observable.h b/gdb/observable.h index 89877950a3c..ebd3766a988 100644 --- a/gdb/observable.h +++ b/gdb/observable.h @@ -111,7 +111,8 @@ extern observable solib_loaded; extern observable solib_unloaded; -/* The symbol file specified by OBJFILE has been loaded. */ +/* The symbol file specified by OBJFILE has been loaded. OBJFILE will not + be NULL. */ extern observable new_objfile; /* All objfiles from PSPACE were removed. */ diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 76e3da9f620..f9deba82d4b 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -163,9 +163,8 @@ python_inferior_exit (struct inferior *inf) gdbpy_print_stack (); } -/* Callback used to notify Python listeners about new objfiles loaded in the - inferior. OBJFILE may be NULL which means that the objfile list has been - cleared (emptied). */ +/* Callback used to notify Python listeners that OBJFILE has been loaded in + to the inferior, OBJFILE will not be NULL. */ static void python_new_objfile (struct objfile *objfile) @@ -173,6 +172,7 @@ python_new_objfile (struct objfile *objfile) if (!gdb_python_initialized) return; + gdb_assert (objfile != nullptr); gdbpy_enter enter_py (objfile->arch ()); if (emit_new_objfile_event (objfile) < 0) diff --git a/gdb/remote.c b/gdb/remote.c index 88b06e688bc..e76f1ca0c08 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -16228,6 +16228,7 @@ remote_objfile_changed_check_symbols (program_space *pspace) static void remote_new_objfile (struct objfile *objfile) { + gdb_assert (objfile != nullptr); remote_objfile_changed_check_symbols (objfile->pspace ()); } diff --git a/gdb/symfile.c b/gdb/symfile.c index 44a9480d9d9..5eb137f3b39 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2662,8 +2662,8 @@ reread_symbols (int from_tty) { clear_symtab_users (0); - /* The registry for each objfile was cleared and - gdb::observers::new_objfile.notify (NULL) has been called by + /* The registry for each objfile was cleared and the + all_objfiles_removed observer was notified by the call to clear_symtab_users above. Notify the new files now. */ for (auto iter : new_objfiles) gdb::observers::new_objfile.notify (iter); diff --git a/gdb/symtab.c b/gdb/symtab.c index cd3bf876551..444cf7dcb20 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1700,6 +1700,7 @@ maintenance_print_symbol_cache_statistics (const char *args, int from_tty) static void symtab_new_objfile_observer (struct objfile *objfile) { + gdb_assert (objfile != nullptr); symbol_cache_flush (objfile->pspace ()); }