From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-78372b895d6so38247539f.2 for ; Thu, 27 Jul 2023 06:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1690466327; x=1691071127; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TmNrN2FoubIH9HiwXi503LflDPLIANqTukEszhEodzU=; b=jdcLMMRDTsDHXRwrHZRR/aeExCBI4gnYTKAr6a5gzw3sVRhZy2fj0Fv+pyeTJFaD2O S0Tqoa35bgTlmJtLOzVEcIszVeyGqK2Xv+7PZnVjlyfuh0qLkUjkILSU11nsjcGv0Gwv P481JnuDRtRtv830D6Rm1Om/pEx8KzJ+Tjs57k1S4cq4GV4ezYsJan5NDXb48qvsbk7a wvR7GCrLSRZqT/NCbjajP2DbzyFxKp42omsECHCqlhmjjbCxZg+GEfa2TFyO07wiHVjz Xvu5/O/F4Qr3yM814Qp53jkTXfV9I2iKHVWf8okN+ro90ArGfoaauXEs3M+9p+K085qv rEJA== 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) From: Tom Tromey To: gdb-patches@sourceware.org Cc: =?UTF-8?q?Alexandra=20H=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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 List-Id: 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 --- 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) -- 2.40.1