From patchwork Fri Feb 23 21:11:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86308 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 93E953858298 for ; Fri, 23 Feb 2024 21:12:22 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id D681F385842A for ; Fri, 23 Feb 2024 21:11:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D681F385842A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D681F385842A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722702; cv=none; b=XLx3Dgw7UFy9MngGktEZYyr15EDHBoJ0Uqind84RGGY+F6BV+lzGEwtoum8rrdVZYPepMXVRKu7eYyDV7Y1NU+MORxcnNcivektuLQx/pfc0KzXwDDR9nmpUG7h1olD7F0kDE6X80elGhCA9180Sr6IB+DBfJ9p9JQRTrsTIi08= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722702; c=relaxed/simple; bh=mF5X3XpCX2bY6kKlrOzC5j9kugxSoujqlOeUd31iTjk=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=bnTTCWyh+zwoUNKN1e7lC7tZw4Cvb7T36usDK2drweg/fergrpIrFqNWPKHfDorPyc87Nj0Y2tgmrLIlF8lRHzyklnMWbXJOLbz5etKHc2twJr708HXF1Odf67fpFqinzr6L500tBM9xhh/uAA1axujDolRu/BuwkMM+tISfRH8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7c788332976so36669639f.3 for ; Fri, 23 Feb 2024 13:11:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1708722699; x=1709327499; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wUEGxzvKRX2NktB0NWTGXkOpxzpgzRsGgIK9PF+7JIk=; b=PBpc6c6o0LjNaLC8LjPjutJDMr/TRWpxys2vNKPJeCGG327s/UWNWSwy6D1U7Mndn9 ENTR2I7Ip5OyvvANrm0K/sY6eah3eejtJphL1bx7y3KlgOZKjhBNWqkybAn3zGoeflMK asiVx/0FjGZqaMLdhyALZDVe1uX6pI+mPSEI2znnNvXGxrswIn+ZD1sssnhIiardqyVG jBG2WkOQrogvNBpXHWy0bcCM/gthPJuOKTnOhM0720pPy/Vko/VdihGzH6Z1yLWaG9BZ mIb9Ef36zDZZhNlsU/Spyz5aSyEQMTkrZkqE3TBG2Vt6atDPcVNIWR4HYM2jYRjxcvGz EGXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722699; x=1709327499; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wUEGxzvKRX2NktB0NWTGXkOpxzpgzRsGgIK9PF+7JIk=; b=o+aPCZgkg8uDV10GoNQScToM7Lq7lLwwp2gN3x4dtSKsmO80ZWT5nr4ok4dZcKEVUF R9FtP4hACP0BAx6za/rH8K/luQDiLs20uAMYeLsPqpyDg13w6gneSIWt3uB5n9ETGy2E eViV0/NYGS4HYVHXmaNQfEbzpK72MFjHKz8w11iCYnTvqAEeYuPCumqedqYNPjAzYzlw LHLZPGwjt1rCoPKX81OORwDYiWTjdPUOaWu/4aBGSEx5ddk+oXb1h0EXzeKqGaWIWgJB SWMoiy1Uoh9sqFuBb9nCQo6DdnyTBM2XUI8wRMv+Xbzn9tD/xnC/9QZL4QA4z8DloL0h AwFA== X-Gm-Message-State: AOJu0YynzqhRpWi4Yo7tUqLRMrh8o1Vs0Pez3RLtakW+XZDaVYiejQBL 3bS81qPTyuCYIYrcHWwpkv/Wtd2kUS58Anh/+CwwMalw1uMyZ9B2AEZruOx0AT9aztImc9BjakU = X-Google-Smtp-Source: AGHT+IH3P4VeI9ehPbx14dprkd7rHcTwzAXJt/TtkY3DSPY8n9faXU9NNiUcAwCU4GcZZ54JSWVPoQ== X-Received: by 2002:a6b:7105:0:b0:7c7:9b0a:6dd1 with SMTP id q5-20020a6b7105000000b007c79b0a6dd1mr1272417iog.6.1708722698835; Fri, 23 Feb 2024 13:11:38 -0800 (PST) Received: from localhost.localdomain (71-211-170-195.hlrn.qwest.net. [71.211.170.195]) by smtp.gmail.com with ESMTPSA id y14-20020a02c00e000000b004741aec6cdasm3497851jai.25.2024.02.23.13.11.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:11:38 -0800 (PST) From: Tom Tromey Date: Fri, 23 Feb 2024 14:11:37 -0700 Subject: [PATCH 1/5] Rewrite final cleanups MIME-Version: 1.0 Message-Id: <20240223-final-cleanups-v1-1-84d5271e9979@adacore.com> References: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> In-Reply-To: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.5 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This patch rewrites final cleanups to use std::function and otherwise be more C++-ish. --- gdb/compile/compile.c | 30 +++++------- gdb/debuginfod-support.c | 14 ++---- gdb/python/python.c | 4 +- gdbsupport/cleanups.cc | 122 +++++------------------------------------------ gdbsupport/cleanups.h | 17 ++----- 5 files changed, 33 insertions(+), 154 deletions(-) diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 8cb2e8ac7f1..27cff2553ee 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -427,23 +427,6 @@ compile_print_command (const char *arg, int from_tty) } } -/* A cleanup function to remove a directory and all its contents. */ - -static void -do_rmdir (void *arg) -{ - const char *dir = (const char *) arg; - char *zap; - int wstat; - - gdb_assert (startswith (dir, TMP_PREFIX)); - zap = concat ("rm -rf ", dir, (char *) NULL); - wstat = system (zap); - if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0) - warning (_("Could not remove temporary directory %s"), dir); - XDELETEVEC (zap); -} - /* Return the name of the temporary directory to use for .o files, and arrange for the directory to be removed at shutdown. */ @@ -465,7 +448,18 @@ get_compile_file_tempdir (void) perror_with_name (_("Could not make temporary directory")); tempdir_name = xstrdup (tempdir_name); - make_final_cleanup (do_rmdir, tempdir_name); + add_final_cleanup ([] () + { + char *zap; + int wstat; + + gdb_assert (startswith (tempdir_name, TMP_PREFIX)); + zap = concat ("rm -rf ", tempdir_name, (char *) NULL); + wstat = system (zap); + if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0) + warning (_("Could not remove temporary directory %s"), tempdir_name); + XDELETEVEC (zap); + }); return tempdir_name; } diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index 7d8ada39e96..9bb3748c8c3 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -188,15 +188,6 @@ progressfn (debuginfod_client *c, long cur, long total) return 0; } -/* Cleanup ARG, which is a debuginfod_client pointer. */ - -static void -cleanup_debuginfod_client (void *arg) -{ - debuginfod_client *client = static_cast (arg); - debuginfod_end (client); -} - /* Return a pointer to the single global debuginfod_client, initialising it first if needed. */ @@ -221,7 +212,10 @@ get_debuginfod_client () handlers, which is too late. So instead, we make use of GDB's final cleanup mechanism. */ - make_final_cleanup (cleanup_debuginfod_client, global_client); + add_final_cleanup ([] () + { + debuginfod_end (global_client); + }); debuginfod_set_progressfn (global_client, progressfn); } } diff --git a/gdb/python/python.c b/gdb/python/python.c index 7b0997c8d52..971fc850dbb 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -2070,7 +2070,7 @@ static struct cmd_list_element *user_show_python_list; interpreter. This lets Python's 'atexit' work. */ static void -finalize_python (void *ignore) +finalize_python () { struct active_ext_lang_state *previous_active; @@ -2310,7 +2310,7 @@ do_start_initialization () /* Release the GIL while gdb runs. */ PyEval_SaveThread (); - make_final_cleanup (finalize_python, NULL); + add_final_cleanup (finalize_python); /* Only set this when initialization has succeeded. */ gdb_python_initialized = 1; diff --git a/gdbsupport/cleanups.cc b/gdbsupport/cleanups.cc index 619db023063..cc14523b2d1 100644 --- a/gdbsupport/cleanups.cc +++ b/gdbsupport/cleanups.cc @@ -19,126 +19,26 @@ #include "common-defs.h" #include "cleanups.h" +#include -/* The cleanup list records things that have to be undone - if an error happens (descriptors to be closed, memory to be freed, etc.) - Each link in the chain records a function to call and an - argument to give it. +/* All the cleanup functions. */ - Use make_cleanup to add an element to the cleanup chain. - Use do_cleanups to do all cleanup actions back to a given - point in the chain. Use discard_cleanups to remove cleanups - from the chain back to a given point, not doing them. +static std::vector> all_cleanups; - If the argument is pointer to allocated memory, then you need - to additionally set the 'free_arg' member to a function that will - free that memory. This function will be called both when the cleanup - is executed and when it's discarded. */ +/* See cleanups.h. */ -struct cleanup -{ - struct cleanup *next; - void (*function) (void *); - void (*free_arg) (void *); - void *arg; -}; - -/* Used to mark the end of a cleanup chain. - The value is chosen so that it: - - is non-NULL so that make_cleanup never returns NULL, - - causes a segv if dereferenced - [though this won't catch errors that a value of, say, - ((struct cleanup *) -1) will] - - displays as something useful when printed in gdb. - This is const for a bit of extra robustness. - It is initialized to coax gcc into putting it into .rodata. - All fields are initialized to survive -Wextra. */ -static const struct cleanup sentinel_cleanup = { 0, 0, 0, 0 }; - -/* Handy macro to use when referring to sentinel_cleanup. */ -#define SENTINEL_CLEANUP ((struct cleanup *) &sentinel_cleanup) - -/* Chain of cleanup actions established with make_final_cleanup, - to be executed when gdb exits. */ -static struct cleanup *final_cleanup_chain = SENTINEL_CLEANUP; - -/* Main worker routine to create a cleanup. - PMY_CHAIN is a pointer to either cleanup_chain or final_cleanup_chain. - FUNCTION is the function to call to perform the cleanup. - ARG is passed to FUNCTION when called. - FREE_ARG, if non-NULL, is called after the cleanup is performed. - - The result is a pointer to the previous chain pointer - to be passed later to do_cleanups or discard_cleanups. */ - -static struct cleanup * -make_my_cleanup2 (struct cleanup **pmy_chain, make_cleanup_ftype *function, - void *arg, void (*free_arg) (void *)) -{ - struct cleanup *newobj = XNEW (struct cleanup); - struct cleanup *old_chain = *pmy_chain; - - newobj->next = *pmy_chain; - newobj->function = function; - newobj->free_arg = free_arg; - newobj->arg = arg; - *pmy_chain = newobj; - - gdb_assert (old_chain != NULL); - return old_chain; -} - -/* Worker routine to create a cleanup without a destructor. - PMY_CHAIN is a pointer to either cleanup_chain or final_cleanup_chain. - FUNCTION is the function to call to perform the cleanup. - ARG is passed to FUNCTION when called. - - The result is a pointer to the previous chain pointer - to be passed later to do_cleanups or discard_cleanups. */ - -static struct cleanup * -make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function, - void *arg) -{ - return make_my_cleanup2 (pmy_chain, function, arg, NULL); -} - -/* Add a new cleanup to the final cleanup_chain, - and return the previous chain pointer - to be passed later to do_cleanups or discard_cleanups. - Args are FUNCTION to clean up with, and ARG to pass to it. */ - -struct cleanup * -make_final_cleanup (make_cleanup_ftype *function, void *arg) -{ - return make_my_cleanup (&final_cleanup_chain, function, arg); -} - -/* Worker routine to perform cleanups. - PMY_CHAIN is a pointer to either cleanup_chain or final_cleanup_chain. - OLD_CHAIN is the result of a "make" cleanup routine. - Cleanups are performed until we get back to the old end of the chain. */ - -static void -do_my_cleanups (struct cleanup **pmy_chain, - struct cleanup *old_chain) +void +add_final_cleanup (std::function &&func) { - struct cleanup *ptr; - - while ((ptr = *pmy_chain) != old_chain) - { - *pmy_chain = ptr->next; /* Do this first in case of recursion. */ - (*ptr->function) (ptr->arg); - if (ptr->free_arg) - (*ptr->free_arg) (ptr->arg); - xfree (ptr); - } + all_cleanups.emplace_back (std::move (func)); } -/* Discard final cleanups and do the actions they describe. */ +/* See cleanups.h. */ void do_final_cleanups () { - do_my_cleanups (&final_cleanup_chain, SENTINEL_CLEANUP); + for (auto &func : all_cleanups) + func (); + all_cleanups.clear (); } diff --git a/gdbsupport/cleanups.h b/gdbsupport/cleanups.h index 3e64f7d1684..985cf81ff7d 100644 --- a/gdbsupport/cleanups.h +++ b/gdbsupport/cleanups.h @@ -19,21 +19,12 @@ #ifndef COMMON_CLEANUPS_H #define COMMON_CLEANUPS_H -/* Outside of cleanups.c, this is an opaque type. */ -struct cleanup; +#include -/* NOTE: cagney/2000-03-04: This typedef is strictly for the - make_cleanup function declarations below. Do not use this typedef - as a cast when passing functions into the make_cleanup() code. - Instead either use a bounce function or add a wrapper function. - Calling a f(char*) function with f(void*) is non-portable. */ -typedef void (make_cleanup_ftype) (void *); - -/* Function type for the dtor in make_cleanup_dtor. */ -typedef void (make_cleanup_dtor_ftype) (void *); - -extern struct cleanup *make_final_cleanup (make_cleanup_ftype *, void *); +/* Register a function that will be called on exit. */ +extern void add_final_cleanup (std::function &&func); +/* Run all the registered functions. */ extern void do_final_cleanups (); #endif /* COMMON_CLEANUPS_H */ From patchwork Fri Feb 23 21:11:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86311 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 9ECFD3858287 for ; Fri, 23 Feb 2024 21:13:07 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id 492DC3858407 for ; Fri, 23 Feb 2024 21:11:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 492DC3858407 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 492DC3858407 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722704; cv=none; b=utDdWskCd+40bpDp8hxqfpf8o+ZGS9LPzUpG9G9OQJj8y9F+5BcS8cu1sq6BLK8vzStf5W3uGDigoUIwO6HWGmM5+CSW+rCGD7yEHJQ3uifmIJeKahey+iFGUJTR5DMOAfUbidQFx2dGVF6GmgcKuUMkf9CYOlVHTctXHvjov3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722704; c=relaxed/simple; bh=arWxRr0MVpxjQxpR7X381xUYNpw6uFdHG8ytU2ZvaTY=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=rHclSPho0fyx800tZffTv2Q2vKec+DJ/d39q6joxNF1APHmVhj8Jgwexaz9KVmlEKQC4KFdxfLpOrrT9cuqYsp9lPYzGmj14othFhsroSl7kqutUwG0ohWmfZKw5pJkmXkMf7aFbA4VXz7Gs3EYgS5iGPuT7kHGILpMmD7Z6D6U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-7c7894b39edso31955739f.3 for ; Fri, 23 Feb 2024 13:11:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1708722699; x=1709327499; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=U7VScV6pmXTXygJqEHpgN+ls9E6KiA7Xx2zo6LpPWIg=; b=CUpjZlVBZaPGtwsRICKh6Hycqc/DwHF3HYoRBVC7wTy409xJmxrDcyBs57vWcgAR7g ndUGkvZj7l0i36FSz6sJNbSQD5hK1NuppTsm6bm0jl1lW198epQaisYaz3EVbAvtKEd9 nBU4x3wuP7ss3wTCBLaZfnNGF4oVbPwQI24ZPMB4uryV97uEQMTQ+DadKXzm4bss55Vc Ph0EKJAmB/tjYYR6w1YXAVkhi9CFPHtf3Ddog5y1g7MEYxDjdZgZt5nzxKrgG2FfXeb0 ykhy1MbErEKgic/4KMI9RWX5n+x/WG7kfkuTe+D1AFkKKWXQX0258d2Yd/ik8qKiXfId rrxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722699; x=1709327499; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U7VScV6pmXTXygJqEHpgN+ls9E6KiA7Xx2zo6LpPWIg=; b=vwyzoQNmx14gsazSWgDLTVtQs0us07WMMDk3yc7lAHzkHoXjQsufiLxBQcxeeuGe5u F4mK91q9mnj9VoSJNs+j6IPtzkql7uZqpD9AXBd/ehEWiMO5iHoIyz7fNkCCP+SlNHbX YU2OuLj/d/m3wc6LzDnB+tWLfBzRTg8zwGbjToGZMJXZNrZwbatMN+6ArA2MCVXGi7If OqxKbdWQLaoqcu+/75ofofTPRtoX30PgjXWd8jxOgf2q3Jn3lJ5VRNfweSoHop/hsR5y nCKA1c3yfyJswfm+/Ycb7bOp+hzFdtY+c1ABZcfu2w8lcJiGOfukP/8VGy2BTHGP+UdP JMVw== X-Gm-Message-State: AOJu0YxRP7WJ5IzLSBhNLh5gZQ+xI7+H682C1axAabubywNVW5886z1c F7R2hUPYhCUCXsWcnFe72YcVUx+K2nVjKJzmPvF3T3xY7bMFTn/vpnFuMevfkgdXa+tuYf2UBXg = X-Google-Smtp-Source: AGHT+IGoVoUvdf0x79oZPrXM+/YZT75nVE4DVTfj7qOQYexbtDruIa7stys9D1Mba0FR2IFbJhAFVQ== X-Received: by 2002:a6b:f014:0:b0:7c7:97ad:91fc with SMTP id w20-20020a6bf014000000b007c797ad91fcmr1271916ioc.1.1708722699431; Fri, 23 Feb 2024 13:11:39 -0800 (PST) Received: from localhost.localdomain (71-211-170-195.hlrn.qwest.net. [71.211.170.195]) by smtp.gmail.com with ESMTPSA id y14-20020a02c00e000000b004741aec6cdasm3497851jai.25.2024.02.23.13.11.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:11:39 -0800 (PST) From: Tom Tromey Date: Fri, 23 Feb 2024 14:11:38 -0700 Subject: [PATCH 2/5] Add extension_language_ops::shutdown MIME-Version: 1.0 Message-Id: <20240223-final-cleanups-v1-2-84d5271e9979@adacore.com> References: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> In-Reply-To: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.5 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Right now, Python is shut down via a final cleanup. However, it seems to me that it is better for extension languages to be shut down explicitly, after all the ordinary final cleanups are run. The main reason for this is that a subsequent patch adds another case like finalize_values; and rather than add a series of workarounds for Python shutdown, it seemed better to let these be done via final cleanups, and then have Python shutdown itself be the special case. --- gdb/extension-priv.h | 4 ++++ gdb/extension.c | 12 ++++++++++++ gdb/extension.h | 3 +++ gdb/guile/guile.c | 1 + gdb/python/python.c | 6 +++--- gdb/top.c | 2 ++ 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gdb/extension-priv.h b/gdb/extension-priv.h index b709494927d..cb00cb6ff7b 100644 --- a/gdb/extension-priv.h +++ b/gdb/extension-priv.h @@ -119,6 +119,10 @@ struct extension_language_ops This method is required. */ int (*initialized) (const struct extension_language_defn *); + /* Called just before GDB exits. This shuts down the extension + language. This can be NULL. */ + void (*shutdown) (const struct extension_language_defn *); + /* Process a sequence of commands embedded in GDB's own scripting language. E.g., python diff --git a/gdb/extension.c b/gdb/extension.c index 42e05199d2c..9f403500497 100644 --- a/gdb/extension.c +++ b/gdb/extension.c @@ -341,6 +341,18 @@ ext_lang_initialization (void) } } +/* See extension.h. */ + +void +ext_lang_shutdown () +{ + for (const struct extension_language_defn *extlang : extension_languages) + { + if (extlang->ops != nullptr && extlang->ops->shutdown != nullptr) + extlang->ops->shutdown (extlang); + } +} + /* Invoke the appropriate extension_language_ops.eval_from_control_command method to perform CMD, which is a list of commands in an extension language. diff --git a/gdb/extension.h b/gdb/extension.h index 0514d7930a2..5260bcbde00 100644 --- a/gdb/extension.h +++ b/gdb/extension.h @@ -282,6 +282,9 @@ extern bool ext_lang_auto_load_enabled (const struct extension_language_defn *); extern void ext_lang_initialization (void); +/* Shut down all extension languages. */ +extern void ext_lang_shutdown (); + extern void eval_ext_lang_from_control_command (struct command_line *cmd); extern void auto_load_ext_lang_scripts_for_objfile (struct objfile *); diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c index 30d1c72fceb..f0db709e4fe 100644 --- a/gdb/guile/guile.c +++ b/gdb/guile/guile.c @@ -115,6 +115,7 @@ static const struct extension_language_ops guile_extension_ops = { gdbscm_initialize, gdbscm_initialized, + nullptr, gdbscm_eval_from_control_command, diff --git a/gdb/python/python.c b/gdb/python/python.c index 971fc850dbb..dde8afc3c65 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -110,6 +110,7 @@ static objfile_script_sourcer_func gdbpy_source_objfile_script; static objfile_script_executor_func gdbpy_execute_objfile_script; static void gdbpy_initialize (const struct extension_language_defn *); static int gdbpy_initialized (const struct extension_language_defn *); +static void finalize_python (const struct extension_language_defn *); static void gdbpy_eval_from_control_command (const struct extension_language_defn *, struct command_line *cmd); static void gdbpy_start_type_printers (const struct extension_language_defn *, @@ -147,6 +148,7 @@ static const struct extension_language_ops python_extension_ops = { gdbpy_initialize, gdbpy_initialized, + finalize_python, gdbpy_eval_from_control_command, @@ -2070,7 +2072,7 @@ static struct cmd_list_element *user_show_python_list; interpreter. This lets Python's 'atexit' work. */ static void -finalize_python () +finalize_python (const struct extension_language_defn *ignore) { struct active_ext_lang_state *previous_active; @@ -2310,8 +2312,6 @@ do_start_initialization () /* Release the GIL while gdb runs. */ PyEval_SaveThread (); - add_final_cleanup (finalize_python); - /* Only set this when initialization has succeeded. */ gdb_python_initialized = 1; return true; diff --git a/gdb/top.c b/gdb/top.c index 5114713baa4..67d6670cd9c 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1819,6 +1819,8 @@ quit_force (int *exit_arg, int from_tty) exception_print (gdb_stderr, ex); } + ext_lang_shutdown (); + exit (exit_code); } From patchwork Fri Feb 23 21:11:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86309 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 0D6E338582B1 for ; Fri, 23 Feb 2024 21:12:26 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id 14F883858413 for ; Fri, 23 Feb 2024 21:11:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14F883858413 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14F883858413 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722703; cv=none; b=YGH9WlKVwkGewoXg6ztLrIstNgeSuyFRTzqrXWUvOzxPaM3yMIZDnkZdoP1HvkhJS9StydIkOFZ4OeEGgLNGhhT2EE2kZD9sWb7md3nJDDTeHT9UykXBsSDp4pI913hkPLl1Iik7I/QOvip5HdHD20sLaU9oy5XCAy1CoagOHzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722703; c=relaxed/simple; bh=x4UKdiOJ4+WmLppHxHBcTLjYqRjV/3VSfIuu8m8NJ7g=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=YDDdoyFOIFKaZJinpR75Qz4yncPKBlpWBZGWIM8s1/lxKAljq9N3X3jmpwP9ImDsQyvlS4H+Zz22SjiDCtdNBl5Ca/vUIncILzHAB3n8nyTuD0zeSttw9qV/pBzCAeawsxrRANilO7UKLe2Rwf9pQGnAjnI6aaMGIri9PDXkW5Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-7bb5fda069bso45148339f.0 for ; Fri, 23 Feb 2024 13:11:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1708722700; x=1709327500; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=GKZH9sGXVUTVf3TxFxShpP1P+jJlwXpDw/pOwY/Hd5M=; b=eejqpJBVm06s++Nmt+kLORWZTzIvlKo5cg+fPau7ax3EWfL42G6ploD48Y6/wibDrJ bdBhyDGBw1pY86Vxdz2+YRw6nRZkRirrEmve6aogg7Fjcve9kJTyzZfVl9MKdp4S0Uix 0agZ4fWyMQHpbo6SR6gR9/HCUb+czvd2ef7BFLbB0teerfcemf8kGWjCyaOwxvRxJtcF 3Q1xvcYeVuuHiN5NYtNI6KK9YUbgMGOkfV6Yn2XNK5XA95e/MUagy0+XBfmgQfG6m6fW VhZ0uUT6Ucs24XerLJdvjaqQt25JArz/HAlJDGlCtG46N30uCIc2YT8jYsbIbuw8HqLY kGsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722700; x=1709327500; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GKZH9sGXVUTVf3TxFxShpP1P+jJlwXpDw/pOwY/Hd5M=; b=KCsPDqnlZlus003N5BWkKvpIbyNHgKLSpH1swxadIr1Ley59ykBvzi8Fk3jtSYHnBa YnbDncowQHOfoQzXIEOo1hrq/aZyYkv4XTlnUtsfsea8RTjLfYLVZpd/x82HZF42HFde 10buvKS2aINv/4hd8ePyp9hFiOVs1ifZotXkclRV/7OcnDInE7E0zhiBecAyanLO+v45 I0ZcBEHoa+GV86iYQh2HoZTj4R0cUjAE5wTxoJp6Ya1T8I1VfyFsKa3LkhTJWAvfSg7D 8wM0JgbvXZjIBrsNgkZz1EtXB8eYp71McQ6lTT6Mgfz8x3UscYTBX96DcKyypmHwVz83 OPpw== X-Gm-Message-State: AOJu0YygkV1psRS7CKeRQuKlx207yShXP55JIA2+/At6VEZe4DwastUh WrKiM2OPFOqkcMRPSZTonLhGNUA6kd2VfRc5IhUeXJKDSl01sI7ZAi4ogeQJnEX2QopGgrdEsOY = X-Google-Smtp-Source: AGHT+IEkg2YZuie7eXHwlX/d5Ojl2Te9J0uwbW0idxMHF8yfy5c2cRLnAZFe8AmT+1wS2oGqUQ9c3A== X-Received: by 2002:a5e:8e09:0:b0:7c4:58cb:38ae with SMTP id a9-20020a5e8e09000000b007c458cb38aemr1221730ion.6.1708722700015; Fri, 23 Feb 2024 13:11:40 -0800 (PST) Received: from localhost.localdomain (71-211-170-195.hlrn.qwest.net. [71.211.170.195]) by smtp.gmail.com with ESMTPSA id y14-20020a02c00e000000b004741aec6cdasm3497851jai.25.2024.02.23.13.11.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:11:39 -0800 (PST) From: Tom Tromey Date: Fri, 23 Feb 2024 14:11:39 -0700 Subject: [PATCH 3/5] Change finalize_values into a final cleanup MIME-Version: 1.0 Message-Id: <20240223-final-cleanups-v1-3-84d5271e9979@adacore.com> References: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> In-Reply-To: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.5 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This removes finalize_values in favor of adding a new final cleanup. This is safe now that extension languages are explicitly shut down. --- gdb/top.c | 6 ------ gdb/value.c | 15 ++++++++------- gdb/value.h | 4 ---- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/gdb/top.c b/gdb/top.c index 67d6670cd9c..cf7d3a913ba 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1803,12 +1803,6 @@ quit_force (int *exit_arg, int from_tty) exception_print (gdb_stderr, ex); } - /* Destroy any values currently allocated now instead of leaving it - to global destructors, because that may be too late. For - example, the destructors of xmethod values call into the Python - runtime, which is finalized via a final cleanup. */ - finalize_values (); - /* Do any final cleanups before exiting. */ try { diff --git a/gdb/value.c b/gdb/value.c index c7e940badb9..a2b2721d183 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -4499,12 +4499,13 @@ and exceeds this limit will cause an error."), selftests::test_insert_into_bit_range_vector); selftests::register_test ("value_copy", selftests::test_value_copy); #endif -} - -/* See value.h. */ -void -finalize_values () -{ - all_values.clear (); + /* Destroy any values currently allocated in a final cleanup instead + of leaving it to global destructors, because that may be too + late. For example, the destructors of xmethod values call into + the Python runtime. */ + add_final_cleanup ([] () + { + all_values.clear (); + }); } diff --git a/gdb/value.h b/gdb/value.h index e8d3c9fd907..9d7e88d9433 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1630,10 +1630,6 @@ struct value *call_internal_function (struct gdbarch *gdbarch, const char *value_internal_function_name (struct value *); -/* Destroy the values currently allocated. This is called when GDB is - exiting (e.g., on quit_force). */ -extern void finalize_values (); - /* Convert VALUE to a gdb_mpq. The caller must ensure that VALUE is of floating-point, fixed-point, or integer type. */ extern gdb_mpq value_to_gdb_mpq (struct value *value); From patchwork Fri Feb 23 21:11:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86310 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 AC1AF385842D for ; Fri, 23 Feb 2024 21:12:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 6C20D385842D for ; Fri, 23 Feb 2024 21:11:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C20D385842D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6C20D385842D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722704; cv=none; b=Jo0D+Ux+XzwGWLyXkdunOYjesBmKmlmHPlE79Ni/FhKa++FLI4Ps2RxCSbjMbsnrZvI/gvGczG22jrYmLaH3V9Wzpkb1HScV/+BWxlJqQUGTxNCP4qIAKi6Hd6vWbLQtCz3OktvvkbVNdOwlpSAeCGkSVx+Lg9uuB7j/f0mzPas= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722704; c=relaxed/simple; bh=WFgmQwlbmmf4r2VGs9+Kj+Ev4J46fn2jQ4EPTaoVN80=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=DuMQEcXyKtRXENdQzaRHjidUpfZe1DeKlVO9lmlBHtsbLe7xF7MB9i8H0DTqjxboVXeNU7Srpx4OzE/kCHJ9nXX3OG2EVBr5I8/f5jBmFQLI+7cFrDF+LSxrHeS2GOH4eabcg9/NtndHOIovwT/W02HkYi7mBd3FYrqPX6k7xwM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-3657dbe2008so2896945ab.1 for ; Fri, 23 Feb 2024 13:11:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1708722700; x=1709327500; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CRA3MOYXAU8Mk1HXzm1RtWRHUUNG5Ty6EpLN/H3k+s0=; b=aPATYK3ICpK0/8B6E/ECi7oXbe5ld7+LCVjjUJ6LUwNf+XFhjilPzvR8ZqFgVza8uM KmzOd+l6aWfx6nyF1/hKutA/37IdBaWQ7LO8k3Twt4sDIy9MtVm+zYshXhkRKKyuOwwQ tzL/K/iX9TeovTyr8UYpxsiXPc5LNeeIFebTKRgNhJqey97O9BDeCLv/xzDOIt6pit/n WPudhxpuM8q8WytAORKv4ENOCI+5ighSAkQ1DIpKfd8P/igNkohmJIU1r01D5guVI4/2 cY4Fuf/iYrl+EDwwoS0MlPnukN/QS4ZNOJae4WS6HvdK90HS2xs1VtE3/uzkiE/GYrHC YG1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722700; x=1709327500; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CRA3MOYXAU8Mk1HXzm1RtWRHUUNG5Ty6EpLN/H3k+s0=; b=VzlAUQnnBwSydX188uYJjHFsNeuKhNjbn0Iq+x3CGpxEqimEYlqUzKSpM/CR42bLvX ZB2osI3SwBJlIN8lTQXR1KFD5YI1jSJNTCMofkPElYzJjBbwiMCvJdk9bnQ+X13mBAO8 k+QuzSa3eu8xomMruV1cgELlGse9wLXkfuTB/L5c7Gh+/+eTUDtL2LbmvOJtZQOKWlqo 78MpXdfjMsgTAhnjDoWDCzLXvi7Ed8HYzhw8XOU683SPb94tireWNP9UGJapGWPRhlmd 1/Ru3ZRA+//1AHvS/iB8dzurpak2uUIMK8gRWk7N7adpczeXi1x6zihf9ziaz02HxChx qZYA== X-Gm-Message-State: AOJu0Yy+Nk7nDRkPqR4KYDGZU5LigVYhyYhJwU61HDLQJ9t7wvQhrtdj JOPVSb2OyX83+7wdzQ/Z2nnDE/MeKorctq9Hrs96qiqijL0sL1HbjTBS/Tlq4Fk/f4daJf/Hy2Q = X-Google-Smtp-Source: AGHT+IHfwTk+zOsdcH+NOFCCCn7fAS0fcvIbWj4JY5OOl5ipd+3UGecmR3BBy2bvVsoz17CJxl3JQg== X-Received: by 2002:a92:cd0d:0:b0:365:1749:cae0 with SMTP id z13-20020a92cd0d000000b003651749cae0mr1306017iln.7.1708722700576; Fri, 23 Feb 2024 13:11:40 -0800 (PST) Received: from localhost.localdomain (71-211-170-195.hlrn.qwest.net. [71.211.170.195]) by smtp.gmail.com with ESMTPSA id y14-20020a02c00e000000b004741aec6cdasm3497851jai.25.2024.02.23.13.11.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:11:40 -0800 (PST) From: Tom Tromey Date: Fri, 23 Feb 2024 14:11:40 -0700 Subject: [PATCH 4/5] Add final cleanup for runnables MIME-Version: 1.0 Message-Id: <20240223-final-cleanups-v1-4-84d5271e9979@adacore.com> References: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> In-Reply-To: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.5 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This changes run-on-main-thread.c to clear 'runnables' in a final cleanup. This avoids an issue where a pending runnable could require Python, but be run after the Python interpreter was finalized. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31172 --- gdb/run-on-main-thread.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c index 2d40048de56..7b9807e0eaf 100644 --- a/gdb/run-on-main-thread.c +++ b/gdb/run-on-main-thread.c @@ -133,4 +133,15 @@ _initialize_run_on_main_thread () runnable_event = make_serial_event (); add_file_handler (serial_event_fd (runnable_event), run_events, nullptr, "run-on-main-thread"); + + /* A runnable may refer to an extension language. So, we want to + make sure any pending ones have been deleted before the extension + languages are shut down. */ + add_final_cleanup ([] () + { +#if CXX_STD_THREAD + std::lock_guard lock (runnable_mutex); +#endif + runnables.clear (); + }); } From patchwork Fri Feb 23 21:11:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86312 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 3E4CD3858437 for ; Fri, 23 Feb 2024 21:13:36 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id 0530D385841B for ; Fri, 23 Feb 2024 21:11:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0530D385841B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0530D385841B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722704; cv=none; b=ny86vGQ9pekUtmnuH01q7dzYgjhk0eYejXJNJkika2b/UOFCc0bbSRL7Ti+s8POWO+0hfG9Mfmbi+hdsQ0xbGKjxy/PfH/AKEfo+Gz9HeeQpMMrdbz8aTpIlOnqEdT8kqrc0xPZrqWg9CVMCyCxXbtliWKaA7CNiYoYe1z/5WOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708722704; c=relaxed/simple; bh=3pXo7a3s3t1F3e8PTJNam5gZTEX+3h2XAq97ZPAgLLc=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=csyPWAdONfSIOunBKo6h747uAM0T5yyJBAULvF1GxhbxN4nzgrdsOB1PBRZHQILI6rgN2xpP/4S4uNLLesw71T9EP3Tk66ZWe0qfHLcLnyNWi7O7hw3nVu9ptauYj8aCDkN52K2eWcCMyiGFxK33WuAh0QM7mOUFdTyOlBhroPI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7c48fc56752so23583039f.3 for ; Fri, 23 Feb 2024 13:11:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1708722701; x=1709327501; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1W4G2MWgiXRoq5RPOdC2TQ38QHHTV38qoUvCpH8Nj/k=; b=aik2FlxAxC9cWygTiHCgnkNqeTEsXizU5j3rxxFKn+Z/RLuJ7kvyQGxyNQJoIuF10c fwLpkKRT88FNbiH7oIE5jbaAEN0pidrtfPZuPcPunL9KADc7qh/7xgcvdBLcHCOAA1LZ IezQd6O/hk98gJSyAoQ6G6fxEduZZ5DE2xi19urDV8hMKVbc5OI67CtaVqmUanKm8DnL JBGC+kHsqpiSvnO86i3VFtOPYvI5fCb6kYQQ5HcDEyxwcy7v2qcbIUeavlZjqTM/ZKVx zicElj4jPlsWdX9GI71xPU5ISUzoWH6hW/0vBQ1UTmICjV9Cf8R3lgBB2FTzsvdcyIlV HtPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708722701; x=1709327501; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1W4G2MWgiXRoq5RPOdC2TQ38QHHTV38qoUvCpH8Nj/k=; b=R9iJxgxKtHePSRNERxdTg9CGZBXg/eXsffLAP5WjYz95uyynTsiAYEX7y/8AmwwxdT Z3kEkFgcJ3+kb4PDdUSt/jKbkRxlFxxRjZym0d7jySwP62vOeOGSN7oC57sqTGU4zJbj E9jnsJbsL6UkSGvw8Tq9gGDvLScY3YBWxnR1ZCV62qkfi6d+f0SIXYrKshisi/UovfMA 9pJ7zvgnc4IIW6Sx5xDr3WSdO6Ae6TdpIHOTSetPdj4OOVcal1AdSmpz+/bvLVThkxP1 kv9nhhpT6U5YJOQiwguMldQI38JshBRRWEjo0rmIt1C8h+mYYUXk7Hj7W2UevKcw+T01 8nfA== X-Gm-Message-State: AOJu0YxQh42eehg8TjnrARoPVLlU5x1LIJQ+3Z+VeTI5t4oZ7jCy4i18 pZ0CU78cXzpbJIsIetrROxWIXw9lYXrLA5WnHbbExMVLcOJlhlj/lNocmmDzBAvuqRnNPN87PPI = X-Google-Smtp-Source: AGHT+IFMlvCP2x5ZKw5bTc/aO77ARNC2SS7zPAX70qgop5tKQqlyGGFdYZULCpqN00mw0pdE0whA0A== X-Received: by 2002:a92:d8ca:0:b0:365:2f3f:846 with SMTP id l10-20020a92d8ca000000b003652f3f0846mr1108814ilo.23.1708722701189; Fri, 23 Feb 2024 13:11:41 -0800 (PST) Received: from localhost.localdomain (71-211-170-195.hlrn.qwest.net. [71.211.170.195]) by smtp.gmail.com with ESMTPSA id y14-20020a02c00e000000b004741aec6cdasm3497851jai.25.2024.02.23.13.11.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 13:11:40 -0800 (PST) From: Tom Tromey Date: Fri, 23 Feb 2024 14:11:41 -0700 Subject: [PATCH 5/5] Explicitly quit gdb from DAP server thread MIME-Version: 1.0 Message-Id: <20240223-final-cleanups-v1-5-84d5271e9979@adacore.com> References: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> In-Reply-To: <20240223-final-cleanups-v1-0-84d5271e9979@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.5 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This changes the DAP code to explicitly request that gdb exit. Previously this could cause crashes, but with the previous cleanups, this should no longer happen. This also adds a tests that ensures that gdb exits with status 0. --- gdb/python/lib/gdb/dap/server.py | 1 + gdb/testsuite/lib/dap-support.exp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 6757f2921bf..19840f4028d 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -230,6 +230,7 @@ class Server: # responses are flushed to the client before exiting. self.write_queue.put(None) json_writer.join() + send_gdb("quit") @in_dap_thread def send_event_later(self, event, body=None): diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index 72c22d00711..54795a34e39 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -400,6 +400,15 @@ proc dap_check_log_file_re { re } { proc dap_shutdown {{terminate false}} { dap_check_request_and_response "shutdown" disconnect \ [format {o terminateDebuggee [l %s]} $terminate] + + # Check gdb's exit status. + global gdb_spawn_id + set result [wait -i $gdb_spawn_id] + gdb_assert {[lindex $result 2] == 0} + gdb_assert {[lindex $result 3] == 0} + + clear_gdb_spawn_id + dap_check_log_file }