From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27948 invoked by alias); 18 Oct 2013 13:41:00 -0000 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 Received: (qmail 27919 invoked by uid 89); 18 Oct 2013 13:41:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mga02.intel.com Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Oct 2013 13:40:59 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 18 Oct 2013 06:40:57 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 18 Oct 2013 06:40:39 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id r9IDecH2020865; Fri, 18 Oct 2013 14:40:38 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id r9IDecTg015362; Fri, 18 Oct 2013 15:40:38 +0200 Received: (from nblanc@localhost) by ulvlx001.iul.intel.com with œ id r9IDecaY015358; Fri, 18 Oct 2013 15:40:38 +0200 From: Nicolas Blanc To: tromey@redhat.com Cc: gdb-patches@sourceware.org, Nicolas Blanc Subject: [PATCH v17 3/5] Create target sections for user-added symbol files. Date: Fri, 18 Oct 2013 13:41:00 -0000 Message-Id: <1382103635-15300-4-git-send-email-nicolas.blanc@intel.com> In-Reply-To: <1382103635-15300-1-git-send-email-nicolas.blanc@intel.com> References: <1382103635-15300-1-git-send-email-nicolas.blanc@intel.com> X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00558.txt.bz2 Add the sections of the symbol files that are provided via 'add-symbol-file' to the set of current target sections. User-added sections are removed upon notification of free_objfile when their corresponding object file is deleted. 2013-14-10 Nicolas Blanc * exec.h (add_target_sections_of_objfile): New declaration. * exec.c (add_target_sections_of_objfile): New function. * symfile.c (add_symbol_file_command): Update current target sections. (symfile_free_objfile): New function. (_initialize_symfile): Register observer for free_objf events. Signed-off-by: Nicolas Blanc --- gdb/exec.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ gdb/exec.h | 6 ++++++ gdb/symfile.c | 20 ++++++++++++++++++-- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 758cdc1..187c412 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -438,6 +438,51 @@ add_target_sections (void *owner, } } +/* Add the sections of OBJFILE to the current set of target sections. */ + +void +add_target_sections_of_objfile (struct objfile *objfile) +{ + struct target_section_table *table = current_target_sections; + struct obj_section *osect; + int space; + unsigned count = 0; + struct target_section *ts; + + if (objfile == NULL) + return; + + /* Compute the number of sections to add. */ + ALL_OBJFILE_OSECTIONS (objfile, osect) + { + if (bfd_get_section_size (osect->the_bfd_section) == 0) + continue; + count++; + } + + if (count == 0) + return; + + space = resize_section_table (table, count); + + ts = table->sections + space; + + ALL_OBJFILE_OSECTIONS (objfile, osect) + { + if (bfd_get_section_size (osect->the_bfd_section) == 0) + continue; + + gdb_assert (ts < table->sections + space + count); + + ts->addr = obj_section_addr (osect); + ts->endaddr = obj_section_endaddr (osect); + ts->the_bfd_section = osect->the_bfd_section; + ts->owner = (void *) objfile; + + ts++; + } +} + /* Remove all target sections owned by OWNER. OWNER must be the same value passed to add_target_sections. */ diff --git a/gdb/exec.h b/gdb/exec.h index 39d5ea5..d8ea389 100644 --- a/gdb/exec.h +++ b/gdb/exec.h @@ -27,6 +27,7 @@ struct target_section; struct target_ops; struct bfd; +struct objfile; extern struct target_ops exec_ops; @@ -93,6 +94,11 @@ extern void add_target_sections (void *owner, struct target_section *sections, struct target_section *sections_end); +/* Add the sections of OBJFILE to the current set of target sections. + * OBJFILE owns the new target sections. */ + +extern void add_target_sections_of_objfile (struct objfile *objfile); + /* Prints info about all sections defined in the TABLE. ABFD is special cased --- it's filename is omitted; if it is the executable file, its entry point is printed. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 0318466..e0a234c 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -57,6 +57,7 @@ #include "stack.h" #include "gdb_bfd.h" #include "cli/cli-utils.h" +#include "target.h" #include #include @@ -2206,6 +2207,7 @@ add_symbol_file_command (char *args, int from_tty) int expecting_sec_name = 0; int expecting_sec_addr = 0; char **argv; + struct objfile *objf; struct sect_opt { @@ -2332,8 +2334,10 @@ add_symbol_file_command (char *args, int from_tty) if (from_tty && (!query ("%s", ""))) error (_("Not confirmed.")); - symbol_file_add (filename, from_tty ? SYMFILE_VERBOSE : 0, - section_addrs, flags); + objf = symbol_file_add (filename, from_tty ? SYMFILE_VERBOSE : 0, + section_addrs, flags); + + add_target_sections_of_objfile (objf); /* Getting new symbols may change our opinion about what is frameless. */ @@ -3819,11 +3823,23 @@ symfile_find_segment_sections (struct objfile *objfile) free_symfile_segment_data (data); } +/* Listen for free_objfile events. */ + +static void +symfile_free_objfile (struct objfile *objfile) +{ + /* Remove the target sections of user-added objfiles. */ + if (objfile != 0 && objfile->flags & OBJF_USERLOADED) + remove_target_sections ((void *) objfile); +} + void _initialize_symfile (void) { struct cmd_list_element *c; + observer_attach_free_objfile (symfile_free_objfile); + c = add_cmd ("symbol-file", class_files, symbol_file_command, _("\ Load symbol table from executable file FILE.\n\ The `file' command can also load symbol tables, as well as setting the file\n\ -- 1.7.6.5