Re: PATCH: gdb/corefile.c (0401 snap on HP-UX).

J.T. Conklin
2001-04-12T09:40:00Z

>>>>> "jtc" == J T Conklin <jtc@redback.com> writes:
Kevin> The code controlled by the above ifdef looks pretty generic and
Kevin> it seems to me that it could be useful on targets other than
Kevin> HP. I suggest that we do one of two things:
Kevin>
Kevin> 1) Enable it for all targets and add Rodney's #include statments
Kevin> unconditionally.
Kevin>
Kevin> 2) Remove it entirely.
Kevin>
Kevin> I'm not familiar enough with the code in question to know what
Kevin> the best course of action is.

jtc> Yes, on second look the code is host/target independent. I can't
jtc> understand why it is wrapped in HPPAHPUX. Perhaps it was part of the
jtc> infamous HP "merge".

Further archaeological research indicates that this is indeed the case.

jtc> The comment before core_file_command() states that the "core-file"
jtc> command exists for backwards compatibility; but the command is not
jtc> marked deprecated in the CLI. If I knew the command was deprecated,
jtc> I wouldn't hesitate suggesting the code be removed.
jtc>
jtc> It is interesting to note that "target core XXX" does look at the name
jtc> of the symbol file, but only to print the name, not to set the symbol
jtc> file. This might be a more appropriate behavior for the "core-file"
jtc> command.
jtc>
jtc> Also note that that section of code is the only bit in GDB that uses
jtc> the .to_core_file_to_sym_file() vector function. If it is removed,
jtc> we'll be able to remove quite a bit of code as well.

Based on the above, I think the correct course of action is to remove
the subject code from core_file_command().

If setting a symbol file from a core file is a desirable feature, I
believe it should be done for both "core-file xxx" and "target core
xxx" commands. Since core_file_command() calls core_open() through
the core_ops.to_open vector, I think the natural place for adding
that code (to add a symbol file) is there (corelow.c:core_open()).

I've enclosed a patch that removes the code from corefile.c and all
the associated infrastructure. I don't have a change log entry yet,
I still have to chase down everything that was changed. I have not
written any code to set the symbol file from the core file. My take
on it is that since the work wasn't finished, it must not have been
important.

Any further thoughts?

--jtc

Index: corefile.c
===================================================================
RCS file: /cvs/src/src/gdb/corefile.c,v
retrieving revision 1.12
diff -c -r1.12 corefile.c
*** corefile.c 2001/03/27 20:36:23 1.12
--- corefile.c 2001/04/12 16:25:48
***************
*** 69,103 ****
dont_repeat (); /* Either way, seems bogus. */

t = find_core_target ();
! if (t != NULL)
! if (!filename)
! (t->to_detach) (filename, from_tty);
! else
! {
! /* Yes, we were given the path of a core file. Do we already
! have a symbol file? If not, can we determine it from the
! core file? If we can, do so.
! */
! #ifdef HPUXHPPA
! if (symfile_objfile == NULL)
! {
! char *symfile;
! symfile = t->to_core_file_to_sym_file (filename);
! if (symfile)
! {
! char *symfile_copy = xstrdup (symfile);

! make_cleanup (xfree, symfile_copy);
! symbol_file_add_main (symfile_copy, from_tty);
! }
! else
! warning ("Unknown symbols for '%s'; use the 'symbol-file' command.", filename);
! }
! #endif
! (t->to_open) (filename, from_tty);
! }
else
! error ("GDB can't read core files on this machine.");
}
\f

--- 69,81 ----
dont_repeat (); /* Either way, seems bogus. */

t = find_core_target ();
! if (t == NULL)
! error ("GDB can't read core files on this machine.");

! if (!filename)
! (t->to_detach) (filename, from_tty);
else
! (t->to_open) (filename, from_tty);
}
\f

Index: corelow.c
===================================================================
RCS file: /cvs/src/src/gdb/corelow.c,v
retrieving revision 1.14
diff -c -r1.14 corelow.c
*** corelow.c 2001/03/06 08:21:06 1.14
--- corelow.c 2001/04/12 16:25:49
***************
*** 77,84 ****

static int ignore (CORE_ADDR, char *);

- static char *core_file_to_sym_file (char *);
-
static int core_file_thread_alive (int tid);

static void init_core_ops (void);
--- 77,82 ----
***************
*** 464,531 ****
registers_fetched ();
}

