From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Il7WOhO1sWgOVw8AWB0awg (envelope-from ) for ; Fri, 29 Aug 2025 10:11:31 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JBcbvmtc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DADCA1E04C; Fri, 29 Aug 2025 10:11:31 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 39A9F1E043 for ; Fri, 29 Aug 2025 10:11:31 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F25643857C6C for ; Fri, 29 Aug 2025 14:11:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F25643857C6C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JBcbvmtc Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 373253858C74 for ; Fri, 29 Aug 2025 14:10:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 373253858C74 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 373253858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756476659; cv=none; b=wn4BoTBv7rw8lV7s2zzvOOiBPJRMg94OI/tW9o6jHfuzneQ6OlyFRBtAr3AIURzGnNJku+Rwy9l9T4kowCC0FZyUXyL03bV7v6KUZEOlPYMLTb5QCOf5DUpzXkfRQNqU0BAilF7F4T8SmTgbzRKRd4ygPjl2q0c/LFrF3fmA0MY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756476659; c=relaxed/simple; bh=ZQUcdUh1yAEpXkt1fcL2sJa0g7B/Bog4g5/I7yx/o7Y=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aUQ633Dag76K5Vc5lcn8yvY0WF1zJk6TgT2JJWWx9H8wT2VM4e2VtN8JGfCYv1u6McMCYdTmp4sIwUyXNsjhyBXhhn7NwJ6CL/I9V110y9k6Zw/kq5rE243sDEoBjcMRR19eqJxK1NRq4aS45yKwO0XLD4Z8rU5Vc+H5WJwwZ0o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 373253858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756476658; 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: in-reply-to:in-reply-to:references:references; bh=aGf0iX1toZ0mkOwC2fYae4aXDAgwQkV6hvnbphuUdM4=; b=JBcbvmtcQY+BcM+e5ghMToE2w2X8XEUuyoyPnelIgOloHAPn+HkcBrkR7nn4oivRRCrgs2 oWZEO1s2WeVNv68X+dzdKuDpI6NKLq0QNahSY2EiVnYzQEpakVAdV9Q/En0yibKLm23wyf w1LlznHSitD6zdKSVU+uSsU0WFQjyI0= 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-645-e_vaZ5-fNOOZoFijumiN9A-1; Fri, 29 Aug 2025 10:10:50 -0400 X-MC-Unique: e_vaZ5-fNOOZoFijumiN9A-1 X-Mimecast-MFC-AGG-ID: e_vaZ5-fNOOZoFijumiN9A_1756476648 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-45a1b0cc989so17109175e9.3 for ; Fri, 29 Aug 2025 07:10:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756476648; x=1757081448; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aGf0iX1toZ0mkOwC2fYae4aXDAgwQkV6hvnbphuUdM4=; b=Of8mvRUJjnll/hV4WhBjYc1G+w/P1fXwYnGPGrYyB4AnVFXGSV2154IJ7Y0ill72Y7 FDXtzQkh0AQ7rYCEtl2t5kD0qknmnt+E/dIFGFV/Kkgvnu4OhmITBwFbsw4LEabH+1AA G0CV9mA3u92R1wq7Pllv9ydZ3dSd+6j2pCkSuc9OdbDMuJL93aDiJ3yEoXWaJxvLWZno t24JQ0OCOPCBKiePoU7pRtf3MrLnloYd/g2PH9oEHEfx3aGS2Uigy+jqJN1R1ZKN6Gsi k8KG8YbMWymXxgpEaaHAAsXSBGVsWujnPm12/rUZ7dwqvaaVerrmyULo/HqeAlrEZbY0 cNPA== X-Forwarded-Encrypted: i=1; AJvYcCVayiC3bfLBFDxQqCcBADbiGg2KAXSDdASKmWsoLzoXpX61oPzcoGXtjP54xzacGSU3a6uqQziARwXAlg==@sourceware.org X-Gm-Message-State: AOJu0YyO/pW8n2gzSPdr9AaXiL7fMER6KnzjJ5znC4iqnYpn8wU3mEpH 0GHgKa1JfyTkwYXNpE+ZTlMJ/1tZIzL/K2LYQdnlfJ6xXRgXYPN4bb/2MQSnMtmjoXAqCHpSo+I TECNbomqs0CTaa0i+2KICo7BVM+emlnBYyAx8RgwVN7wmW4RsvX7yOROsmV/CQ6w= X-Gm-Gg: ASbGncvzNnetIYDYM9hwsHOl+P7A3U2tPPJsCoZlvWz1mpWS6J6QzSddyHvuS7ECLjw SaR4A7jhX9lGSGWbBtHh0hVLZDgNEjLTZ9a61fPXOczKaEtOPTmSMQU38KH4Nm/pVDmen2p51o6 Nj6RKfF4OHleR8tD/2JLYOgDZIoC5UlQfezDFy80xLpdz5hKSvKLq6BwdME6R8B1rHzsUm5JyYY YD1Aip+x2W6lHib4xI/+mpga16aP/P0dvbL1uqi3NhXTndh3qZUQ5RTwei2hz0aeGA9WjwOzetx JQLwq1iPUp5MPNkrhzDaD17asrSTb3Ua31Q= X-Received: by 2002:a05:600c:1c09:b0:43c:eeee:b713 with SMTP id 5b1f17b1804b1-45b68a59459mr112881955e9.20.1756476647970; Fri, 29 Aug 2025 07:10:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEk6GRpg8wD3A8qo3EYFV56N9zgue4XsHiJtRccZI1yB7HctF9aAV+BqPrTe8OVqcQnpsq0nA== X-Received: by 2002:a05:600c:1c09:b0:43c:eeee:b713 with SMTP id 5b1f17b1804b1-45b68a59459mr112881735e9.20.1756476647452; Fri, 29 Aug 2025 07:10:47 -0700 (PDT) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b7e74b72esm41880115e9.0.2025.08.29.07.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 07:10:46 -0700 (PDT) From: Andrew Burgess To: Jan Vrany , gdb-patches@sourceware.org Cc: Jan Vrany , Eli Zaretskii Subject: Re: [RFC v5 14/18] gdb/python: add add_symbol () method to gdb.Block In-Reply-To: <20250623161013.650814-15-jan.vrany@labware.com> References: <20250623161013.650814-1-jan.vrany@labware.com> <20250623161013.650814-15-jan.vrany@labware.com> Date: Fri, 29 Aug 2025 15:10:46 +0100 Message-ID: <87ecsuqkux.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -FQQQddtJXDzcwW9_pP1vKgdUGjVF53wctt-UzmmIgQ_1756476648 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Jan Vrany writes: > This commit adds new method add_symbol () to gdb.Block objects. > A typical use of it is to add previously instantiated gdb.Symbol object > to block when interfacing with JIT compiler. > > Reviewed-By: Eli Zaretskii > --- > gdb/doc/python.texi | 5 +++ > gdb/python/py-block.c | 52 +++++++++++++++++++++++---- > gdb/testsuite/gdb.python/py-block.exp | 20 +++++++++++ > 3 files changed, 71 insertions(+), 6 deletions(-) > > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 709ef7c9d1a..15f851e5fd0 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -6180,6 +6180,11 @@ The new block's @var{start}--@var{end} range must be within superblock's > range and must not overlap with any block already contained in superblock. > @end defun > > +@defun Block.add_symbol (symbol) > +Add @var{symbol} to this block. Both the block and the @var{symbol} must > +belong to the same compunit (@pxref{Compunits In Python}). > +@end defun > + > @defun Block.is_valid () > Returns @code{True} if the @code{gdb.Block} object is valid, > @code{False} if not. A block object can become invalid if the block it > diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c > index 43b15b6013e..7926808d4db 100644 > --- a/gdb/python/py-block.c > +++ b/gdb/python/py-block.c > @@ -263,6 +263,43 @@ blpy_is_static (PyObject *self, void *closure) > Py_RETURN_FALSE; > } > > +/* Implementation of gdb.Block.add_symbol (self, symbol). > + Adds SYMBOL to this block. */ > + > +static PyObject * > +blpy_add_symbol (PyObject *self, PyObject *symbol_obj) > +{ > + const struct block *block; > + > + BLPY_REQUIRE_VALID (self, block); > + > + struct symbol *symbol = symbol_object_to_symbol (symbol_obj); > + if (symbol == nullptr) > + { > + return PyErr_Format (PyExc_TypeError, > + _("The symbol argument is not valid gdb.Symbol")); > + } > + > + if (symbol->symtab ()->compunit() != block->global_block ()->compunit ()) > + { > + return PyErr_Format (PyExc_TypeError, > + _("The symbol argument belongs to different " > + "compunit than block")); > + } In both these `if` blocks, the '{' and '}' are not needed. In the second one, is TypeError the best choice? Would ValueError? Or RuntimeError? be better? Thanks, Andrew > + > + multidictionary *dict = block->multidict (); > + if (dict == nullptr) > + { > + auto_obstack *obstack = > + &(block->global_block ()->compunit ()->objfile ()->objfile_obstack); > + dict = mdict_create_linear (obstack, nullptr); > + const_cast(block)->set_multidict (dict); > + } > + > + mdict_add_symbol (dict, symbol); > + Py_RETURN_NONE; > +} > + > /* Given a string, returns the gdb.Symbol representing that symbol in this > block. If such a symbol does not exist, returns NULL with a Python > exception. */ > @@ -360,7 +397,7 @@ blpy_init (PyObject *zelf, PyObject *args, PyObject *kw) > return -1; > } > > - static const char *keywords[] = { "superblock", "start", "end", NULL }; > + static const char *keywords[] = { "superblock", "start", "end", nullptr }; > PyObject *superblock_obj; > uint64_t start; > uint64_t end; > @@ -400,9 +437,9 @@ blpy_init (PyObject *zelf, PyObject *args, PyObject *kw) > > /* Check that start-end range does not overlap with any > "sibling" blocks' range. */ > - auto cu = superblock->global_block ()->compunit (); > + compunit_symtab *cu = superblock->global_block ()->compunit (); > > - for (auto each : cu->blockvector ()->blocks ()) > + for (const struct block *each : cu->blockvector ()->blocks ()) > { > if (each->superblock () == superblock) > { > @@ -417,11 +454,11 @@ blpy_init (PyObject *zelf, PyObject *args, PyObject *kw) > } > } > > - auto obstack = &(cu->objfile ()->objfile_obstack); > - auto blk = new (obstack) block (); > + auto_obstack *obstack = &(cu->objfile ()->objfile_obstack); > + struct block *blk = new (obstack) block (); > > blk->set_superblock (superblock); > - blk->set_multidict (mdict_create_linear (obstack, NULL)); > + blk->set_multidict (mdict_create_linear (obstack, nullptr)); > blk->set_start ((CORE_ADDR) start); > blk->set_end ((CORE_ADDR) end); > > @@ -653,6 +690,9 @@ static PyMethodDef block_object_methods[] = { > { "is_valid", blpy_is_valid, METH_NOARGS, > "is_valid () -> Boolean.\n\ > Return true if this block is valid, false if not." }, > + { "add_symbol", blpy_add_symbol, METH_O, > + "add_symbol (symbol) -> None.\n\ > +Add given symbol to the block." }, > {NULL} /* Sentinel */ > }; > > diff --git a/gdb/testsuite/gdb.python/py-block.exp b/gdb/testsuite/gdb.python/py-block.exp > index afa306be00f..b1cb93ca718 100644 > --- a/gdb/testsuite/gdb.python/py-block.exp > +++ b/gdb/testsuite/gdb.python/py-block.exp > @@ -138,6 +138,26 @@ gdb_test "python print ( gdb.Block(cu.static_block(), 160, 170))" \ > " \{.*\}>" \ > "Create sibling block" > > +# Test adding symbols to a block. > +gdb_py_test_silent_cmd "python symtab = gdb.Symtab(\"some_file.txt\", cu)" \ > + "Create new symtab" 1 > +gdb_py_test_silent_cmd "python typ = gdb.selected_inferior().architecture().integer_type(0).function()" \ > + "Create type of new symbol" 1 > +gdb_py_test_silent_cmd "python sym = gdb.Symbol(\"static_block\", symtab, typ, gdb.SYMBOL_FUNCTION_DOMAIN, gdb.SYMBOL_LOC_BLOCK, cu.static_block() )" \ > + "Create new symbol" 1 > +gdb_test "python print ( sym in list(cu.global_block()) )" \ > + "False" \ > + "Symbol is not in global block" > +gdb_py_test_silent_cmd "python cu.global_block().add_symbol(sym)" \ > + "Add new symbol to block" 1 > +gdb_test "python print ( sym in list(cu.global_block()) )" \ > + "True" \ > + "Symbol is in global block" > +gdb_test "python print ( cu.global_block().add_symbol(cu))" \ > + "TypeError.*:.*" \ > + "Add non-symbol to block" > + > + > # Test Block is_valid. This must always be the last test in this > # testcase as it unloads the object file. > delete_breakpoints > -- > 2.47.2