From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31402 invoked by alias); 16 Apr 2013 07:52:28 -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 31320 invoked by uid 89); 16 Apr 2013 07:52:28 -0000 X-Spam-SWARE-Status: No, score=-6.1 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,TW_BJ,TW_GC,TW_RG autolearn=ham version=3.3.1 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 16 Apr 2013 07:52:27 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 16 Apr 2013 00:52:25 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 16 Apr 2013 00:52:24 -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 r3G7qNYB003735; Tue, 16 Apr 2013 08:52:23 +0100 Received: from ulslx001.iul.intel.com (localhost [127.0.0.1]) by ulslx001.iul.intel.com with ESMTP id r3G7qNX0018357; Tue, 16 Apr 2013 09:52:23 +0200 Received: (from nblanc@localhost) by ulslx001.iul.intel.com with id r3G7qNgB018353; Tue, 16 Apr 2013 09:52:23 +0200 From: Nicolas Blanc To: gdb-patches@sourceware.org Cc: Nicolas Blanc Subject: [PATCH 1/3] Command remove-symbol-file. Date: Tue, 16 Apr 2013 12:18:00 -0000 Message-Id: <1366098721-18302-3-git-send-email-nicolas.blanc@intel.com> In-Reply-To: <1366098721-18302-1-git-send-email-nicolas.blanc@intel.com> References: <1366098721-18302-1-git-send-email-nicolas.blanc@intel.com> X-SW-Source: 2013-04/txt/msg00460.txt.bz2 Added command remove-symbol-file for removing symbol files added via the add-symbol-file command. 2013-18-03 Nicolas Blanc * breakpoint.c (disable_breakpoints_in_free_objfile): Created function for disabling breakoints in objfiles upon FREE_OBJFILE notifications. * doc/observer.text: Created FREE_OBJFILE event. * objfiles.c (free_objfile): Notify FREE_OBJFILE. * printcmd.c (clear_dangling_display_expressions): Act upon FREE_OBJFILE events instead of SOLIB_UNLOADED events. (_initialize_printcmd): Register observer for FREE_OBJFILE instead of SOLIB_UNLOADED notifications. * solib.c (remove_user_added_objfile): Created function for removing dangling references upon notification of FREE_OBJFILE. * symfile.c (add_symbol_file_command): Set OBJFILE->LOW_ADDRESS. (remove_symbol_file_command): Created command for removing symbol files. (_initialize_symfile): Added remove-symbol-file. Signed-off-by: Nicolas Blanc --- gdb/breakpoint.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++-- gdb/doc/observer.texi | 4 +++ gdb/objfiles.c | 3 ++ gdb/printcmd.c | 11 ++++---- gdb/solib.c | 26 +++++++++++++++++++ gdb/symfile.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 163 insertions(+), 9 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 09933f4..b09049e 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -7430,9 +7430,9 @@ disable_breakpoints_in_shlibs (void) } } -/* Disable any breakpoints and tracepoints that are in an unloaded shared - library. Only apply to enabled breakpoints, disabled ones can just stay - disabled. */ +/* Disable any breakpoints and tracepoints that are in SOLIB upon + notification of UNLOADED_SHLIB. Only apply to enabled breakpoints, + disabled ones can just stay disabled. */ static void disable_breakpoints_in_unloaded_shlib (struct so_list *solib) @@ -7484,6 +7484,64 @@ disable_breakpoints_in_unloaded_shlib (struct so_list *solib) } } +/* Disable any breakpoints and tracepoints in OBJFILE upon + notification of FREE_OBJFILE. Only apply to enabled breakpoints, + disabled ones can just stay disabled. */ + +static void +disable_breakpoints_in_free_objfile (struct objfile * objfile) +{ + struct bp_location *loc, **locp_tmp; + + if (objfile == NULL) + return; + + /* If the file is a shared library not loaded by the user then + SOLIB_UNLOADED was notified and DISABLE_BREAKPIONTS_IN_UNLOADED_SHLIB + was called. In that case there is no need to take action again. */ + if ((objfile->flags & OBJF_SHARED) && !(objfile->flags & OBJF_USERLOADED)) + return; + + ALL_BP_LOCATIONS (loc, locp_tmp) + { + struct obj_section *osect; + CORE_ADDR loc_addr = loc->address; + + /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ + struct breakpoint *b = loc->owner; + + if (loc->shlib_disabled != 0) + continue; + + if (objfile->pspace != loc->pspace) + continue; + + if (!is_tracepoint(b)) + { + if (b->type != bp_breakpoint + && b->type != bp_jit_event + && b->type != bp_hardware_breakpoint) + continue; + + if (loc->loc_type != bp_loc_hardware_breakpoint + && loc->loc_type != bp_loc_software_breakpoint) + continue; + } + + ALL_OBJFILE_OSECTIONS (objfile, osect) + { + if (obj_section_addr (osect) <= loc_addr + && loc_addr < obj_section_endaddr (osect)) + { + loc->shlib_disabled = 1; + loc->inserted = 0; + observer_notify_breakpoint_modified (loc->owner); + break; + } + } + } +} + /* FORK & VFORK catchpoints. */ /* An instance of this type is used to represent a fork or vfork @@ -16030,6 +16088,7 @@ _initialize_breakpoint (void) initialize_breakpoint_ops (); observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); + observer_attach_free_objfile (disable_breakpoints_in_free_objfile); observer_attach_inferior_exit (clear_syscall_counts); observer_attach_memory_changed (invalidate_bp_value_on_memory_change); diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi index adb7085..7b420ea 100644 --- a/gdb/doc/observer.texi +++ b/gdb/doc/observer.texi @@ -138,6 +138,10 @@ Called with @var{objfile} equal to @code{NULL} to indicate previously loaded symbol table data has now been invalidated. @end deftypefun +@deftypefun void free_objfile (struct objfile *@var{objfile}) +The symbol file specified by @var{objfile} is about to be freed. +@end deftypefun + @deftypefun void new_thread (struct thread_info *@var{t}) The thread specified by @var{t} has been created. @end deftypefun diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 93b7ba7..0a0c2c0 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -530,6 +530,9 @@ free_objfile_separate_debug (struct objfile *objfile) void free_objfile (struct objfile *objfile) { + /* First notify observers that this objfile is about to be freed. */ + observer_notify_free_objfile (objfile); + /* Free all separate debug objfiles. */ free_objfile_separate_debug (objfile); diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 4f8c9d4..0165487 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1928,21 +1928,22 @@ disable_display_command (char *args, int from_tty) an item by re-parsing .exp_string field in the new execution context. */ static void -clear_dangling_display_expressions (struct so_list *solib) +clear_dangling_display_expressions (struct objfile *objfile) { - struct objfile *objfile = solib->objfile; struct display *d; + struct program_space *pspace; /* With no symbol file we cannot have a block or expression from it. */ if (objfile == NULL) return; + pspace = objfile->pspace; if (objfile->separate_debug_objfile_backlink) objfile = objfile->separate_debug_objfile_backlink; - gdb_assert (objfile->pspace == solib->pspace); + gdb_assert (objfile->pspace == pspace); for (d = display_chain; d != NULL; d = d->next) { - if (d->pspace != solib->pspace) + if (d->pspace != pspace) continue; if (lookup_objfile_from_block (d->block) == objfile @@ -2474,7 +2475,7 @@ _initialize_printcmd (void) current_display_number = -1; - observer_attach_solib_unloaded (clear_dangling_display_expressions); + observer_attach_free_objfile (clear_dangling_display_expressions); add_info ("address", address_info, _("Describe where symbol SYM is stored.")); diff --git a/gdb/solib.c b/gdb/solib.c index 8129c0f..c528f87 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1448,6 +1448,30 @@ gdb_bfd_lookup_symbol (bfd *abfd, return symaddr; } +/* Upon notification of FREE_OBJFILE remove any reference + to any user-added file that is about to be freed. */ +static void +remove_user_added_objfile (struct objfile *objfile) +{ + struct so_list *gdb; + + if (!objfile) + return; + + if (!(objfile->flags & OBJF_USERLOADED) + || !(objfile->flags & OBJF_SHARED)) + return; + + gdb = so_list_head; + while (gdb) + { + if (gdb->objfile == objfile) + gdb->objfile = NULL; + gdb = gdb->next; + } +} + + extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */ void @@ -1455,6 +1479,8 @@ _initialize_solib (void) { solib_data = gdbarch_data_register_pre_init (solib_init); + observer_attach_free_objfile (remove_user_added_objfile); + add_com ("sharedlibrary", class_files, sharedlibrary_command, _("Load shared object library symbols for files matching REGEXP.")); add_info ("sharedlibrary", info_sharedlibrary_command, diff --git a/gdb/symfile.c b/gdb/symfile.c index 3e66bd1..94013c0 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -91,6 +91,8 @@ static void symbol_file_add_main_1 (char *args, int from_tty, int flags); static void add_symbol_file_command (char *, int); +static void remove_symbol_file_command (char *, int); + bfd *symfile_bfd_open (char *); int get_section_index (struct objfile *, char *); @@ -2219,6 +2221,8 @@ add_symbol_file_command (char *args, int from_tty) int expecting_sec_name = 0; int expecting_sec_addr = 0; char **argv; + CORE_ADDR addr_low = 0; + struct objfile *objf; struct sect_opt { @@ -2267,6 +2271,7 @@ add_symbol_file_command (char *args, int from_tty) num_sect_opts * sizeof (struct sect_opt))); } + addr_low = parse_and_eval_address (arg); } else { @@ -2354,9 +2359,12 @@ 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, + objf = symbol_file_add (filename, from_tty ? SYMFILE_VERBOSE : 0, section_addrs, flags); + /* Set the low address of the object for identification. */ + objf->addr_low = addr_low; + /* Getting new symbols may change our opinion about what is frameless. */ reinit_frame_cache (); @@ -2364,6 +2372,54 @@ add_symbol_file_command (char *args, int from_tty) } + +/* This function removes a symbol file that was added via add-symbol-file. */ +static void +remove_symbol_file_command (char *args, int from_tty) +{ + char **argv; + char *arg; + int argcnt; + struct cleanup *my_cleanups; + CORE_ADDR addr = 0; + struct objfile* objf; + + dont_repeat (); + + if (args == NULL) + error (_("remove-symbol-file takes an address as parameter.")); + + my_cleanups = make_cleanup (null_cleanup, NULL); + + argv = gdb_buildargv (args); + make_cleanup_freeargv (argv); + + for (arg = argv[0], argcnt = 0; arg != NULL; arg = argv[++argcnt]) + { + if (argcnt == 0) + addr = parse_and_eval_address (arg); + else + error (_("USAGE: remove-symbol-file ")); + } + + + ALL_OBJFILES (objf) + { + if (objf->flags & OBJF_USERLOADED && objf->addr_low == addr) + break; + } + + if (!objf) + error (_("no user-added symbol file for address 0x%s"), + phex_nz(addr, sizeof(addr))); + + free_objfile (objf); + clear_symtab_users (0); + + do_cleanups (my_cleanups); +} + + typedef struct objfile *objfilep; DEF_VEC_P (objfilep); @@ -3777,6 +3833,11 @@ with the text. SECT is a section name to be loaded at SECT_ADDR."), &cmdlist); set_cmd_completer (c, filename_completer); + c = add_cmd ("remove-symbol-file", class_files, remove_symbol_file_command, _("\ +Remove a symbol file loaded via the add-symbol-file command.\n\ +Usage: remove-symbol-file START_ADDR.\nSTART_ADDR is the start address \ +of the module to remove."), &cmdlist); + c = add_cmd ("load", class_files, load_command, _("\ Dynamically load FILE into the running program, and record its symbols\n\ for access from GDB.\n\ -- 1.7.6.5