From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694859503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A9fW2jDOdbglnL3gEG67j31/y0zkVDR39tzT9yTnqJg=; b=P7IW24L2g9D+pThwKTTqfVizkQ/Ag55JPOoUzY8l796xbosnW7t/ai5hrnkDotkyPWAjPe 9JwybliJSS0LKR2Oo9A5X4JAldznJ6ybA72ZinrsmC4Z9LQkjgpXseKavd6Wuny7glf1W+ IsFvJUJp9xM3fyV9d6+u+iJ+YQG85MY= 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) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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. --- 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.*" -- 2.25.4