From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21007 invoked by alias); 17 Jul 2013 16:28:10 -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 20992 invoked by uid 89); 17 Jul 2013 16:28:10 -0000 X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL,BAYES_05,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RDNS_NONE,TW_BJ autolearn=no version=3.3.1 Received: from Unknown (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 17 Jul 2013 16:28:09 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 17 Jul 2013 09:27:48 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 17 Jul 2013 09:27:46 -0700 Received: from ulslx001.iul.intel.com (ulslx001.iul.intel.com [172.28.207.63]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id r6HGRjGC027836; Wed, 17 Jul 2013 17:27:46 +0100 Received: from ulslx001.iul.intel.com (localhost [127.0.0.1]) by ulslx001.iul.intel.com with ESMTP id r6HGRjYD000974; Wed, 17 Jul 2013 18:27:45 +0200 Received: (from nblanc@localhost) by ulslx001.iul.intel.com with id r6HGRjCk000970; Wed, 17 Jul 2013 18:27:45 +0200 From: Nicolas Blanc To: gdb-patches@sourceware.org, dje@google.com Cc: nicolas.blanc@intel.com Subject: [PATCH v12 3/5] 'add-symbol-file' should update the current target sections. Date: Wed, 17 Jul 2013 16:28:00 -0000 Message-Id: <1374078455-906-4-git-send-email-nicolas.blanc@intel.com> In-Reply-To: <1374078455-906-1-git-send-email-nicolas.blanc@intel.com> References: <1374078455-906-1-git-send-email-nicolas.blanc@intel.com> X-SW-Source: 2013-07/txt/msg00396.txt.bz2 2013-17-06 Nicolas Blanc * symfile.c (add_target_sections_of_objfile): New function. (add_symbol_file_command): Update the current target sections. (symfile_free_objfile): New function. (_initialize_symfile): Attach observer for free_objfile. Signed-off-by: Nicolas Blanc --- gdb/symfile.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 66 insertions(+), 2 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index dbcccd3..96d9cdc 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 @@ -2158,6 +2159,51 @@ print_transfer_performance (struct ui_file *stream, ui_out_text (uiout, ".\n"); } +/* Add the sections of OBJFILE to the current set of target sections. */ + +static 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->key = (void *) objfile; + + ts++; + } +} + /* This function allows the addition of incrementally linked object files. It does not modify any state in the target, only in the debugger. */ /* Note: ezannoni 2000-04-13 This function/command used to have a @@ -2181,6 +2227,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 { @@ -2316,8 +2363,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. */ @@ -3792,11 +3841,26 @@ 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) +{ + if (objfile == NULL) + return; + + /* Remove the target sections of user-added objfiles. */ + if (objfile->flags & OBJF_USERLOADED && objfile->obfd) + remove_target_sections ((void*)objfile, objfile->obfd); +} + 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