- static char *
- core_file_to_sym_file (char *core)
- {
- CONST char *failing_command;
- char *p;
- char *temp;
- bfd *temp_bfd;
- int scratch_chan;
-
- if (!core)
- error ("No core file specified.");
-
- core = tilde_expand (core);
- if (core[0] != '/')
- {
- temp = concat (current_directory, "/", core, NULL);
- core = temp;
- }
-
- scratch_chan = open (core, write_files ? O_RDWR : O_RDONLY, 0);
- if (scratch_chan < 0)
- perror_with_name (core);
-
- temp_bfd = bfd_fdopenr (core, gnutarget, scratch_chan);
- if (temp_bfd == NULL)
- perror_with_name (core);
-
- if (!bfd_check_format (temp_bfd, bfd_core))
- {
- /* Do it after the err msg */
- /* FIXME: should be checking for errors from bfd_close (for one thing,
- on error it does not free all the storage associated with the
- bfd). */
- make_cleanup_bfd_close (temp_bfd);
- error ("\"%s\" is not a core dump: %s",
- core, bfd_errmsg (bfd_get_error ()));
- }
-
- /* Find the data section */
- if (build_section_table (temp_bfd, &core_ops.to_sections,
- &core_ops.to_sections_end))
- error ("\"%s\": Can't find sections: %s",
- bfd_get_filename (temp_bfd), bfd_errmsg (bfd_get_error ()));
-
- failing_command = bfd_core_file_failing_command (temp_bfd);
-
- bfd_close (temp_bfd);
-
- /* If we found a filename, remember that it is probably saved
- relative to the executable that created it. If working directory
- isn't there now, we may not be able to find the executable. Rather
- than trying to be sauve about finding it, just check if the file
- exists where we are now. If not, then punt and tell our client
- we couldn't find the sym file.
- */
- p = (char *) failing_command;
- if ((p != NULL) && (access (p, F_OK) != 0))
- p = NULL;
-
- return p;
- }
-
static void
core_files_info (struct target_ops *t)
{
--- 462,467 ----
***************
*** 577,583 ****
core_ops.to_create_inferior = find_default_create_inferior;
core_ops.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
core_ops.to_thread_alive = core_file_thread_alive;
- core_ops.to_core_file_to_sym_file = core_file_to_sym_file;
core_ops.to_stratum = core_stratum;
core_ops.to_has_memory = 1;
core_ops.to_has_stack = 1;
--- 513,518 ----
Index: gnu-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/gnu-nat.c,v
retrieving revision 1.13
diff -c -r1.13 gnu-nat.c
*** gnu-nat.c 2001/03/20 01:37:09 1.13
--- gnu-nat.c 2001/04/12 16:25:54
***************
*** 2561,2567 ****
gnu_ops.to_pid_to_str = gnu_pid_to_str; /* to_pid_to_str */
gnu_ops.to_stop = gnu_stop; /* to_stop */
gnu_ops.to_pid_to_exec_file = gnu_pid_to_exec_file; /* to_pid_to_exec_file */
- gnu_ops.to_core_file_to_sym_file = NULL;
gnu_ops.to_stratum = process_stratum; /* to_stratum */
gnu_ops.DONT_USE = 0; /* to_next */
gnu_ops.to_has_all_memory = 1; /* to_has_all_memory */
--- 2561,2566 ----
Index: inftarg.c
===================================================================
RCS file: /cvs/src/src/gdb/inftarg.c,v
retrieving revision 1.5
diff -c -r1.5 inftarg.c
*** inftarg.c 2001/03/06 08:21:08 1.5
--- inftarg.c 2001/04/12 16:25:55
***************
*** 797,803 ****
child_ops.to_enable_exception_callback = child_enable_exception_callback;
child_ops.to_get_current_exception_event = child_get_current_exception_event;
child_ops.to_pid_to_exec_file = child_pid_to_exec_file;
- child_ops.to_core_file_to_sym_file = child_core_file_to_sym_file;
child_ops.to_stratum = process_stratum;
child_ops.to_has_all_memory = 1;
child_ops.to_has_memory = 1;
--- 797,802 ----
Index: mac-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/mac-nat.c,v
retrieving revision 1.7
diff -c -r1.7 mac-nat.c
*** mac-nat.c 2001/03/15 16:55:14 1.7
--- mac-nat.c 2001/04/12 16:25:56
***************
*** 381,387 ****
child_ops.to_thread_alive = 0;
child_ops.to_stop = child_stop;
child_ops.to_pid_to_exec_file = NULL; /* to_pid_to_exec_file */
- child_ops.to_core_file_to_sym_file = NULL;
child_ops.to_stratum = process_stratum;
child_ops.DONT_USE = 0;
child_ops.to_has_all_memory = 1;
--- 381,386 ----
Index: monitor.c
===================================================================
RCS file: /cvs/src/src/gdb/monitor.c,v
retrieving revision 1.23
diff -c -r1.23 monitor.c
*** monitor.c 2001/04/05 17:44:06 1.23
--- monitor.c 2001/04/12 16:26:01
***************
*** 2309,2315 ****
monitor_ops.to_stop = monitor_stop;
monitor_ops.to_rcmd = monitor_rcmd;
monitor_ops.to_pid_to_exec_file = NULL;
- monitor_ops.to_core_file_to_sym_file = NULL;
monitor_ops.to_stratum = process_stratum;
monitor_ops.DONT_USE = 0;
monitor_ops.to_has_all_memory = 1;
--- 2309,2314 ----
Index: ppc-bdm.c
===================================================================
RCS file: /cvs/src/src/gdb/ppc-bdm.c,v
retrieving revision 1.9
diff -c -r1.9 ppc-bdm.c
*** ppc-bdm.c 2001/03/06 08:21:11 1.9
--- ppc-bdm.c 2001/04/12 16:26:02
***************
*** 364,370 ****
bdm_ppc_ops.to_thread_alive = ocd_thread_alive;
bdm_ppc_ops.to_stop = ocd_stop;
bdm_ppc_ops.to_pid_to_exec_file = NULL;
- bdm_ppc_ops.to_core_file_to_sym_file = NULL;
bdm_ppc_ops.to_stratum = process_stratum;
bdm_ppc_ops.DONT_USE = NULL;
bdm_ppc_ops.to_has_all_memory = 1;
--- 364,369 ----
Index: remote-adapt.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-adapt.c,v
retrieving revision 1.11
diff -c -r1.11 remote-adapt.c
*** remote-adapt.c 2001/03/14 16:42:30 1.11
--- remote-adapt.c 2001/04/12 16:26:06
***************
*** 1502,1508 ****
adapt_ops.to_thread_alive = 0;
adapt_ops.to_stop = 0; /* process_stratum; */
adapt_ops.to_pid_to_exec_file = NULL;
- adapt_ops.to_core_file_to_sym_file = NULL;
adapt_ops.to_stratum = 0;
adapt_ops.DONT_USE = 0;
adapt_ops.to_has_all_memory = 1;
--- 1502,1507 ----
Index: remote-array.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-array.c,v
retrieving revision 1.12
diff -c -r1.12 remote-array.c
*** remote-array.c 2001/03/06 08:21:12 1.12
--- remote-array.c 2001/04/12 16:26:10
***************
*** 178,184 ****
array_ops.to_thread_alive = 0;
array_ops.to_stop = 0;
array_ops.to_pid_to_exec_file = NULL;
- array_ops.to_core_file_to_sym_file = NULL;
array_ops.to_stratum = process_stratum;
array_ops.DONT_USE = 0;
array_ops.to_has_all_memory = 1;
--- 178,183 ----
Index: remote-bug.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-bug.c,v
retrieving revision 1.16
diff -c -r1.16 remote-bug.c
*** remote-bug.c 2001/04/02 14:47:21 1.16
--- remote-bug.c 2001/04/12 16:26:12
***************
*** 946,952 ****
bug_ops.to_thread_alive = 0;
bug_ops.to_stop = 0;
bug_ops.to_pid_to_exec_file = NULL;
- bug_ops.to_core_file_to_sym_file = NULL;
bug_ops.to_stratum = process_stratum;
bug_ops.DONT_USE = 0;
bug_ops.to_has_all_memory = 1;
--- 946,951 ----
Index: remote-e7000.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-e7000.c,v
retrieving revision 1.18
diff -c -r1.18 remote-e7000.c
*** remote-e7000.c 2001/04/05 02:02:13 1.18
--- remote-e7000.c 2001/04/12 16:26:16
***************
*** 2199,2205 ****
e7000_ops.to_thread_alive = 0;
e7000_ops.to_stop = e7000_stop;
e7000_ops.to_pid_to_exec_file = NULL;
- e7000_ops.to_core_file_to_sym_file = NULL;
e7000_ops.to_stratum = process_stratum;
e7000_ops.DONT_USE = 0;
e7000_ops.to_has_all_memory = 1;
--- 2199,2204 ----
Index: remote-eb.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-eb.c,v
retrieving revision 1.11
diff -c -r1.11 remote-eb.c
*** remote-eb.c 2001/03/14 16:42:30 1.11
--- remote-eb.c 2001/04/12 16:26:19
***************
*** 1068,1074 ****
eb_ops.to_thread_alive = 0; /* thread-alive */
eb_ops.to_stop = 0; /* to_stop */
eb_ops.to_pid_to_exec_file = NULL;
- eb_ops.to_core_file_to_sym_file = NULL;
eb_ops.to_stratum = process_stratum;
eb_ops.DONT_USE = 0; /* next */
eb_ops.to_has_all_memory = 1;
--- 1068,1073 ----
Index: remote-es.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-es.c,v
retrieving revision 1.14
diff -c -r1.14 remote-es.c
*** remote-es.c 2001/03/06 08:21:12 1.14
--- remote-es.c 2001/04/12 16:26:26
***************
*** 2026,2032 ****
es1800_ops.to_thread_alive = 0;
es1800_ops.to_stop = 0;
es1800_ops.to_pid_to_exec_file = NULL;
- es1800_ops.to_core_file_to_sym_file = NULL;
es1800_ops.to_stratum = core_stratum;
es1800_ops.DONT_USE = 0;
es1800_ops.to_has_all_memory = 0;
--- 2026,2031 ----
***************
*** 2099,2105 ****
es1800_child_ops.to_thread_alive = 0;
es1800_child_ops.to_stop = 0;
es1800_child_ops.to_pid_to_exec_file = NULL;
- es1800_child_ops.to_core_file_to_sym_file = NULL;
es1800_child_ops.to_stratum = process_stratum;
es1800_child_ops.DONT_USE = 0;
es1800_child_ops.to_has_all_memory = 1;
--- 2098,2103 ----
Index: remote-mm.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-mm.c,v
retrieving revision 1.10
diff -c -r1.10 remote-mm.c
*** remote-mm.c 2001/03/14 16:42:30 1.10
--- remote-mm.c 2001/04/12 16:26:36
***************
*** 1821,1827 ****
mm_ops.to_thread_alive = 0;
mm_ops.to_stop = 0;
mm_ops.to_pid_to_exec_file = NULL;
- mm_ops.to_core_file_to_sym_file = NULL;
mm_ops.to_stratum = process_stratum;
mm_ops.DONT_USE = 0;
mm_ops.to_has_all_memory = 1;
--- 1821,1826 ----
Index: remote-nindy.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-nindy.c,v
retrieving revision 1.14
diff -c -r1.14 remote-nindy.c
*** remote-nindy.c 2001/03/06 08:21:12 1.14
--- remote-nindy.c 2001/04/12 16:26:40
***************
*** 738,744 ****
nindy_ops.to_thread_alive = 0; /* to_thread_alive */
nindy_ops.to_stop = 0; /* to_stop */
nindy_ops.to_pid_to_exec_file = NULL;
- nindy_ops.to_core_file_to_sym_file = NULL;
nindy_ops.to_stratum = process_stratum;
nindy_ops.DONT_USE = 0; /* next */
nindy_ops.to_has_all_memory = 1;
--- 738,743 ----
Index: remote-nrom.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-nrom.c,v
retrieving revision 1.6
diff -c -r1.6 remote-nrom.c
*** remote-nrom.c 2001/03/27 20:36:24 1.6
--- remote-nrom.c 2001/04/12 16:26:42
***************
*** 317,323 ****
nrom_ops.to_thread_alive = 0;
nrom_ops.to_stop = 0;
nrom_ops.to_pid_to_exec_file = NULL;
- nrom_ops.to_core_file_to_sym_file = NULL;
nrom_ops.to_stratum = download_stratum;
nrom_ops.DONT_USE = NULL;
nrom_ops.to_has_all_memory = 1;
--- 317,322 ----
Index: remote-os9k.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-os9k.c,v
retrieving revision 1.12
diff -c -r1.12 remote-os9k.c
*** remote-os9k.c 2001/03/06 08:21:12 1.12
--- remote-os9k.c 2001/04/12 16:26:47
***************
*** 1169,1175 ****
rombug_ops.to_thread_alive = 0;
rombug_ops.to_stop = 0; /* to_stop */
rombug_ops.to_pid_to_exec_file = NULL;
- rombug_ops.to_core_file_to_sym_file = NULL;
rombug_ops.to_stratum = process_stratum;
rombug_ops.DONT_USE = 0; /* next */
rombug_ops.to_has_all_memory = 1;
--- 1169,1174 ----
Index: remote-rdp.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-rdp.c,v
retrieving revision 1.15
diff -c -r1.15 remote-rdp.c
*** remote-rdp.c 2001/03/27 17:23:47 1.15
--- remote-rdp.c 2001/04/12 16:26:52
***************
*** 1433,1439 ****
remote_rdp_ops.to_thread_alive = 0;
remote_rdp_ops.to_stop = 0;
remote_rdp_ops.to_pid_to_exec_file = NULL;
- remote_rdp_ops.to_core_file_to_sym_file = NULL;
remote_rdp_ops.to_stratum = process_stratum;
remote_rdp_ops.DONT_USE = NULL;
remote_rdp_ops.to_has_all_memory = 1;
--- 1433,1438 ----
Index: remote-sim.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-sim.c,v
retrieving revision 1.14
diff -c -r1.14 remote-sim.c
*** remote-sim.c 2001/03/06 08:21:13 1.14
--- remote-sim.c 2001/04/12 16:26:56
***************
*** 915,921 ****
gdbsim_ops.to_thread_alive = 0;
gdbsim_ops.to_stop = gdbsim_stop;
gdbsim_ops.to_pid_to_exec_file = NULL;
- gdbsim_ops.to_core_file_to_sym_file = NULL;
gdbsim_ops.to_stratum = process_stratum;
gdbsim_ops.DONT_USE = NULL;
gdbsim_ops.to_has_all_memory = 1;
--- 915,920 ----
Index: remote-st.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-st.c,v
retrieving revision 1.10
diff -c -r1.10 remote-st.c
*** remote-st.c 2001/03/06 08:21:13 1.10
--- remote-st.c 2001/04/12 16:26:58
***************
*** 807,813 ****
st2000_ops.to_thread_alive = 0; /* thread alive */
st2000_ops.to_stop = 0; /* to_stop */
st2000_ops.to_pid_to_exec_file = NULL;
- st2000_run_ops.to_core_file_to_sym_file = NULL;
st2000_ops.to_stratum = process_stratum;
st2000_ops.DONT_USE = 0; /* next */
st2000_ops.to_has_all_memory = 1;
--- 807,812 ----
Index: target.c
===================================================================
RCS file: /cvs/src/src/gdb/target.c,v
retrieving revision 1.23
diff -c -r1.23 target.c
*** target.c 2001/03/07 02:57:08 1.23
--- target.c 2001/04/12 16:27:05
***************
*** 503,511 ****
de_fault (to_pid_to_exec_file,
(char *(*) (int))
return_zero);
- de_fault (to_core_file_to_sym_file,
- (char *(*) (char *))
- return_zero);
de_fault (to_can_async_p,
(int (*) (void))
return_zero);
--- 503,508 ----
***************
*** 599,605 ****
INHERIT (to_enable_exception_callback, t);
INHERIT (to_get_current_exception_event, t);
INHERIT (to_pid_to_exec_file, t);
- INHERIT (to_core_file_to_sym_file, t);
INHERIT (to_stratum, t);
INHERIT (DONT_USE, t);
INHERIT (to_has_all_memory, t);
--- 596,601 ----
***************
*** 2873,2891 ****
return exec_file;
}

