public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Re: [RFA] Make dwarf2_free_objfile static
@ 2018-06-28 13:33 Simon Marchi
  2018-06-28 14:18 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Marchi @ 2018-06-28 13:33 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, Tom Tromey

On 2018-06-27 18:31, Andrew Burgess wrote:
> I don't know if we have a preference for static_cast over C style
> casting these days?

Indeed, static_cast provides some compile-time safety, so I guess we 
should always prefer that over the C-style cast.

> Otherwise, FWIW, this looks like a nice clean up.

Indeed, LGTM (with possibly the cast fixed up).

Thanks,

Simon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] Make dwarf2_free_objfile static
  2018-06-28 13:33 [RFA] Make dwarf2_free_objfile static Simon Marchi
@ 2018-06-28 14:18 ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2018-06-28 14:18 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Andrew Burgess, gdb-patches, Tom Tromey

>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

>> I don't know if we have a preference for static_cast over C style
>> casting these days?

Simon> Indeed, static_cast provides some compile-time safety, so I guess we
Simon> should always prefer that over the C-style cast.

I made this change.

I think it would be even nicer if the registry functions were type-safe.
I haven't looked into this though.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] Make dwarf2_free_objfile static
  2018-06-05 19:22 Tom Tromey
@ 2018-06-27 22:31 ` Andrew Burgess
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Burgess @ 2018-06-27 22:31 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

* Tom Tromey <tom@tromey.com> [2018-06-05 13:22:27 -0600]:

> I noticed that dwarf2_free_objfile can be made static, by changing it
> to be a registry cleanup function.  This simplifies the code, as well,
> because now symbol readers don't have to explicitly call it.
> 
> Tested by the buildbot.
> 
> gdb/ChangeLog
> 2018-06-05  Tom Tromey  <tom@tromey.com>
> 
> 	* coffread.c (coff_symfile_finish): Update.
> 	* xcoffread.c (xcoff_symfile_finish): Update.
> 	* elfread.c (elf_symfile_finish): Update.
> 	* symfile.h (dwarf2_free_objfile): Don't declare.
> 	* dwarf2read.c (_initialize_dwarf2_read): Use
> 	register_objfile_data_with_cleanup.
> 	(dwarf2_free_objfile): Now static.  Change signature.
> ---
>  gdb/ChangeLog    | 10 ++++++++++
>  gdb/coffread.c   |  2 --
>  gdb/dwarf2read.c | 12 ++++++------
>  gdb/elfread.c    |  1 -
>  gdb/symfile.h    |  2 --
>  gdb/xcoffread.c  |  2 --
>  6 files changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/gdb/coffread.c b/gdb/coffread.c
> index bc266fb60e3..30583e1dda4 100644
> --- a/gdb/coffread.c
> +++ b/gdb/coffread.c
> @@ -766,8 +766,6 @@ coff_symfile_finish (struct objfile *objfile)
>  {
>    /* Let stabs reader clean up.  */
>    stabsread_clear_cache ();
> -
> -  dwarf2_free_objfile (objfile);
>  }
>  \f
>  
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 1cabfbb0d45..55377dc1004 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -25003,13 +25003,13 @@ free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu)
>      }
>  }
>  
> -/* Release all extra memory associated with OBJFILE.  */
> +/* Cleanup function for the dwarf2_per_objfile data.  */
>  
> -void
> -dwarf2_free_objfile (struct objfile *objfile)
> +static void
> +dwarf2_free_objfile (struct objfile *objfile, void *datum)
>  {
>    struct dwarf2_per_objfile *dwarf2_per_objfile
> -    = get_dwarf2_per_objfile (objfile);
> +    = (struct dwarf2_per_objfile *) datum;

I don't know if we have a preference for static_cast over C style
casting these days?

Otherwise, FWIW, this looks like a nice clean up.

Thanks,
Andrew


>  
>    delete dwarf2_per_objfile;
>  }
> @@ -25331,8 +25331,8 @@ show_check_physname (struct ui_file *file, int from_tty,
>  void
>  _initialize_dwarf2_read (void)
>  {
> -
> -  dwarf2_objfile_data_key = register_objfile_data ();
> +  dwarf2_objfile_data_key
> +    = register_objfile_data_with_cleanup (nullptr, dwarf2_free_objfile);
>  
>    add_prefix_cmd ("dwarf", class_maintenance, set_dwarf_cmd, _("\
>  Set DWARF specific variables.\n\
> diff --git a/gdb/elfread.c b/gdb/elfread.c
> index 0fe2adbd4d2..358ec77b35b 100644
> --- a/gdb/elfread.c
> +++ b/gdb/elfread.c
> @@ -1333,7 +1333,6 @@ elf_new_init (struct objfile *ignore)
>  static void
>  elf_symfile_finish (struct objfile *objfile)
>  {
> -  dwarf2_free_objfile (objfile);
>  }
>  
>  /* ELF specific initialization routine for reading symbols.  */
> diff --git a/gdb/symfile.h b/gdb/symfile.h
> index d9185092eec..62072b104cc 100644
> --- a/gdb/symfile.h
> +++ b/gdb/symfile.h
> @@ -614,8 +614,6 @@ extern bool dwarf2_initialize_objfile (struct objfile *objfile,
>  extern void dwarf2_build_psymtabs (struct objfile *);
>  extern void dwarf2_build_frame_info (struct objfile *);
>  
> -void dwarf2_free_objfile (struct objfile *);
> -
>  /* From mdebugread.c */
>  
>  extern void mdebug_build_psymtabs (minimal_symbol_reader &,
> diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
> index 7b9694bcff9..79b1df70fd0 100644
> --- a/gdb/xcoffread.c
> +++ b/gdb/xcoffread.c
> @@ -1959,8 +1959,6 @@ xcoff_symfile_finish (struct objfile *objfile)
>        inclTable = NULL;
>      }
>    inclIndx = inclLength = inclDepth = 0;
> -
> -  dwarf2_free_objfile (objfile);
>  }
>  
>  
> -- 
> 2.13.6
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RFA] Make dwarf2_free_objfile static
@ 2018-06-05 19:22 Tom Tromey
  2018-06-27 22:31 ` Andrew Burgess
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2018-06-05 19:22 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I noticed that dwarf2_free_objfile can be made static, by changing it
to be a registry cleanup function.  This simplifies the code, as well,
because now symbol readers don't have to explicitly call it.

Tested by the buildbot.

gdb/ChangeLog
2018-06-05  Tom Tromey  <tom@tromey.com>

	* coffread.c (coff_symfile_finish): Update.
	* xcoffread.c (xcoff_symfile_finish): Update.
	* elfread.c (elf_symfile_finish): Update.
	* symfile.h (dwarf2_free_objfile): Don't declare.
	* dwarf2read.c (_initialize_dwarf2_read): Use
	register_objfile_data_with_cleanup.
	(dwarf2_free_objfile): Now static.  Change signature.
---
 gdb/ChangeLog    | 10 ++++++++++
 gdb/coffread.c   |  2 --
 gdb/dwarf2read.c | 12 ++++++------
 gdb/elfread.c    |  1 -
 gdb/symfile.h    |  2 --
 gdb/xcoffread.c  |  2 --
 6 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/gdb/coffread.c b/gdb/coffread.c
index bc266fb60e3..30583e1dda4 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -766,8 +766,6 @@ coff_symfile_finish (struct objfile *objfile)
 {
   /* Let stabs reader clean up.  */
   stabsread_clear_cache ();
-
-  dwarf2_free_objfile (objfile);
 }
 \f
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1cabfbb0d45..55377dc1004 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -25003,13 +25003,13 @@ free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu)
     }
 }
 
-/* Release all extra memory associated with OBJFILE.  */
+/* Cleanup function for the dwarf2_per_objfile data.  */
 
-void
-dwarf2_free_objfile (struct objfile *objfile)
+static void
+dwarf2_free_objfile (struct objfile *objfile, void *datum)
 {
   struct dwarf2_per_objfile *dwarf2_per_objfile
-    = get_dwarf2_per_objfile (objfile);
+    = (struct dwarf2_per_objfile *) datum;
 
   delete dwarf2_per_objfile;
 }
@@ -25331,8 +25331,8 @@ show_check_physname (struct ui_file *file, int from_tty,
 void
 _initialize_dwarf2_read (void)
 {
-
-  dwarf2_objfile_data_key = register_objfile_data ();
+  dwarf2_objfile_data_key
+    = register_objfile_data_with_cleanup (nullptr, dwarf2_free_objfile);
 
   add_prefix_cmd ("dwarf", class_maintenance, set_dwarf_cmd, _("\
 Set DWARF specific variables.\n\
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 0fe2adbd4d2..358ec77b35b 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1333,7 +1333,6 @@ elf_new_init (struct objfile *ignore)
 static void
 elf_symfile_finish (struct objfile *objfile)
 {
-  dwarf2_free_objfile (objfile);
 }
 
 /* ELF specific initialization routine for reading symbols.  */
diff --git a/gdb/symfile.h b/gdb/symfile.h
index d9185092eec..62072b104cc 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -614,8 +614,6 @@ extern bool dwarf2_initialize_objfile (struct objfile *objfile,
 extern void dwarf2_build_psymtabs (struct objfile *);
 extern void dwarf2_build_frame_info (struct objfile *);
 
-void dwarf2_free_objfile (struct objfile *);
-
 /* From mdebugread.c */
 
 extern void mdebug_build_psymtabs (minimal_symbol_reader &,
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 7b9694bcff9..79b1df70fd0 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -1959,8 +1959,6 @@ xcoff_symfile_finish (struct objfile *objfile)
       inclTable = NULL;
     }
   inclIndx = inclLength = inclDepth = 0;
-
-  dwarf2_free_objfile (objfile);
 }
 
 
-- 
2.13.6

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-28 14:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-28 13:33 [RFA] Make dwarf2_free_objfile static Simon Marchi
2018-06-28 14:18 ` Tom Tromey
  -- strict thread matches above, loose matches on Subject: below --
2018-06-05 19:22 Tom Tromey
2018-06-27 22:31 ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).