From patchwork Fri Mar 29 21:43:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 32091 Received: (qmail 92061 invoked by alias); 29 Mar 2019 21:44:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 92039 invoked by uid 89); 29 Mar 2019 21:44:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-13.0 required=5.0 tests=AWL, BAYES_50, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=xmethod, collective, quit_force, 1690120 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 29 Mar 2019 21:43:52 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CD72308339F; Fri, 29 Mar 2019 21:43:51 +0000 (UTC) Received: from localhost (unused-10-15-17-196.yyz.redhat.com [10.15.17.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1347C1001E7C; Fri, 29 Mar 2019 21:43:51 +0000 (UTC) From: Sergio Durigan Junior To: Pedro Alves Cc: Tom Tromey , Tom Tromey , gdb-patches@sourceware.org Subject: [PATCH] Destroy allocated values when exiting GDB (was: Re: [PATCH] Merge handle_inferior_event and handle_inferior_event_1) References: <20190320140846.13031-1-tromey@adacore.com> <87r2azkhmq.fsf@redhat.com> <87mulnkcab.fsf@redhat.com> <87a7hjj7aw.fsf@tromey.com> <87ef6uj408.fsf@tromey.com> <87mulia94w.fsf@redhat.com> <87sgv9bwyg.fsf@tromey.com> <87tvfpr55a.fsf@redhat.com> <87y351mhki.fsf@redhat.com> <87sgv81nld.fsf@tromey.com> <5a2d4016-9e4d-dc18-8c3a-2c9ecf214c94@redhat.com> Date: Fri, 29 Mar 2019 17:43:50 -0400 In-Reply-To: <5a2d4016-9e4d-dc18-8c3a-2c9ecf214c94@redhat.com> (Pedro Alves's message of "Thu, 28 Mar 2019 14:12:42 +0000") Message-ID: <87lg0xwe3t.fsf_-_@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes On Thursday, March 28 2019, Pedro Alves wrote: > On 03/27/2019 12:57 PM, Tom Tromey wrote: >> Sergio> I did that, and we (Pedro, Mark, Frank and I) did a session of >> Sergio> collective investigation. I summarized what we found here: >> Sergio> https://bugzilla.redhat.com/show_bug.cgi?id=1690120#c25 >> >> Thanks, that's very interesting. >> I suppose either better control over the order of destruction is needed, >> or maybe finalize_python should clear gdb_python_initialized and then >> this should be checked in xmethod destructor. > I think the former is better. I think we should put an > all_values.clear (); > call in quit_force, before the do_final_cleanups call. Even > better, add a new finalize_values function next to > _initialize_values, and call that. How does this look? From b88067edfb2289cd5af3c9b8984b0b0354c965db Mon Sep 17 00:00:00 2001 From: Sergio Durigan Junior Date: Fri, 29 Mar 2019 17:34:54 -0400 Subject: [PATCH] Destroy allocated values when exiting GDB When the user exits GDB, we might still have some allocated values in the chain, which, in specific scenarios, can cause problems when GDB attempts to destroy them in "quit_force". For example, see the bug reported at: https://bugzilla.redhat.com/show_bug.cgi?id=1690120 And the thread starting at: https://sourceware.org/ml/gdb-patches/2019-03/msg00475.html Message-ID: <87r2azkhmq.fsf@redhat.com> In order to avoid that, and to be more aware of our allocated resources, this commit implements a new function "finalize_values" and calls it from inside "quit_force". Tested by the BuildBot. 2019-03-29 Sergio Durigan Junior Pedro Alves * top.c (quit_force): Call 'finalize_values'. * value.c (finalize_values): New function. * value.h (finalize_values): Declare. --- gdb/top.c | 3 +++ gdb/value.c | 8 ++++++++ gdb/value.h | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/gdb/top.c b/gdb/top.c index b10b0649e9..ffbe8e517f 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1672,6 +1672,9 @@ quit_force (int *exit_arg, int from_tty) } END_CATCH + /* Destroy any values currently allocated. */ + finalize_values (); + /* Do any final cleanups before exiting. */ TRY { diff --git a/gdb/value.c b/gdb/value.c index dc297dfe0f..bcfc084e09 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -4132,3 +4132,11 @@ prevents future values, larger than this size, from being allocated."), selftests::test_insert_into_bit_range_vector); #endif } + +/* See value.h. */ + +void +finalize_values () +{ + all_values.clear (); +} diff --git a/gdb/value.h b/gdb/value.h index d3905cc354..7853950ca3 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1189,4 +1189,8 @@ extern struct value *call_xmethod (struct value *method, extern int value_union_variant (struct type *union_type, const gdb_byte *contents); +/* Destroy the values currently allocated. This is mostly called when + GDB is exiting (e.g., on quit_force). */ +extern void finalize_values (); + #endif /* !defined (VALUE_H) */