From patchwork Tue Nov 29 02:50:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 61207 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 D3779385AC29 for ; Tue, 29 Nov 2022 02:52:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3779385AC29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669690320; bh=nBpI7drGD6I/vQSD1Kh89f3Ogufxcg5yruVq+3C23Gc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=mDC1UBoF5t0j6eFV107922ZfqhGMr3DmmEn1bxIraiC/uOsiBY5l1rt0Arr+BDVeP BV4cI6jOXs2h5SQJ8c2AbElhy2QrG6BG5Vy0P3gXwBgPxdoGL29PZxr3vZJm7wIsW2 1N5sNokOl9tWBg6LNsZnNAVr5XAXP8sP1dpWWntc= 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 499583858D32 for ; Tue, 29 Nov 2022 02:51:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 499583858D32 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 2AT2ottu008904 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Nov 2022 21:51:00 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2AT2ottu008904 Received: from simark.localdomain (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 7ED571E112; Mon, 28 Nov 2022 21:50:55 -0500 (EST) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/3] gdb: add inferior_target_stack_changed observer, use it to clear auxv cache Date: Mon, 28 Nov 2022 21:50:46 -0500 Message-Id: <20221129025048.44490-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 29 Nov 2022 02:50:55 +0000 X-Spam-Status: No, score=-3189.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.29 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" A following patch expects to be able to read the core target's auxv data right after pushing it to the inferior's target stack. It is not the case today, because the read requests would hit the auxv cache, filled earlier using (empty) auxv data obtained from the exec target. The auxv cache is only cleared a bit later in the core target initialization, when the inferior_appeared observers are notified. I think it would make sense to flush an inferiors auxv cache as soone as its target stack is modified. The auxv cache should reflect what reading an inferior's auxv data would look like at any point in time, and simply speed up that process. In other words, it should work the same with the cache as it would work without the cache. It seems obvious that pushing/popping a target from the stack may change what reading auxv for that inferior would return, and that we should therefore flush the cache at that point. Add an inferior_target_stack_changed observable, and attach invalidate_auxv_cache_inf to it. Notify this observable in the push_target and unpush_target methods of inferior. Change-Id: I76b00cebe933e3b26620eda39f57425aaba928e5 --- gdb/auxv.c | 2 ++ gdb/inferior.c | 23 ++++++++++++++++++++++- gdb/inferior.h | 9 ++------- gdb/observable.c | 1 + gdb/observable.h | 3 +++ 5 files changed, 30 insertions(+), 8 deletions(-) base-commit: d0a2cfbd3141dae38498fa077b01ae6bb394462b diff --git a/gdb/auxv.c b/gdb/auxv.c index 0ac74826aebb..73e84cf144db 100644 --- a/gdb/auxv.c +++ b/gdb/auxv.c @@ -614,4 +614,6 @@ This is information provided by the operating system at program startup.")); gdb::observers::inferior_exit.attach (invalidate_auxv_cache_inf, "auxv"); gdb::observers::inferior_appeared.attach (invalidate_auxv_cache_inf, "auxv"); gdb::observers::executable_changed.attach (invalidate_auxv_cache, "auxv"); + gdb::observers::inferior_target_stack_changed.attach + (invalidate_auxv_cache_inf, "auxv"); } diff --git a/gdb/inferior.c b/gdb/inferior.c index 23cbfd63bde0..23a68a87c728 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -84,6 +84,25 @@ inferior::inferior (int pid_) /* See inferior.h. */ +void +inferior::push_target (target_ops *t) +{ + m_target_stack.push (t); + gdb::observers::inferior_target_stack_changed.notify (this); +} + +/* See inferior.h. */ + +void +inferior::push_target (target_ops_up &&t) +{ + m_target_stack.push (t.get ()); + t.release (); + gdb::observers::inferior_target_stack_changed.notify (this); +} + +/* See inferior.h. */ + int inferior::unpush_target (struct target_ops *t) { @@ -100,7 +119,9 @@ inferior::unpush_target (struct target_ops *t) proc_target->maybe_remove_resumed_with_pending_wait_status (thread); } - return m_target_stack.unpush (t); + bool ret = m_target_stack.unpush (t); + gdb::observers::inferior_target_stack_changed.notify (this); + return ret; } void diff --git a/gdb/inferior.h b/gdb/inferior.h index 69525a2e053f..909e1819922d 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -352,15 +352,10 @@ class inferior : public refcounted_object, bool deletable () const { return refcount () == 0; } /* Push T in this inferior's target stack. */ - void push_target (struct target_ops *t) - { m_target_stack.push (t); } + void push_target (target_ops *t); /* An overload that deletes the target on failure. */ - void push_target (target_ops_up &&t) - { - m_target_stack.push (t.get ()); - t.release (); - } + void push_target (target_ops_up &&t); /* Unpush T from this inferior's target stack. */ int unpush_target (struct target_ops *t); diff --git a/gdb/observable.c b/gdb/observable.c index 0bc8697f137a..dd17ec9ab769 100644 --- a/gdb/observable.c +++ b/gdb/observable.c @@ -44,6 +44,7 @@ DEFINE_OBSERVABLE (target_changed); DEFINE_OBSERVABLE (executable_changed); DEFINE_OBSERVABLE (inferior_created); DEFINE_OBSERVABLE (inferior_execd); +DEFINE_OBSERVABLE (inferior_target_stack_changed); DEFINE_OBSERVABLE (record_changed); DEFINE_OBSERVABLE (solib_loaded); DEFINE_OBSERVABLE (solib_unloaded); diff --git a/gdb/observable.h b/gdb/observable.h index 1103c5c98a6b..23ea6d5f6a30 100644 --- a/gdb/observable.h +++ b/gdb/observable.h @@ -93,6 +93,9 @@ extern observable inferior_created; /* The inferior INF has exec'ed a new executable file. */ extern observable inferior_execd; +/* Inferior INF's target stack changed (a target was pushed or popped). */ +extern observable inferior_target_stack_changed; + /* The status of process record for inferior inferior in gdb has changed. The process record is started if STARTED is true, and the process record is stopped if STARTED is false.