Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Improve "start" command for Ada
@ 2004-10-21  3:48 Joel Brobecker
  2004-10-21  5:31 ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Joel Brobecker @ 2004-10-21  3:48 UTC (permalink / raw)
  To: gdb-patches

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

This is a followup on a thread started at:

        http://sources.redhat.com/ml/gdb-patches/2004-05/msg00521.html

It is the second part of the change that introduced the start
command, needed to make this command work for Ada. The principle
was sort of agreed on but it was a while ago, so things may have
changed. See:

        http://sources.redhat.com/ml/gdb-patches/2004-05/msg00618.html

Small refresher (it took me a while to collect all the elements of
the puzzle again):

        . Around the 20th of March 2004, I introduced a new command
          named "start". The implementation of this command was
          relying on a function called "main_name". At the time,
          this function was returning either the name of the main
          provided by STABS, or was defaulting to "main".

          The name of the main procedure in Ada changes from executable
          to executable, so this is not enough for Ada. But this Ada
          support was not activated then, we stopped there.

        . Now that Ada is activated, it is no longer enough for
          main_name to default to "main". So the intent was to
          later update that main_name() to search for the name of
          the main procedure a bit more precisely. And the approach
          selected was just to call language-specific procedures that
          would return either the name of the main procedure, or NULL
          if not found.

This is essentially what this patch does.

But on top of this, we have to be a bit careful, because the name
of the main program is cached, and we don't want to use an old name
incorrectly. So I added a small observer, that notifies us when the
executable file being debug changes, so that we can reset the cached
name.

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.
        * Makefile.in (exec.o): Add dependency on observer.h.
        (symtab.o): Likewise.

Tested on x86-linux. Fixes the failure that I introduced with
the patch I submitted for gdb.ada/null_record.exp (making the
expected output a bit more stringent on what we verify). See

        http://sources.redhat.com/ml/gdb-patches/2004-10/msg00350.html

OK to commit?

Thanks,
-- 
Joel

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

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 03:43:33 -0000
@@ -83,6 +83,10 @@ 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.
+@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: 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 03:43:35 -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: 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 03:43:35 -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: 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 03:43:38 -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)
@@ -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)

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2005-03-08  4:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-21  3:48 [RFA] Improve "start" command for Ada Joel Brobecker
2004-10-21  5:31 ` Eli Zaretskii
2004-10-21 21:09   ` Joel Brobecker
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox