From patchwork Wed Oct 4 02:20:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 77073 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A9383857726 for ; Wed, 4 Oct 2023 02:23:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A9383857726 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696386216; bh=+a5eq2V3pn3BFiT3X3fRNPiRB1FC04Kz+fhZbtTQxCQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=wIaQhg7X59TK7xIG82DK8maJQdm/PqfPUzOhtn7U2dSTCaTE5q6gc3NQCHas02UOj 6RL4X7JMpdrilAor8uxNw4P9jfnhHQ8Dm+bM0OUL+ZDwoU7DFDdzKe9MggLTEj162s 7JfRwQbR6TwDmHMAzvByIhBCsluwnvjDTGRNZJNY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id A394F385800C for ; Wed, 4 Oct 2023 02:23:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A394F385800C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 3942N76F025333 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 3 Oct 2023 22:23:11 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 3942N76F025333 Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 056A11E0C2; Tue, 3 Oct 2023 22:23:06 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/8] gdb: add program_space parameter to ada_clear_symbol_cache Date: Tue, 3 Oct 2023 22:20:16 -0400 Message-ID: <20231004022305.298534-2-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004022305.298534-1-simon.marchi@polymtl.ca> References: <20231004022305.298534-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 4 Oct 2023 02:23:07 +0000 X-Spam-Status: No, score=-3188.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi Make the references to current_program_space bubble up one level. Change-Id: I82acab5628c30f6535d52aa32ce2c1d0375cbeed --- gdb/ada-lang.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 53d53e0ffa58..4dc405580645 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -4673,9 +4673,9 @@ make_array_descriptor (struct type *type, struct value *arr) /* Clear all entries from the symbol cache. */ static void -ada_clear_symbol_cache () +ada_clear_symbol_cache (program_space *pspace) { - ada_pspace_data_handle.clear (current_program_space); + ada_pspace_data_handle.clear (pspace); } /* Search the symbol cache for an entry matching NAME and DOMAIN. @@ -13884,7 +13884,7 @@ static struct cmd_list_element *show_ada_list; static void ada_new_objfile_observer (struct objfile *objfile) { - ada_clear_symbol_cache (); + ada_clear_symbol_cache (current_program_space); } /* This module's 'free_objfile' observer. */ @@ -13892,7 +13892,7 @@ ada_new_objfile_observer (struct objfile *objfile) static void ada_free_objfile_observer (struct objfile *objfile) { - ada_clear_symbol_cache (); + ada_clear_symbol_cache (current_program_space); } /* Charsets known to GNAT. */ From patchwork Wed Oct 4 02:20:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 77074 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DDAB8385770D for ; Wed, 4 Oct 2023 02:24:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDAB8385770D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696386242; bh=wNrPuQZgj3mRpCodOoUT/5pK6v2xdjlkcXtI4n71jKY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=P7OX8Z3Bc6wXXWyJi6Nra4zOuNET7+iiZHUDvvjpeKwSZ1/b2smU2EJEmRzknVug0 4+A0Sftwq3Txnuuo/pc99LbsH0hTHcHU4yzUx4F6NPWVN595JD4AimMS2UhEWwB+t3 VjINj2c9gzNdxuxi0LOL0oEp0LDPom+CqE/QFRbY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 49DC6385841B for ; Wed, 4 Oct 2023 02:23:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49DC6385841B Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 3942N7jQ025343 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 3 Oct 2023 22:23:11 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 3942N7jQ025343 Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 298F61E0C3; Tue, 3 Oct 2023 22:23:07 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/8] gdb: add program_space parameters to some functions in symtab.c Date: Tue, 3 Oct 2023 22:20:17 -0400 Message-ID: <20231004022305.298534-3-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004022305.298534-1-simon.marchi@polymtl.ca> References: <20231004022305.298534-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 4 Oct 2023 02:23:07 +0000 X-Spam-Status: No, score=-3188.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi Add some program_space parameters to functions related to getting and setting the main name, making the references to current_program_space bubble up a bit. find_main_name calls ada_main_name, which implicitly relies on the current program space, so I didn't add a parameter to that function. Change-Id: I9996955e8ae56832bbd461964d978e700e6feaf4 --- gdb/symtab.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index e399dd81d810..afad782fcdbf 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -100,7 +100,8 @@ static struct block_symbol enum block_enum block_index, const char *name, const domain_enum domain); -static void set_main_name (const char *name, enum language lang); +static void set_main_name (program_space *pspace, const char *name, + language lang); /* Type of the data stored on the program space. */ @@ -1700,7 +1701,7 @@ symtab_new_objfile_observer (struct objfile *objfile) /* When all objfiles have been removed (OBJFILE is nullptr), then forget everything we know about the main function. */ if (objfile == nullptr) - set_main_name (nullptr, language_unknown); + set_main_name (current_program_space, nullptr, language_unknown); } /* This module's 'free_objfile' observer. */ @@ -6178,10 +6179,10 @@ make_source_files_completion_list (const char *text, const char *word) the object has not yet been created, create it and fill in some default values. */ -static struct main_info * -get_main_info (void) +static main_info * +get_main_info (program_space *pspace) { - struct main_info *info = main_progspace_key.get (current_program_space); + main_info *info = main_progspace_key.get (pspace); if (info == NULL) { @@ -6191,16 +6192,16 @@ get_main_info (void) gdb returned "main" as the name even if no function named "main" was defined the program; and this approach lets us keep compatibility. */ - info = main_progspace_key.emplace (current_program_space); + info = main_progspace_key.emplace (pspace); } return info; } static void -set_main_name (const char *name, enum language lang) +set_main_name (program_space *pspace, const char *name, enum language lang) { - struct main_info *info = get_main_info (); + main_info *info = get_main_info (pspace); if (!info->name_of_main.empty ()) { @@ -6221,6 +6222,7 @@ static void find_main_name (void) { const char *new_main_name; + program_space *pspace = current_program_space; /* First check the objfiles to see whether a debuginfo reader has picked up the appropriate main name. Historically the main name @@ -6232,7 +6234,8 @@ find_main_name (void) { if (objfile->per_bfd->name_of_main != NULL) { - set_main_name (objfile->per_bfd->name_of_main, + set_main_name (pspace, + objfile->per_bfd->name_of_main, objfile->per_bfd->language_of_main); return; } @@ -6257,28 +6260,28 @@ find_main_name (void) new_main_name = ada_main_name (); if (new_main_name != NULL) { - set_main_name (new_main_name, language_ada); + set_main_name (pspace, new_main_name, language_ada); return; } new_main_name = d_main_name (); if (new_main_name != NULL) { - set_main_name (new_main_name, language_d); + set_main_name (pspace, new_main_name, language_d); return; } new_main_name = go_main_name (); if (new_main_name != NULL) { - set_main_name (new_main_name, language_go); + set_main_name (pspace, new_main_name, language_go); return; } new_main_name = pascal_main_name (); if (new_main_name != NULL) { - set_main_name (new_main_name, language_pascal); + set_main_name (pspace, new_main_name, language_pascal); return; } @@ -6289,14 +6292,14 @@ find_main_name (void) bool symbol_found_p = false; gdbarch_iterate_over_objfiles_in_search_order (target_gdbarch (), - [&symbol_found_p] (objfile *obj) + [&symbol_found_p, pspace] (objfile *obj) { language lang = obj->lookup_global_symbol_language ("main", VAR_DOMAIN, &symbol_found_p); if (symbol_found_p) { - set_main_name ("main", lang); + set_main_name (pspace, "main", lang); return 1; } @@ -6306,7 +6309,7 @@ find_main_name (void) if (symbol_found_p) return; - set_main_name ("main", language_unknown); + set_main_name (pspace, "main", language_unknown); } /* See symtab.h. */ @@ -6314,7 +6317,7 @@ find_main_name (void) const char * main_name () { - struct main_info *info = get_main_info (); + main_info *info = get_main_info (current_program_space); if (info->name_of_main.empty ()) find_main_name (); @@ -6328,7 +6331,7 @@ main_name () enum language main_language (void) { - struct main_info *info = get_main_info (); + main_info *info = get_main_info (current_program_space); if (info->name_of_main.empty ()) find_main_name (); From patchwork Wed Oct 4 02:20:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 77075 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF9AE3857707 for ; Wed, 4 Oct 2023 02:24:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF9AE3857707 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696386243; bh=uSt1N+I7YXohw1k1DHkIZZdAcp7R//m51oaW7rqWRtw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=upOwPC8QilWPJ8sVH7adq3fBuYDDacEDk6DVW/3IWPdWHJUl/gouFlc3KyBqMXwaM /IrmdYx7ApRqhhAur2Y8s0ihoRc0FuUFrkvFkpylHHdU6KvOlaW8/umAqJvsA7g9wb 6gdndTXkc3MmqjQ0y4dR+WVGnyip39gMkFgND9TQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id A0F90385842C for ; Wed, 4 Oct 2023 02:23:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0F90385842C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 3942N7Ck025356 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 3 Oct 2023 22:23:12 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 3942N7Ck025356 Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 5E47F1E0D0; Tue, 3 Oct 2023 22:23:07 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 3/8] gdb: add program_space parameter to emit_clear_objfiles_event Date: Tue, 3 Oct 2023 22:20:18 -0400 Message-ID: <20231004022305.298534-4-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004022305.298534-1-simon.marchi@polymtl.ca> References: <20231004022305.298534-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 4 Oct 2023 02:23:07 +0000 X-Spam-Status: No, score=-3188.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi Add program_space space parameters to emit_clear_objfiles_event and create_clear_objfiles_event_object, making the reference to current_program_space bubble up a bit. Change-Id: I5fde2071712781e5d45971fa0ab34d85d3a49a71 --- gdb/python/py-event.h | 2 +- gdb/python/py-inferior.c | 2 +- gdb/python/py-newobjfileevent.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h index 01386dde84cd..b9e9af4d7329 100644 --- a/gdb/python/py-event.h +++ b/gdb/python/py-event.h @@ -78,7 +78,7 @@ extern gdbpy_ref<> create_thread_event_object (PyTypeObject *py_type, extern int emit_new_objfile_event (struct objfile *objfile); extern int emit_free_objfile_event (struct objfile *objfile); -extern int emit_clear_objfiles_event (void); +extern int emit_clear_objfiles_event (program_space *pspace); extern void evpy_dealloc (PyObject *self); extern int evpy_add_attribute (PyObject *event, diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 906d402827ce..e7a9d822409b 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -196,7 +196,7 @@ python_new_objfile (struct objfile *objfile) if (objfile == NULL) { - if (emit_clear_objfiles_event () < 0) + if (emit_clear_objfiles_event (current_program_space) < 0) gdbpy_print_stack (); } else diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileevent.c index 34e8e4923b58..2068d39353a4 100644 --- a/gdb/python/py-newobjfileevent.c +++ b/gdb/python/py-newobjfileevent.c @@ -93,14 +93,14 @@ emit_free_objfile_event (struct objfile *objfile) /* Subroutine of emit_clear_objfiles_event to simplify it. */ static gdbpy_ref<> -create_clear_objfiles_event_object (void) +create_clear_objfiles_event_object (program_space *pspace) { gdbpy_ref<> objfile_event = create_event_object (&clear_objfiles_event_object_type); if (objfile_event == NULL) return NULL; - gdbpy_ref<> py_progspace = pspace_to_pspace_object (current_program_space); + gdbpy_ref<> py_progspace = pspace_to_pspace_object (pspace); if (py_progspace == NULL || evpy_add_attribute (objfile_event.get (), "progspace", py_progspace.get ()) < 0) @@ -115,12 +115,12 @@ create_clear_objfiles_event_object (void) Return -1 if emit fails. */ int -emit_clear_objfiles_event (void) +emit_clear_objfiles_event (program_space *pspace) { if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles)) return 0; - gdbpy_ref<> event = create_clear_objfiles_event_object (); + gdbpy_ref<> event = create_clear_objfiles_event_object (pspace); if (event != NULL) return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles); return -1; From patchwork Wed Oct 4 02:20:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 77077 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E16A63857359 for ; Wed, 4 Oct 2023 02:30:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E16A63857359 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696386636; bh=5UTsuX7N+ly5yQ4+23tZKgRwgi/CWC8xgEXOmWYCHJ4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=qr9lTRWrYoxw/xpYCCzLQyQEZK1rdjgpOuxFAnKnlkB0ufh0lpFN+sJlp3Br2JFnD LMRrSnclDINRo22Zg/q+ZadAkEntkbxiF+/g2WZ7spMxe+YvbNcCHu+qhwDeFEwzwb IjUrKEBw0XrSP+89GsBa+yF3wjPosRPJhKDPQJUU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 98EEF385842C for ; Wed, 4 Oct 2023 02:30:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98EEF385842C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 3942U34G029759 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 3 Oct 2023 22:30:08 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 3942U34G029759 Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 745551E0D2; Tue, 3 Oct 2023 22:23:07 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 4/8] gdb: use objfile->pspace in auto-load.c Date: Tue, 3 Oct 2023 22:20:19 -0400 Message-ID: <20231004022305.298534-5-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004022305.298534-1-simon.marchi@polymtl.ca> References: <20231004022305.298534-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 4 Oct 2023 02:30:03 +0000 X-Spam-Status: No, score=-3188.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi Use objfile->pspace instead of current_program_space in two spots. Change-Id: Idf94fad486252d1250380f295e71b0fe76dce76c --- gdb/auto-load.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 5267cb4e64d7..c6744ca25554 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -788,7 +788,7 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname, /* Add this script to the hash table too so "info auto-load ${lang}-scripts" can print it. */ pspace_info - = get_auto_load_pspace_data_for_loading (current_program_space); + = get_auto_load_pspace_data_for_loading (objfile->pspace); maybe_add_script_file (pspace_info, is_safe, debugfile, debugfile, language); @@ -1052,12 +1052,10 @@ static void source_section_scripts (struct objfile *objfile, const char *section_name, const char *start, const char *end) { - const char *p; - struct auto_load_pspace_info *pspace_info; - - pspace_info = get_auto_load_pspace_data_for_loading (current_program_space); + auto_load_pspace_info *pspace_info + = get_auto_load_pspace_data_for_loading (objfile->pspace); - for (p = start; p < end; ++p) + for (const char *p = start; p < end; ++p) { const char *entry; const struct extension_language_defn *language; From patchwork Wed Oct 4 02:20:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 77078 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B59C385702F for ; Wed, 4 Oct 2023 02:30:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B59C385702F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696386637; bh=vi+1UCxP2N+XuORr1nI4UarIEq5ojDUt0AbFHAqHb5I=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=RdJWrUukk1cbsAvegE1OlqymOkB4CwRPhQRfkpnVgghLlzQ+XcsjSzZAFCpU7UNUM TD80S5BDjQbICX+ZUM8WrpSbR4ooRzgEMX/1ftLlUlg9Fw/tXqHdNggmTTOYY+liTX QoH9EshiAfWqMCCqQn8AzY0+NeS9Cgzyo6Sw3i8Q= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 8E3F1385841B for ; Wed, 4 Oct 2023 02:30:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E3F1385841B Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 3942U3no029758 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 3 Oct 2023 22:30:08 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 3942U3no029758 Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id A25361E110; Tue, 3 Oct 2023 22:23:07 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 5/8] gdb: add program_space parameters to some auto-load functions Date: Tue, 3 Oct 2023 22:20:20 -0400 Message-ID: <20231004022305.298534-6-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004022305.298534-1-simon.marchi@polymtl.ca> References: <20231004022305.298534-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 4 Oct 2023 02:30:03 +0000 X-Spam-Status: No, score=-3188.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi Make the current_program_space references bubble up a bit. Change-Id: Id047a48cc8d8a45504cdbb5960bafe3e7735d652 --- gdb/auto-load.c | 19 ++++++++----------- gdb/auto-load.h | 5 +++-- gdb/guile/scm-auto-load.c | 3 ++- gdb/python/py-auto-load.c | 3 ++- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gdb/auto-load.c b/gdb/auto-load.c index c6744ca25554..37a44cc2eaa6 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -706,12 +706,9 @@ maybe_add_script_text (struct auto_load_pspace_info *pspace_info, /* Clear the table of loaded section scripts. */ static void -clear_section_scripts (void) +clear_section_scripts (program_space *pspace) { - struct program_space *pspace = current_program_space; - struct auto_load_pspace_info *info; - - info = auto_load_pspace_data.get (pspace); + auto_load_pspace_info *info = auto_load_pspace_data.get (pspace); if (info != NULL && info->loaded_script_files != NULL) auto_load_pspace_data.clear (pspace); } @@ -1175,7 +1172,7 @@ auto_load_new_objfile (struct objfile *objfile) if (!objfile) { /* OBJFILE is NULL when loading a new "main" symbol-file. */ - clear_section_scripts (); + clear_section_scripts (current_program_space); return; } @@ -1262,15 +1259,14 @@ print_scripts (const std::vector &scripts) PATTERN. FROM_TTY is the usual GDB boolean for user interactivity. */ void -auto_load_info_scripts (const char *pattern, int from_tty, - const struct extension_language_defn *language) +auto_load_info_scripts (program_space *pspace, const char *pattern, + int from_tty, const extension_language_defn *language) { struct ui_out *uiout = current_uiout; - struct auto_load_pspace_info *pspace_info; dont_repeat (); - pspace_info = get_auto_load_pspace_data (current_program_space); + auto_load_pspace_info *pspace_info = get_auto_load_pspace_data (pspace); if (pattern && *pattern) { @@ -1347,7 +1343,8 @@ auto_load_info_scripts (const char *pattern, int from_tty, static void info_auto_load_gdb_scripts (const char *pattern, int from_tty) { - auto_load_info_scripts (pattern, from_tty, &extension_language_gdb); + auto_load_info_scripts (current_program_space, pattern, from_tty, + &extension_language_gdb); } /* Implement 'info auto-load local-gdbinit'. */ diff --git a/gdb/auto-load.h b/gdb/auto-load.h index 8db904e9098f..1a7753e2d99b 100644 --- a/gdb/auto-load.h +++ b/gdb/auto-load.h @@ -56,8 +56,9 @@ extern void auto_load_objfile_script (struct objfile *objfile, const struct extension_language_defn *); extern void load_auto_scripts_for_objfile (struct objfile *objfile); extern char auto_load_info_scripts_pattern_nl[]; -extern void auto_load_info_scripts (const char *pattern, int from_tty, - const struct extension_language_defn *); +extern void auto_load_info_scripts (program_space *pspace, const char *pattern, + int from_tty, + const extension_language_defn *); extern struct cmd_list_element **auto_load_set_cmdlist_get (void); extern struct cmd_list_element **auto_load_show_cmdlist_get (void); diff --git a/gdb/guile/scm-auto-load.c b/gdb/guile/scm-auto-load.c index fc98d99bc0a4..d94300893854 100644 --- a/gdb/guile/scm-auto-load.c +++ b/gdb/guile/scm-auto-load.c @@ -54,7 +54,8 @@ gdbscm_auto_load_enabled (const struct extension_language_defn *extlang) static void info_auto_load_guile_scripts (const char *pattern, int from_tty) { - auto_load_info_scripts (pattern, from_tty, &extension_language_guile); + auto_load_info_scripts (current_program_space, pattern, from_tty, + &extension_language_guile); } void diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c index 76ae3af39a02..34d5386d6c9b 100644 --- a/gdb/python/py-auto-load.c +++ b/gdb/python/py-auto-load.c @@ -53,7 +53,8 @@ gdbpy_auto_load_enabled (const struct extension_language_defn *extlang) static void info_auto_load_python_scripts (const char *pattern, int from_tty) { - auto_load_info_scripts (pattern, from_tty, &extension_language_python); + auto_load_info_scripts (current_program_space, pattern, from_tty, + &extension_language_python); } static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION From patchwork Wed Oct 4 02:20:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 77079 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF4B23856943 for ; Wed, 4 Oct 2023 02:30:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF4B23856943 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696386642; bh=DZRvtIHLpthcN5eGm839Uq0uy9yxehNBmsGICpEl5YM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dRUIK3fnBQTbr3Cl5WgovaY/WlpRdUIi3DyZ9U4571VpcN9fdPXmCfQoRUprjwY1v fL/Ldv8xNqIYyOpxZhnb9hD9A8VKJk1cufpffln+IDPBqMr/vNeRaAdmXoYfPPov4S cGCa7zC/mxzAQIE9ek+V4Zw+uDR9KOZqgp6I7zn8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id EBADD385800C for ; Wed, 4 Oct 2023 02:30:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBADD385800C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 3942U3BF029757 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 3 Oct 2023 22:30:08 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 3942U3BF029757 Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id D5D141E11B; Tue, 3 Oct 2023 22:23:07 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 6/8] gdb: add all_objfiles_removed observer Date: Tue, 3 Oct 2023 22:20:21 -0400 Message-ID: <20231004022305.298534-7-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004022305.298534-1-simon.marchi@polymtl.ca> References: <20231004022305.298534-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 4 Oct 2023 02:30:03 +0000 X-Spam-Status: No, score=-3188.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi The new_objfile observer is currently used to indicate both when a new objfile is added to program space (when passed non-nullptr) and when all objfiles of a program space were just removed (when passed nullptr). I think this is confusing (and Andrew apparently thinks so too [1]). Add a new "all_objfiles_removed" observer to remove the second role from "new_objfile". Some existing users of new_objfile do nothing if the passed objfile is nullptr. For them, we can simply drop the nullptr check. For others, add a new all_objfiles_removed callback, and refactor things a bit to keep the existing behavior as much as possible. Some callbacks relied on current_program_space, and following the refactoring now use either objfile->pspace or the pspace passed to all_objfiles_removed. I think this should be relatively safe, and in general a step in the right direction. On the notify side, I found only one call site to change from new_objfile to all_objfiles_removed, in clear_symtab_users. It is not entirely clear to me that this is entirely correct. clear_symtab_users appears to be called in spots that don't remove all objfiles (functions finish_new_objfile, remove_symbol_file_command, reread_symbols, do_module_cleanups). But I think that this patch at least makes the current code clearer. [1] https://gitlab.com/gnutools/binutils-gdb/-/commit/a0a031bce0527b1521788b5dad640e7883b3a252 Change-Id: Icb648f72862e056267f30f44dd439bd4ec766f13 --- gdb/ada-lang.c | 6 ++++-- gdb/ada-tasks.c | 41 ++++++++++++++++++---------------------- gdb/agent.c | 2 +- gdb/aix-thread.c | 7 +++---- gdb/arm-tdep.c | 2 +- gdb/auto-load.c | 29 ++++++++-------------------- gdb/auxv.c | 13 +++++++------ gdb/linux-thread-db.c | 5 ++--- gdb/observable.c | 1 + gdb/observable.h | 7 ++++--- gdb/python/py-inferior.c | 30 ++++++++++++++++------------- gdb/remote.c | 18 +++++++++++++----- gdb/sol-thread.c | 3 +-- gdb/symfile.c | 2 +- gdb/symtab.c | 19 +++++++++++++------ gdb/tui/tui-hooks.c | 13 +++++++++++-- 16 files changed, 105 insertions(+), 93 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 4dc405580645..a37e56375341 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13884,7 +13884,7 @@ static struct cmd_list_element *show_ada_list; static void ada_new_objfile_observer (struct objfile *objfile) { - ada_clear_symbol_cache (current_program_space); + ada_clear_symbol_cache (objfile->pspace); } /* This module's 'free_objfile' observer. */ @@ -13892,7 +13892,7 @@ ada_new_objfile_observer (struct objfile *objfile) static void ada_free_objfile_observer (struct objfile *objfile) { - ada_clear_symbol_cache (current_program_space); + ada_clear_symbol_cache (objfile->pspace); } /* Charsets known to GNAT. */ @@ -14025,6 +14025,8 @@ DWARF attribute."), /* The ada-lang observers. */ gdb::observers::new_objfile.attach (ada_new_objfile_observer, "ada-lang"); + gdb::observers::all_objfiles_removed.attach (ada_clear_symbol_cache, + "ada-lang"); gdb::observers::free_objfile.attach (ada_free_objfile_observer, "ada-lang"); gdb::observers::inferior_exit.attach (ada_inferior_exit, "ada-lang"); diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index 14b0bf11c2a6..1de6b0fc930b 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -1469,38 +1469,31 @@ ada_tasks_normal_stop_observer (struct bpstat *unused_args, int unused_args2) ada_task_list_changed (current_inferior ()); } -/* A routine to be called when the objfiles have changed. */ +/* Clear data associated to PSPACE and all inferiors using that program + space. */ static void -ada_tasks_new_objfile_observer (struct objfile *objfile) +ada_tasks_clear_pspace_data (program_space *pspace) { - /* Invalidate the relevant data in our program-space data. */ - - if (objfile == NULL) - { - /* All objfiles are being cleared, so we should clear all - our caches for all program spaces. */ - for (struct program_space *pspace : program_spaces) - ada_tasks_invalidate_pspace_data (pspace); - } - else - { - /* The associated program-space data might have changed after - this objfile was added. Invalidate all cached data. */ - ada_tasks_invalidate_pspace_data (objfile->pspace); - } + /* The associated program-space data might have changed after + this objfile was added. Invalidate all cached data. */ + ada_tasks_invalidate_pspace_data (pspace); /* Invalidate the per-inferior cache for all inferiors using - this objfile (or, in other words, for all inferiors who have - the same program-space as the objfile's program space). - If all objfiles are being cleared (OBJFILE is NULL), then - clear the caches for all inferiors. */ - + this program space. */ for (inferior *inf : all_inferiors ()) - if (objfile == NULL || inf->pspace == objfile->pspace) + if (inf->pspace == pspace) ada_tasks_invalidate_inferior_data (inf); } +/* Called when a new objfile was added. */ + +static void +ada_tasks_new_objfile_observer (objfile *objfile) +{ + ada_tasks_clear_pspace_data (objfile->pspace); +} + /* The qcs command line flags for the "task apply" commands. Keep this in sync with the "frame apply" commands. */ @@ -1667,6 +1660,8 @@ _initialize_tasks () "ada-tasks"); gdb::observers::new_objfile.attach (ada_tasks_new_objfile_observer, "ada-tasks"); + gdb::observers::all_objfiles_removed.attach (ada_tasks_clear_pspace_data, + "ada-tasks"); static struct cmd_list_element *task_cmd_list; static struct cmd_list_element *task_apply_list; diff --git a/gdb/agent.c b/gdb/agent.c index e2ad3b582fa2..d7e48589ab9a 100644 --- a/gdb/agent.c +++ b/gdb/agent.c @@ -65,7 +65,7 @@ set_can_use_agent (const char *args, int from_tty, struct cmd_list_element *c) static void agent_new_objfile (struct objfile *objfile) { - if (objfile == NULL || agent_loaded_p ()) + if (agent_loaded_p ()) return; if (can_use_agent == can_use_agent_off) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index 1f7b3c511cf2..2077491d3cf7 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -1109,14 +1109,13 @@ pd_disable (inferior *inf) /* new_objfile observer callback. - If OBJFILE is non-null, check whether a threaded application is - being debugged, and if so, prepare for thread debugging. */ + Check whether a threaded application is being debugged, and if so, prepare + for thread debugging. */ static void new_objfile (struct objfile *objfile) { - if (objfile) - pd_enable (current_inferior ()); + pd_enable (current_inferior ()); } /* Attach to process specified by ARGS. */ diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 24952840e085..7e069d187708 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -2543,7 +2543,7 @@ arm_exidx_new_objfile (struct objfile *objfile) LONGEST i; /* If we've already touched this file, do nothing. */ - if (!objfile || arm_exidx_data_key.get (objfile->obfd.get ()) != NULL) + if (arm_exidx_data_key.get (objfile->obfd.get ()) != nullptr) return; /* Read contents of exception table and index. */ diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 37a44cc2eaa6..ae5efa3ac126 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -1138,7 +1138,11 @@ auto_load_section_scripts (struct objfile *objfile, const char *section_name) } } -/* Load any auto-loaded scripts for OBJFILE. */ +/* Load any auto-loaded scripts for OBJFILE. + + Two flavors of auto-loaded scripts are supported. + 1) based on the path to the objfile + 2) from .debug_gdb_scripts section */ void load_auto_scripts_for_objfile (struct objfile *objfile) @@ -1160,25 +1164,6 @@ load_auto_scripts_for_objfile (struct objfile *objfile) auto_load_section_scripts (objfile, AUTO_SECTION_NAME); } -/* This is a new_objfile observer callback to auto-load scripts. - - Two flavors of auto-loaded scripts are supported. - 1) based on the path to the objfile - 2) from .debug_gdb_scripts section */ - -static void -auto_load_new_objfile (struct objfile *objfile) -{ - if (!objfile) - { - /* OBJFILE is NULL when loading a new "main" symbol-file. */ - clear_section_scripts (current_program_space); - return; - } - - load_auto_scripts_for_objfile (objfile); -} - /* Collect scripts to be printed in a vec. */ struct collect_matching_scripts_data @@ -1531,9 +1516,11 @@ _initialize_auto_load () python_name_help, guile_name_help; const char *suffix; - gdb::observers::new_objfile.attach (auto_load_new_objfile, + gdb::observers::new_objfile.attach (load_auto_scripts_for_objfile, auto_load_new_objfile_observer_token, "auto-load"); + gdb::observers::all_objfiles_removed.attach (clear_section_scripts, + "auto-load"); add_setshow_boolean_cmd ("gdb-scripts", class_support, &auto_load_gdb_scripts, _("\ Enable or disable auto-loading of canned sequences of commands scripts."), _("\ diff --git a/gdb/auxv.c b/gdb/auxv.c index 9f599b04a4fe..d25e8b494ab2 100644 --- a/gdb/auxv.c +++ b/gdb/auxv.c @@ -344,14 +344,14 @@ invalidate_auxv_cache_inf (struct inferior *inf) auxv_inferior_data.clear (inf); } -/* Invalidate current inferior's auxv cache when all symbol table data is - cleared (indicated by OBJFILE being nullptr). */ +/* Invalidate the auxv cache for all inferiors using PSPACE. */ static void -auxv_new_objfile_observer (struct objfile *objfile) +auxv_all_objfiles_removed (program_space *pspace) { - if (objfile == nullptr) - invalidate_auxv_cache_inf (current_inferior ()); + for (inferior *inf : all_inferiors ()) + if (inf->pspace == pspace) + invalidate_auxv_cache_inf (inf); } /* See auxv.h. */ @@ -615,5 +615,6 @@ This is information provided by the operating system at program startup.")); /* Observers used to invalidate the auxv cache when needed. */ gdb::observers::inferior_exit.attach (invalidate_auxv_cache_inf, "auxv"); gdb::observers::inferior_appeared.attach (invalidate_auxv_cache_inf, "auxv"); - gdb::observers::new_objfile.attach (auxv_new_objfile_observer, "auxv"); + gdb::observers::all_objfiles_removed.attach (auxv_all_objfiles_removed, + "auxv"); } diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 16c250c104da..cef78f599be0 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1278,13 +1278,12 @@ thread_db_new_objfile (struct objfile *objfile) /* This observer must always be called with inferior_ptid set correctly. */ - if (objfile != NULL - /* libpthread with separate debug info has its debug info file already + 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. Static executables have their separate debug info loaded already before the inferior has started. */ - && objfile->separate_debug_objfile_backlink == NULL + objfile->separate_debug_objfile_backlink == NULL /* Only check for thread_db if we loaded libpthread, or if this is the main symbol file. We need to check OBJF_MAINLINE to handle the case of debugging diff --git a/gdb/observable.c b/gdb/observable.c index 93a842e911fe..09613b2ddda3 100644 --- a/gdb/observable.c +++ b/gdb/observable.c @@ -42,6 +42,7 @@ DEFINE_OBSERVABLE (inferior_forked); DEFINE_OBSERVABLE (solib_loaded); DEFINE_OBSERVABLE (solib_unloaded); DEFINE_OBSERVABLE (new_objfile); +DEFINE_OBSERVABLE (all_objfiles_removed); DEFINE_OBSERVABLE (free_objfile); DEFINE_OBSERVABLE (new_thread); DEFINE_OBSERVABLE (thread_exit); diff --git a/gdb/observable.h b/gdb/observable.h index d9fc5cbcc8bc..5a2144030b3e 100644 --- a/gdb/observable.h +++ b/gdb/observable.h @@ -107,11 +107,12 @@ extern observable solib_loaded; extern observable solib_unloaded; -/* The symbol file specified by OBJFILE has been loaded. Called - with OBJFILE equal to NULL to indicate previously loaded symbol - table data has now been invalidated. */ +/* The symbol file specified by OBJFILE has been loaded. */ extern observable new_objfile; +/* All objfiles from PSPACE were removed. */ +extern observable all_objfiles_removed; + /* The object file specified by OBJFILE is about to be freed. */ extern observable free_objfile; diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index e7a9d822409b..1f20b9acd112 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -190,20 +190,22 @@ python_new_objfile (struct objfile *objfile) if (!gdb_python_initialized) return; - gdbpy_enter enter_py (objfile != NULL - ? objfile->arch () - : target_gdbarch ()); + gdbpy_enter enter_py (objfile->arch ()); - if (objfile == NULL) - { - if (emit_clear_objfiles_event (current_program_space) < 0) - gdbpy_print_stack (); - } - else - { - if (emit_new_objfile_event (objfile) < 0) - gdbpy_print_stack (); - } + if (emit_new_objfile_event (objfile) < 0) + gdbpy_print_stack (); +} + +static void +python_all_objfiles_removed (program_space *pspace) +{ + if (!gdb_python_initialized) + return; + + gdbpy_enter enter_py (target_gdbarch ()); + + if (emit_clear_objfiles_event (pspace) < 0) + gdbpy_print_stack (); } /* Emit a Python event when an objfile is about to be removed. */ @@ -1020,6 +1022,8 @@ gdbpy_initialize_inferior (void) gdb::observers::new_objfile.attach (python_new_objfile, "py-inferior", { &auto_load_new_objfile_observer_token }); + gdb::observers::all_objfiles_removed.attach (python_all_objfiles_removed, + "py-inferior"); gdb::observers::free_objfile.attach (python_free_objfile, "py-inferior"); gdb::observers::inferior_added.attach (python_new_inferior, "py-inferior"); gdb::observers::inferior_removed.attach (python_inferior_deleted, diff --git a/gdb/remote.c b/gdb/remote.c index 9bb4f1de5982..ae08c980efce 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -14963,14 +14963,12 @@ show_remote_cmd (const char *args, int from_tty) } } +/* Some change happened in PSPACE's objfile list (obfiles added or removed), + offer all inferiors using that program space a change to look up symbols. */ -/* Function to be called whenever a new objfile (shlib) is detected. */ static void -remote_new_objfile (struct objfile *objfile) +remote_objfile_changed_check_symbols (program_space *pspace) { - /* The objfile change happened in that program space. */ - program_space *pspace = current_program_space; - /* The affected program space is possibly shared by multiple inferiors. Consider sending a qSymbol packet for each of the inferiors using that program space. */ @@ -15019,6 +15017,14 @@ remote_new_objfile (struct objfile *objfile) } } +/* Function to be called whenever a new objfile (shlib) is detected. */ + +static void +remote_new_objfile (struct objfile *objfile) +{ + remote_objfile_changed_check_symbols (objfile->pspace); +} + /* Pull all the tracepoints defined on the target and create local data structures representing them. We don't want to create real tracepoints yet, we don't want to mess up the user's existing @@ -15333,6 +15339,8 @@ _initialize_remote () /* Hook into new objfile notification. */ gdb::observers::new_objfile.attach (remote_new_objfile, "remote"); + gdb::observers::all_objfiles_removed.attach + (remote_objfile_changed_check_symbols, "remote"); #if 0 init_remote_threadtests (); diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c index ed1a803fbdb0..c152b44dea63 100644 --- a/gdb/sol-thread.c +++ b/gdb/sol-thread.c @@ -668,8 +668,7 @@ check_for_thread_db (void) static void sol_thread_new_objfile (struct objfile *objfile) { - if (objfile != NULL) - check_for_thread_db (); + check_for_thread_db (); } /* Clean up after the inferior dies. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index cc35a5389ee3..d8b67d094ab2 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2902,7 +2902,7 @@ clear_symtab_users (symfile_add_flags add_flags) clear_displays (); clear_last_displayed_sal (); clear_pc_function_cache (); - gdb::observers::new_objfile.notify (NULL); + gdb::observers::all_objfiles_removed.notify (current_program_space); /* Now that the various caches have been cleared, we can re_set our breakpoints without risking it using stale data. */ diff --git a/gdb/symtab.c b/gdb/symtab.c index afad782fcdbf..e9bc7b2c9339 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1695,13 +1695,18 @@ maintenance_print_symbol_cache_statistics (const char *args, int from_tty) static void symtab_new_objfile_observer (struct objfile *objfile) { - /* Ideally we'd use OBJFILE->pspace, but OBJFILE may be NULL. */ - symbol_cache_flush (current_program_space); + symbol_cache_flush (objfile->pspace); +} + +/* This module's 'all_objfiles_removed' observer. */ + +static void +symtab_all_objfiles_removed (program_space *pspace) +{ + symbol_cache_flush (pspace); - /* When all objfiles have been removed (OBJFILE is nullptr), then forget - everything we know about the main function. */ - if (objfile == nullptr) - set_main_name (current_program_space, nullptr, language_unknown); + /* Forget everything we know about the main function. */ + set_main_name (pspace, nullptr, language_unknown); } /* This module's 'free_objfile' observer. */ @@ -7022,5 +7027,7 @@ the use of prologue scanners."), deprecate_cmd (c, "maintenancelist flush symbol-cache"); gdb::observers::new_objfile.attach (symtab_new_objfile_observer, "symtab"); + gdb::observers::all_objfiles_removed.attach (symtab_all_objfiles_removed, + "symtab"); gdb::observers::free_objfile.attach (symtab_free_objfile_observer, "symtab"); } diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c index d67c3d7f3531..6525f0f2b6cf 100644 --- a/gdb/tui/tui-hooks.c +++ b/gdb/tui/tui-hooks.c @@ -49,13 +49,20 @@ #include "gdb_curses.h" -static void -tui_new_objfile_hook (struct objfile* objfile) +static void tui_on_objfiles_changed () { if (tui_active) tui_display_main (); } +static void +tui_new_objfile_hook (struct objfile* objfile) +{ tui_on_objfiles_changed (); } + +static void +tui_all_objfiles_removed (program_space *pspace) +{ tui_on_objfiles_changed (); } + /* Prevent recursion of deprecated_register_changed_hook(). */ static bool tui_refreshing_registers = false; @@ -283,4 +290,6 @@ _initialize_tui_hooks () { /* Install the permanent hooks. */ gdb::observers::new_objfile.attach (tui_new_objfile_hook, "tui-hooks"); + gdb::observers::all_objfiles_removed.attach (tui_all_objfiles_removed, + "tui-hooks"); } From patchwork Wed Oct 4 02:20:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 77080 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39A953857726 for ; Wed, 4 Oct 2023 02:31:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39A953857726 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696386665; bh=QCqS9hxpESqKJp7Upkr3URDlS8nsyTwcENeXG++xN7o=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZYtOT2xtpNskT5Jen3YyYKHw7scVcJ5707KSfKsgAqSZQxU5BcnxDDwt8sINGHtsv Okssn3RLAqZ8aaNd+Zpxu3gphOwC6FUt1TL8oJoFz2FBhHyksmAovA7qyeD4WfUBpt BlSSt+Hxense8BIQc18GBw6e8JaoCj1C1CJK9yg4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 8D5243858017 for ; Wed, 4 Oct 2023 02:30:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D5243858017 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 3942U3th029756 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 3 Oct 2023 22:30:08 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 3942U3th029756 Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 0165E1E1A6; Tue, 3 Oct 2023 22:23:07 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 7/8] gdb: remove unnecessary nullptr check in free_objfile observers Date: Tue, 3 Oct 2023 22:20:22 -0400 Message-ID: <20231004022305.298534-8-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004022305.298534-1-simon.marchi@polymtl.ca> References: <20231004022305.298534-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 4 Oct 2023 02:30:03 +0000 X-Spam-Status: No, score=-3188.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi The free_objfile observable is never called with a nullptr objfile. Change-Id: I1e990edeb45bc38009ccb129c623911097ab65fe --- gdb/breakpoint.c | 3 --- gdb/printcmd.c | 7 +------ gdb/symfile.c | 3 +-- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index f378edf865ea..db7d2e6a8e53 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8065,9 +8065,6 @@ disable_breakpoints_in_unloaded_shlib (program_space *pspace, so_list *solib) static void disable_breakpoints_in_freed_objfile (struct objfile *objfile) { - if (objfile == NULL) - return; - /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually managed by the user with add-symbol-file/remove-symbol-file. Similarly to how breakpoints in shared libraries are handled in diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 7e5f062caec3..d29a57f89b55 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -2355,12 +2355,7 @@ disable_display_command (const char *args, int from_tty) static void clear_dangling_display_expressions (struct objfile *objfile) { - struct program_space *pspace; - - /* With no symbol file we cannot have a block or expression from it. */ - if (objfile == NULL) - return; - pspace = objfile->pspace; + program_space *pspace = objfile->pspace; if (objfile->separate_debug_objfile_backlink) { objfile = objfile->separate_debug_objfile_backlink; diff --git a/gdb/symfile.c b/gdb/symfile.c index d8b67d094ab2..c2779681cd21 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3736,8 +3736,7 @@ static void symfile_free_objfile (struct objfile *objfile) { /* Remove the target sections owned by this objfile. */ - if (objfile != NULL) - current_program_space->remove_target_sections ((void *) objfile); + current_program_space->remove_target_sections (objfile); } /* Wrapper around the quick_symbol_functions expand_symtabs_matching "method". From patchwork Wed Oct 4 02:20:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 77076 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7256D3857C44 for ; Wed, 4 Oct 2023 02:25:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7256D3857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696386337; bh=hNlXR6Q5FcSrWUkch4WjTknCGon5ayusW2OqCKs6VR8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=XRvUWXRMqMcGpJoEWv8heSEM5PbFNmtEpaEXcuQWqOk1bcPVa73P9tXkhH7jhIsTe qZqvy36jwem0QZAojSxkED4UkEXlh832ZdKpXaFJQ3j//fFW2NRjS5q9TqNaNPi6XT X4XSilJBB2T9qF1vG9q3ChKmMNgThQvCOera6+YI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 46EE63858402 for ; Wed, 4 Oct 2023 02:25:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46EE63858402 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 3942P8te026380 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 3 Oct 2023 22:25:13 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 3942P8te026380 Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 7BB1C1E092; Tue, 3 Oct 2023 22:25:08 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 8/8] gdb: use objfile->pspace in free_objfile observers Date: Tue, 3 Oct 2023 22:20:23 -0400 Message-ID: <20231004022305.298534-9-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004022305.298534-1-simon.marchi@polymtl.ca> References: <20231004022305.298534-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 4 Oct 2023 02:25:08 +0000 X-Spam-Status: No, score=-3188.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" From: Simon Marchi Use objfile->pspace instead of current_program_space. Change-Id: I127a1788e155b321563114452ed5b530f1d1f618 --- gdb/solib.c | 2 +- gdb/symfile.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gdb/solib.c b/gdb/solib.c index f914822d2096..5280e5ffefd7 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1739,7 +1739,7 @@ remove_user_added_objfile (struct objfile *objfile) { if (objfile != 0 && objfile->flags & OBJF_USERLOADED) { - for (struct so_list *so : current_program_space->solibs ()) + for (struct so_list *so : objfile->pspace->solibs ()) if (so->objfile == objfile) so->objfile = NULL; } diff --git a/gdb/symfile.c b/gdb/symfile.c index c2779681cd21..e3228d1925f0 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3736,7 +3736,7 @@ static void symfile_free_objfile (struct objfile *objfile) { /* Remove the target sections owned by this objfile. */ - current_program_space->remove_target_sections (objfile); + objfile->pspace->remove_target_sections (objfile); } /* Wrapper around the quick_symbol_functions expand_symtabs_matching "method".