eb9d945
2007-10-29  Jan Kratochvil  <jan.kratochvil@redhat.com>
eb9d945
eb9d945
	* symfile.c (reread_symbols): Reread also EXEC_BFD if changed.
eb9d945
eb9d945
Testcase: Regressed by the gdb-6.7 version of `gdb-6.3-pie-20050110.patch':
eb9d945
 Running ../../../gdb/testsuite/gdb.base/reread.exp ...
eb9d945
 PASS: gdb.base/reread.exp: breakpoint foo in first file (PRMS 13484)
eb9d945
 PASS: gdb.base/reread.exp: run to foo() (PRMS 13484)
eb9d945
-PASS: gdb.base/reread.exp: run to foo() second time
eb9d945
+FAIL: gdb.base/reread.exp: run to foo() second time
eb9d945
 PASS: gdb.base/reread.exp: second pass: breakpoint foo in first file
eb9d945
-PASS: gdb.base/reread.exp: second pass: run to foo()
eb9d945
-PASS: gdb.base/reread.exp: second pass: continue to completion
eb9d945
-PASS: gdb.base/reread.exp: second pass: run to foo() second time
eb9d945
+FAIL: gdb.base/reread.exp: second pass: run to foo()
eb9d945
+FAIL: gdb.base/reread.exp: second pass: continue to completion
eb9d945
+FAIL: gdb.base/reread.exp: second pass: run to foo() second time
eb9d945
eb9d945
--- gdb-6.7-orig/gdb/symfile.c	2007-10-29 01:04:35.000000000 +0100
eb9d945
+++ gdb-6.7-patched/gdb/symfile.c	2007-10-29 01:03:13.000000000 +0100
eb9d945
@@ -2810,6 +2810,33 @@ reread_symbols (void)
eb9d945
 	      /* We need to do this whenever any symbols go away.  */
eb9d945
 	      make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
eb9d945
 
eb9d945
+	      if (exec_bfd != NULL && strcmp (bfd_get_filename (objfile->obfd),
eb9d945
+					      bfd_get_filename (exec_bfd)) == 0)
eb9d945
+		{
eb9d945
+		  char *exec_filename = bfd_get_filename (exec_bfd);
eb9d945
+		  bfd *exec_bfd_new;
eb9d945
+
eb9d945
+		  /* We have to leak the memory here as there are stale
eb9d945
+		     references to EXEC_BFD, at least by
eb9d945
+		     `(struct section_table *)->bfd'.  So far we need to update
eb9d945
+		     only START_ADDRESS there.  */
eb9d945
+#if 0
eb9d945
+		  if (!bfd_close (exec_bfd))
eb9d945
+		    error (_("Can't close BFD for %s: %s"), exec_filename,
eb9d945
+			   bfd_errmsg (bfd_get_error ()));
eb9d945
+#endif
eb9d945
+		  exec_bfd_new = bfd_openr (exec_filename, gnutarget);
eb9d945
+		  if (exec_bfd_new == NULL)
eb9d945
+		    error (_("Can't open %s as a new main executable."),
eb9d945
+			   exec_filename);
eb9d945
+		  /* bfd_openr sets cacheable to true, which is what we want.  */
eb9d945
+		  if (!bfd_check_format (exec_bfd_new, bfd_object))
eb9d945
+		    error (_("Can't reopen the main executable %s: %s."),
eb9d945
+			   exec_filename, bfd_errmsg (bfd_get_error ()));
eb9d945
+		  /* FIXME: The non-freeing hack.  */
eb9d945
+		  memcpy (exec_bfd, exec_bfd_new, sizeof (*exec_bfd));
eb9d945
+		}
eb9d945
+
eb9d945
 	      /* Clean up any state BFD has sitting around.  We don't need
eb9d945
 	         to close the descriptor but BFD lacks a way of closing the
eb9d945
 	         BFD without closing the descriptor.  */