From patchwork Sat Sep 16 10:18:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76228 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 655E93856DE6 for ; Sat, 16 Sep 2023 10:18:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 655E93856DE6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694859526; bh=NgYlrUdEftzrNNWX3Yx1L4eOq2y/h2ns0ZYfqyezG4k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=yMAYoFmwMqEd6T2ktGr5U9RZLSiPRhBh9OHVecdHKj3tlVqu8+P2CQUUxndl093sv 9pcyP7t14JuqeAjKfxJcquAizNnwkO/w7XQuNfnUmSE0N0epxvFJDxLOTpVlcKdgiV ryqAS+05JJ6LpM9HhavKNT8LzJXe5m3zO4e1XcjQ= 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 ESMTPS id 61A9D3858D33 for ; Sat, 16 Sep 2023 10:18:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61A9D3858D33 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-195-xevCGSpmNGKmjdu97xLoRg-1; Sat, 16 Sep 2023 06:18:18 -0400 X-MC-Unique: xevCGSpmNGKmjdu97xLoRg-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-30932d15a30so2001269f8f.1 for ; Sat, 16 Sep 2023 03:18:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694859497; x=1695464297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NgYlrUdEftzrNNWX3Yx1L4eOq2y/h2ns0ZYfqyezG4k=; b=s6vf9pfUH8aeRYFrFWf3TlOYrHFR+Dxt2RCZPYlm1wZRC1VVyQ1YfcgE92WRHKydrT Tv2ZUe2Eko27AfkmUSOumHovzogybpd3/8/BuwPAr4rE2JvwvQDwwARl5VEAXQyk+8M+ wkaJAg1gdsfX/HIgzVw68uai3JSqiPhcwYIu5ZM3CbPZUjCeRa7aAi2Va+fGGFXQyaww otvedwl5+wPnUXHVFJ3gC9EIErXZLUbDdQcgzNYCyfvpOGnR9tpiApwqCrmwcRWEdRsL Hmk5S5xN5pMlzrSFuq4X5ZXAY5rMlFcNTDKdmS08D7wI968EKKSZcIL2xW/acce25MdT 0GWA== X-Gm-Message-State: AOJu0Yx9lda/QZ7RmI33ZhLSEMWrKLp39JCM+OzX+8IbgAVbNHPsiLh2 qVbhzyFMUVFNeEMxciUd0gJu9UAqyyAVjEZZJ6wAoKb7JC178eW/bhSPWPspMpsXWfvPU7sZJY5 KbP3msrTsLzQiFXbvibDCCnAMoPn351+gxNQbUphfUcc6DsJZDk2rhtbaSz/E9SARGj0f5g5z5e PRc0Pl5Q== X-Received: by 2002:adf:ee03:0:b0:317:727f:3bc7 with SMTP id y3-20020adfee03000000b00317727f3bc7mr3528536wrn.17.1694859497193; Sat, 16 Sep 2023 03:18:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5M9dYXbpMPb/INFtP5gOX/klRgX5WOlSjcpwfCjZCGaMqmEfBKNMsPbaYp0A5LHYbl9JisQ== X-Received: by 2002:adf:ee03:0:b0:317:727f:3bc7 with SMTP id y3-20020adfee03000000b00317727f3bc7mr3528523wrn.17.1694859496835; Sat, 16 Sep 2023 03:18:16 -0700 (PDT) Received: from localhost (92.40.218.107.threembb.co.uk. [92.40.218.107]) by smtp.gmail.com with ESMTPSA id f24-20020a1c6a18000000b003fbb25da65bsm6967574wmc.30.2023.09.16.03.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 03:18:16 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 1/9] gdb/doc: extend the description for Progspace.filename Date: Sat, 16 Sep 2023 11:18:02 +0100 Message-Id: <4161e22ba4f066bfe15534abc7f7eab9358f6f5a.1694858967.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.2 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Extend the description for Progspace.filename in the documentation to mention what the returned string is actually the filename for (e.g. that it is the filename passed to the 'symbol-file' or 'file' command). Also document that this attribute will be None if no symbol file is currently loaded. Reviewed-By: Eli Zaretskii --- gdb/doc/python.texi | 7 ++++++- gdb/python/py-progspace.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 5b13958aeaf..ba9b0141e13 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -5034,7 +5034,12 @@ class. @defvar Progspace.filename -The file name of the progspace as a string. +The file name, as a string, of the main symbol file (from which debug +symbols have been loaded) for the progspace, e.g.@: the argument to +the @kbd{symbol-file} or @kbd{file} commands. + +If there is no main symbol table currently loaded, then this attribute +will be @code{None}. @end defvar @defvar Progspace.pretty_printers diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index b98ac8dde61..2b1d1605ca0 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -572,7 +572,7 @@ static gdb_PyGetSetDef pspace_getset[] = { "__dict__", gdb_py_generic_dict, NULL, "The __dict__ for this progspace.", &pspace_object_type }, { "filename", pspy_get_filename, NULL, - "The progspace's main filename, or None.", NULL }, + "The filename of the progspace's main symbol file, or None.", nullptr }, { "pretty_printers", pspy_get_printers, pspy_set_printers, "Pretty printers.", NULL }, { "frame_filters", pspy_get_frame_filters, pspy_set_frame_filters, From patchwork Sat Sep 16 10:18:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76231 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 CE0C33857342 for ; Sat, 16 Sep 2023 10:19:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE0C33857342 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694859558; bh=A9fW2jDOdbglnL3gEG67j31/y0zkVDR39tzT9yTnqJg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=TZqJverHghq8Fu9TKsIVbOCXO3K1yYYNLF5j+TL6Z3jPU0XyHZDwDUSY37V5hqXd0 /FUxhK5CnF34bF/4lY5QRc2plpb5ouedplZGglNROkFNQfa+ymkStszqMV6sEx9h+3 peXkIu1eMaRbKvMuXsPEi7WL7dia0cd1RIR325ws= 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 ESMTPS id 076DC3858284 for ; Sat, 16 Sep 2023 10:18:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 076DC3858284 Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-139-WnUy8CVzMF-h5u7OlcyF8Q-1; Sat, 16 Sep 2023 06:18:21 -0400 X-MC-Unique: WnUy8CVzMF-h5u7OlcyF8Q-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-501c7c4059aso3385266e87.1 for ; Sat, 16 Sep 2023 03:18:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694859500; x=1695464300; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A9fW2jDOdbglnL3gEG67j31/y0zkVDR39tzT9yTnqJg=; b=nCSoedKZHF9n+X1yuS6G4ac+c3DmmmUhXcGMLP3Ijv22ss6+jFCMbAbgoK2DLf3yAo FHEJsjIXTkeM5PKwasGn/+7PjxalMVKLeelJmuGW5adxaf0YFb6Wuo8D4PxwJJLnj+3o o/Kt/uituFnHAt5VXQ0Iiws5COcujKmZ1LMDXAb6d10haT6P16FJWz56fJcltQGm0RFp XPSN9aN2Xy2apj3tIfYEd2b3HnB2A/MNXTWlNmfXQqu3muGl4FWndeYWZlsjolHoFef4 yZcPodan8178f/iErONBBhfsYDrQkZVcjQKezVAMUDD27s5zp+o/LAlce+/NoTZDZF3e bF+w== X-Gm-Message-State: AOJu0YzjfWqZrF7g0yt5njdcVjpirsbtpiKObhLo3tnTu3hBWzMYV8LH /AiLBRhHrKLfeZUMTp9iS7vSbYyiogQPrOXlFD73MRV7fFqqml3Sc1DBehzchTMH/fDYbFDrpL0 p/CKnEc9jGlvFP6oahjM8Qmt1maYawNHd9lXQBu19VdzBaoWjbVIGbqbsX8fzr38iL9ViPny62n LdPxyyoA== X-Received: by 2002:a05:6512:281b:b0:501:bf37:1fc5 with SMTP id cf27-20020a056512281b00b00501bf371fc5mr4157283lfb.22.1694859500169; Sat, 16 Sep 2023 03:18:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPLL1wwwxkgiGdCoGRh+zTTQzEXcsSi6fqtUqbDLRmmNxbDDXDfQdwFqSj3y6loxwMFGVfWQ== X-Received: by 2002:a05:6512:281b:b0:501:bf37:1fc5 with SMTP id cf27-20020a056512281b00b00501bf371fc5mr4157257lfb.22.1694859499696; Sat, 16 Sep 2023 03:18:19 -0700 (PDT) Received: from localhost (92.40.218.107.threembb.co.uk. [92.40.218.107]) by smtp.gmail.com with ESMTPSA id f16-20020a5d4dd0000000b0031c6cc74882sm6767049wru.107.2023.09.16.03.18.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 03:18:19 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 2/9] gdb/python: new Progspace.symbol_file attribute Date: Sat, 16 Sep 2023 11:18:03 +0100 Message-Id: <18f00290a1030c12a42ec7cc64ddae8486294115.1694858967.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.2 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Add a new Progspace.symbol_file attribute. This attribute holds the gdb.Objfile object that corresponds to Progspace.filename, or None if there is no main symbol file currently set. Currently, to get this gdb.Objfile, a user would need to use Progspace.objfiles, and then search for the objfile with a name that matches Progspace.filename -- which should work just fine, but having direct access seems a little nicer. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 5 +++++ gdb/doc/python.texi | 17 +++++++++++++++++ gdb/python/py-progspace.c | 23 +++++++++++++++++++++++ gdb/testsuite/gdb.python/py-progspace.exp | 9 +++++++++ 4 files changed, 54 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 98ff00d5efc..f2f5dabb287 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -286,6 +286,11 @@ info main might be array- or string-like, even if they do not have the corresponding type code. + ** New attribute Progspace.symbol_file. This attribute holds the + gdb.Objfile that corresponds to Progspace.filename (when + Progspace.filename is not None), otherwise, this attribute is + itself None. + *** Changes in GDB 13 * MI version 1 is deprecated, and will be removed in GDB 14. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index ba9b0141e13..03299cc3cf7 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -5042,6 +5042,23 @@ will be @code{None}. @end defvar +@defvar Progspace.symbol_file +The @code{gdb.Objfile} representing the main symbol file (from which +debug symbols have been loaded) for the @code{gdb.Progspace}. This is +the symbol file set by the @kbd{symbol-file} or @kbd{file} commands. + +This will be the @code{gdb.Objfile} representing +@code{Progspace.filename} when @code{Progspace.filename} is not +@code{None}. + +If there is no main symbol table currently loaded, then this attribute +will be @code{None}. + +If the @code{Progspace} is invalid, i.e.@:, when +@code{Progspace.is_valid()} returns @code{False}, then attempting to +access this attribute will raise a @code{RuntimeError} exception. +@end defvar + @defvar Progspace.pretty_printers The @code{pretty_printers} attribute is a list of functions. It is used to look up pretty-printers. A @code{Value} is passed to each diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 2b1d1605ca0..929c5f4fa70 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -111,6 +111,26 @@ pspy_get_filename (PyObject *self, void *closure) Py_RETURN_NONE; } +/* Implement the gdb.Progspace.symbol_file attribute. Retun the + gdb.Objfile corresponding to the currently loaded symbol-file, or None + if no symbol-file is loaded. If the Progspace is invalid then raise an + exception. */ + +static PyObject * +pspy_get_symbol_file (PyObject *self, void *closure) +{ + pspace_object *obj = (pspace_object *) self; + + PSPY_REQUIRE_VALID (obj); + + struct objfile *objfile = obj->pspace->symfile_object_file; + + if (objfile != nullptr) + return objfile_to_objfile_object (objfile).release (); + + Py_RETURN_NONE; +} + static void pspy_dealloc (PyObject *self) { @@ -573,6 +593,9 @@ static gdb_PyGetSetDef pspace_getset[] = "The __dict__ for this progspace.", &pspace_object_type }, { "filename", pspy_get_filename, NULL, "The filename of the progspace's main symbol file, or None.", nullptr }, + { "symbol_file", pspy_get_symbol_file, nullptr, + "The gdb.Objfile for the progspace's main symbol file, or None.", + nullptr}, { "pretty_printers", pspy_get_printers, pspy_set_printers, "Pretty printers.", NULL }, { "frame_filters", pspy_get_frame_filters, pspy_set_frame_filters, diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index f0dc208ae4b..befd6433e47 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -30,6 +30,8 @@ clean_restart gdb_test "python print (gdb.current_progspace().filename)" "None" \ "current progspace filename (None)" +gdb_test "python print (gdb.current_progspace().symbol_file)" "None" \ + "current progspace symbol_file is None" gdb_test "python print (gdb.progspaces())" "\\\[\\\]" gdb_test_no_output "python dir(gdb.current_progspace())" @@ -42,6 +44,10 @@ gdb_py_test_silent_cmd "python progspace = gdb.current_progspace()" \ gdb_test "python print (progspace.filename)" "py-progspace" \ "current progspace filename (py-progspace)" +gdb_test "python print (gdb.current_progspace().symbol_file)" \ + "" \ + "current progspace symbol_file is set correctly" + gdb_py_test_silent_cmd "python progspace.random_attribute = 42" \ "Set random attribute in progspace" 1 gdb_test "python print (progspace.random_attribute)" "42" \ @@ -100,3 +106,6 @@ gdb_test "inferior 1" "Switching to inferior 1.*" gdb_test_no_output "remove-inferiors 2" gdb_test "python print (progspace2.objfiles ())" \ "RuntimeError: Program space no longer exists.*" + +gdb_test "python print (progspace2.symbol_file)" \ + "RuntimeError: Program space no longer exists.*" From patchwork Sat Sep 16 10:18:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76229 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 381943858002 for ; Sat, 16 Sep 2023 10:18:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 381943858002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694859538; bh=SHs0PuauLcYlKtbf6GxlYSwJ5CduA/i96XlaHhHIhDg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=TkjqPEVSlCtbfk/FmZOJw/0XuuTiKCSkRVHa9xlY164KTVrsn+tyfBzIP5CNMhyHE I++HR/wxL64v2ydedtJXMuEVxTacYHIsMaE/MOTV5mLYRHwP4HSRVMrcYMewx4/Xwi xUMkklfMX0e5emM3b6fvWAGGHfPS5gLauMr+xSoo= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id EFB893857B9B for ; Sat, 16 Sep 2023 10:18:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFB893857B9B Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-158-fTTrnYcEPqW8VNs5QpwjpQ-1; Sat, 16 Sep 2023 06:18:24 -0400 X-MC-Unique: fTTrnYcEPqW8VNs5QpwjpQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f42bcef2acso23813905e9.2 for ; Sat, 16 Sep 2023 03:18:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694859503; x=1695464303; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SHs0PuauLcYlKtbf6GxlYSwJ5CduA/i96XlaHhHIhDg=; b=rfW2FFWHUsuQqIGi2ZWcbmpLAsA6lrffUJE/e94L4Lo//jRAbpW7EPpOa8Fb/THppv 0z5lXcv9V5YpoQ3zdkAr4G6QY/3haP/NYqIwL4AX0GiCmLHy9YfK1h+jffbmmwXH1rsx FPoEiwg0cMMFIypEw03XNXMXpLOac11Er6LC+c5wFBGcIg3Q5v96/VYYG6XA0s9zegK3 hOuzB31PP0Uzjhno1vbPZ/Qgdz9aSCt1DTGhJ2c06zEe/eVxUOnu6bP2Trzhmo3iqq1l YD91Cg3Tnecn406L19OZkLy4v3Ay7ToaYLH8Vrk/EjtmUZ6XqRN0Yh57Y+jdbf/ETm1G wSlg== X-Gm-Message-State: AOJu0Yz37jGqENLLoeVuJk1QCyl79N+3K4CgM50CrU6FUys0bfGXpGLU 1ZEH5iZk/6jGmp/wM0DsoHEtKbkTnSbDJVFIn1kTcFC4i9LEx0BO6fliWSCGbry7XHA5nAUTOSU ylyz/v2oBXQvVUqyV71AMzDXI6exDOaeRIBZ8oH5Stble7LxmElz7kmG5UnR+tJwcsEtCwGB5y6 3qTS5cnQ== X-Received: by 2002:a05:600c:221a:b0:3fa:97ad:2ba5 with SMTP id z26-20020a05600c221a00b003fa97ad2ba5mr3731980wml.31.1694859502655; Sat, 16 Sep 2023 03:18:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHadpTBRJiJjveeDajw3jUqK/f4ToZk6Pc6nBp76XODQPrNCIO/NQCmzN8rn1KSWDrkEZvMUw== X-Received: by 2002:a05:600c:221a:b0:3fa:97ad:2ba5 with SMTP id z26-20020a05600c221a00b003fa97ad2ba5mr3731963wml.31.1694859502216; Sat, 16 Sep 2023 03:18:22 -0700 (PDT) Received: from localhost (92.40.218.107.threembb.co.uk. [92.40.218.107]) by smtp.gmail.com with ESMTPSA id z25-20020a1c4c19000000b003fe29f6b61bsm6879672wmf.46.2023.09.16.03.18.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 03:18:21 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 3/9] gdb/python: new Progspace.executable_filename attribute Date: Sat, 16 Sep 2023 11:18:04 +0100 Message-Id: <4c77a079079814ae5d476b5fc61b2e25539bd37f.1694858967.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Add a new Progspace.executable_filename attribute that contains the path to the executable for this program space, or None if no executable is set. The path within this attribute will be set by the "exec-file" and/or "file" commands. Accessing this attribute for an invalid program space will raise an exception. This new attribute is similar too, but not the same as the existing gdb.Progspace.filename attribute. If I could change the past, I'd change the 'filename' attribute to 'symbol_filename', which is what it actually represents. The old attribute will be set by the 'symbol-file' command, while the new attribute is set by the 'exec-file' command. Obviously the 'file' command sets both of these attributes. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 6 ++ gdb/doc/python.texi | 15 ++++ gdb/python/py-progspace.c | 21 +++++ gdb/testsuite/gdb.python/py-exec-file.c | 22 +++++ gdb/testsuite/gdb.python/py-exec-file.exp | 100 ++++++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 gdb/testsuite/gdb.python/py-exec-file.c create mode 100644 gdb/testsuite/gdb.python/py-exec-file.exp diff --git a/gdb/NEWS b/gdb/NEWS index f2f5dabb287..93bc9c6a2c0 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -291,6 +291,12 @@ info main Progspace.filename is not None), otherwise, this attribute is itself None. + ** New attribute Progspace.executable_filename. This attribute + holds a string containing a path set by the "exec-file" or "file" + commands, or None if no executable file is set. This isn't the + exact string passed by the user to these commands; the path will + have been partially resolved to an absolute path. + *** Changes in GDB 13 * MI version 1 is deprecated, and will be removed in GDB 14. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 03299cc3cf7..206cf6b4e18 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -5059,6 +5059,21 @@ access this attribute will raise a @code{RuntimeError} exception. @end defvar +@defvar Progspace.executable_filename +The file name, as a string, of the executable file in use by this +program space. The executable file is the file that @value{GDBN} will +invoke in order to start an inferior when using a native target. The +file name within this attribute is updated by the @kbd{exec-file} and +@kbd{file} commands. + +If no executable is currently set within this @code{Progspace} then +this attribute contains @code{None}. + +If the @code{Progspace} is invalid, i.e.@:, when +@code{Progspace.is_valid()} returns @code{False}, then attempting to +access this attribute will raise a @code{RuntimeError} exception. +@end defvar + @defvar Progspace.pretty_printers The @code{pretty_printers} attribute is a list of functions. It is used to look up pretty-printers. A @code{Value} is passed to each diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 929c5f4fa70..1319978d34a 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -131,6 +131,25 @@ pspy_get_symbol_file (PyObject *self, void *closure) Py_RETURN_NONE; } +/* Implement the gdb.Progspace.executable_filename attribute. Retun a + string containing the name of the current executable, or None if no + executable is currently set. If the Progspace is invalid then raise an + exception. */ + +static PyObject * +pspy_get_exec_file (PyObject *self, void *closure) +{ + pspace_object *obj = (pspace_object *) self; + + PSPY_REQUIRE_VALID (obj); + + const char *filename = obj->pspace->exec_filename.get (); + if (filename != nullptr) + return host_string_to_python_string (filename).release (); + + Py_RETURN_NONE; +} + static void pspy_dealloc (PyObject *self) { @@ -596,6 +615,8 @@ static gdb_PyGetSetDef pspace_getset[] = { "symbol_file", pspy_get_symbol_file, nullptr, "The gdb.Objfile for the progspace's main symbol file, or None.", nullptr}, + { "executable_filename", pspy_get_exec_file, nullptr, + "The filename for the progspace's executable, or None.", nullptr}, { "pretty_printers", pspy_get_printers, pspy_set_printers, "Pretty printers.", NULL }, { "frame_filters", pspy_get_frame_filters, pspy_set_frame_filters, diff --git a/gdb/testsuite/gdb.python/py-exec-file.c b/gdb/testsuite/gdb.python/py-exec-file.c new file mode 100644 index 00000000000..8cbea3b6892 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-exec-file.c @@ -0,0 +1,22 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.python/py-exec-file.exp b/gdb/testsuite/gdb.python/py-exec-file.exp new file mode 100644 index 00000000000..14e5088af1c --- /dev/null +++ b/gdb/testsuite/gdb.python/py-exec-file.exp @@ -0,0 +1,100 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +require allow_python_tests + +load_lib gdb-python.exp + +standard_testfile + +set binfile1 ${binfile}-a +set binfile2 ${binfile}-b + +if {[build_executable "failed to prepare first executable" \ + $binfile1 $srcfile]} { + return -1 +} + +if {[build_executable "failed to prepare second executable" \ + $binfile2 $srcfile]} { + return -1 +} + +set binfile1 [gdb_remote_download host $binfile1] +set binfile2 [gdb_remote_download host $binfile2] + +# Check that the executable_filename is set correctly after using the +# 'file' command. +with_test_prefix "using 'file' command" { + clean_restart + + gdb_test "python print(gdb.current_progspace().executable_filename)" \ + "None" \ + "check executable_filename when no file is loaded" + + gdb_test "file $binfile1" \ + "Reading symbols from [string_to_regexp $binfile1]\\.\\.\\..*" \ + "load first executable" + gdb_test "python print(gdb.current_progspace().executable_filename)" \ + "[string_to_regexp $binfile1]" \ + "check executable_filename when first executable is loaded" + + gdb_test "file $binfile2" \ + "Reading symbols from [string_to_regexp $binfile2]\\.\\.\\..*" \ + "load second executable" \ + "Load new symbol table from .*\? .y or n. " "y" + gdb_test "python print(gdb.current_progspace().executable_filename)" \ + "[string_to_regexp $binfile2]" \ + "check executable_filename when second executable is loaded" + + gdb_unload + gdb_test "python print(gdb.current_progspace().executable_filename)" \ + "None" \ + "check executable_filename after unloading file" +} + +# Check that the executable_filename is correctly set when we only set +# the exec-file. +with_test_prefix "using 'exec-file' command" { + clean_restart + gdb_test_no_output "exec-file $binfile1" \ + "load first executable" + gdb_test "python print(gdb.current_progspace().executable_filename)" \ + "[string_to_regexp $binfile1]" \ + "check executable_filename when first executable is loaded" + + gdb_test_no_output "exec-file $binfile2" \ + "load second executable" + gdb_test "python print(gdb.current_progspace().executable_filename)" \ + "[string_to_regexp $binfile2]" \ + "check executable_filename when second executable is loaded" + + gdb_test "exec-file" "No executable file now\\." + gdb_test "python print(gdb.current_progspace().executable_filename)" \ + "None" \ + "check executable_filename after unloading file" +} + +# Check that setting the symbol-file doesn't cause the +# executable_filename to be set. +with_test_prefix "using 'symbol-file' command" { + clean_restart + gdb_test "symbol-file $binfile1" \ + "Reading symbols from [string_to_regexp $binfile1]\\.\\.\\..*" \ + "load first executable" + gdb_test "python print(gdb.current_progspace().executable_filename)" \ + "None" \ + "check executable_filename after setting symbol-file" +} From patchwork Sat Sep 16 10:18:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76230 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 4A12E385CC93 for ; Sat, 16 Sep 2023 10:19:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A12E385CC93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694859544; bh=UIvqNzS/LQCnCG2otzpw2EMXo9aDxeY+w9tnZF7xjQw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=yT+VFEWGDY4NEzfF5uG05iC9XHa9+c3j7dkxDpdWppH33/PBkj/HjxLPdVdaU6pvY uvvf76tslQ4gyco274FSE7rP7BJsX15TlBOpDFYfQBgSRrQ2CmrS8fUrfz5MCdp6A9 mSTVchqOQbD2B/triaYQC05DPR2+8EMQRasED0hc= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 599353857738 for ; Sat, 16 Sep 2023 10:18:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 599353857738 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-AfFnwxMPNuKsKtixCeMpnA-1; Sat, 16 Sep 2023 06:18:26 -0400 X-MC-Unique: AfFnwxMPNuKsKtixCeMpnA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-401d8873904so23957365e9.0 for ; Sat, 16 Sep 2023 03:18:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694859505; x=1695464305; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UIvqNzS/LQCnCG2otzpw2EMXo9aDxeY+w9tnZF7xjQw=; b=BAnYWypxluEPt4Y8OyIs4WgLfJIhgkCYMEmFkyUZ/2IeLYI9p5VPcoK3Kk6R8abMKl Np+NdbnRJtAjnlxlzY/w2zj9Agozt6RyfCZgPMHUp6kGNRb2HlDD35i3Gh4xstyiu1DG CQmfX3/nh44L0wCCaaK3t/pMggiVYQaarVg8+l4hHFLMVDPVQxD8Snv59B7XhMnAyY1V ByUptXpKGkjncaZMjaqsEihd8XwmPt97QZk2f7UC/dxnpaMz5O5B/dyy/KJwMWe/0ucr JQpsuwHppaPpaJuYH+sad1JSIWP1bNaFmXXECfXmoOGgDB5OtRs90bNFHZhrbyJ1FbPm 1poA== X-Gm-Message-State: AOJu0Yy+bSbduBuzhiNRQpBWeb0dulj46L4TlMu2xBh/6AiAyI061E8l LXpFQqnm+rV7x5GIMBTo5mcqZS5gCv8A/pzTOIHTIguwmjZv6KIRf0shrLYAmVIeq8LzPXtp+nx HkPH3wW3V9dALsYyw5gR+gbOXItlmDwa9jJC/kZAekltJDZtMwcc2GB813hswMCvN6dGN7rklfN Ov9+kmug== X-Received: by 2002:a05:6000:806:b0:320:82d:59a8 with SMTP id bt6-20020a056000080600b00320082d59a8mr212718wrb.62.1694859504734; Sat, 16 Sep 2023 03:18:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3kD6rG4/1q2YOfLmwCMN0zH06FBf5mSAisvdHBYH0CHAWs+I8S690oSHTzRlnEZFPttViuw== X-Received: by 2002:a05:6000:806:b0:320:82d:59a8 with SMTP id bt6-20020a056000080600b00320082d59a8mr212710wrb.62.1694859504427; Sat, 16 Sep 2023 03:18:24 -0700 (PDT) Received: from localhost (92.40.218.107.threembb.co.uk. [92.40.218.107]) by smtp.gmail.com with ESMTPSA id k8-20020a5d5248000000b0031fc4c31d77sm6759053wrc.88.2023.09.16.03.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 03:18:24 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 4/9] gdb: remove one user of the executable changed observer Date: Sat, 16 Sep 2023 11:18:05 +0100 Message-Id: <5e9c1c90c7ba3adf0a7062285ec40617cd0ef14a.1694858967.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.2 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" My goal for the next few commits is to expose the executable_changed observable from the Python API. However, there is call to the executable_changed observable in the reread_symbols function (in symfile.c), and this doesn't actually correspond to the executable changing. My idea then, is to remove this use of the executable_changed observable, but, before I can do that, I need to check that nothing is going to break, and that requires my to think about the current users of this observable. One current user of executable_changed is in symtab.c. We add an executable_changed observer that calls: set_main_name (nullptr, language_unknown); to discard all information about the main function when the executable changes. However, changing the executable doesn't actually change the debug information. The debug information changes when the symbol-file changes, so I think this observer is in slightly the wrong place. The new_objfile observable is (unfortunately) overloaded, it is called when a new objfile is loaded, and also (when its argument is nullptr), when all debug information should be discarded. It turns out that there is already a new_objfile observer in symtab.c. I propose that, when the argument is nullptr (indicating all debug info should be discarded), that we should call set_main_name to discard the information about the main function. We can then remove the executable_changed observer from symtab.c. All tests still pass, and, in my local world, I added some debug printf calls, and I think we are still discarded the main information everywhere we need to. --- gdb/symtab.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index c0c2454d967..2d446331ed1 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -100,6 +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); + /* Type of the data stored on the program space. */ struct main_info @@ -1694,6 +1696,11 @@ symtab_new_objfile_observer (struct objfile *objfile) { /* Ideally we'd use OBJFILE->pspace, but OBJFILE may be NULL. */ symbol_cache_flush (current_program_space); + + /* 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); } /* This module's 'free_objfile' observer. */ @@ -6329,15 +6336,6 @@ main_language (void) return info->language_of_main; } -/* Handle ``executable_changed'' events for the symtab module. */ - -static void -symtab_observer_executable_changed (void) -{ - /* NAME_OF_MAIN may no longer be the same, so reset it for now. */ - set_main_name (NULL, language_unknown); -} - /* Return 1 if the supplied producer string matches the ARM RealView compiler (armcc). */ @@ -7020,8 +7018,6 @@ the use of prologue scanners."), class_maintenance, 0, &maintenancelist); deprecate_cmd (c, "maintenancelist flush symbol-cache"); - gdb::observers::executable_changed.attach (symtab_observer_executable_changed, - "symtab"); gdb::observers::new_objfile.attach (symtab_new_objfile_observer, "symtab"); gdb::observers::free_objfile.attach (symtab_free_objfile_observer, "symtab"); } From patchwork Sat Sep 16 10:18:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76234 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 7994D3853D1D for ; Sat, 16 Sep 2023 10:19:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7994D3853D1D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694859574; bh=N+imonrpznzZO6+5BuwP29QmiMgXUzsmLHzHRageVDc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Bhkcg4ikrQSK5Y4anmOwBklc/bRa1mzPTSdipZto+mEAMS2BPJzpbnDQeEq3ixFES keuQXZx+L9FJqTqmHGaI3jKPp31ZxCFYXahmCtECF01ASt4k+3ch1O4iEjtsCxk7Vb Sh+IT2OSBFuX8BogbkvCrWRHku5AurfSpI9slqCQ= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id A3FC33858426 for ; Sat, 16 Sep 2023 10:18:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3FC33858426 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-210-20QdFuQyPtCQIEIYFv18Pg-1; Sat, 16 Sep 2023 06:18:27 -0400 X-MC-Unique: 20QdFuQyPtCQIEIYFv18Pg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-31fa1631b0eso1926087f8f.2 for ; Sat, 16 Sep 2023 03:18:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694859506; x=1695464306; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N+imonrpznzZO6+5BuwP29QmiMgXUzsmLHzHRageVDc=; b=n3E4nIWlfYkZyWpEppB9O7vKrtYgiDcCyXjqp4DOqfk3PHmcJZlw9CS23htpwW+09x p3JTGkqd0VHlAbvF4Dzlwed7/CcOoySC1PbmPU/kVl4lExIlz+uM/8jx1wNtgRPgRj/v HsPPOGkwKbvUbOsZxkvAPQrTsR5Cc5yccs/BfCmOYAl6V75e1LQkdG/Vfs+9NcBj3qmv qlKJAoR8XXLYF5zQaVQC/aRSmeUBr4y2h52Fm7JSCB5x1xfpNHdeg+En5r5H0kpvCzsT ihhbKVxXG3G1jKPxhZBnoZsI8G9sk+yG/jDVXBJ0up1UL+XMtOx5bh8o+Q2XqXrDvJ2F 9mxg== X-Gm-Message-State: AOJu0YxdU0Pxiv032nM2NQn6o//u0V7TubE+lQIFrGu21iljQzhbsAYd MyUHuD8sJuC9OQKltpKav43/Y/iaQRCaWktM1WBR2Xhnglj/RYV/+QxU8Z67/L73/jDL0kM7foH AyyczzLIJ1//oBQmnQqvyfyjkdSLaRKPRznScSyYT6b9qih6ywjYlsfR7rFnZRW7YR/BM5wsg3G lp/GLpYg== X-Received: by 2002:a5d:6f0f:0:b0:320:1c7:fd30 with SMTP id ay15-20020a5d6f0f000000b0032001c7fd30mr1043245wrb.17.1694859506565; Sat, 16 Sep 2023 03:18:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYBxQIMU8jXqVLf27v6gR2jjt7n+ezoOp3ZLitCV/u09aMKNM+Img1BMgXgneXezNpQ6n1Lg== X-Received: by 2002:a5d:6f0f:0:b0:320:1c7:fd30 with SMTP id ay15-20020a5d6f0f000000b0032001c7fd30mr1043233wrb.17.1694859506301; Sat, 16 Sep 2023 03:18:26 -0700 (PDT) Received: from localhost (92.40.218.107.threembb.co.uk. [92.40.218.107]) by smtp.gmail.com with ESMTPSA id k8-20020a5d4288000000b0031431fb40fasm6793530wrq.89.2023.09.16.03.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 03:18:25 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 5/9] gdb: remove final user of the executable_changed observer Date: Sat, 16 Sep 2023 11:18:06 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.2 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit continues with the task started in the previous commit, and is similar in many ways. The goal of the next couple of commits is to expose the executable_changed observable in the Python API as an event. Before I do this I would like to remove the additional call to the executable_changed observable which can be found in the reread_symbols function in the symfile.c file, as I don't believe that this use actually corresponds to a change in the current executable. The previous commit removed one user of the executable_changed observable and replaced it with a new_obfile observer instead, and this commit does the same thing. In auxv.c we use the executable_changed observable to call invalidate_auxv_cache, which then calls: invalidate_auxv_cache_inf (current_inferior ()); The auxv cache is already (additionally) cleared when an inferior exits and when an inferior appears. As with the previous commit, I think we can safely replace the use of the executable_changed observable with a use of the new_obfile observable. All the tests still pass, and with some locally placed printf calls, I think that the cache is still being cleared in all the cases that should matter. --- gdb/auxv.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gdb/auxv.c b/gdb/auxv.c index 3c27c1f1ffe..9f599b04a4f 100644 --- a/gdb/auxv.c +++ b/gdb/auxv.c @@ -344,12 +344,14 @@ invalidate_auxv_cache_inf (struct inferior *inf) auxv_inferior_data.clear (inf); } -/* Invalidate current inferior's auxv cache. */ +/* Invalidate current inferior's auxv cache when all symbol table data is + cleared (indicated by OBJFILE being nullptr). */ static void -invalidate_auxv_cache (void) +auxv_new_objfile_observer (struct objfile *objfile) { - invalidate_auxv_cache_inf (current_inferior ()); + if (objfile == nullptr) + invalidate_auxv_cache_inf (current_inferior ()); } /* See auxv.h. */ @@ -613,5 +615,5 @@ 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::executable_changed.attach (invalidate_auxv_cache, "auxv"); + gdb::observers::new_objfile.attach (auxv_new_objfile_observer, "auxv"); } From patchwork Sat Sep 16 10:18:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76233 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 9DAC238555A9 for ; Sat, 16 Sep 2023 10:19:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DAC238555A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694859569; bh=4SFGn8Z3D/dicim8liNRdgT28CUAwedh0TP/iPgQMPo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dPDvp/n/mCm28KP2eVBJ31V9e/jJByE32MbNYRpjalkrciaQv2+PrAZwFYVS3C/zO 3eNV5Z/YEvCpB42CGaAH6XBmrq4aJp+ZXKEeJutA5jzFH9Iv52BdaTTrHx70e87HYM AMVxF3rheYzHJlBiRyv0wW6qtxzXYvqA1UXxQLHk= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 8B86A385782B for ; Sat, 16 Sep 2023 10:18:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B86A385782B Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-XTZQPV93N6G46yoRCF0AZw-1; Sat, 16 Sep 2023 06:18:29 -0400 X-MC-Unique: XTZQPV93N6G46yoRCF0AZw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-404daa4f3c1so6337145e9.1 for ; Sat, 16 Sep 2023 03:18:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694859508; x=1695464308; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4SFGn8Z3D/dicim8liNRdgT28CUAwedh0TP/iPgQMPo=; b=S4Z0WuvdO83IJ03cZ+3IRF5sN4SHdimfOIwVTGJtzAuf4wmNpKEe6WXaHrXIOD7yZW 4hhnuLjHyhWzxh4wmRzsORx2vsSMpIhQBXrT+7MToHKkqqp7N0Usbg26NZgnDjQ1cu/j GPUdM0tesklQiHO7SIGk1IjA6BOAP+3rK6zNBy+SZa+1l7J0uSQnHvJ6UWUkcm+uEbfc G844B7YijjBTn4sZ4JB1PFd9yYopVZHVRnqqDYkL46LJKxBFFZBbWN7OUjxTUJzD9ny8 0rXg2WdKnkIIK378WRdTdmy8OG2QB9WJUXe1t3R8WAUDB744PWiqCe/pRyy3wh3y7ByQ Pjbw== X-Gm-Message-State: AOJu0Yw8RqgHG7zFJEFQ4PxBdJ4tFn3O5aN6v5LjDm+Q/3xueHOWa/9K 7y6O/yXr+HpATOZ2/Jgm0XC83+zzE6eMF2zDAUdh+YIKo5o1F5T/K/Iqi369M9Xb+MZZrB46qmT bz6tHWwkzhCRfgIw0tY9kowdHGiWc7lSVlqgWFOD4r4GGinOy0tzqvJf1vjdYQtZtjxk3R3lRTW HYt+7Dlw== X-Received: by 2002:adf:efd2:0:b0:317:5ddb:a8bf with SMTP id i18-20020adfefd2000000b003175ddba8bfmr3264430wrp.29.1694859508596; Sat, 16 Sep 2023 03:18:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH87rnD/KNqBLwmO8PqAmnTZHxqj1KSt4KraQyI7WWAYPcvhOdIg7Y6s39xrrrBb9kaZUppgg== X-Received: by 2002:adf:efd2:0:b0:317:5ddb:a8bf with SMTP id i18-20020adfefd2000000b003175ddba8bfmr3264422wrp.29.1694859508317; Sat, 16 Sep 2023 03:18:28 -0700 (PDT) Received: from localhost (92.40.218.107.threembb.co.uk. [92.40.218.107]) by smtp.gmail.com with ESMTPSA id s10-20020a5d510a000000b0031971ab70c9sm6820803wrt.73.2023.09.16.03.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 03:18:27 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 6/9] gdb: remove unnecessary notification of executable_changed observer Date: Sat, 16 Sep 2023 11:18:07 +0100 Message-Id: <019cf397b93d42ee8f6d8d7db536d2e4048724c1.1694858967.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit continues the work of the previous two commits. My goal, in the next couple of commits, is to expose the executable_changed observable in the Python API as an event. However, before I do that I want to remove the use of the executable_changed observable from the reread_symbols function in symfile.c as this use isn't directly associated with a change of the executable file, and so seems wrong. In the previous two commits I have removed all users of the executable_changed observer as I believe those users can, and should, actually be listening for the new_objfile observable instead, so now there are no users of the executable_changed observable. As such, I think removing the use of executable_changed from the function reread_symbols is perfectly safe, and correct. At this point the executable has not been changed, so we shouldn't be sending an executable_changed notification, and, as there is nobody listening to this observable, we can't break anything by removing this call. There should be no user visible changes after this commit. --- gdb/symfile.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index 85a9c4e1da0..43fd45c4050 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2684,10 +2684,6 @@ reread_symbols (int from_tty) clear_symtab_users above. Notify the new files now. */ for (auto iter : new_objfiles) gdb::observers::new_objfile.notify (iter); - - /* At least one objfile has changed, so we can consider that - the executable we're debugging has changed too. */ - gdb::observers::executable_changed.notify (); } } From patchwork Sat Sep 16 10:18:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76232 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 6DDBC38555A1 for ; Sat, 16 Sep 2023 10:19:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DDBC38555A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694859565; bh=PXZdRK78jhWsd/2ZAKhAnPq0knojLvnB0saH1NCuXVo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=M766hDfvqYnhh+etU8s0LhByTbPvdD3DeIt2/IZQmvXsJYTzhpToq7qaB4G1eoFun 3eyN16qAILALorNapv6mckJWBxqUa7UgP7PAFHdwwZKQnPxDokAh6qrIy60TpNRwoA 6uefJbCO9gwyfFBOSMOSAllzL4Ur/r9wqsf9To64= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id F010D385700D for ; Sat, 16 Sep 2023 10:18:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F010D385700D Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-a4kWyCfROMeAE0M2TU5dMg-1; Sat, 16 Sep 2023 06:18:32 -0400 X-MC-Unique: a4kWyCfROMeAE0M2TU5dMg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-40472855114so19598885e9.0 for ; Sat, 16 Sep 2023 03:18:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694859511; x=1695464311; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PXZdRK78jhWsd/2ZAKhAnPq0knojLvnB0saH1NCuXVo=; b=ReBggit+9nqWRuRBnp9rymvoKUS9CnRax9CeZVrhlRprXH/MA263Olzd7MtyHz7a3c mF/fvu35ZCuQh7lO9QDpV95cgV0OsrSNn+n9MMvfnNv4QrGqH9CtvvulTcBWCBo6BDZl ONMLvYNf3aOZt8Ud/e7FpO/Kex9TzqxYnejIRfq3tT/UWVS0MEP4mwjFaTTLqrvTygly fNm8BYRBdMHvlLAYHIqk1PO+b+2z7KJCqkns8YU5uuvuYZ1lWynHNjfFVkUzl42dCGZz 5d3PebcHGchG4q2i4CVaez4pIdJQGUtRRPrn3VyUurv+X9Q2T8CeO0ayCu3WZ2Pbvx0R rSyg== X-Gm-Message-State: AOJu0YzgqNiqJDtgv/ahi4jdWQOfxQOlb2FIzeltO+ZxUiH6/nUHDo5A P+Lna+Jg7VT1bn5Vhe4/aFLHDLMRpHoBvokwbuEVeFb3Todqpift2IodehvcSfa5m4qyyesXC9f fbQk/m1A7RqTIgPYTxPuRnvyBDFnkIflJFzM7who6CzpxBAPlsn4lu8bVM9GYEIrF+EYNvmNTwC +02mJFOg== X-Received: by 2002:a7b:cc84:0:b0:3fb:b3aa:1c8a with SMTP id p4-20020a7bcc84000000b003fbb3aa1c8amr3496587wma.16.1694859510773; Sat, 16 Sep 2023 03:18:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsmACtQcmMg/RYmE2ajtLGbIrB1os089f2x05wkDUXIkjKupCCS4nFJJlD8Re738z+VhYX3A== X-Received: by 2002:a7b:cc84:0:b0:3fb:b3aa:1c8a with SMTP id p4-20020a7bcc84000000b003fbb3aa1c8amr3496573wma.16.1694859510427; Sat, 16 Sep 2023 03:18:30 -0700 (PDT) Received: from localhost (92.40.218.107.threembb.co.uk. [92.40.218.107]) by smtp.gmail.com with ESMTPSA id m10-20020a7bcb8a000000b003fed7fa6c00sm9906634wmi.7.2023.09.16.03.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 03:18:30 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 7/9] gdb: pass more arguments to the executable_changed observer Date: Sat, 16 Sep 2023 11:18:08 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.1 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit continues the work of the previous few commits. My goal is to expose the executable_changed observer through the Python API as an event. At this point adding executable_changed as an event to the Python API is trivial, but before I do that I would like to add some additional arguments to the observable, which currently has no arguments at all. The new arguments I wish to add are: 1. The program_space in which the executable was changed, and 2. A boolean flag that will indicate if the executable changed to a whole new path, or if GDB just spotted that the executable changed on disk (e.g. the user recompiled the executable). In this commit I change the signature of the observable and then pass the arguments through at the one place where this observable is notified. As there are (currently) no users of this observable nothing else needs updating. In the next commit I'll add a listener for this observable in the Python code, and expose this as an event in the Python API. Additionally, with this change, it should be possible to update the insight debugger to make use of this observable rather than using the deprecated_exec_file_display_hook (as it currently does), which will then allow this hook to be removed from GDB. There should be no user visible changes after this commit. --- gdb/exec.c | 11 ++++++++++- gdb/observable.h | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 07759725711..a1396c2aa3d 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -501,7 +501,16 @@ exec_file_attach (const char *filename, int from_tty) } bfd_cache_close_all (); - gdb::observers::executable_changed.notify (); + + /* Are are loading the same executable? */ + bfd *prev_bfd = exec_bfd_holder.get (); + bfd *curr_bfd = current_program_space->exec_bfd (); + bool reload_p = (((prev_bfd != nullptr) == (curr_bfd != nullptr)) + && (prev_bfd == nullptr + || (strcmp (bfd_get_filename (prev_bfd), + bfd_get_filename (curr_bfd)) == 0))); + + gdb::observers::executable_changed.notify (current_program_space, reload_p); } /* Process the first arg in ARGS as the new exec file. diff --git a/gdb/observable.h b/gdb/observable.h index c0bafc51f14..e5305fa081e 100644 --- a/gdb/observable.h +++ b/gdb/observable.h @@ -31,6 +31,7 @@ struct inferior; struct process_stratum_target; struct target_ops; struct trace_state_variable; +struct program_space; namespace gdb { @@ -60,11 +61,18 @@ extern observable signal_received; /* The target's register contents have changed. */ extern observable target_changed; -/* The executable being debugged by GDB has changed: The user - decided to debug a different program, or the program he was - debugging has been modified since being loaded by the debugger - (by being recompiled, for instance). */ -extern observable<> executable_changed; +/* The executable being debugged by GDB in PSPACE has changed: The user + decided to debug a different program, or the program he was debugging + has been modified since being loaded by the debugger (by being + recompiled, for instance). The path to the new executable can be found + by examining PSPACE->exec_filename. + + When RELOAD is true the path to the executable hasn't changed, but the + file does appear to have changed, so GDB reloaded it, e.g. if the user + recompiled the executable. when RELOAD is false then the path to the + executable has not changed. */ +extern observable executable_changed; /* gdb has just connected to an inferior. For 'run', gdb calls this observer while the inferior is still stopped at the entry-point From patchwork Sat Sep 16 10:18:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76235 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 4E8C23853D3C for ; Sat, 16 Sep 2023 10:19:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E8C23853D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694859590; bh=H8Ri08Q8lvZ0EdIsUBsyrkJYNqV1tkvFV1sZcwKxmSM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ZH2PErrkQ5TiGUiC+9OzO5oJ2bVoE/dVAD4dwSxsN0XlkMLHSJQ/apMIfqDFhnR4Q punXHrX4NcX0PgmsM+ONiIfrMJak4ddydYxI+8C5lRki/ZfUmy3/joBKujbuHtG4E0 H653NFnBzUR8z05h5Kj9RpiZymoSUB4NuN9YwCUQ= 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 ESMTPS id BB52C3856962 for ; Sat, 16 Sep 2023 10:18:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB52C3856962 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-bc_EB7alPDuAz-uXnfAD9g-1; Sat, 16 Sep 2023 06:18:34 -0400 X-MC-Unique: bc_EB7alPDuAz-uXnfAD9g-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3fef5403093so13805615e9.0 for ; Sat, 16 Sep 2023 03:18:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694859513; x=1695464313; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H8Ri08Q8lvZ0EdIsUBsyrkJYNqV1tkvFV1sZcwKxmSM=; b=j8LvL0XFJLkWYRRuFVRNgzdQ/7jS/KmobfZDoy2R+3+KQatn+4zfDcFGgTwZ6LskNT 6FAbRrf/7DNWwD0bI5PtKrp+ZUGRm2/i6oFTk8y+AuszS7lVcnjeYrFgg7GaSMkod3Vd q+ASfMrqE/WkQGXJVolcMZ4K9f4Bt8TUWo/Wcs5yWAu2LhaBVNn2iBsHf1Z2Dg7wkkqQ PV5D7Of8yYvstnSi9W++dwt45fec5PBJZJSHPVVD3GOOKs5mKiaZHTBsLKmZ2YjxGlco 9jU05AvDNe/ePTiVElRIAXnzGSuVMB92g+cZ9ynEPCe5ZiymE1ep5TY0hChgDi5X0ByJ RcCA== X-Gm-Message-State: AOJu0YwHd3oMp/25oDNAg9V9LCWXtI9tQj3c1SraHy0ZSU0iBku+ECS9 Jj9YKLS8cxps2p3+QZ1lJtWhFLTVNatK61OnmpeX52cwtV2HS10JafkOeOk2yKfZDL1YayXh4zz 8B2f+eicF05SNRJq5i4cpQaN2VxdXDqnNvVW14HRpBRWE7kEElAsL1cCSAQHPuwbkpFy5P1qikg +81NdpeA== X-Received: by 2002:a7b:c857:0:b0:401:b425:2414 with SMTP id c23-20020a7bc857000000b00401b4252414mr5589971wml.18.1694859513252; Sat, 16 Sep 2023 03:18:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFg3tlFeWMkl+dRSj2Dv+iyv7lt8dCuyFMrBGWYHlBX8qZW6F84Aqz1LUhxz5TOuSRGjvFUpw== X-Received: by 2002:a7b:c857:0:b0:401:b425:2414 with SMTP id c23-20020a7bc857000000b00401b4252414mr5589953wml.18.1694859512824; Sat, 16 Sep 2023 03:18:32 -0700 (PDT) Received: from localhost (92.40.218.107.threembb.co.uk. [92.40.218.107]) by smtp.gmail.com with ESMTPSA id k16-20020a05600c1c9000b004047f3b73f9sm3445886wms.21.2023.09.16.03.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 03:18:32 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 8/9] gdb/python: make the executable_changed event available from Python Date: Sat, 16 Sep 2023 11:18:09 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.1 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit makes the executable_changed observable available through the Python API as an event. There's nothing particularly interesting going on here, it just follows the same pattern as many of the other Python events we support. The new event registry is called events.executable_changed, and this emits an ExecutableChangedEvent object which has two attributes, a gdb.Progspace called 'progspace', this is the program space in which the executable changed, and a Boolean called 'reload', which is True if the same executable changed on disk and has been reloaded, or is False when a new executable has been loaded. One interesting thing did come up during testing though, you'll notice the test contains a setup_kfail call. During testing I observed that the executable_changed event would trigger twice when GDB restarted an inferior. However, the ExecutableChangedEvent object is identical for both calls, so the wrong information is never sent out, we just see one too many events. I tracked this down to how the reload_symbols function (symfile.c) takes care to also reload the executable, however, I've split fixing this into a separate commit, so see the next commit for details. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 5 ++ gdb/doc/python.texi | 32 +++++++ gdb/python/py-all-events.def | 1 + gdb/python/py-event-types.def | 5 ++ gdb/python/py-progspace.c | 54 ++++++++++++ gdb/testsuite/gdb.python/py-exec-file.exp | 100 ++++++++++++++++++++++ 6 files changed, 197 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 93bc9c6a2c0..10975dbb27b 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -297,6 +297,11 @@ info main exact string passed by the user to these commands; the path will have been partially resolved to an absolute path. + ** A new executable_changed event registry is available. This event + emits ExecutableChangedEvent objects, which have 'progspace' (a + gdb.Progspace) and 'reload' (a Boolean) attributes. This event + is emitted when gdb.Progspace.executable_filename changes. + *** Changes in GDB 13 * MI version 1 is deprecated, and will be removed in GDB 14. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 206cf6b4e18..9f7c7cb076a 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3893,6 +3893,38 @@ The @code{gdb.TargetConnection} that is being removed. @end defvar +@item events.executable_changed +Emit @code{gdb.ExecutableChangedEvent} which indicates that the +@code{gdb.Progspace.executable_filename} has changed. + +Changed can mean that either, the value in +@code{gdb.Progspace.executable_filename} has changed to a new path, or +the executable pointed to by @code{gdb.Progspace.executable_filename} +has changed on disk, and @value{GDBN} has reloaded it. + +@defvar ExecutableChangedEvent.progspace +The @code{gdb.Progspace} in which the current executable has changed. +The path to the updated executable will be visible in +@code{gdb.Progspace.executable_filename} (@pxref{Progspaces In Python}). +@end defvar +@defvar ExecutableChangedEvent.reload +This attribute will be @code{True} if the value of +@code{gdb.Progspace.executable_filename} didn't change, but the file +pointed to instead changed on disk, and @value{GDBN} reloaded it. + +When this attribute is @code{False}, the value in +@code{gdb.Progspace.executable_filename} was changed to point to a new +file. +@end defvar + +Remember that @value{GDBN} tracks the executable file, and the symbol +file separately, these are visible as +@code{gdb.Progspace.executable_filename} and +@code{gdb.Progspace.filename} respectively. When using the @kbd{file} +command, @value{GDBN} updates both of these fields, but the executable +file is updated first, so when this event is emitted, the executable +filename will have changed, but the symbol filename might still hold +its previous value. @end table @node Threads In Python diff --git a/gdb/python/py-all-events.def b/gdb/python/py-all-events.def index aa28f2c6f8b..04a12e1bdf0 100644 --- a/gdb/python/py-all-events.def +++ b/gdb/python/py-all-events.def @@ -42,3 +42,4 @@ GDB_PY_DEFINE_EVENT(breakpoint_modified) GDB_PY_DEFINE_EVENT(before_prompt) GDB_PY_DEFINE_EVENT(gdb_exiting) GDB_PY_DEFINE_EVENT(connection_removed) +GDB_PY_DEFINE_EVENT(executable_changed) diff --git a/gdb/python/py-event-types.def b/gdb/python/py-event-types.def index 395d6c07447..b862094650d 100644 --- a/gdb/python/py-event-types.def +++ b/gdb/python/py-event-types.def @@ -125,3 +125,8 @@ GDB_PY_DEFINE_EVENT_TYPE (connection, "ConnectionEvent", "GDB connection added or removed object", event_object_type); + +GDB_PY_DEFINE_EVENT_TYPE (executable_changed, + "ExecutableChangedEvent", + "GDB executable changed event", + event_object_type); diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 1319978d34a..082509b2b5b 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -26,6 +26,8 @@ #include "arch-utils.h" #include "solib.h" #include "block.h" +#include "py-event.h" +#include "observable.h" struct pspace_object { @@ -592,9 +594,61 @@ gdbpy_is_progspace (PyObject *obj) return PyObject_TypeCheck (obj, &pspace_object_type); } +/* Emit an ExecutableChangedEvent event to REGISTRY. Return 0 on success, + or a negative value on error. PSPACE is the program_space in which the + current executable has changed, and RELOAD_P is true if the executable + path stayed the same, but the file on disk changed, or false if the + executable path actually changed. */ + +static int +emit_executable_changed_event (eventregistry_object *registry, + struct program_space *pspace, bool reload_p) +{ + gdbpy_ref<> event_obj + = create_event_object (&executable_changed_event_object_type); + if (event_obj == nullptr) + return -1; + + gdbpy_ref<> py_pspace = pspace_to_pspace_object (pspace); + if (py_pspace == nullptr + || evpy_add_attribute (event_obj.get (), "progspace", + py_pspace.get ()) < 0) + return -1; + + gdbpy_ref<> py_reload_p (PyBool_FromLong (reload_p ? 1 : 0)); + if (py_reload_p == nullptr + || evpy_add_attribute (event_obj.get (), "reload", + py_reload_p.get ()) < 0) + return -1; + + return evpy_emit_event (event_obj.get (), registry); +} + +/* Listener for the executable_changed observable, this is called when the + current executable within PSPACE changes. RELOAD_P is true if the + executable path stayed the same but the file changed on disk. RELOAD_P + is false if the executable path was changed. */ + +static void +gdbpy_executable_changed (struct program_space *pspace, bool reload_p) +{ + if (!gdb_python_initialized) + return; + + gdbpy_enter enter_py; + + if (!evregpy_no_listeners_p (gdb_py_events.executable_changed)) + if (emit_executable_changed_event (gdb_py_events.executable_changed, + pspace, reload_p) < 0) + gdbpy_print_stack (); +} + static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_pspace (void) { + gdb::observers::executable_changed.attach (gdbpy_executable_changed, + "py-progspace"); + if (PyType_Ready (&pspace_object_type) < 0) return -1; diff --git a/gdb/testsuite/gdb.python/py-exec-file.exp b/gdb/testsuite/gdb.python/py-exec-file.exp index 14e5088af1c..5ad3cd7e50f 100644 --- a/gdb/testsuite/gdb.python/py-exec-file.exp +++ b/gdb/testsuite/gdb.python/py-exec-file.exp @@ -35,11 +35,59 @@ if {[build_executable "failed to prepare second executable" \ set binfile1 [gdb_remote_download host $binfile1] set binfile2 [gdb_remote_download host $binfile2] +# Setup a Python function to listen for the executable changed event. +proc setup_exec_change_handler {} { + gdb_py_test_silent_cmd \ + [multi_line \ + "python" \ + "def reset_state():" \ + " global exec_changed_state" \ + " exec_changed_state = \[0, None, None\]" \ + "end" ] \ + "build reset_state function" 0 + + gdb_py_test_silent_cmd \ + [multi_line \ + "python" \ + "def executable_changed(event):" \ + " global exec_changed_state" \ + " exec_changed_state\[0\] += 1" \ + " exec_changed_state\[1\] = event.progspace.executable_filename" \ + " exec_changed_state\[2\] = event.reload" \ + "end" ] \ + "build executable_changed function" 0 + + gdb_test_no_output -nopass "python reset_state()" + gdb_test_no_output "python gdb.events.executable_changed.connect(executable_changed)" +} + +# Check the global Python state that is updated when the +# executable_changed event occurs, and then reset the global state. +# FILENAME is a string, the name of the new executable file. RELOAD +# is a string, which should be 'True' or 'False', and represents if +# the executable file was reloaded, or changed. +proc check_exec_change { filename_re reload testname } { + if { $filename_re ne "None" } { + set filename_re "'$filename_re'" + } + if { $filename_re eq "None" && $reload eq "None" } { + set count 0 + } else { + set count 1 + } + gdb_test "python print(exec_changed_state)" \ + "\\\[$count, $filename_re, $reload\\\]" \ + $testname + gdb_test_no_output -nopass "python reset_state()" +} + # Check that the executable_filename is set correctly after using the # 'file' command. with_test_prefix "using 'file' command" { clean_restart + setup_exec_change_handler + gdb_test "python print(gdb.current_progspace().executable_filename)" \ "None" \ "check executable_filename when no file is loaded" @@ -51,6 +99,9 @@ with_test_prefix "using 'file' command" { "[string_to_regexp $binfile1]" \ "check executable_filename when first executable is loaded" + check_exec_change [string_to_regexp $binfile1] False \ + "check executable_changed state after first executable was loaded" + gdb_test "file $binfile2" \ "Reading symbols from [string_to_regexp $binfile2]\\.\\.\\..*" \ "load second executable" \ @@ -59,42 +110,91 @@ with_test_prefix "using 'file' command" { "[string_to_regexp $binfile2]" \ "check executable_filename when second executable is loaded" + check_exec_change [string_to_regexp $binfile2] False \ + "check executable_changed state after second executable was loaded" + gdb_unload gdb_test "python print(gdb.current_progspace().executable_filename)" \ "None" \ "check executable_filename after unloading file" + + check_exec_change None False \ + "check executable_changed state after unloading the executable" } # Check that the executable_filename is correctly set when we only set # the exec-file. with_test_prefix "using 'exec-file' command" { clean_restart + + setup_exec_change_handler + gdb_test_no_output "exec-file $binfile1" \ "load first executable" gdb_test "python print(gdb.current_progspace().executable_filename)" \ "[string_to_regexp $binfile1]" \ "check executable_filename when first executable is loaded" + check_exec_change [string_to_regexp $binfile1] False \ + "check executable_changed state after first executable was loaded" + gdb_test_no_output "exec-file $binfile2" \ "load second executable" gdb_test "python print(gdb.current_progspace().executable_filename)" \ "[string_to_regexp $binfile2]" \ "check executable_filename when second executable is loaded" + check_exec_change [string_to_regexp $binfile2] False \ + "check executable_changed state after second executable was loaded" + gdb_test "exec-file" "No executable file now\\." gdb_test "python print(gdb.current_progspace().executable_filename)" \ "None" \ "check executable_filename after unloading file" + + check_exec_change None False \ + "check executable_changed state after unloading the executable" } # Check that setting the symbol-file doesn't cause the # executable_filename to be set. with_test_prefix "using 'symbol-file' command" { clean_restart + + setup_exec_change_handler + gdb_test "symbol-file $binfile1" \ "Reading symbols from [string_to_regexp $binfile1]\\.\\.\\..*" \ "load first executable" gdb_test "python print(gdb.current_progspace().executable_filename)" \ "None" \ "check executable_filename after setting symbol-file" + + check_exec_change None None \ + "check executable_changed state after setting symbol-file" +} + +# Check the executable_changed event when the executable changes on disk. +with_test_prefix "exec changes on disk" { + clean_restart $binfile1 + + setup_exec_change_handler + + runto_main + + gdb_test_no_output "shell sleep 1" \ + "ensure executable is at least 1 second old" + + gdb_test "shell touch ${binfile1}" "" \ + "update the executable on disk" + + runto_main + + # There is currently an issue where the executable_changed event + # will trigger twice during an inferior restart. This should be + # fixed in the next commit, at which point this kfail can be + # removed. + setup_kfail "????" *-*-* + check_exec_change [string_to_regexp $binfile1] True \ + "check executable_changed state after exec changed on disk" } From patchwork Sat Sep 16 10:18:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76236 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 203933858288 for ; Sat, 16 Sep 2023 10:19:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 203933858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694859598; bh=GyQSEz+iett/t5842KFtqg8Mo9gXDAYT4uXzrLCrbrc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kKeoB7VC7cMJs3q0G+3Xr6kP5LyxEyMNbvS57PpplVnKAt3Rc3AGF71kMvCgXCw1v ep0n2Wp/IicDt9Ak5pxV7jTTr7gm6gs/vp5C9LV63faiMzeUIloj2dRxRO6mNorHHz KtBFPfh+2StHpVsJ5qJ1ijb6qN6FXo7YBt7Xh6uk= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 5F75238582A1 for ; Sat, 16 Sep 2023 10:18:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F75238582A1 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-JKQa6uT6OXuYmUjf4xn73w-1; Sat, 16 Sep 2023 06:18:37 -0400 X-MC-Unique: JKQa6uT6OXuYmUjf4xn73w-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-30e3ee8a42eso1952949f8f.1 for ; Sat, 16 Sep 2023 03:18:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694859515; x=1695464315; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GyQSEz+iett/t5842KFtqg8Mo9gXDAYT4uXzrLCrbrc=; b=Yaz5CrphPE5LRYOn9ir69lOk/n0HjZM9Rd5E9BuVH8xXJiIRCuWxbSqdNiFSLZBYLc pjdNnuMzaQ6Jmf33Nlu66rUyJUEUUuRaqdjkF+PUZTIEeREaHgplg+L2UiJDv/UxxC/9 1xIBkzc+tEKWbTzB4LTgpWgFKqbIB6CfY+xNgGiA2m7ZuT7fx6bRTRmSma4e8K+7qptx LgXFIRdTOWdjOTF5/ITdrVi2oV3MErIS0BBRZOGnDcEnc0fnoFNRCIELjl48O7QtSGLq 3mYJ3sXWpC5pxt9c4xPUjukSwlbchJBPFb+4C/j8xBfB4YV2ppNWWIqiT6TSejrdiM/F /KlQ== X-Gm-Message-State: AOJu0Yzmg2ujy9PrZvsA9OS4wTH4XFd9/deeW4nMaKLN7Om0Tc4pkFJx G9LjT4OwZ+csvRzs1kQpDDfvBCwcdzrnmzkJZiFN7JPJSiXoik+Xs5RRtJxgqoJCx06P25cFb+l yx3Sy89TLT2jQJ4T8Y16GpSwNxM1C4kQAczI2Jj9Y8SiaozTNAGTq4xLKFDEQ/AI7nuuj/6kRMn rlgQ3Wkg== X-Received: by 2002:adf:e9c6:0:b0:31c:e933:9590 with SMTP id l6-20020adfe9c6000000b0031ce9339590mr3309615wrn.33.1694859515711; Sat, 16 Sep 2023 03:18:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE87UEKyPGQJS+uPWgV73OGK2ag8mIxON5gIrN28nShcWMZDr4/EoWVyrqHPzTi1qre84Vj1w== X-Received: by 2002:adf:e9c6:0:b0:31c:e933:9590 with SMTP id l6-20020adfe9c6000000b0031ce9339590mr3309601wrn.33.1694859515353; Sat, 16 Sep 2023 03:18:35 -0700 (PDT) Received: from localhost (92.40.218.107.threembb.co.uk. [92.40.218.107]) by smtp.gmail.com with ESMTPSA id l26-20020a056000023a00b0031ff1ef7dc0sm3942081wrz.66.2023.09.16.03.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 03:18:34 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 9/9] gdb: use reopen_exec_file from reread_symbols Date: Sat, 16 Sep 2023 11:18:10 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.1 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit fixes an issue that was discovered while writing the tests for the previous commit. I noticed that, when GDB restarts an inferior, the executable_changed event would trigger twice. The first notification would originate from: #0 exec_file_attach (filename=0x4046680 "/tmp/hello.x", from_tty=0) at ../../src/gdb/exec.c:513 #1 0x00000000006f3adb in reopen_exec_file () at ../../src/gdb/corefile.c:122 #2 0x0000000000e6a3f2 in generic_mourn_inferior () at ../../src/gdb/target.c:3682 #3 0x0000000000995121 in inf_child_target::mourn_inferior (this=0x2fe95c0 ) at ../../src/gdb/inf-child.c:192 #4 0x0000000000995cff in inf_ptrace_target::mourn_inferior (this=0x2fe95c0 ) at ../../src/gdb/inf-ptrace.c:125 #5 0x0000000000a32472 in linux_nat_target::mourn_inferior (this=0x2fe95c0 ) at ../../src/gdb/linux-nat.c:3609 #6 0x0000000000e68a40 in target_mourn_inferior (ptid=...) at ../../src/gdb/target.c:2761 #7 0x0000000000a323ec in linux_nat_target::kill (this=0x2fe95c0 ) at ../../src/gdb/linux-nat.c:3593 #8 0x0000000000e64d1c in target_kill () at ../../src/gdb/target.c:924 #9 0x00000000009a19bc in kill_if_already_running (from_tty=1) at ../../src/gdb/infcmd.c:328 #10 0x00000000009a1a6f in run_command_1 (args=0x0, from_tty=1, run_how=RUN_STOP_AT_MAIN) at ../../src/gdb/infcmd.c:381 #11 0x00000000009a20a5 in start_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:527 #12 0x000000000068dc5d in do_simple_func (args=0x0, from_tty=1, c=0x35c7200) at ../../src/gdb/cli/cli-decode.c:95 While the second originates from: #0 exec_file_attach (filename=0x3d7a1d0 "/tmp/hello.x", from_tty=0) at ../../src/gdb/exec.c:513 #1 0x0000000000dfe525 in reread_symbols (from_tty=1) at ../../src/gdb/symfile.c:2517 #2 0x00000000009a1a98 in run_command_1 (args=0x0, from_tty=1, run_how=RUN_STOP_AT_MAIN) at ../../src/gdb/infcmd.c:398 #3 0x00000000009a20a5 in start_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:527 #4 0x000000000068dc5d in do_simple_func (args=0x0, from_tty=1, c=0x35c7200) at ../../src/gdb/cli/cli-decode.c:95 In the first case the call to exec_file_attach first passes through reopen_exec_file. The reopen_exec_file performs a modification time check on the executable file, and only calls exec_file_attach if the executable has changed on disk since it was last loaded. However, in the second case things work a little differently. In this case GDB is really trying to reread the debug symbol. As such, we iterate over the objfiles list, and for each of those we check the modification time, if the file on disk has changed then we reload the debug symbols from that file. However, there is an additional check, if the objfile has the same name as the executable then we will call exec_file_attach, but we do so without checking the cached modification time that indicates when the executable was last reloaded, as a result, we reload the executable twice. In this commit I propose that reread_symbols be changed to unconditionally call reopen_exec_file before performing the objfile iteration. This will ensure that, if the executable has changed, then the executable will be reloaded, however, if the executable has already been recently reloaded, we will not reload it for a second time. After handling the executable, GDB can then iterate over the objfiles list and reload them in the normal way. With this done I now see the executable reloaded only once when GDB restarts an inferior, which means I can remove the kfail that I added to the gdb.python/py-exec-file.exp test in the previous commit. --- gdb/symfile.c | 18 +++++------------- gdb/testsuite/gdb.python/py-exec-file.exp | 5 ----- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index 43fd45c4050..fac8ec19a22 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2457,11 +2457,10 @@ remove_symbol_file_command (const char *args, int from_tty) void reread_symbols (int from_tty) { - long new_modtime; - struct stat new_statbuf; - int res; std::vector new_objfiles; + reopen_exec_file (); + for (objfile *objfile : current_program_space->objfiles ()) { if (objfile->obfd.get () == NULL) @@ -2475,6 +2474,8 @@ reread_symbols (int from_tty) `ar', often called a `static library' on most systems, though a `shared library' on AIX is also an archive), then you should stat on the archive name, not member name. */ + int res; + struct stat new_statbuf; if (objfile->obfd->my_archive) res = stat (bfd_get_filename (objfile->obfd->my_archive), &new_statbuf); else @@ -2486,7 +2487,7 @@ reread_symbols (int from_tty) objfile_name (objfile)); continue; } - new_modtime = new_statbuf.st_mtime; + long new_modtime = new_statbuf.st_mtime; if (new_modtime != objfile->mtime) { gdb_printf (_("`%ps' has changed; re-reading symbols.\n"), @@ -2508,15 +2509,6 @@ reread_symbols (int from_tty) /* We need to do this whenever any symbols go away. */ clear_symtab_users_cleanup defer_clear_users (0); - if (current_program_space->exec_bfd () != NULL - && filename_cmp (bfd_get_filename (objfile->obfd.get ()), - bfd_get_filename (current_program_space->exec_bfd ())) == 0) - { - /* Reload EXEC_BFD without asking anything. */ - - exec_file_attach (bfd_get_filename (objfile->obfd.get ()), 0); - } - /* Keep the calls order approx. the same as in free_objfile. */ /* Free the separate debug objfiles. It will be diff --git a/gdb/testsuite/gdb.python/py-exec-file.exp b/gdb/testsuite/gdb.python/py-exec-file.exp index 5ad3cd7e50f..7aa19a867d7 100644 --- a/gdb/testsuite/gdb.python/py-exec-file.exp +++ b/gdb/testsuite/gdb.python/py-exec-file.exp @@ -190,11 +190,6 @@ with_test_prefix "exec changes on disk" { runto_main - # There is currently an issue where the executable_changed event - # will trigger twice during an inferior restart. This should be - # fixed in the next commit, at which point this kfail can be - # removed. - setup_kfail "????" *-*-* check_exec_change [string_to_regexp $binfile1] True \ "check executable_changed state after exec changed on disk" }