Patchwork [PR,python/17936] Only emit one clear_objfiles event for main + separate debug file

login
register
mail settings
Submitter Doug Evans
Date Feb. 7, 2015, 12:51 a.m.
Message ID <yjt2twyyilxa.fsf@ruffy.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/4952/
State New
Headers show

Comments

Doug Evans - Feb. 7, 2015, 12:51 a.m.
Hi.

This patch fixes 17936 by moving the call to
observer_notify_new_objfile (NULL) up to a point before any
symbols are loaded.
This call triggers a "clear_objfiles" python event.
With current sources, when you load a binary with separate debug info
the following events are emitted:

1) clear_objfiles
2) new_objfile (separate_debug_file_of_main)
3) clear_objfiles
4) new_objfile (main_objfile)

This patch changes that to:

1) clear_objfiles
2) new_objfile (separate_debug_file_of_main)
3) new_objfile (main_objfile)

which is much easier for some of my python scripts to work with.

It also turns off SYMFILE_MAINLINE when loading separate debug files,
which removes clear_symtab_users processing for the separate debug
file of the main objfile. This call is unnecessary as it will be done
later for the main objfile itself.

It's odd that the new_objfile event for the separate debug file
goes out first before the new_objfile event for the "real" objfile,
but that's a separate PR 17937.

There is still an issue of SYMFILE_DEFER_BP_RESET processing for
separate debug files (there's no need to call breakpoint_re_set for
them, unless they're added through the gdb.Objfile.add_separate_debug_file
python function), but that's a separate issue, and not critical.

Regression tested on amd64-linux.

2015-02-06  Doug Evans  <dje@google.com>

	PR python/17936
	* symfile.c (symbol_file_add_with_addrs): Call
	observer_notify_new_objfile (NULL) early, before loading symbols.
	(symbol_file_add_separate): Turn off SYMFILE_MAINLINE when loading
	separate debug files.
	(clear_symtab_users): Don't call observer_notify_new_objfile (NULL)
	here if SYMFILE_MAINLINE.

Patch

diff --git a/gdb/symfile.c b/gdb/symfile.c
index c2a71ec..3171c2c 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1168,6 +1168,15 @@  symbol_file_add_with_addrs (bfd *abfd, const char *name, int add_flags,
       && !query (_("Load new symbol table from \"%s\"? "), name))
     error (_("Not confirmed."));
 
+  /* If mainline, send the new_objfile (NULL) notification now.
+     This is done here so that clients will see one event instead of one for
+     the main objfile and a second one for a possible separate debug file, and
+     will see the event before any objfiles are loaded including possible
+     separate debug files. Note that if there is a separate debug file, we
+     will end up back here from calling syms_from_objfile below.  PR 17936.  */
+  if (mainline)
+    observer_notify_new_objfile (NULL);
+
   objfile = allocate_objfile (abfd, name,
 			      flags | (mainline ? OBJF_MAINLINE : 0));
 
@@ -1260,7 +1269,7 @@  symbol_file_add_separate (bfd *bfd, const char *name, int symfile_flags,
   my_cleanup = make_cleanup_free_section_addr_info (sap);
 
   new_objfile = symbol_file_add_with_addrs
-    (bfd, name, symfile_flags, sap,
+    (bfd, name, symfile_flags & ~SYMFILE_MAINLINE, sap,
      objfile->flags & (OBJF_REORDERED | OBJF_SHARED | OBJF_READNOW
 		       | OBJF_USERLOADED),
      objfile);
@@ -3030,7 +3039,11 @@  clear_symtab_users (int add_flags)
   clear_displays ();
   clear_last_displayed_sal ();
   clear_pc_function_cache ();
-  observer_notify_new_objfile (NULL);
+
+  /* If this is the main objfile, the notification is sent out sooner,
+     by symbol_file_add_with_addrs.  PR 17936.  */
+  if ((add_flags & SYMFILE_MAINLINE) == 0)
+    observer_notify_new_objfile (NULL);
 
   /* Clear globals which might have pointed into a removed objfile.
      FIXME: It's not clear which of these are supposed to persist