From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6440 invoked by alias); 10 Sep 2009 20:00:40 -0000 Received: (qmail 6426 invoked by uid 22791); 10 Sep 2009 20:00:39 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 10 Sep 2009 20:00:33 +0000 Received: from zps36.corp.google.com (zps36.corp.google.com [172.25.146.36]) by smtp-out.google.com with ESMTP id n8AJxU6C019833; Thu, 10 Sep 2009 20:59:31 +0100 Received: from localhost (ruffy.mtv.corp.google.com [172.18.118.116]) by zps36.corp.google.com with ESMTP id n8AJxRLn028909; Thu, 10 Sep 2009 12:59:27 -0700 Received: by localhost (Postfix, from userid 67641) id F303E843B9; Thu, 10 Sep 2009 12:59:26 -0700 (PDT) To: gdb-patches@sourceware.org cc: ppluzhnikov@google.com, tromey@redhat.com, brobecker@adacore.com Subject: [patch] Fix segv during objfile_data cleanup Message-Id: <20090910195926.F303E843B9@localhost> Date: Thu, 10 Sep 2009 20:00: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/msg00281.txt.bz2 Hi. This patch fixes the segv reported here http://sourceware.org/ml/gdb/2009-09/msg00078.html by splitting the objfile_data cleanup into two steps, as discussed here http://sourceware.org/ml/gdb/2009-09/msg00142.html I will check it in tomorrow (pending objections). 2009-09-10 Doug Evans * objfiles.c (struct objfile_data): Delete member cleanup and replace with save, free. (register_objfile_data_with_cleanup): Delete arg cleanup and replace with save, free. All callers updated. (clear_objfile_data): Replace cleanup loop with separate save and free loops. * objfiles.h (register_objfile_data_with_cleanup): Update. * arm-tdep.c (arm_objfile_data_free): Renamed from arm_objfile_data_cleanup, all callers updated. * dwarf2read.c (dwarf2_per_objfile_free): Renamed from dwarf2_per_objfile_cleanup, all callers updated. * python/py-objfile.c (py_free_objfile): Renamed from clean_up_objfile, all callers updated. * python/py-type.c (save_objfile_types): Renamed from clean_up_objfile_types, all callers updated. Index: arm-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/arm-tdep.c,v retrieving revision 1.287 diff -u -p -r1.287 arm-tdep.c --- arm-tdep.c 3 Sep 2009 18:52:02 -0000 1.287 +++ arm-tdep.c 10 Sep 2009 19:34:17 -0000 @@ -5240,7 +5240,7 @@ arm_coff_make_msymbol_special(int val, s } static void -arm_objfile_data_cleanup (struct objfile *objfile, void *arg) +arm_objfile_data_free (struct objfile *objfile, void *arg) { struct arm_per_objfile *data = arg; unsigned int i; @@ -6032,7 +6032,7 @@ _initialize_arm_tdep (void) gdbarch_register (bfd_arch_arm, arm_gdbarch_init, arm_dump_tdep); arm_objfile_data_key - = register_objfile_data_with_cleanup (arm_objfile_data_cleanup); + = register_objfile_data_with_cleanup (NULL, arm_objfile_data_free); /* Register an ELF OS ABI sniffer for ARM binaries. */ gdbarch_register_osabi_sniffer (bfd_arch_arm, 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 10 Sep 2009 19:34:18 -0000 @@ -11837,7 +11837,7 @@ munmap_section_buffer (struct dwarf2_sec /* munmap debug sections for OBJFILE, if necessary. */ static void -dwarf2_per_objfile_cleanup (struct objfile *objfile, void *d) +dwarf2_per_objfile_free (struct objfile *objfile, void *d) { struct dwarf2_per_objfile *data = d; munmap_section_buffer (&data->info); @@ -11857,7 +11857,7 @@ void _initialize_dwarf2_read (void) { dwarf2_objfile_data_key - = register_objfile_data_with_cleanup (dwarf2_per_objfile_cleanup); + = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ Set DWARF 2 specific variables.\n\ Index: objfiles.c =================================================================== RCS file: /cvs/src/src/gdb/objfiles.c,v retrieving revision 1.94 diff -u -p -r1.94 objfiles.c --- objfiles.c 27 Aug 2009 21:56:38 -0000 1.94 +++ objfiles.c 10 Sep 2009 19:34:18 -0000 @@ -975,7 +975,8 @@ in_plt_section (CORE_ADDR pc, char *name struct objfile_data { unsigned index; - void (*cleanup) (struct objfile *, void *); + void (*save) (struct objfile *, void *); + void (*free) (struct objfile *, void *); }; struct objfile_data_registration @@ -993,7 +994,8 @@ struct objfile_data_registry static struct objfile_data_registry objfile_data_registry = { NULL, 0 }; const struct objfile_data * -register_objfile_data_with_cleanup (void (*cleanup) (struct objfile *, void *)) +register_objfile_data_with_cleanup (void (*save) (struct objfile *, void *), + void (*free) (struct objfile *, void *)) { struct objfile_data_registration **curr; @@ -1005,7 +1007,8 @@ register_objfile_data_with_cleanup (void (*curr)->next = NULL; (*curr)->data = XMALLOC (struct objfile_data); (*curr)->data->index = objfile_data_registry.num_registrations++; - (*curr)->data->cleanup = cleanup; + (*curr)->data->save = save; + (*curr)->data->free = free; return (*curr)->data; } @@ -1013,7 +1016,7 @@ register_objfile_data_with_cleanup (void const struct objfile_data * register_objfile_data (void) { - return register_objfile_data_with_cleanup (NULL); + return register_objfile_data_with_cleanup (NULL, NULL); } static void @@ -1041,11 +1044,21 @@ clear_objfile_data (struct objfile *objf gdb_assert (objfile->data != NULL); + /* Process all the save handlers. */ + + for (registration = objfile_data_registry.registrations, i = 0; + i < objfile->num_data; + registration = registration->next, i++) + if (objfile->data[i] != NULL && registration->data->save != NULL) + registration->data->save (objfile, objfile->data[i]); + + /* Now process all the free handlers. */ + for (registration = objfile_data_registry.registrations, i = 0; i < objfile->num_data; registration = registration->next, i++) - if (objfile->data[i] != NULL && registration->data->cleanup) - registration->data->cleanup (objfile, objfile->data[i]); + if (objfile->data[i] != NULL && registration->data->free != NULL) + registration->data->free (objfile, objfile->data[i]); memset (objfile->data, 0, objfile->num_data * sizeof (void *)); } Index: objfiles.h =================================================================== RCS file: /cvs/src/src/gdb/objfiles.h,v retrieving revision 1.63 diff -u -p -r1.63 objfiles.h --- objfiles.h 27 Aug 2009 21:56:38 -0000 1.63 +++ objfiles.h 10 Sep 2009 19:34:18 -0000 @@ -500,9 +500,18 @@ extern int in_plt_section (CORE_ADDR, ch /* Keep a registry of per-objfile data-pointers required by other GDB modules. */ +/* Allocate an entry in the per-objfile registry. */ extern const struct objfile_data *register_objfile_data (void); + +/* Allocate an entry in the per-objfile registry. + SAVE and FREE are called when clearing objfile data. + First all registered SAVE functions are called. + Then all registered FREE functions are called. + Either or both of SAVE, FREE may be NULL. */ extern const struct objfile_data *register_objfile_data_with_cleanup - (void (*cleanup) (struct objfile *, void *)); + (void (*save) (struct objfile *, void *), + void (*free) (struct objfile *, void *)); + extern void clear_objfile_data (struct objfile *objfile); extern void set_objfile_data (struct objfile *objfile, const struct objfile_data *data, void *value); Index: python/py-objfile.c =================================================================== RCS file: /cvs/src/src/gdb/python/py-objfile.c,v retrieving revision 1.1 diff -u -p -r1.1 py-objfile.c --- python/py-objfile.c 9 Sep 2009 17:45:40 -0000 1.1 +++ python/py-objfile.c 10 Sep 2009 19:34:18 -0000 @@ -118,7 +118,7 @@ objfpy_set_printers (PyObject *o, PyObje /* Clear the OBJFILE pointer in an Objfile object and remove the reference. */ static void -clean_up_objfile (struct objfile *objfile, void *datum) +py_free_objfile (struct objfile *objfile, void *datum) { struct cleanup *cleanup; objfile_object *object = datum; @@ -166,7 +166,7 @@ void gdbpy_initialize_objfile (void) { objfpy_objfile_data_key - = register_objfile_data_with_cleanup (clean_up_objfile); + = register_objfile_data_with_cleanup (NULL, py_free_objfile); if (PyType_Ready (&objfile_object_type) < 0) return; Index: python/py-type.c =================================================================== RCS file: /cvs/src/src/gdb/python/py-type.c,v retrieving revision 1.1 diff -u -p -r1.1 py-type.c --- python/py-type.c 9 Sep 2009 17:45:40 -0000 1.1 +++ python/py-type.c 10 Sep 2009 19:34:18 -0000 @@ -527,7 +527,7 @@ typy_str (PyObject *self) static const struct objfile_data *typy_objfile_data_key; static void -clean_up_objfile_types (struct objfile *objfile, void *datum) +save_objfile_types (struct objfile *objfile, void *datum) { type_object *obj = datum; htab_t copied_types; @@ -643,7 +643,7 @@ gdbpy_initialize_types (void) int i; typy_objfile_data_key - = register_objfile_data_with_cleanup (clean_up_objfile_types); + = register_objfile_data_with_cleanup (save_objfile_types, NULL); if (PyType_Ready (&type_object_type) < 0) return;