- static char *
- debug_to_core_file_to_sym_file (char *core)
- {
- char *sym_file;
-
- sym_file = debug_target.to_core_file_to_sym_file (core);
-
- fprintf_unfiltered (gdb_stdlog, "target_core_file_to_sym_file (%s) = %s\n",
- core, sym_file);
-
- return sym_file;
- }
-
static void
setup_target_debug (void)
{
--- 2869,2874 ----
***************
*** 2946,2952 ****
current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
- current_target.to_core_file_to_sym_file = debug_to_core_file_to_sym_file;

}
\f
--- 2929,2934 ----
Index: target.h
===================================================================
RCS file: /cvs/src/src/gdb/target.h,v
retrieving revision 1.17
diff -c -r1.17 target.h
*** target.h 2001/03/24 02:07:49 1.17
--- target.h 2001/04/12 16:27:09
***************
*** 294,300 ****
int);
struct exception_event_record *(*to_get_current_exception_event) (void);
char *(*to_pid_to_exec_file) (int pid);
- char *(*to_core_file_to_sym_file) (char *);
enum strata to_stratum;
struct target_ops
*DONT_USE; /* formerly to_next */
--- 294,299 ----
Index: v850ice.c
===================================================================
RCS file: /cvs/src/src/gdb/v850ice.c,v
retrieving revision 1.9
diff -c -r1.9 v850ice.c
*** v850ice.c 2001/03/06 08:21:18 1.9
--- v850ice.c 2001/04/12 16:27:10
***************
*** 931,937 ****
v850ice_ops.to_thread_alive = NULL;
v850ice_ops.to_stop = v850ice_stop;
v850ice_ops.to_pid_to_exec_file = NULL;
- v850ice_ops.to_core_file_to_sym_file = NULL;
v850ice_ops.to_stratum = process_stratum;
v850ice_ops.DONT_USE = NULL;
v850ice_ops.to_has_all_memory = 1;
--- 931,936 ----