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 CE04D3858D3C for ; Fri, 18 Mar 2022 16:12:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CE04D3858D3C 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-77pJFRE4N9ySWNZcsMPkEw-1; Fri, 18 Mar 2022 12:12:47 -0400 X-MC-Unique: 77pJFRE4N9ySWNZcsMPkEw-1 Received: by mail-wm1-f72.google.com with SMTP id v67-20020a1cac46000000b00383e71bb26fso3222344wme.1 for ; Fri, 18 Mar 2022 09:12:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=aqUU2YYAtJurO4RgrGSos7tsuxKM38STOR0vlq6sGac=; b=0hRFylo6gS3ft/j45JPuArQYZmq1oDXw31kxWCMHJR/k/9uuTggvysvm5WDX8NMTq/ 6HF0cpvjo0YLgwHyHblpg1q7UXf0MOak50XfwYX1PA1BoC7tX6x+sYuGdAYABvmM8WbD HVhEajQwD0m6TZO62fgNs57uo51kTSk0uCCiG93mlk8bQGuFnFG3i6RpEw8Ltqxf6Vfh bxWReOm/vYxaLAy8VhYMTxq2YgLhKj+UB6/lZkS7BhH4GGRKrS+C0FrgZ2t8cV+tTJst QOQOx6K5+pFFikK5hOfx+ZyTh04LzOWl/qn6r1Q16h+FYfT9S020YY7uQKlk3jm8LyMb B5aA== X-Gm-Message-State: AOAM532ok/Y/cAbxIUry+2Hy2EK+mHOd6IQhSNDof5szTvumxZsNsUbu cTpHupNhsrimjJZd9A+5QWeqoW+/efuWhhQI8tpXBA7i1aytUC4ZTlH8cDOyMNtY7yulF0H4OEL GANFIIHNdAWMfDz/SZm8m8Q== X-Received: by 2002:a7b:c5d5:0:b0:37b:fda9:a5e2 with SMTP id n21-20020a7bc5d5000000b0037bfda9a5e2mr8529204wmk.62.1647619965913; Fri, 18 Mar 2022 09:12:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8KA/w3pckaT8xW4fwwK33P+oKpR+Uip/A+9HaTZEO19fCoblWkZbBCa2KhizTiu2CHuvB8g== X-Received: by 2002:a7b:c5d5:0:b0:37b:fda9:a5e2 with SMTP id n21-20020a7bc5d5000000b0037bfda9a5e2mr8529176wmk.62.1647619965650; Fri, 18 Mar 2022 09:12:45 -0700 (PDT) Received: from localhost (host109-155-5-90.range109-155.btcentralplus.com. [109.155.5.90]) by smtp.gmail.com with ESMTPSA id u15-20020a5d6daf000000b00203db33b2e4sm6962680wrs.26.2022.03.18.09.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Mar 2022 09:12:44 -0700 (PDT) Date: Fri, 18 Mar 2022 16:12:43 +0000 From: Andrew Burgess To: Simon Marchi Cc: gdb-patches@sourceware.org, Jan Vrany Subject: Re: [PATCHv5] gdb/python/mi: create MI commands using python Message-ID: <20220318161243.GQ1212730@redhat.com> References: <20220224103749.1719761-1-aburgess@redhat.com> <20220228164801.1276366-1-aburgess@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 16:09:03 up 19 days, 5:46, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.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_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Mar 2022 16:12:52 -0000 * Simon Marchi [2022-03-18 11:06:43 -0400]: > > + /* Lookup the gdb.MICommand object in the dictionary of all Python M= I > > + commands, this is gdb._mi_command, and remove it. */ > > + PyObject *curr =3D PyDict_GetItemWithError (mi_cmd_dict.get (), > > +=09=09=09=09=09 name_obj.get ()); >=20 > This doesn't build with Python 2: >=20 > /home/simark/src/binutils-gdb/gdb/python/py-micmd.c: In function =E2=80= =98int micmdpy_uninstall_command(micmdpy_object*)=E2=80=99: > /home/simark/src/binutils-gdb/gdb/python/py-micmd.c:430:20: error: =E2=80= =98PyDict_GetItemWithError=E2=80=99 was not declared in this scope; did you= mean =E2=80=98PyDict_GetItemString=E2=80=99? > 430 | PyObject *curr =3D PyDict_GetItemWithError (mi_cmd_dict.get (), > | ^~~~~~~~~~~~~~~~~~~~~~~ > | PyDict_GetItemString >=20 Simon, After discussion on IRC, I believe you are working on a patch that switches this code to make use of a C++ map (or some other container). If/when that patch is ready then that has my +1 as a better solution. However, just in case you don't have time for that, below is a work around which I believe should be acceptable. I believe this patch is OK only because I know that in a couple of weeks Py2 support is going to be removed from master, so this work around would only live on in the GDB 12 branch. Comments welcome, Thanks, Andrew --- commit 5ec0444e8312c17e628739ebd7b8f0e29df3c9e9 Author: Andrew Burgess Date: Fri Mar 18 15:55:34 2022 +0000 gdb: supply PyDict_GetItemWithError when compiling with Python2 =20 Commit =20 commit 740b42ceb7c7ae7b5343183782973576a93bc7b3 Date: Tue Jun 23 14:45:38 2020 +0100 =20 gdb/python/mi: create MI commands using python =20 Introduced a use of PyDict_GetItemWithError, which is not available in Python2, and so the Python2 build was broken. =20 This commit provides a work around for this: =20 #define PyDict_GetItemWithError PyDict_GetItem =20 The arguments passed to these calls are identical, the difference is that the WithError version will return with an exception raised in some error cases, while the PyDict_GetItem suppresses some errors, and just returns nullptr. =20 Given that we are almost at the GDB 12 branch point, this commit is the easiest change to get the Python2 build working again. After GDB 12 branches the plan is to remove Python2 support, so this #define will be removed anyway. =20 As far as functionality I think this #define will be fine. In the "normal" no error case, then obviously, everything will be fine. The only difference is what happens when an error occurs. =20 The only errors I think could happen if Python runs into problems hashing the string, or comparing the strings for equality. Given the limited strings we're working with I don't expect that this should occur during normal operation. So, my expectation is that this should only happen if they user has gone and messed around with this hash in some way - in which case I think it's OK if weird things happen. =20 This issue was discussed on IRC, and I think Simon might be working on an alternative patch to remove the _mi_commands dictionary from the gdb module, in which case the use of PyDict_GetItemWithError will be removed completely. I'm posting this just in case people want to consider a minimal work around for the breakage in the short term. diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 083c4dbdbc3..e9f786ca61c 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -102,6 +102,9 @@ #define PyString_Decode PyUnicode_Decode #define PyString_FromFormat PyUnicode_FromFormat #define PyString_Check PyUnicode_Check +#else +/* Until Python2 support is removed. */ +#define PyDict_GetItemWithError PyDict_GetItem #endif =20 /* If Python.h does not define WITH_THREAD, then the various