Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@gnat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFA] Improve "start" command for Ada
Date: Thu, 21 Oct 2004 21:09:00 -0000	[thread overview]
Message-ID: <20041021210951.GZ21300@gnat.com> (raw)
In-Reply-To: <01c4b72e$Blat.v2.2.2$b14feb80@zahav.net.il>

[-- Attachment #1: Type: text/plain, Size: 1383 bytes --]

> > +@deftypefun void executable_changed (void *@var{unused_args})
> > +The executable being debugged by GDB has changed.
> > +@end deftypefun
> 
> This is not clear enough: what does it mean ``the executable has
> changed''?  Did its file name change? what if its the same program,
> but it was recompiled and its debugging session restarted?

That's a very good point, which pointed at something I didn't consider
when I first wrote the patch: The signal needs to be sent when the
program has been recompiled, or course. Is this version better?

2004-10-20  Joel Brobecker  <brobecker@gnat.com>

        * doc/observer.texi (executable_changed): New observer.
        * symtab.c: Include "observer.h".
        (find_main_name): New function.
        (main_name): If name_of_main is unset, then compute it
        using find_main_name.
        (symtab_observer_executable_changed): New function.
        (_initialize_symtab): Attach executable_changed observer.
        * exec.c: Include "observer.h".
        (exec_file_attach): Emit executable_changed notification.
        * symfile.c: Include "observer.h".
        (reread_symbols): Send an executable_changed if appropriate.
        * Makefile.in (exec.o): Add dependency on observer.h.
        (symfile.o): Likewise.
        (symtab.o): Likewise.

Tested on x86-linux. Still fixes 1 FAIL in gdb.ada/null_record.exp.

-- 
Joel

[-- Attachment #2: find_main_name.diff --]
[-- Type: text/plain, Size: 5965 bytes --]

Index: exec.c
===================================================================
RCS file: /cvs/src/src/gdb/exec.c,v
retrieving revision 1.43
diff -u -p -r1.43 exec.c
--- exec.c	8 Oct 2004 20:29:46 -0000	1.43
+++ exec.c	21 Oct 2004 20:57:08 -0000
@@ -32,6 +32,7 @@
 #include "completer.h"
 #include "value.h"
 #include "exec.h"
+#include "observer.h"
 
 #include <fcntl.h>
 #include "readline/readline.h"
@@ -268,6 +269,7 @@ exec_file_attach (char *filename, int fr
 	(*deprecated_exec_file_display_hook) (filename);
     }
   bfd_cache_close_all ();
+  observer_notify_executable_changed (NULL);
 }
 
 /*  Process the first arg in ARGS as the new exec file.
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.143
diff -u -p -r1.143 symfile.c
--- symfile.c	1 Oct 2004 10:23:09 -0000	1.143
+++ symfile.c	21 Oct 2004 20:59:03 -0000
@@ -48,6 +48,7 @@
 #include "readline/readline.h"
 #include "gdb_assert.h"
 #include "block.h"
+#include "observer.h"
 
 #include <sys/types.h>
 #include <fcntl.h>
@@ -1990,7 +1991,13 @@ reread_symbols (void)
     }
 
   if (reread_one)
-    clear_symtab_users ();
+    {
+      clear_symtab_users ();
+      /* At least one objfile has changed, so we can consider that
+         the executable we're debugging has changed too.  */
+      observer_notify_executable_changed (NULL);
+    }
+      
 }
 
 
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.140
diff -u -p -r1.140 symtab.c
--- symtab.c	2 Oct 2004 09:55:15 -0000	1.140
+++ symtab.c	21 Oct 2004 20:59:05 -0000
@@ -55,6 +55,7 @@
 #include "gdb_stat.h"
 #include <ctype.h>
 #include "cp-abi.h"
+#include "observer.h"
 
 /* Prototypes for local functions */
 
@@ -4090,15 +4091,44 @@ set_main_name (const char *name)
     }
 }
 
+/* Deduce the name of the main procedure, and set NAME_OF_MAIN
+   accordingly.  */
+
+static void
+find_main_name (void)
+{
+  char *new_main_name;
+
+  /* Try to see if the main procedure is in Ada.  */
+  new_main_name = ada_main_name ();
+  if (new_main_name != NULL)
+    { 
+      set_main_name (new_main_name);
+      return;
+    }
+
+  /* The languages above didn't identify the name of the main procedure.
+     Fallback to "main".  */
+  set_main_name ("main");
+}
+
 char *
 main_name (void)
 {
-  if (name_of_main != NULL)
-    return name_of_main;
-  else
-    return "main";
+  if (name_of_main == NULL)
+    find_main_name ();
+
+  return name_of_main;
 }
 
+/* Handle ``executable_changed'' events for the symtab module.  */
+
+static void
+symtab_observer_executable_changed (void *unused)
+{
+  /* NAME_OF_MAIN may no longer be the same, so reset it for now.  */
+  set_main_name (NULL);
+}
 
 void
 _initialize_symtab (void)
