From mboxrd@z Thu Jan 1 00:00:00 1970 From: Randolph Chung To: gdb-patches@sources.redhat.com Subject: [patch/rfc] New program_changed event, cleanup some HPUXHPPA mess Date: Wed, 19 May 2004 20:40:00 -0000 Message-id: <20040519204003.GU566@tausq.org> X-SW-Source: 2004-05/msg00581.html This patch introduces a new event that gets triggered when a new program is being debugged. It then uses this to fix some FIXMEs in the hppa tdep code, and remove some #ifdef HPUXHPPA's that are scattered in arch-indep code. There is also one unrelated HPUXHPPA cleanup in thread.c. The old code used to do: #ifdef HPUXHPPA printf_filtered ("%d %s", tp->num, target_tid_to_str (tp->ptid)); #else printf_filtered ("%d %s", tp->num, target_pid_to_str (tp->ptid)); #endif tm-hppah.h overrode target_tid_to_str to do it's own thing. The default target.h definition checks to see if there's a target_tid_to_str define, and if not automatically reverts to target_pid_to_str, so the #ifdef here is useless. Tested on hppa-linux and hppa2.0w-hp-hpux11.11 with no regressions. Comments? randolph 2004-05-18 Randolph Chung * Makefile.in (hppa-hpux-tdep.o, hppa-tdep.o, symfile.o): Update dependency. * hppa-hpux-tdep.c (hppa32_hpux_in_solib_call_trampoline): Use dyncall and sr4export addresses from tdep structure. (hppa_hpux_skip_trampoline_code): Likewise. (hp_cxx_exception_support_initialized): Make static. (hppa_hpux_observer_program_changed): New function; reset hp compiler flags when new file is loaded. (_initialize_hppa_hpux_tdep): Register for program change notification. * hppa-linux-tdep.c (hppa_linux_in_dyncall): Use dyncall address from tdep structure. * hppa-tdep.c: Include observer.h (hppa_observer_program_changed): New function; listen to program change notification and update addresses in tdep structure. (_initialize_hppa_tdep): Register for program change notification. * hppa-tdep.h (struct gdbarch_tdep): Add dyncall, dyncall_external and sr4export variables. * symfile.c: Include observer.h, remove HPUXHPPA-specific code. (symbol_file_add_main_1): Remove HPUXHPPA-specific code; notify observers when a new symbol file has been loaded. (symbol_file_clear, reread_symbols): Remove HPUXHPPA-specific code. * thread.c (info_threads_command, thread_apply_all_command) (thread_apply_command, thread_command, do_captured_thread_select): Remove HPUXHPPA-specific code. * doc/observer.texi (program_changed): Document new event. Index: Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.572 diff -u -p -r1.572 Makefile.in --- Makefile.in 17 May 2004 15:16:39 -0000 1.572 +++ Makefile.in 19 May 2004 06:22:38 -0000 @@ -1829,12 +1829,12 @@ hppah-nat.o: hppah-nat.c $(defs_h) $(inf $(gdb_wait_h) $(regcache_h) $(gdb_string_h) $(infttrace_h) \ $(hppa_tdep_h) hppa-hpux-tdep.o: hppa-hpux-tdep.c $(defs_h) $(arch_utils_h) $(gdbcore_h) \ - $(osabi_h) $(gdb_string_h) $(frame_h) $(hppa_tdep_h) + $(osabi_h) $(gdb_string_h) $(frame_h) $(hppa_tdep_h) $(observer_h) hppa-tdep.o: hppa-tdep.c $(defs_h) $(frame_h) $(bfd_h) $(inferior_h) \ $(regcache_h) $(completer_h) $(osabi_h) $(gdb_assert_h) \ $(arch_utils_h) $(symtab_h) $(dis_asm_h) $(trad_frame_h) \ $(frame_unwind_h) $(frame_base_h) $(gdbcore_h) $(gdbcmd_h) \ - $(symfile_h) $(objfiles_h) $(hppa_tdep_h) + $(symfile_h) $(objfiles_h) $(hppa_tdep_h) $(observer_h) hppa-linux-tdep.o: hppa-linux-tdep.c $(defs_h) $(gdbcore_h) $(osabi_h) \ $(target_h) $(objfiles_h) $(solib_svr4_h) $(glibc_tdep_h) \ $(frame_unwind_h) $(trad_frame_h) $(dwarf2_frame_h) $(hppa_tdep_h) \ @@ -2430,7 +2430,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) \ $(symfile_mem_h) Index: hppa-hpux-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/hppa-hpux-tdep.c,v retrieving revision 1.18 diff -u -p -r1.18 hppa-hpux-tdep.c --- hppa-hpux-tdep.c 7 May 2004 05:48:48 -0000 1.18 +++ hppa-hpux-tdep.c 19 May 2004 06:22:38 -0000 @@ -174,32 +174,12 @@ hppa32_hpux_in_solib_call_trampoline (CO { struct minimal_symbol *minsym; struct unwind_table_entry *u; - static CORE_ADDR dyncall = 0; - static CORE_ADDR sr4export = 0; + struct gdbarch_tdep *tdep; - /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a - new exec file */ + tdep = gdbarch_tdep (current_gdbarch); /* First see if PC is in one of the two C-library trampolines. */ - if (!dyncall) - { - minsym = lookup_minimal_symbol ("$$dyncall", NULL, NULL); - if (minsym) - dyncall = SYMBOL_VALUE_ADDRESS (minsym); - else - dyncall = -1; - } - - if (!sr4export) - { - minsym = lookup_minimal_symbol ("_sr4export", NULL, NULL); - if (minsym) - sr4export = SYMBOL_VALUE_ADDRESS (minsym); - else - sr4export = -1; - } - - if (pc == dyncall || pc == sr4export) + if (pc == tdep->dyncall || pc == tdep->sr4export) return 1; minsym = lookup_minimal_symbol_by_pc (pc); @@ -408,45 +388,15 @@ hppa_hpux_skip_trampoline_code (CORE_ADD { long orig_pc = pc; long prev_inst, curr_inst, loc; - static CORE_ADDR dyncall = 0; - static CORE_ADDR dyncall_external = 0; - static CORE_ADDR sr4export = 0; struct minimal_symbol *msym; struct unwind_table_entry *u; + struct gdbarch_tdep *tdep; - /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a - new exec file */ - - if (!dyncall) - { - msym = lookup_minimal_symbol ("$$dyncall", NULL, NULL); - if (msym) - dyncall = SYMBOL_VALUE_ADDRESS (msym); - else - dyncall = -1; - } - - if (!dyncall_external) - { - msym = lookup_minimal_symbol ("$$dyncall_external", NULL, NULL); - if (msym) - dyncall_external = SYMBOL_VALUE_ADDRESS (msym); - else - dyncall_external = -1; - } - - if (!sr4export) - { - msym = lookup_minimal_symbol ("_sr4export", NULL, NULL); - if (msym) - sr4export = SYMBOL_VALUE_ADDRESS (msym); - else - sr4export = -1; - } + tdep = gdbarch_tdep (current_gdbarch); /* Addresses passed to dyncall may *NOT* be the actual address of the function. So we may have to do something special. */ - if (pc == dyncall) + if (pc == tdep->dyncall) { pc = (CORE_ADDR) read_register (22); @@ -456,12 +406,12 @@ hppa_hpux_skip_trampoline_code (CORE_ADD if (pc & 0x2) pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8); } - if (pc == dyncall_external) + if (pc == tdep->dyncall_external) { pc = (CORE_ADDR) read_register (22); pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8); } - else if (pc == sr4export) + else if (pc == tdep->sr4export) pc = (CORE_ADDR) (read_register (22)); /* Get the unwind descriptor corresponding to PC, return zero @@ -701,7 +651,7 @@ __eh_notification; /* Is exception-handling support available with this executable? */ static int hp_cxx_exception_support = 0; /* Has the initialize function been run? */ -int hp_cxx_exception_support_initialized = 0; +static int hp_cxx_exception_support_initialized = 0; /* Address of __eh_notify_hook */ static CORE_ADDR eh_notify_hook_addr = 0; /* Address of __d_eh_notify_callback */ @@ -1257,6 +1207,18 @@ hppa_hpux_elf_init_abi (struct gdbarch_i hppa_hpux_init_abi (info, gdbarch); } +static void +hppa_hpux_observer_program_changed (const char *filename) +{ + /* Some HP-UX related globals to clear when a new "main" + symbol file is loaded. HP-specific. */ + + /* Indicates HP-compiled code. */ + deprecated_hp_som_som_object_present = 0; + /* Must reinitialize exception stuff. */ + hp_cxx_exception_support_initialized = 0; +} + void _initialize_hppa_hpux_tdep (void) { @@ -1264,4 +1226,6 @@ _initialize_hppa_hpux_tdep (void) hppa_hpux_som_init_abi); gdbarch_register_osabi (bfd_arch_hppa, bfd_mach_hppa20w, GDB_OSABI_HPUX_ELF, hppa_hpux_elf_init_abi); + observer_attach_program_changed (hppa_hpux_observer_program_changed); + } Index: hppa-linux-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/hppa-linux-tdep.c,v retrieving revision 1.5 diff -u -p -r1.5 hppa-linux-tdep.c --- hppa-linux-tdep.c 8 May 2004 03:59:34 -0000 1.5 +++ hppa-linux-tdep.c 19 May 2004 06:22:38 -0000 @@ -161,21 +161,10 @@ insns_match_pattern (CORE_ADDR pc, static int hppa_linux_in_dyncall (CORE_ADDR pc) { - static CORE_ADDR dyncall = 0; + struct gdbarch_tdep *tdep; + tdep = gdbarch_tdep (current_gdbarch); - /* FIXME: if we switch exec files, dyncall should be reinitialized */ - if (!dyncall) - { - struct minimal_symbol *minsym; - - minsym = lookup_minimal_symbol ("$$dyncall", NULL, NULL); - if (minsym) - dyncall = SYMBOL_VALUE_ADDRESS (minsym); - else - dyncall = -1; - } - - return pc == dyncall; + return pc == tdep->dyncall; } /* There are several kinds of "trampolines" that we need to deal with: Index: hppa-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/hppa-tdep.c,v retrieving revision 1.162 diff -u -p -r1.162 hppa-tdep.c --- hppa-tdep.c 19 May 2004 03:07:58 -0000 1.162 +++ hppa-tdep.c 19 May 2004 06:22:39 -0000 @@ -42,6 +42,7 @@ #include "gdbcore.h" #include "gdbcmd.h" #include "objfiles.h" +#include "observer.h" #include "hppa-tdep.h" static int hppa_debug = 0; @@ -2336,6 +2337,34 @@ hppa_frame_prev_register_helper (struct extract_unsigned_integer (valuep, regsize) + 4); } +static void +hppa_observer_program_changed (const char *filename) +{ + struct gdbarch_tdep *tdep; + struct minimal_symbol *minsym; + + tdep = gdbarch_tdep (current_gdbarch); + + minsym = lookup_minimal_symbol ("$$dyncall", NULL, NULL); + if (minsym) + tdep->dyncall = SYMBOL_VALUE_ADDRESS (minsym); + else + tdep->dyncall = -1; + + /* These are HPUX only. */ + minsym = lookup_minimal_symbol ("$$dyncall_external", NULL, NULL); + if (minsym) + tdep->dyncall_external = SYMBOL_VALUE_ADDRESS (minsym); + else + tdep->dyncall_external = -1; + + minsym = lookup_minimal_symbol ("_sr4export", NULL, NULL); + if (minsym) + tdep->sr4export = SYMBOL_VALUE_ADDRESS (minsym); + else + tdep->sr4export = -1; +} + /* Here is a table of C type sizes on hppa with various compiles and options. I measured this on PA 9000/800 with HP-UX 11.11 and these compilers: @@ -2524,6 +2553,8 @@ _initialize_hppa_tdep (void) gdbarch_register (bfd_arch_hppa, hppa_gdbarch_init, hppa_dump_tdep); hppa_objfile_priv_data = register_objfile_data (); + + observer_attach_program_changed (hppa_observer_program_changed); add_cmd ("unwind", class_maintenance, unwind_command, "Print unwind table entry at given address.", Index: hppa-tdep.h =================================================================== RCS file: /cvs/src/src/gdb/hppa-tdep.h,v retrieving revision 1.9 diff -u -p -r1.9 hppa-tdep.h --- hppa-tdep.h 16 May 2004 04:33:41 -0000 1.9 +++ hppa-tdep.h 19 May 2004 06:22:39 -0000 @@ -79,6 +79,12 @@ struct gdbarch_tdep /* Is this an ELF target? This can be 64-bit HP-UX, or a 32/64-bit GNU/Linux system. */ int is_elf; + + /* Internal symbols that are needed for handling this target; the values + are reinitialized if the program being debug changes. */ + CORE_ADDR dyncall; + CORE_ADDR dyncall_external; + CORE_ADDR sr4export; }; /* Index: symfile.c =================================================================== RCS file: /cvs/src/src/gdb/symfile.c,v retrieving revision 1.129 diff -u -p -r1.129 symfile.c --- symfile.c 2 May 2004 10:14:01 -0000 1.129 +++ symfile.c 19 May 2004 06:22:41 -0000 @@ -48,6 +48,7 @@ #include "readline/readline.h" #include "gdb_assert.h" #include "block.h" +#include "observer.h" #include #include @@ -60,18 +61,6 @@ #define O_BINARY 0 #endif -#ifdef HPUXHPPA - -/* Some HP-UX related globals to clear when a new "main" - symbol file is loaded. HP-specific. */ - -extern int hp_cxx_exception_support_initialized; -#define RESET_HP_UX_GLOBALS() do {\ - deprecated_hp_som_som_object_present = 0; /* indicates HP-compiled code */ \ - hp_cxx_exception_support_initialized = 0; /* must reinitialize exception stuff */ \ - } while (0) -#endif - int (*deprecated_ui_load_progress_hook) (const char *section, unsigned long num); void (*deprecated_show_load_progress) (const char *section, unsigned long section_sent, @@ -957,15 +946,13 @@ symbol_file_add_main_1 (char *args, int { symbol_file_add (args, from_tty, NULL, 1, flags); -#ifdef HPUXHPPA - RESET_HP_UX_GLOBALS (); -#endif - /* Getting new symbols may change our opinion about what is frameless. */ reinit_frame_cache (); set_initial_language (); + + observer_notify_program_changed (args); } void @@ -989,9 +976,6 @@ symbol_file_clear (int from_tty) symfile_objfile = NULL; if (from_tty) printf_unfiltered ("No symbol file now.\n"); -#ifdef HPUXHPPA - RESET_HP_UX_GLOBALS (); -#endif } static char * @@ -1944,9 +1928,6 @@ reread_symbols (void) if (objfile == symfile_objfile) { (*objfile->sf->sym_new_init) (objfile); -#ifdef HPUXHPPA - RESET_HP_UX_GLOBALS (); -#endif } (*objfile->sf->sym_init) (objfile); Index: thread.c =================================================================== RCS file: /cvs/src/src/gdb/thread.c,v retrieving revision 1.36 diff -u -p -r1.36 thread.c --- thread.c 12 May 2004 22:19:02 -0000 1.36 +++ thread.c 19 May 2004 06:22:41 -0000 @@ -424,11 +424,7 @@ info_threads_command (char *arg, int fro else printf_filtered (" "); -#ifdef HPUXHPPA printf_filtered ("%d %s", tp->num, target_tid_to_str (tp->ptid)); -#else - printf_filtered ("%d %s", tp->num, target_pid_to_str (tp->ptid)); -#endif extra_info = target_extra_thread_info (tp); if (extra_info) @@ -541,13 +537,8 @@ thread_apply_all_command (char *cmd, int if (thread_alive (tp)) { switch_to_thread (tp->ptid); -#ifdef HPUXHPPA printf_filtered ("\nThread %d (%s):\n", tp->num, target_tid_to_str (inferior_ptid)); -#else - printf_filtered ("\nThread %d (%s):\n", tp->num, - target_pid_to_str (inferior_ptid)); -#endif execute_command (cmd, from_tty); strcpy (cmd, saved_cmd); /* Restore exact command used previously */ } @@ -617,13 +608,8 @@ thread_apply_command (char *tidlist, int else { switch_to_thread (tp->ptid); -#ifdef HPUXHPPA printf_filtered ("\nThread %d (%s):\n", tp->num, target_tid_to_str (inferior_ptid)); -#else - printf_filtered ("\nThread %d (%s):\n", tp->num, - target_pid_to_str (inferior_ptid)); -#endif execute_command (cmd, from_tty); strcpy (cmd, saved_cmd); /* Restore exact command used previously */ } @@ -646,12 +632,7 @@ thread_command (char *tidstr, int from_t if (target_has_stack) printf_filtered ("[Current thread is %d (%s)]\n", pid_to_thread_id (inferior_ptid), -#if defined(HPUXHPPA) - target_tid_to_str (inferior_ptid) -#else - target_pid_to_str (inferior_ptid) -#endif - ); + target_tid_to_str (inferior_ptid)); else error ("No stack."); return; @@ -681,11 +662,7 @@ do_captured_thread_select (struct ui_out ui_out_text (uiout, "[Switching to thread "); ui_out_field_int (uiout, "new-thread-id", pid_to_thread_id (inferior_ptid)); ui_out_text (uiout, " ("); -#if defined(HPUXHPPA) ui_out_text (uiout, target_tid_to_str (inferior_ptid)); -#else - ui_out_text (uiout, target_pid_to_str (inferior_ptid)); -#endif ui_out_text (uiout, ")]"); print_stack_frame (get_selected_frame (), 1, SRC_AND_LOC); Index: doc/observer.texi =================================================================== RCS file: /cvs/src/src/gdb/doc/observer.texi,v retrieving revision 1.6 diff -u -p -r1.6 observer.texi --- doc/observer.texi 7 May 2004 22:51:55 -0000 1.6 +++ doc/observer.texi 19 May 2004 06:22:41 -0000 @@ -82,3 +82,7 @@ The inferior has stopped for real. @deftypefun void target_changed (struct target_ops *@var{target}) The target's register contents have changed. @end deftypefun + +@deftypefun void program_changed (const char *@var{filename}) +The program being debugged has changed. +@end deftypefun -- Randolph Chung Debian GNU/Linux Developer, hppa/ia64 ports http://www.tausq.org/