This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2 1/3] Added command remove-symbol-file.


Added command remove-symbol-file for removing
symbol files added via the add-symbol-file command.

2013-18-03  Nicolas Blanc  <nicolas.blanc@intel.com>

	* breakpoint.c (disable_breakpoints_in_free_objfile): Created
	function for disabling breakoints in objfiles upon FREE_OBJFILE
	notifications.
	* 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.
gdb/doc
	* observer.texi: Created FREE_OBJFILE event.

Signed-off-by: Nicolas Blanc <nicolas.blanc@intel.com>
---
 gdb/breakpoint.c      |   65 ++++++++++++++++++++++++++++++++++++++++++++++---
 gdb/doc/observer.texi |    4 +++
 gdb/objfiles.c        |    3 +++
 gdb/printcmd.c        |   15 +++++++-----
 gdb/solib.c           |   27 ++++++++++++++++++++
 gdb/symfile.c         |   64 +++++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 168 insertions(+), 10 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index f155b9e..b2cf1b4 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -7429,9 +7429,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)
@@ -7483,6 +7483,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
@@ -15887,6 +15945,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..f753965 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 object 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 2cc33d0..bd4bd42 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1928,21 +1928,24 @@ 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);
+    {
+      objfile = objfile->separate_debug_objfile_backlink;
+      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 +2477,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 319538f..5a547da 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1443,6 +1443,31 @@ 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
@@ -1450,6 +1475,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..18c4b4e 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,55 @@ 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 <text_low_address>"));
+    }
+
+
+  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 +3834,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.10.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]