@@ -4140,4 +4170,6 @@ _initialize_symtab (void)
   /* Initialize the one built-in type that isn't language dependent... */
   builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
 				  "<unknown type>", (struct objfile *) NULL);
+
+  observer_attach_executable_changed (symtab_observer_executable_changed);
 }
Index: doc/observer.texi
===================================================================
RCS file: /cvs/src/src/gdb/doc/observer.texi,v
retrieving revision 1.8
diff -u -p -r1.8 observer.texi
--- doc/observer.texi	1 Sep 2004 17:59:37 -0000	1.8
+++ doc/observer.texi	21 Oct 2004 20:59:52 -0000
@@ -83,6 +83,13 @@ The inferior has stopped for real.
 The target's register contents have changed.
 @end deftypefun
 
+@deftypefun void executable_changed (void *@var{unused_args})
+The executable being debugged by GDB has changed: The user decided
+to debug a different program, or the program he was debugging has
+been modified since being loaded by the debugger (by being recompiled,
+for instance).
+@end deftypefun
+
 @deftypefun void inferior_created (struct target_ops *@var{objfile}, int @var{from_tty})
 @value{GDBN} has just connected to an inferior.  For @samp{run},
 @value{GDBN} calls this observer while the inferior is still stopped
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.643
diff -u -p -r1.643 Makefile.in
--- Makefile.in	15 Oct 2004 16:17:34 -0000	1.643
+++ Makefile.in	21 Oct 2004 21:08:16 -0000
@@ -1887,7 +1887,7 @@ event-top.o: event-top.c $(defs_h) $(top
 exec.o: exec.c $(defs_h) $(frame_h) $(inferior_h) $(target_h) $(gdbcmd_h) \
 	$(language_h) $(symfile_h) $(objfiles_h) $(completer_h) $(value_h) \
 	$(exec_h) $(readline_h) $(gdb_string_h) $(gdbcore_h) $(gdb_stat_h) \
-	$(xcoffsolib_h)
+	$(xcoffsolib_h) $(observer_h)
 expprint.o: expprint.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \
 	$(value_h) $(language_h) $(parser_defs_h) $(user_regs_h) $(target_h) \
 	$(gdb_string_h) $(block_h)
@@ -2598,7 +2598,7 @@ symfile.o: symfile.c $(defs_h) $(bfdlink
 	$(complaints_h) $(demangle_h) $(inferior_h) $(filenames_h) \
 	$(gdb_stabs_h) $(gdb_obstack_h) $(completer_h) $(bcache_h) \
 	$(hashtab_h) $(readline_h) $(gdb_assert_h) $(block_h) \
-	$(gdb_string_h) $(gdb_stat_h)
+	$(gdb_string_h) $(gdb_stat_h) $(observer_h)
 symfile-mem.o: symfile-mem.c $(defs_h) $(symtab_h) $(gdbcore_h) \
 	$(objfiles_h) $(gdbcmd_h) $(target_h) $(value_h) $(symfile_h)
 symmisc.o: symmisc.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(bfd_h) \
@@ -2611,7 +2611,7 @@ symtab.o: symtab.c $(defs_h) $(symtab_h)
 	$(language_h) $(demangle_h) $(inferior_h) $(linespec_h) $(source_h) \
 	$(filenames_h) $(objc_lang_h) $(ada_lang_h) $(hashtab_h) \
 	$(gdb_obstack_h) $(block_h) $(dictionary_h) $(gdb_string_h) \
-	$(gdb_stat_h) $(cp_abi_h)
+	$(gdb_stat_h) $(cp_abi_h) $(observer_h)
 target.o: target.c $(defs_h) $(gdb_string_h) $(target_h) $(gdbcmd_h) \
 	$(symtab_h) $(inferior_h) $(bfd_h) $(symfile_h) $(objfiles_h) \
 	$(gdb_wait_h) $(dcache_h) $(regcache_h) $(gdb_assert_h) $(gdbcore_h)

  reply	other threads:[~2004-10-21 21:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-21  3:48 Joel Brobecker
2004-10-21  5:31 ` Eli Zaretskii
2004-10-21 21:09   ` Joel Brobecker [this message]
2004-10-23 10:05     ` Eli Zaretskii
2004-11-01 19:47     ` Joel Brobecker
2004-11-29  2:12       ` Elena Zannoni
2004-12-01  3:03         ` Joel Brobecker
2005-02-09 18:22           ` Joel Brobecker
2005-03-07 19:30             ` Joel Brobecker
2005-03-07 20:59               ` Elena Zannoni
2005-03-07 21:12                 ` Joel Brobecker
2005-03-08  4:40                 ` Joel Brobecker
2004-11-22 19:10     ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041021210951.GZ21300@gnat.com \
    --to=brobecker@gnat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox