* [PATCH] Fix ada inferior-data cleanup
@ 2013-10-26 3:58 Yao Qi
2013-10-28 3:43 ` Joel Brobecker
2013-10-28 11:28 ` Pedro Alves
0 siblings, 2 replies; 6+ messages in thread
From: Yao Qi @ 2013-10-26 3:58 UTC (permalink / raw)
To: gdb-patches
Hi,
'struct ada_inferior_data' is registered to per-inferior-data with
cleanup ada_inferior_data_cleanup, which means the data will be
destroyed when the inferior exits. It is unnecessary to call
observer_attach_inferior_exit to do cleanups again.
Regression tested by "make check RUNTESTFLAGS='--directory=gdb.ada'"
on x86 Fedora 16 linux.
gdb:
2013-10-26 Yao Qi <yao@codesourcery.com>
* ada-lang.c (ada_inferior_data_cleanup): Don't get data from
inferior_data. Don't check NULL. Free 'arg'.
(ada_inferior_exit): Remove.
(_initialize_ada_language): Don't call
observer_attach_inferior_exit.
---
gdb/ada-lang.c | 17 +----------------
1 files changed, 1 insertions(+), 16 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 75f9fe8..600f835 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -336,11 +336,7 @@ static const struct inferior_data *ada_inferior_data;
static void
ada_inferior_data_cleanup (struct inferior *inf, void *arg)
{
- struct ada_inferior_data *data;
-
- data = inferior_data (inf, ada_inferior_data);
- if (data != NULL)
- xfree (data);
+ xfree (arg);
}
/* Return our inferior data for the given inferior (INF).
@@ -366,16 +362,6 @@ get_ada_inferior_data (struct inferior *inf)
return data;
}
-/* Perform all necessary cleanups regarding our module's inferior data
- that is required after the inferior INF just exited. */
-
-static void
-ada_inferior_exit (struct inferior *inf)
-{
- ada_inferior_data_cleanup (inf, NULL);
- set_inferior_data (inf, ada_inferior_data, NULL);
-}
-
/* Utilities */
/* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
@@ -12958,7 +12944,6 @@ With an argument, catch only exceptions with the given name."),
NULL, xcalloc, xfree);
/* Setup per-inferior data. */
- observer_attach_inferior_exit (ada_inferior_exit);
ada_inferior_data
= register_inferior_data_with_cleanup (NULL, ada_inferior_data_cleanup);
}
--
1.7.7.6
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix ada inferior-data cleanup
2013-10-26 3:58 [PATCH] Fix ada inferior-data cleanup Yao Qi
@ 2013-10-28 3:43 ` Joel Brobecker
2013-10-28 12:06 ` Yao Qi
2013-10-28 11:28 ` Pedro Alves
1 sibling, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2013-10-28 3:43 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
> 'struct ada_inferior_data' is registered to per-inferior-data with
> cleanup ada_inferior_data_cleanup, which means the data will be
> destroyed when the inferior exits. It is unnecessary to call
> observer_attach_inferior_exit to do cleanups again.
Can you explain where the data actually gets destroyed? I've been
going through the code, and I just can't find where this would be
happening. Adding a debug trace confirms that the cleanup routine
never gets called if you remeove the inferior-exit observer.
> Regression tested by "make check RUNTESTFLAGS='--directory=gdb.ada'"
> on x86 Fedora 16 linux.
>
> gdb:
>
> 2013-10-26 Yao Qi <yao@codesourcery.com>
>
> * ada-lang.c (ada_inferior_data_cleanup): Don't get data from
> inferior_data. Don't check NULL. Free 'arg'.
> (ada_inferior_exit): Remove.
> (_initialize_ada_language): Don't call
> observer_attach_inferior_exit.
> ---
> gdb/ada-lang.c | 17 +----------------
> 1 files changed, 1 insertions(+), 16 deletions(-)
>
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index 75f9fe8..600f835 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -336,11 +336,7 @@ static const struct inferior_data *ada_inferior_data;
> static void
> ada_inferior_data_cleanup (struct inferior *inf, void *arg)
> {
> - struct ada_inferior_data *data;
> -
> - data = inferior_data (inf, ada_inferior_data);
> - if (data != NULL)
> - xfree (data);
> + xfree (arg);
> }
>
> /* Return our inferior data for the given inferior (INF).
> @@ -366,16 +362,6 @@ get_ada_inferior_data (struct inferior *inf)
> return data;
> }
>
> -/* Perform all necessary cleanups regarding our module's inferior data
> - that is required after the inferior INF just exited. */
> -
> -static void
> -ada_inferior_exit (struct inferior *inf)
> -{
> - ada_inferior_data_cleanup (inf, NULL);
> - set_inferior_data (inf, ada_inferior_data, NULL);
> -}
> -
> /* Utilities */
>
> /* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
> @@ -12958,7 +12944,6 @@ With an argument, catch only exceptions with the given name."),
> NULL, xcalloc, xfree);
>
> /* Setup per-inferior data. */
> - observer_attach_inferior_exit (ada_inferior_exit);
> ada_inferior_data
> = register_inferior_data_with_cleanup (NULL, ada_inferior_data_cleanup);
> }
> --
> 1.7.7.6
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix ada inferior-data cleanup
2013-10-26 3:58 [PATCH] Fix ada inferior-data cleanup Yao Qi
2013-10-28 3:43 ` Joel Brobecker
@ 2013-10-28 11:28 ` Pedro Alves
2013-10-28 12:24 ` Yao Qi
1 sibling, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2013-10-28 11:28 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
On 10/26/2013 04:56 AM, Yao Qi wrote:
> 'struct ada_inferior_data' is registered to per-inferior-data with
> cleanup ada_inferior_data_cleanup, which means the data will be
> destroyed when the inferior exits.
That's not correct. The registry data cleanups are only ran when
the inferior object is destroyed, IOW, when the inferior is
removed/deleted (e.g, with "remove-inferiors"), not when the program
exits.
> It is unnecessary to call
> observer_attach_inferior_exit to do cleanups again.
>
> Regression tested by "make check RUNTESTFLAGS='--directory=gdb.ada'"
> on x86 Fedora 16 linux.
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix ada inferior-data cleanup
2013-10-28 3:43 ` Joel Brobecker
@ 2013-10-28 12:06 ` Yao Qi
0 siblings, 0 replies; 6+ messages in thread
From: Yao Qi @ 2013-10-28 12:06 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On 10/28/2013 11:43 AM, Joel Brobecker wrote:
> Can you explain where the data actually gets destroyed? I've been
> going through the code, and I just can't find where this would be
> happening. Adding a debug trace confirms that the cleanup routine
> never gets called if you remeove the inferior-exit observer.
Joel,
I miss a chunk when splitting patches, which is to call
clear_inferior_data in exit_inferior_1. I'll re-org them and post the
new one. Sorry about that.
--
Yao (é½å°§)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix ada inferior-data cleanup
2013-10-28 11:28 ` Pedro Alves
@ 2013-10-28 12:24 ` Yao Qi
2013-10-28 14:27 ` Pedro Alves
0 siblings, 1 reply; 6+ messages in thread
From: Yao Qi @ 2013-10-28 12:24 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On 10/28/2013 07:27 PM, Pedro Alves wrote:
>> 'struct ada_inferior_data' is registered to per-inferior-data with
>> >cleanup ada_inferior_data_cleanup, which means the data will be
>> >destroyed when the inferior exits.
> That's not correct. The registry data cleanups are only ran when
> the inferior object is destroyed, IOW, when the inferior is
> removed/deleted (e.g, with "remove-inferiors"), not when the program
> exits.
>
Is it a good idea to call clear_inferior_data when inferior exists (in
exit_inferior_1)?
The comment in registry.h says:
- clear_TAG_data(TAG, OBJECT)
Clear all the data associated with OBJECT. Should be called by the
container implementation when a container object is destroyed.
It is unclear whether I can use clear_inferior_data in exit_inferior_1.
The benefit of this change is that we can remove some attached
inferior_exit observers. These inferior_exit observer functions are
duplicated to inferior_data_cleanup functions. WDYT?
--
Yao (é½å°§)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix ada inferior-data cleanup
2013-10-28 12:24 ` Yao Qi
@ 2013-10-28 14:27 ` Pedro Alves
0 siblings, 0 replies; 6+ messages in thread
From: Pedro Alves @ 2013-10-28 14:27 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
On 10/28/2013 12:22 PM, Yao Qi wrote:
> On 10/28/2013 07:27 PM, Pedro Alves wrote:
>>> 'struct ada_inferior_data' is registered to per-inferior-data with
>>>> cleanup ada_inferior_data_cleanup, which means the data will be
>>>> destroyed when the inferior exits.
>> That's not correct. The registry data cleanups are only ran when
>> the inferior object is destroyed, IOW, when the inferior is
>> removed/deleted (e.g, with "remove-inferiors"), not when the program
>> exits.
>>
>
> Is it a good idea to call clear_inferior_data when inferior exists (in
> exit_inferior_1)?
IMO, it's not, for it confuses two different lifetimes. It's quite
plausible to have data associated with the inferior object that should
be preserved across runs.
> These inferior_exit observer functions are duplicated to
> inferior_data_cleanup functions. WDYT?
There's really no reason for the code to be duplicated. For each
case, a helper that does the real work can be called from
wherever necessary, for instance.
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-10-28 14:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-26 3:58 [PATCH] Fix ada inferior-data cleanup Yao Qi
2013-10-28 3:43 ` Joel Brobecker
2013-10-28 12:06 ` Yao Qi
2013-10-28 11:28 ` Pedro Alves
2013-10-28 12:24 ` Yao Qi
2013-10-28 14:27 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox