From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23172 invoked by alias); 4 Sep 2009 23:50:42 -0000 Received: (qmail 23164 invoked by uid 22791); 4 Sep 2009 23:50:41 -0000 X-SWARE-Spam-Status: No, hits=0.6 required=5.0 tests=AWL,BAYES_00,KAM_STOCKTIP,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Sep 2009 23:50:36 +0000 Received: from zps37.corp.google.com (zps37.corp.google.com [172.25.146.37]) by smtp-out.google.com with ESMTP id n84NoBFY014687; Fri, 4 Sep 2009 16:50:11 -0700 Received: from localhost (ruffy.mtv.corp.google.com [172.18.118.116]) by zps37.corp.google.com with ESMTP id n84No9WY021373; Fri, 4 Sep 2009 16:50:09 -0700 Received: by localhost (Postfix, from userid 67641) id 5FA8D843B9; Fri, 4 Sep 2009 16:50:09 -0700 (PDT) To: gdb-patches@sourceware.org, brobecker@adacore.com Subject: [RFA] move dwarf2_free_objfile to dwarf2_per_objfile_cleanup Message-Id: <20090904235009.5FA8D843B9@localhost> Date: Fri, 04 Sep 2009 23:50:00 -0000 From: dje@google.com (Doug Evans) X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-09/txt/msg00108.txt.bz2 Hi. While working on the dwarf2 mmapped strings issue, I noticed that there are two routines in dwarf2read.c that are called to release memory for an objfile. This patch cleans things up and moves everything to dwarf2_per_objfile_cleanup. Ok to check in? Joel, did you want to have some kind of freeze before the branch? [Maybe you said so and I missed it.] This can wait until after the branch. 2009-09-04 Doug Evans * symfile.h (dwarf2_free_objfile): Delete. * dwarf2read.c (dwarf2_build_psymtabs_hard): Pass dwarf2_per_objfile to free_cached_comp_units. (free_cached_comp_units): Remove reference to global dwarf2_per_objfile, use passed parameter instead. (dwarf2_free_objfile): Delete, contents moved to ... (dwarf2_per_objfile_cleanup): ... here. * coffread.c (coff_symfile_finish): Delete call to dwarf2_free_objfile. * elfread.c (elf_symfile_finish): Delete call to dwarf2_free_objfile. Index: coffread.c =================================================================== RCS file: /cvs/src/src/gdb/coffread.c,v retrieving revision 1.95 diff -u -p -r1.95 coffread.c --- coffread.c 29 Jun 2009 13:18:37 -0000 1.95 +++ coffread.c 4 Sep 2009 23:30:18 -0000 @@ -670,8 +670,6 @@ coff_symfile_finish (struct objfile *obj /* Let stabs reader clean up */ stabsread_clear_cache (); - - dwarf2_free_objfile (objfile); } Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.325 diff -u -p -r1.325 dwarf2read.c --- dwarf2read.c 28 Aug 2009 10:49:05 -0000 1.325 +++ dwarf2read.c 4 Sep 2009 23:30:18 -0000 @@ -2049,7 +2049,7 @@ dwarf2_build_psymtabs_hard (struct objfi /* Any cached compilation units will be linked by the per-objfile read_in_chain. Make sure to free them when we're done. */ - back_to = make_cleanup (free_cached_comp_units, NULL); + back_to = make_cleanup (free_cached_comp_units, dwarf2_per_objfile); build_type_psymtabs (objfile); @@ -11535,12 +11548,13 @@ free_stack_comp_unit (void *data) /* Free all cached compilation units. */ static void -free_cached_comp_units (void *data) +free_cached_comp_units (void *d) { + struct dwarf2_per_objfile *data = d; struct dwarf2_per_cu_data *per_cu, **last_chain; - per_cu = dwarf2_per_objfile->read_in_chain; - last_chain = &dwarf2_per_objfile->read_in_chain; + per_cu = data->read_in_chain; + last_chain = &data->read_in_chain; while (per_cu != NULL) { struct dwarf2_per_cu_data *next_cu; @@ -11620,22 +11634,6 @@ free_one_cached_comp_unit (void *target_ } } -/* Release all extra memory associated with OBJFILE. */ - -void -dwarf2_free_objfile (struct objfile *objfile) -{ - dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); - - if (dwarf2_per_objfile == NULL) - return; - - /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ - free_cached_comp_units (NULL); - - /* Everything else should be on the objfile obstack. */ -} - /* A pair of DIE offset and GDB type pointer. We store these in a hash table separate from the DIEs, and preserve them when the DIEs are flushed out of cache. */ @@ -11834,12 +11832,14 @@ munmap_section_buffer (struct dwarf2_sec } } -/* munmap debug sections for OBJFILE, if necessary. */ +/* Release all extra memory associated with OBJFILE. + And munmap debug sections for OBJFILE, if necessary. */ static void dwarf2_per_objfile_cleanup (struct objfile *objfile, void *d) { struct dwarf2_per_objfile *data = d; + munmap_section_buffer (&data->info); munmap_section_buffer (&data->abbrev); munmap_section_buffer (&data->line); @@ -11849,6 +11849,11 @@ dwarf2_per_objfile_cleanup (struct objfi munmap_section_buffer (&data->loc); munmap_section_buffer (&data->frame); munmap_section_buffer (&data->eh_frame); + + /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ + free_cached_comp_units (data); + + /* Everything else should be on the objfile obstack. */ } void _initialize_dwarf2_read (void); Index: elfread.c =================================================================== RCS file: /cvs/src/src/gdb/elfread.c,v retrieving revision 1.77 diff -u -p -r1.77 elfread.c --- elfread.c 30 Apr 2009 21:59:03 -0000 1.77 +++ elfread.c 4 Sep 2009 23:30:18 -0000 @@ -787,8 +787,6 @@ elf_symfile_finish (struct objfile *objf { xfree (objfile->deprecated_sym_stab_info); } - - dwarf2_free_objfile (objfile); } /* ELF specific initialization routine for reading symbols. Index: symfile.h =================================================================== RCS file: /cvs/src/src/gdb/symfile.h,v retrieving revision 1.52 diff -u -p -r1.52 symfile.h --- symfile.h 27 Aug 2009 21:56:38 -0000 1.52 +++ symfile.h 4 Sep 2009 23:30:18 -0000 @@ -382,8 +382,6 @@ extern int dwarf2_has_info (struct objfi extern void dwarf2_build_psymtabs (struct objfile *, int); extern void dwarf2_build_frame_info (struct objfile *); -void dwarf2_free_objfile (struct objfile *); - /* From mdebugread.c */ /* Hack to force structures to exist before use in parameter list. */