Destroy allocated values when exiting GDB
authorSergio Durigan Junior <sergiodj@redhat.com>
Fri, 29 Mar 2019 21:34:54 +0000 (17:34 -0400)
committerSergio Durigan Junior <sergiodj@redhat.com>
Mon, 1 Apr 2019 14:58:12 +0000 (10:58 -0400)
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-04-01  Sergio Durigan Junior  <sergiodj@redhat.com>
    Pedro Alves  <palves@redhat.com>

* top.c (quit_force): Call 'finalize_values'.
* value.c (finalize_values): New function.
* value.h (finalize_values): Declare.

gdb/ChangeLog
gdb/top.c
gdb/value.c
gdb/value.h

index a3dfd3169873113365687defd15902e7d8ffe730..3de5992d87bd86456876b48c0b37e2e02a061e15 100644 (file)
@@ -1,3 +1,10 @@
+2019-04-01  Sergio Durigan Junior  <sergiodj@redhat.com>
+           Pedro Alves  <palves@redhat.com>
+
+       * top.c (quit_force): Call 'finalize_values'.
+       * value.c (finalize_values): New function.
+       * value.h (finalize_values): Declare.
+
 2019-03-30  Eli Zaretskii  <eliz@gnu.org>
 
        * NEWS: Announce $_gdb_major and $_gdb_minor.
index afb77c0ec956f40726a33d0c987e8e4fe22c39a0..1fc259fe0f487a208bc4fcbba782f34847e94b64 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1673,6 +1673,12 @@ quit_force (int *exit_arg, int from_tty)
     }
   END_CATCH
 
+  /* 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
     {
index dc297dfe0f9efaf827c84b58107c1e4a2d87141b..bcfc084e09092a187baa691856f7b3f940573073 100644 (file)
@@ -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 ();
+}
index d3905cc354a775dd4c97ed558f4933e058f782de..0756d13b6d79f060e9ada774518092e49ec1a9d4 100644 (file)
@@ -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 called when GDB is
+   exiting (e.g., on quit_force).  */
+extern void finalize_values ();
+
 #endif /* !defined (VALUE_H) */
This page took 0.029179 seconds and 4 git commands to generate.