From patchwork Thu Jul 27 13:58:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 73266 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 25A7A385AFB1 for ; Thu, 27 Jul 2023 13:59:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25A7A385AFB1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690466355; bh=TmNrN2FoubIH9HiwXi503LflDPLIANqTukEszhEodzU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=FZJZ7k6Kkcnn5RSGnMcIoWvPY1oh25HgEGU9w//AWK6+vyUuLCXGzNKj89Su+7+Q9 GwcFiZOqa/r469o2eK95Mb5ajTBaJj1+tUKqdibAaHWvGXkp9xXnzCKblw5ak7jcop b6XaxbyoQ18eLFGZMCg/SYm1lA9tq36vJy7YrMpk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by sourceware.org (Postfix) with ESMTPS id 2A2D63858C36 for ; Thu, 27 Jul 2023 13:58:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A2D63858C36 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-78372b895d6so38247539f.2 for ; Thu, 27 Jul 2023 06:58:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690466327; x=1691071127; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TmNrN2FoubIH9HiwXi503LflDPLIANqTukEszhEodzU=; b=j2HiV14DMIMqE1KcyzqZiuHjD6TKS6LOh+D/DCw/Sdrh9IDdVYVVPrzcxpgfAaITd3 Lpaw0aJgdg9wxIMmTzkVnoo05/cOVcV+zfYAjrWpE7PcytR85h3YQ7UbCr7gr8rAJDTX AAndPYR5R2XtGpSajV1GJur6gRwFS64pNrX8BJy5K7P8J+9ir8jCg0Zj4Puhjz73o5lD gvrfp+OEQgx3gQL0yOicaWANKFxSH0c9nLzFBK08DUBroT+NaunOBg7DeIedx3bbQ0aT qD+JhCTzqtuZwSl9/TdndhQsd9ejDxGGV7eEWbH8Gc5apXuHy/GSd9IMP77t5U5vkqjD rrYA== X-Gm-Message-State: ABy/qLbNo+YE2zKhMUBXGBhuUVfl1E/Ae8G1svevMZmrVSMdjOT5VhKV 5pKH+XyLSgDLq9XSoteeojgRohP1HDx/dQTc+IWUZQ== X-Google-Smtp-Source: APBJJlHSgi4OAgALohVO6ayp/RE+TtPkAN67TtKo3CqJvl4c556IiMF9jCnXnVZ6ID7BLfwqzSdCcw== X-Received: by 2002:a6b:ee07:0:b0:785:5917:a35f with SMTP id i7-20020a6bee07000000b007855917a35fmr5276921ioh.8.1690466327281; Thu, 27 Jul 2023 06:58:47 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id h22-20020a02c4d6000000b0042b394eb984sm268570jaj.105.2023.07.27.06.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 06:58:46 -0700 (PDT) To: gdb-patches@sourceware.org Cc: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= , Tom de Vries , Tom Tromey Subject: [PATCH] Re-acquire GIL earlier in gdbpy_parse_and_eval Date: Thu, 27 Jul 2023 07:58:35 -0600 Message-Id: <20230727135835.2450275-1-tromey@adacore.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Tom de Vries filed a bug about an intermittent gdb DAP failure -- and coincidentally, at the same time, Alexandra Hájková sent email about a somewhat similar failure. After looking into this for a while (with no results) using ASan and valgrind, I found that setting PYTHONMALLOC=malloc_debug found the bug instantly. The problem is that gdbpy_parse_and_eval releases the GIL while calling parse_and_eval, but fails to re-acquire it before calling value_to_value_object. This is easily fixed by introducing a new scope. I wonder whether the test suite should unconditionally set PYTHONMALLOC=malloc_debug. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30686 Tested-by: Tom de Vries Reviewed-By: Tom de Vries --- gdb/python/python.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gdb/python/python.c b/gdb/python/python.c index 505fc4412d1..6a978d632e9 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -994,9 +994,17 @@ gdbpy_parse_and_eval (PyObject *self, PyObject *args, PyObject *kw) PyObject *result = nullptr; try { - gdbpy_allow_threads allow_threads; scoped_value_mark free_values; - struct value *val = parse_and_eval (expr_str, flags); + struct value *val; + { + /* Allow other Python threads to run while we're evaluating + the expression. This is important because the expression + could involve inferior calls or otherwise be a lengthy + calculation. We take care here to re-acquire the GIL here + before continuing with Python work. */ + gdbpy_allow_threads allow_threads; + val = parse_and_eval (expr_str, flags); + } result = value_to_value_object (val); } catch (const gdb_exception &except)