From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GDRtD3x9WWhu1xoAWB0awg (envelope-from ) for ; Mon, 23 Jun 2025 12:14:52 -0400 Received: by simark.ca (Postfix, from userid 112) id 3AD471E11C; Mon, 23 Jun 2025 12:14:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham 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 5D84A1E0C2 for ; Mon, 23 Jun 2025 12:14:51 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0FA13386B8A2 for ; Mon, 23 Jun 2025 16:14:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FA13386B8A2 Received: from us-smtp-delivery-114.mimecast.com (us-smtp-delivery-114.mimecast.com [170.10.129.114]) by sourceware.org (Postfix) with ESMTP id F393E384671A for ; Mon, 23 Jun 2025 16:11:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F393E384671A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=labware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=labware.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F393E384671A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.114 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750695086; cv=none; b=Uh0tQ+KO5olQNM2zW95ElN36MVDAiLwvO/x+MIEc2Cqn0a9ybUHdSZA8YSvHbivSYedh//9Wr0+OHbtg4pvEOa+A17YXCPF8fFRorhn0+SFCSqn9+I9IexLR/dUZi+V8ipvNcMcSL/GcpvBUWPD1MNjBwA1Dcpy9nhZeS00aIvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750695086; c=relaxed/simple; bh=vERQe++1qzlEzOAzZB48MWVifYsb5SObniV7nDBoILs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=mrpSRY9kBn/bvuMm1CGIiZl2HfmFokQKt1/8hXG7JUS5WUkh5+DBxOUbAiA/a+gaIgKqDSxw11QhPQf3ivtfVoTbJQdKYWqWHoRw9RdqKHDLwlRMvuWwXFz25UoKnYn3Bp8NzdvrVoSmg7IlMADRI9W0Q0N6xejdHoGK7ljIqI4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F393E384671A Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2130.outbound.protection.outlook.com [40.107.243.130]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-HAUjjAs7OSu7rNUq7WSNAw-1; Mon, 23 Jun 2025 12:11:24 -0400 X-MC-Unique: HAUjjAs7OSu7rNUq7WSNAw-1 X-Mimecast-MFC-AGG-ID: HAUjjAs7OSu7rNUq7WSNAw_1750695083 Received: from SA1PR17MB5365.namprd17.prod.outlook.com (2603:10b6:806:1d8::11) by CH3PR17MB6292.namprd17.prod.outlook.com (2603:10b6:610:14b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8857.27; Mon, 23 Jun 2025 16:11:22 +0000 Received: from SA1PR17MB5365.namprd17.prod.outlook.com ([fe80::6398:7dc0:7d88:5a4d]) by SA1PR17MB5365.namprd17.prod.outlook.com ([fe80::6398:7dc0:7d88:5a4d%5]) with mapi id 15.20.8857.026; Mon, 23 Jun 2025 16:11:22 +0000 From: Jan Vrany To: gdb-patches@sourceware.org CC: Jan Vrany , Eli Zaretskii Subject: [RFC v5 13/18] gdb/python: allow instantiation of gdb.Symbol from Python Date: Mon, 23 Jun 2025 17:10:08 +0100 Message-ID: <20250623161013.650814-14-jan.vrany@labware.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250623161013.650814-1-jan.vrany@labware.com> References: <20250623161013.650814-1-jan.vrany@labware.com> X-ClientProxiedBy: LO4P123CA0616.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:314::16) To SA1PR17MB5365.namprd17.prod.outlook.com (2603:10b6:806:1d8::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR17MB5365:EE_|CH3PR17MB6292:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ba2e3c4-f432-446d-1675-08ddb2709862 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024 X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?nMsWxnZeF/iw26oDh0JIklzCk8jj07ljIdtI99/QjmMWffN/91DmER6nCnSi?= =?us-ascii?Q?86YXgzaNjVZ3WQ6I/l0eHyna8oNjTrFl1xoARdrrKvhj1RGhkf0ak634HljR?= =?us-ascii?Q?NV1wGvUxB6kwexEWD/Ohnej7erW6whRkqvPkGzxUgLY5nF+AbqDfQXPJ50P0?= =?us-ascii?Q?rt6V2dGqgXwIUow4kUtp1Ymj9rWtzbOJiCW+O8xtTkIqz+3N3/tAlRXJ4Uxu?= =?us-ascii?Q?JChZTlwAFtk75r5mAwMdeoMjzs9LWYkirGQDdRp2PcHFvV4cJxPS34z7JLzO?= =?us-ascii?Q?XrZbgLVTenj+v+ct4JElw5WLvJbjw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m36g+fZDGEzK1x0caNdbhMe8XLqi7daqg2WMswXCSm5w5x1LFSQmnFbKxxTC?= =?us-ascii?Q?3i3gfp9o1fy6r8clWDTsQsabK0DhrQI926LS0DI+TqSgAyOwUYiVOM7VpAyL?= =?us-ascii?Q?3jMa+kncwQoeWsS5w16e3IcJ7FezlFrf8qhl5zrAlEdrzuvFyCqbl4KnC98w?= =?us-ascii?Q?2vGtCS11MSkZ9ut7DCiuqSwAIN48Jn3FU/Zxfd3UbO3cytJ2Uyi6+YFIrChc?= =?us-ascii?Q?HEJ4DSqcD8c=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR17MB5365.namprd17.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(366016)(1800799024); DIR:OUT; SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?4+7qEjFc46OiYeiD3P+2dNbqeVS7uDcw01DZwC87Z/UqiNnOFgqvQ74tbIz2?= =?us-ascii?Q?1uYC0R/TzuPgyKfYcJh939GY7GdnCTnbSqHBIK6a3Xfbbo1D9WF17W4QX4sf?= =?us-ascii?Q?zBgtd6yjG0GeAv/ioVrqNIORIx+Cjsnp9/RU8T2edycbKbaxhf1RulfXwWHa?= =?us-ascii?Q?d13m0wZPlLeKVJZ7+EFfiG7YbTCLMqJEQHGND+YtJEqzgHllcrl7anfxP59L?= =?us-ascii?Q?TP/EYB6wpq3HXoGLkzFq4IeganNxEJQ4uzGxr14w2iokEI20S7fAP5TF+16G?= =?us-ascii?Q?MPcyzMfsM4aXRCxbsh2qME5jBOs/fO9Ln/GOiYhqB4oSNbOeAPgRexSEGNJr?= =?us-ascii?Q?9IXLvpki9b2YoLQPVBsW1ML4tiKFqPVvNu+mu/4vngsLyuUtQ1LW+SpuvKnj?= =?us-ascii?Q?CllYJxgNqNkMOcUxhDk7N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lMAA?= =?us-ascii?Q?dvhmt2fSsGQ0eqSmVJZEcj2CRzBiv+j/0ANF4eKC5fbbSEQPRPWCVtUWER5A?= =?us-ascii?Q?UOQxMUXqAAmX8poJ1CBCiZJP/93tByCAPPbWHvV2byqFmhz3Iy7L9ewnmgE2?= =?us-ascii?Q?2VyGRqOCftVTwaGy5PIHquMLQED9Z2GEhLPiJ4TOpmQQtAif8FqJLWqilffL?= =?us-ascii?Q?VRRAkr/BeVAIp8R1rcbgfET4JbN1Q36QGglGgrNuRxysLbBUHKAFZeAcwgfv?= =?us-ascii?Q?L6O7wFJsxzEJyNDpSCF/qOr3ydX67KQWw6vCSvZ9?= X-OriginatorOrg: labware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ba2e3c4-f432-446d-1675-08ddb2709862 X-MS-Exchange-CrossTenant-AuthSource: SA1PR17MB5365.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2025 16:11:22.1572 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b5db0322-1aa0-4c0a-859c-ad0f96966f4c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bv4lnvTONIaycuPub/k8mm+MEYLIpzAjWR+0ZinQy+FObjMoisUE1QdEOxJQZ55TU2m/lGl/C6IBJw+dleBt4A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR17MB6292 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: tVAXxTCXHk4sgMFas98V4f3O0kK6ZukkYKUqtvkiQMA_1750695083 X-Mimecast-Originator: labware.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252 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 This commit adds code to allow user extension to instantiate gdb.Symbol. As of now only "function" symbols can be created (that is: symbols of FUNCTION_DOMAIN and with address class LOC_BLOCK). This is enough to be able to implement "JIT reader" equivalent in Python. Future commits may extend this API to allow creation of other kinds of symbols (static variables, arguments, locals and so on). Like previous similar commits, this is a step towards a Python support for dynamically generated code (JIT) in GDB. Reviewed-By: Eli Zaretskii --- gdb/doc/python.texi | 26 +++++ gdb/objfiles.c | 20 ++++ gdb/objfiles.h | 4 + gdb/python/py-symbol.c | 139 ++++++++++++++++++++++++- gdb/testsuite/gdb.python/py-symbol.exp | 13 +++ 5 files changed, 201 insertions(+), 1 deletion(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 7f50615d151..709ef7c9d1a 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -6420,6 +6420,32 @@ arguments. =20 A @code{gdb.Symbol} object has the following methods: =20 +@defun Symbol.__init__ (name, symtab, type, domain, addr_class, value) +Creates new symbol named @var{name} and adds it to symbol table +@var{symtab}. + +The @var{type} argument specifies type of the symbol as @var{gdb.Type} +object (@pxref{Types In Python}). + +The @var{domain} argument specifies domain of the symbol. Each domain is +a constant defined in the @code{gdb} module and described later in this +chapter. + +The @var{addr_class} argument, together with @var{value} argument, specifi= es +how to find the value of this symbol. Each address class is a constant +defined in the @code{gdb} module and described later in this chapter. As = of +now, only @code{gdb.SYMBOL_LOC_BLOCK} address class is supported, but futu= re +versions of @value{GDBN} may support more address classes. + +The meaning of @var{value} argument depends on the value of @var{addr_clas= s}: +@vtable @code +@item gdb.SYMBOL_LOC_BLOCK +The @var{value} argument must be a block (a @code{gdb.Block} object). Blo= ck +must belong to the same compunit as the +@var{symtab} parameter (@pxref{Compunits In Python}). +@end vtable +@end defun + @defun Symbol.is_valid () Returns @code{True} if the @code{gdb.Symbol} object is valid, @code{False} if not. A @code{gdb.Symbol} object can become invalid if diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 6d5dd588f91..f65620ae400 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -1251,3 +1251,23 @@ objfile_int_type (struct objfile *of, int size_in_by= tes, bool unsigned_p) =20 gdb_assert_not_reached ("unable to find suitable integer type"); } + +/* See objfiles.h. */ + +int +objfile::find_section_index (CORE_ADDR start, CORE_ADDR end) +{ + obj_section *sect; + int sect_index; + for (sect =3D this->sections_start, sect_index =3D 0; + sect < this->sections_end; + sect++, sect_index++) + { + if (sect->the_bfd_section =3D=3D nullptr) +=09continue; + + if (sect->addr () <=3D start && end <=3D sect->endaddr ()) +=09return sect_index; + } + return -1; +} \ No newline at end of file diff --git a/gdb/objfiles.h b/gdb/objfiles.h index cadb4525782..606928ec08b 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -665,6 +665,10 @@ struct objfile : intrusive_list_node this->section_offsets[idx] =3D offset; } =20 + /* Return the section index for section mapped at memory range + [START, END]. If there's no such section, return -1. */ + int find_section_index (CORE_ADDR start, CORE_ADDR end); + class section_iterator { public: diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 3028a307205..16bc8efca32 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -398,6 +398,135 @@ sympy_repr (PyObject *self) =09=09=09 symbol->print_name ()); } =20 +/* Object initializer; creates new symbol. + + Use: __init__(NAME, SYMTAB, TYPE, DOMAIN, ADDR_CLASS, VALUE). */ + +static int +sympy_init (PyObject *zelf, PyObject *args, PyObject *kw) +{ + struct symbol_object *self =3D (struct symbol_object*) zelf; + + if (self->symbol) + { + PyErr_Format (PyExc_RuntimeError, +=09=09 _("Symbol object already initialized.")); + return -1; + } + + static const char *keywords[] =3D { "name", "symtab", "type", +=09=09=09=09 "domain", "addr_class", "value", +=09=09=09=09 nullptr }; + const char *name; + PyObject *symtab_obj =3D nullptr; + PyObject *type_obj =3D nullptr; + domain_enum domain; + unsigned int addr_class; + PyObject *value_obj =3D nullptr; + + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "sOOIIO", keywords, +=09=09=09=09=09 &name, &symtab_obj, &type_obj, +=09=09=09=09=09 &domain, &addr_class, &value_obj)) + return -1; + + + struct symtab *symtab =3D symtab_object_to_symtab (symtab_obj); + if (symtab =3D=3D nullptr) + { + PyErr_Format (PyExc_TypeError, +=09=09 _("The symtab argument is not valid gdb.Symtab object")); + return -1; + } + + struct type *type =3D type_object_to_type (type_obj); + if (type =3D=3D nullptr) + { + PyErr_Format (PyExc_TypeError, +=09=09 _("The type argument is not valid gdb.Type object")); + return -1; + } + if (type->objfile_owner () !=3D nullptr && + type->objfile_owner () !=3D symtab->compunit ()->objfile ()) + { + PyErr_Format (PyExc_ValueError, +=09=09 _("The type argument's owning objfile differs from " +=09=09 "symtab's objfile.")); + return -1; + } + + union _value { + const struct block *block; + } value; + + switch (addr_class) + { + default: +=09PyErr_Format (PyExc_ValueError, +=09=09 _("The value of addr_class argument is not supported")); +=09return -1; + + case LOC_BLOCK: +=09if ((value.block =3D block_object_to_block (value_obj)) =3D=3D nullptr) +=09 { +=09 PyErr_Format (PyExc_TypeError, +=09=09=09 _("The addr_class argument is SYMBOL_LOC_BLOCK but " +=09=09=09 "the value argument is not a valid gdb.Block.")); +=09 return -1; +=09 } +=09if (type->code () !=3D TYPE_CODE_FUNC) +=09 { +=09 PyErr_Format (PyExc_ValueError, +=09=09=09 _("The addr_class argument is SYMBOL_LOC_BLOCK but " +=09=09=09 "the type argument is not a function type.")); +=09 return -1; +=09 } +=09break; + } + + struct objfile *objfile =3D symtab->compunit ()->objfile (); + auto_obstack *obstack =3D &(objfile->objfile_obstack); + struct symbol *sym =3D new (obstack) symbol(); + + sym->m_name =3D obstack_strdup (obstack, name); + sym->set_symtab (symtab); + sym->set_type (type); + sym->set_domain (domain); + sym->set_aclass_index (addr_class); + + switch (addr_class) + { + case LOC_BLOCK: +=09{ +=09 sym->set_value_block (value.block); + +=09 if (domain =3D=3D FUNCTION_DOMAIN) +=09 const_cast (value.block)->set_function (sym); + +=09 /* Set symbol's section index. This needed in somewhat unusual +=09 usecase where dynamic code is generated into a special section +=09 (defined in custom linker script or otherwise). Otherwise, +=09 find_pc_sect_compunit_symtab () would not find the compunit +=09 symtab and commands like "disassemble function_name" would +=09 resort to disassemble complete section. + +=09 Note that in usual case where new objfile is created for +=09 dynamic code, the objfile has no sections at all and +=09 objfile::find_section_index () returns -1. +=09 */ +=09 CORE_ADDR start =3D value.block->start (); +=09 CORE_ADDR end =3D value.block->end (); +=09 sym->set_section_index (objfile->find_section_index (start, end)); +=09} +=09break; + default: +=09gdb_assert_not_reached("unreachable"); +=09break; + } + + set_symbol (self, sym); + return 0; +} + /* Implementation of gdb.lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_t= his) A tuple with 2 elements is always returned. The first is the symbol @@ -773,5 +902,13 @@ PyTypeObject symbol_object_type =3D { 0,=09=09=09=09 /*tp_iternext */ symbol_object_methods,=09 /*tp_methods */ 0,=09=09=09=09 /*tp_members */ - symbol_object_getset=09=09 /*tp_getset */ + symbol_object_getset,=09=09 /*tp_getset */ + 0,=09=09=09=09 /*tp_base */ + 0,=09=09=09=09 /*tp_dict */ + 0,=09=09=09=09 /*tp_descr_get */ + 0,=09=09=09=09 /*tp_descr_set */ + 0, /*tp_dictoffset */ + sympy_init,=09 /*tp_init */ + 0,=09=09=09=09 /*tp_alloc */ + PyType_GenericNew,=09=09 /*tp_new */ }; diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.pyt= hon/py-symbol.exp index 55cdebe5124..12c6268aace 100644 --- a/gdb/testsuite/gdb.python/py-symbol.exp +++ b/gdb/testsuite/gdb.python/py-symbol.exp @@ -212,6 +212,19 @@ if { [is_remote host] } { } gdb_test "python print (t\[0\].symtab)" "${py_symbol_c}" "get symtab" =20 +# Test creation of new symbols +gdb_py_test_silent_cmd "python s =3D gdb.Symbol(\"ns1\", t\[0\].symtab, t\= [0\].type.function(), gdb.SYMBOL_FUNCTION_DOMAIN, gdb.SYMBOL_LOC_BLOCK, t\[= 0\].symtab.static_block() )" \ +=09"create symbol" 0 +gdb_test "python print (s)" \ +=09 "ns1" \ +=09 "test new symbol's __str__" +gdb_test "python print (s.symtab =3D=3D t\[0\].symtab)" \ +=09 "True" \ +=09 "test new symbol's symtab" +gdb_test "python print (s.type =3D=3D t\[0\].type.function())" \ +=09 "True" \ +=09 "test new symbol's type" + # C++ tests # Recompile binary. lappend opts c++ --=20 2.47.2