From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23026 invoked by alias); 1 May 2004 05:27:20 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 23019 invoked from network); 1 May 2004 05:27:20 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sources.redhat.com with SMTP; 1 May 2004 05:27:20 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.10/8.12.10) with ESMTP id i415RKKG031276 for ; Sat, 1 May 2004 01:27:20 -0400 Received: from zenia.home.redhat.com (porkchop.devel.redhat.com [172.16.58.2]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id i415RFv12657; Sat, 1 May 2004 01:27:16 -0400 To: gdb-patches@sources.redhat.com Subject: RFC: fix for symtab/1627 From: Jim Blandy Date: Sat, 01 May 2004 05:27:00 -0000 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-SW-Source: 2004-05/txt/msg00009.txt.bz2 --=-=-= Content-length: 112 I'd like to commit the following patch for the bug reported in symtab/1627. Comments? Tomatoes? Spirulina? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=jimb.gdb-symfile-copy-section-addr-info.patch Content-Description: patch to fix symtab/1627 Content-length: 6869 2004-04-28 Jim Blandy Fix bug reported and analyzed by Olivier Crete: * symfile.c (copy_section_addr_info): New function. (symbol_file_add_with_addrs_or_offsets): Use it to save the original set of address arguments, instead of handwritten code that uses one length to allocate and a different length to initialize. Use make_cleanup_free_section_addr_info. * symfile.h (copy_section_addr_info): New declaration. * utils.c: #include "symfile.h". (do_free_section_addr_info, make_cleanup_free_section_addr_info): New functions. * defs.h (make_cleanup_free_section_addr_info): New declaration. * Makefile.in (utils.o): Update dependencies. Index: gdb/Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.552 diff -c -r1.552 Makefile.in *** gdb/Makefile.in 30 Apr 2004 23:28:51 -0000 1.552 --- gdb/Makefile.in 1 May 2004 05:22:09 -0000 *************** *** 2483,2489 **** utils.o: utils.c $(defs_h) $(gdb_assert_h) $(gdb_string_h) $(event_top_h) \ $(tui_h) $(gdbcmd_h) $(serial_h) $(bfd_h) $(target_h) $(demangle_h) \ $(expression_h) $(language_h) $(charset_h) $(annotate_h) \ ! $(filenames_h) $(inferior_h) $(readline_h) uw-thread.o: uw-thread.c $(defs_h) $(gdbthread_h) $(target_h) $(inferior_h) \ $(regcache_h) $(gregset_h) v850ice.o: v850ice.c $(defs_h) $(gdb_string_h) $(frame_h) $(symtab_h) \ --- 2483,2489 ---- utils.o: utils.c $(defs_h) $(gdb_assert_h) $(gdb_string_h) $(event_top_h) \ $(tui_h) $(gdbcmd_h) $(serial_h) $(bfd_h) $(target_h) $(demangle_h) \ $(expression_h) $(language_h) $(charset_h) $(annotate_h) \ ! $(filenames_h) $(inferior_h) $(readline_h) $(symfile_h) uw-thread.o: uw-thread.c $(defs_h) $(gdbthread_h) $(target_h) $(inferior_h) \ $(regcache_h) $(gregset_h) v850ice.o: v850ice.c $(defs_h) $(gdb_string_h) $(frame_h) $(symtab_h) \ Index: gdb/defs.h =================================================================== RCS file: /cvs/src/src/gdb/defs.h,v retrieving revision 1.145 diff -c -r1.145 defs.h *** gdb/defs.h 30 Apr 2004 20:44:58 -0000 1.145 --- gdb/defs.h 1 May 2004 05:22:10 -0000 *************** *** 374,379 **** --- 374,383 ---- struct ui_file; extern struct cleanup *make_cleanup_ui_file_delete (struct ui_file *); + struct section_addr_info; + extern struct cleanup *(make_cleanup_free_section_addr_info + (struct section_addr_info *)); + extern struct cleanup *make_cleanup_close (int fd); extern struct cleanup *make_cleanup_bfd_close (bfd *abfd); Index: gdb/symfile.c =================================================================== RCS file: /cvs/src/src/gdb/symfile.c,v retrieving revision 1.128 diff -c -r1.128 symfile.c *** gdb/symfile.c 21 Apr 2004 23:52:21 -0000 1.128 --- gdb/symfile.c 1 May 2004 05:22:13 -0000 *************** *** 336,341 **** --- 336,367 ---- return sap; } + + /* Return a freshly allocated copy of ADDRS. The section names, if + any, are also freshly allocated copies of those in ADDRS. */ + struct section_addr_info * + copy_section_addr_info (struct section_addr_info *addrs) + { + struct section_addr_info *copy + = alloc_section_addr_info (addrs->num_sections); + int i; + + copy->num_sections = addrs->num_sections; + for (i = 0; i < addrs->num_sections; i++) + { + copy->other[i].addr = addrs->other[i].addr; + if (addrs->other[i].name) + copy->other[i].name = xstrdup (addrs->other[i].name); + else + copy->other[i].name = NULL; + copy->other[i].sectindex = addrs->other[i].sectindex; + } + + return copy; + } + + + /* Build (allocate and populate) a section_addr_info struct from an existing section table. */ *************** *** 784,790 **** struct objfile *objfile; struct partial_symtab *psymtab; char *debugfile; ! struct section_addr_info *orig_addrs; struct cleanup *my_cleanups; const char *name = bfd_get_filename (abfd); --- 810,816 ---- struct objfile *objfile; struct partial_symtab *psymtab; char *debugfile; ! struct section_addr_info *orig_addrs = NULL; struct cleanup *my_cleanups; const char *name = bfd_get_filename (abfd); *************** *** 802,815 **** objfile = allocate_objfile (abfd, flags); discard_cleanups (my_cleanups); - orig_addrs = alloc_section_addr_info (bfd_count_sections (abfd)); - my_cleanups = make_cleanup (xfree, orig_addrs); if (addrs) { ! int i; ! orig_addrs->num_sections = addrs->num_sections; ! for (i = 0; i < addrs->num_sections; i++) ! orig_addrs->other[i] = addrs->other[i]; } /* We either created a new mapped symbol table, mapped an existing --- 828,837 ---- objfile = allocate_objfile (abfd, flags); discard_cleanups (my_cleanups); if (addrs) { ! orig_addrs = copy_section_addr_info (addrs); ! make_cleanup_free_section_addr_info (orig_addrs); } /* We either created a new mapped symbol table, mapped an existing Index: gdb/symfile.h =================================================================== RCS file: /cvs/src/src/gdb/symfile.h,v retrieving revision 1.29 diff -c -r1.29 symfile.h *** gdb/symfile.h 15 Apr 2004 21:39:27 -0000 1.29 --- gdb/symfile.h 1 May 2004 05:22:13 -0000 *************** *** 194,199 **** --- 194,204 ---- extern struct section_addr_info *alloc_section_addr_info (size_t num_sections); + /* Return a freshly allocated copy of ADDRS. The section names, if + any, are also freshly allocated copies of those in ADDRS. */ + extern struct section_addr_info *(copy_section_addr_info + (struct section_addr_info *addrs)); + /* Build (allocate and populate) a section_addr_info struct from an existing section table. */ Index: gdb/utils.c =================================================================== RCS file: /cvs/src/src/gdb/utils.c,v retrieving revision 1.120 diff -c -r1.120 utils.c *** gdb/utils.c 21 Apr 2004 23:52:21 -0000 1.120 --- gdb/utils.c 1 May 2004 05:22:15 -0000 *************** *** 51,56 **** --- 51,57 ---- #include "charset.h" #include "annotate.h" #include "filenames.h" + #include "symfile.h" #include "inferior.h" /* for signed_pointer_to_address */ *************** *** 259,264 **** --- 260,278 ---- { return make_my_cleanup (&cleanup_chain, do_ui_file_delete, arg); } + + static void + do_free_section_addr_info (void *arg) + { + free_section_addr_info (arg); + } + + struct cleanup * + make_cleanup_free_section_addr_info (struct section_addr_info *addrs) + { + return make_my_cleanup (&cleanup_chain, do_free_section_addr_info, addrs); + } + struct cleanup * make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function, --=-=-=--