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 #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, "", (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 #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)