From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2015 invoked by alias); 13 May 2003 02:59:01 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 1912 invoked from network); 13 May 2003 02:58:59 -0000 Received: from unknown (HELO gateway.sf.frob.com) (64.163.213.212) by sources.redhat.com with SMTP; 13 May 2003 02:58:59 -0000 Received: from magilla.sf.frob.com (magilla.sf.frob.com [198.49.250.228]) by gateway.sf.frob.com (Postfix) with ESMTP id B6384354C; Mon, 12 May 2003 19:58:58 -0700 (PDT) Received: (from roland@localhost) by magilla.sf.frob.com (8.11.6/8.11.6) id h4D2wvY23487; Mon, 12 May 2003 19:58:57 -0700 Date: Tue, 13 May 2003 02:59:00 -0000 Message-Id: <200305130258.h4D2wvY23487@magilla.sf.frob.com> From: Roland McGrath To: Mark Kettenis Cc: gdb-patches@sources.redhat.com Subject: [branch patch] core files as symfiles X-Antipastobozoticataclysm: When George Bush projectile vomits antipasto on the Japanese. X-SW-Source: 2003-05/txt/msg00194.txt.bz2 The following patch causes core files to be implicitly read as symbol files as well. Using this along with my previous dwarf-frame.c patch vs current kettenis_i386newframe-20030419-branch gdb, on Linux 2.5.69 on x86 the backtrace of a thread in a system call from a core dump Just Works. I've included the trivial symfile.c patch that was in with my dwarf-frame.c patch again here too, since it's required for the corelow.c patch to work and these patches work (but cause nothing interesting to happen) independent of the dwarf-frame.c changes. Thanks, Roland 2003-05-12 Roland McGrath * corelow.c (core_objfile): New variable. (core_close): If core_objfile is set, call free_objfile on it. (core_open): Open the core file with add_symbol_file, and save the struct objfile pointer in core_objfile. * symfile.c (symfile_bfd_open): Try bfd_check_format with bfd_core if bfd_object fails. Index: corelow.c =================================================================== RCS file: /cvs/src/src/gdb/corelow.c,v retrieving revision 1.29 diff -B -p -u -r1.29 corelow.c --- corelow.c 18 Jan 2003 15:55:51 -0000 1.29 +++ corelow.c 13 May 2003 02:57:07 -0000 @@ -38,6 +38,7 @@ #include "gdbthread.h" #include "regcache.h" #include "symfile.h" +#include "objfiles.h" #include #ifndef O_BINARY @@ -50,6 +51,8 @@ static struct core_fns *core_file_fns = NULL; +static struct objfile *core_objfile = NULL; + /* The core_fns for a core file handler that is prepared to read the core file currently open on core_bfd. */ @@ -200,6 +203,8 @@ core_close (int quitting) warning ("cannot close \"%s\": %s", name, bfd_errmsg (bfd_get_error ())); xfree (name); + if (core_objfile && core_objfile->obfd == core_bfd) + core_objfile->obfd = NULL; core_bfd = NULL; if (core_ops.to_sections) { @@ -209,6 +214,12 @@ core_close (int quitting) } } core_vec = NULL; + + if (core_objfile) + { + free_objfile (core_objfile); + core_objfile = NULL; + } } static void @@ -263,6 +274,7 @@ core_open (char *filename, int from_tty) struct cleanup *old_chain; char *temp; bfd *temp_bfd; + struct objfile *temp_objfile; int ontop; int scratch_chan; @@ -274,23 +286,42 @@ core_open (char *filename, int from_tty) : "No core file specified."); } - filename = tilde_expand (filename); - if (filename[0] != '/') - { - temp = concat (current_directory, "/", filename, NULL); - xfree (filename); - filename = temp; - } + old_chain = NULL; - old_chain = make_cleanup (xfree, filename); + /* Try to open the core file as a symbol file. We do this first + so we can reuse the same bfd that the objfile points to. */ + temp_objfile = symbol_file_add (filename, 0, NULL, 0, 0); + if (temp_objfile != NULL) + old_chain = make_cleanup ((void (*) (void *)) free_objfile, temp_objfile); - scratch_chan = open (filename, O_BINARY | ( write_files ? O_RDWR : O_RDONLY ), 0); - if (scratch_chan < 0) - perror_with_name (filename); + if (temp_objfile != NULL && !write_files) + temp_bfd = temp_objfile->obfd; + else + { + /* symbol_file_add did the expansion and opening for us if it worked. */ + + filename = tilde_expand (filename); + if (filename[0] != '/') + { + temp = concat (current_directory, "/", filename, NULL); + xfree (filename); + filename = temp; + } - temp_bfd = bfd_fdopenr (filename, gnutarget, scratch_chan); - if (temp_bfd == NULL) - perror_with_name (filename); + if (old_chain == NULL) + old_chain = make_cleanup (xfree, filename); + else + make_cleanup (xfree, filename); + + scratch_chan = open (filename, + O_BINARY | (write_files ? O_RDWR : O_RDONLY), 0); + if (scratch_chan < 0) + perror_with_name (filename); + + temp_bfd = bfd_fdopenr (filename, gnutarget, scratch_chan); + if (temp_bfd == NULL) + perror_with_name (filename); + } if (!bfd_check_format (temp_bfd, bfd_core) && !gdb_check_format (temp_bfd)) @@ -299,7 +330,8 @@ core_open (char *filename, int from_tty) /* 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); + if (temp_objfile == NULL || temp_bfd != temp_objfile->obfd) + make_cleanup_bfd_close (temp_bfd); error ("\"%s\" is not a core dump: %s", filename, bfd_errmsg (bfd_get_error ())); } @@ -308,6 +340,7 @@ core_open (char *filename, int from_tty) discard_cleanups (old_chain); /* Don't free filename any more */ unpush_target (&core_ops); + core_objfile = temp_objfile; core_bfd = temp_bfd; old_chain = make_cleanup (core_close_cleanup, 0 /*ignore*/); --- symfile.c.~1.93.~ Fri Apr 4 14:29:12 2003 +++ symfile.c Mon May 12 02:04:07 2003 @@ -1338,7 +1338,9 @@ symfile_bfd_open (char *name) } sym_bfd->cacheable = 1; - if (!bfd_check_format (sym_bfd, bfd_object)) + if (!bfd_check_format (sym_bfd, bfd_object) + /* Yes, Virginia, core files can have symbols! */ + && !bfd_check_format (sym_bfd, bfd_core)) { /* FIXME: should be checking for errors from bfd_close (for one thing, on error it does not free all the storage associated with the