This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

New branch cagney_bigcore-20040122-branch for 64-bit off_t


Hello,

[recommend binutils@ for discussion]

I've create the branch:

cvs -d ... co -r cagney_bigcore-20040122-branch gdb+binutils

and committed my current >2gb core file patches (attached). Finding all the binutils bugs this change tickles is starting to look like a long drawn out war. Hopefully this branch will make it easier for others to test it on their system.

BTW, binutils, on its own has problems so it also needs the patch. objdump, for instance, appears to dump sections beyond 2gb as zero.

enjoy,
Andrew
Index: bfd/ChangeLog
2004-01-21  Andrew Cagney  <cagney@redhat.com>

	* bfdio.c: Update copyright.  Include "bfdio.h".
	(real_ftell, real_fseek): New functions.
	(bfd_tell): Use real_ftell, change return-type to file_ptr.
	(bfd_seek): Use real_ftell and real_fseek.  Change type of
	file_position to a file_ptr.
	* cache.c: Update copyright.  Include "bfdio.h".
	(close_one): Use real_ftell.
	(bfd_cache_lookup_worker): Use real_fseek, use ufile_ptr in cast.
	* bfd-in.h: Update copyright.
	(file_ptr, ufile_ptr): Specify type using @BFD_FILE_PTR@.
	(bfd_tell): Make return-type "file_ptr".
	* bfd-in2.h: Re-generate.
	* configure.in (AC_CHECK_FUNCS): Check for ftello, ftello64,
	fseeko and fseeko64.
	* config.in, configure: Re-generate.
	* libbfd-in.h: Update copyright.
	(real_ftell, real_fseek): Declare.
	* libbfd.h: Re-generate.
	* elf.c (offset_vma_page_alignment): New function.
	(assign_file_positions_for_segments): Replace broken modulo code
	with offset_vma_page_alignment.
	(assign_file_positions_except_relocs): Ditto.

Index: gdb/testsuite/ChangeLog
2004-01-22  Andrew Cagney  <cagney@redhat.com>

	* gdb.base/bigcore.exp: New file.
	* gdb.base/bigcore.c: New file.

Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.70
diff -u -r1.70 bfd-in.h
--- bfd/bfd-in.h	24 Nov 2003 18:06:39 -0000	1.70
+++ bfd/bfd-in.h	22 Jan 2004 16:42:43 -0000
@@ -1,7 +1,7 @@
 /* Main header file for the bfd library -- portable access to object files.
 
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -160,16 +160,10 @@
 
 #endif /* not BFD64  */
 
-/* A pointer to a position in a file.  */
-/* FIXME:  This should be using off_t from <sys/types.h>.
-   For now, try to avoid breaking stuff by not including <sys/types.h> here.
-   This will break on systems with 64-bit file offsets (e.g. 4.4BSD).
-   Probably the best long-term answer is to avoid using file_ptr AND off_t
-   in this header file, and to handle this in the BFD implementation
-   rather than in its interface.  */
-/* typedef off_t	file_ptr; */
-typedef bfd_signed_vma file_ptr;
-typedef bfd_vma ufile_ptr;
+/* An offset into a file.  BFD always uses the largest possible offset
+   based on the build time availability of fseek, fseeko, or fseeko64.  */
+typedef @bfd_file_ptr@ file_ptr;
+typedef unsigned @bfd_file_ptr@ ufile_ptr;
 
 extern void bfd_sprintf_vma (bfd *, char *, bfd_vma);
 extern void bfd_fprintf_vma (bfd *, void *, bfd_vma);
@@ -456,7 +450,7 @@
 extern bfd_size_type bfd_bread (void *, bfd_size_type, bfd *);
 extern bfd_size_type bfd_bwrite (const void *, bfd_size_type, bfd *);
 extern int bfd_seek (bfd *, file_ptr, int);
-extern ufile_ptr bfd_tell (bfd *);
+extern file_ptr bfd_tell (bfd *);
 extern int bfd_flush (bfd *);
 extern int bfd_stat (bfd *, struct stat *);
 
Index: bfd/bfdio.c
===================================================================
RCS file: /cvs/src/src/bfd/bfdio.c,v
retrieving revision 1.4
diff -u -r1.4 bfdio.c
--- bfd/bfdio.c	24 Nov 2003 18:06:39 -0000	1.4
+++ bfd/bfdio.c	22 Jan 2004 16:42:46 -0000
@@ -1,6 +1,8 @@
 /* Low-level I/O routines for BFDs.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -36,6 +38,30 @@
 #define S_IXOTH 0001    /* Execute by others.  */
 #endif
 
+file_ptr
+real_ftell (FILE *file)
+{
+#if defined (HAVE_FTELLO64)
+  return ftello64 (file);
+#elif defined (HAVE_FTELLO)
+  return ftello (file);
+#else
+  return ftell (file);
+#endif
+}
+
+int
+real_fseek (FILE *file, file_ptr offset, int whence)
+{
+#if defined (HAVE_FTELLO64)
+  return fseeko64 (file, offset, whence);
+#elif defined (HAVE_FTELLO)
+  return fseeko (file, offset, whence);
+#else
+  return fseek (file, offset, whence);
+#endif
+}
+
 /* Note that archive entries don't have streams; they share their parent's.
    This allows someone to play with the iostream behind BFD's back.
 
@@ -162,7 +188,7 @@
   return nwrote;
 }
 
-bfd_vma
+file_ptr
 bfd_tell (bfd *abfd)
 {
   file_ptr ptr;
@@ -170,7 +196,7 @@
   if ((abfd->flags & BFD_IN_MEMORY) != 0)
     return abfd->where;
 
-  ptr = ftell (bfd_cache_lookup (abfd));
+  ptr = real_ftell (bfd_cache_lookup (abfd));
 
   if (abfd->my_archive)
     ptr -= abfd->origin;
@@ -217,7 +243,7 @@
 {
   int result;
   FILE *f;
-  long file_position;
+  file_ptr file_position;
   /* For the time being, a BFD may not seek to it's end.  The problem
      is that we don't easily have a way to recognize the end of an
      element in an archive.  */
@@ -278,7 +304,7 @@
 	 tripping the abort, we can probably safely disable this code,
 	 so that the real optimizations happen.  */
       file_ptr where_am_i_now;
-      where_am_i_now = ftell (bfd_cache_lookup (abfd));
+      where_am_i_now = real_ftell (bfd_cache_lookup (abfd));
       if (abfd->my_archive)
 	where_am_i_now -= abfd->origin;
       if (where_am_i_now != abfd->where)
@@ -307,7 +333,7 @@
   if (direction == SEEK_SET && abfd->my_archive != NULL)
     file_position += abfd->origin;
 
-  result = fseek (f, file_position, direction);
+  result = real_fseek (f, file_position, direction);
   if (result != 0)
     {
       int hold_errno = errno;
Index: bfd/cache.c
===================================================================
RCS file: /cvs/src/src/bfd/cache.c,v
retrieving revision 1.10
diff -u -r1.10 cache.c
--- bfd/cache.c	29 Jun 2003 10:06:39 -0000	1.10
+++ bfd/cache.c	22 Jan 2004 16:42:46 -0000
@@ -1,6 +1,8 @@
 /* BFD library -- caching of file descriptors.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002, 2003
-   Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002,
+   2003, 2004 Free Software Foundation, Inc.
+
    Hacked by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -155,7 +157,7 @@
       return TRUE;
     }
 
-  kill->where = ftell ((FILE *) kill->iostream);
+  kill->where = real_ftell ((FILE *) kill->iostream);
 
   return bfd_cache_delete (kill);
 }
@@ -354,9 +356,9 @@
     {
       if (bfd_open_file (abfd) == NULL)
 	return NULL;
-      if (abfd->where != (unsigned long) abfd->where)
+      if (abfd->where != (ufile_ptr) abfd->where)
 	return NULL;
-      if (fseek ((FILE *) abfd->iostream, (long) abfd->where, SEEK_SET) != 0)
+      if (real_fseek ((FILE *) abfd->iostream, abfd->where, SEEK_SET) != 0)
 	return NULL;
     }
 
Index: bfd/configure.in
===================================================================
RCS file: /cvs/src/src/bfd/configure.in,v
retrieving revision 1.142
diff -u -r1.142 configure.in
--- bfd/configure.in	19 Dec 2003 11:43:53 -0000	1.142
+++ bfd/configure.in	22 Jan 2004 16:42:49 -0000
@@ -917,6 +917,31 @@
 AC_SUBST(bfd_machines)
 AC_SUBST(bfd_default_target_size)
 
+# Determine the host dependant file_ptr a.k.a. off_t type.  In order
+# prefer: off64_t - if ftello64 and fseeko64, off_t - if ftello and
+# fseeko, long.  This assumes that sizeof off_t is .ge. sizeof long.
+# Hopefully a reasonable assumption since fseeko et.al. should be
+# upward compatible.
+AC_CHECK_FUNCS(ftello ftello64 fseeko fseeko64)
+AC_MSG_CHECKING([file_ptr type])
+bfd_file_ptr="long"
+bfd_ufile_ptr="unsigned long"
+if test x"$ac_cv_func_ftello" = xyes -a x"$ac_cv_func_fseeko" = xyes; then
+    AC_COMPILE_CHECK_SIZEOF(off_t)
+    if test "x${ac_cv_sizeof_off_t}" = "x8"; then
+	bfd_file_ptr=BFD_HOST_64_BIT
+	bfd_ufile_ptr=BFD_HOST_U_64_BIT
+    fi
+fi
+if test x"$ac_cv_func_ftello64" = xyes -a x"$ac_cv_func_fseeko64" = xyes; then
+    bfd_file_ptr=BFD_HOST_64_BIT
+    bfd_ufile_ptr=BFD_HOST_U_64_BIT
+fi
+AC_MSG_RESULT($bfd_file_ptr)
+AC_SUBST(bfd_file_ptr)
+AC_SUBST(bfd_ufile_ptr)
+
+
 tdefaults=""
 test -n "${defvec}" && tdefaults="${tdefaults} -DDEFAULT_VECTOR=${defvec}"
 test -n "${selvecs}" && tdefaults="${tdefaults} -DSELECT_VECS='${selvecs}'"
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.215
diff -u -r1.215 elf.c
--- bfd/elf.c	11 Dec 2003 18:10:19 -0000	1.215
+++ bfd/elf.c	22 Jan 2004 16:42:51 -0000
@@ -3571,6 +3571,34 @@
   return sec1->target_index - sec2->target_index;
 }
 
+/* Ian Lance Taylor writes:
+
+   We shouldn't be using % with a negative signed number.  That's just
+   not good.  We have to make sure either that the number is not
+   negative, or that the number has an unsigned type.  When the types
+   are all the same size they wind up as unsigned.  When file_ptr is a
+   larger signed type, the arithmetic winds up as signed long long,
+   which is wrong.
+
+   What we're trying to say here is something like ``increase OFF by
+   the least amount that will cause it to be equal to the VMA modulo
+   the page size.''  */
+/* In other words, something like:
+
+   vma_offset = m->sections[0]->vma % bed->maxpagesize;
+   off_offset = off % bed->maxpagesize;
+   if (vma_offset < off_offset)
+     adjustment = vma_offset + bed->maxpagesize - off_offset;
+   else
+     adjustment = vma_offset - off_offset;
+     
+   this can be colapsed into the expression below.  */
+static file_ptr
+offset_vma_page_adjustment (bfd_vma vma, ufile_ptr off, bfd_vma maxpagesize)
+{
+  return ((vma - off) % maxpagesize);
+}
+
 /* Assign file positions to the sections based on the mapping from
    sections to segments.  This function also sets up some fields in
    the file header, and writes out the program headers.  */
@@ -3698,7 +3726,8 @@
 	  && (m->sections[0]->flags & SEC_ALLOC) != 0)
 	{
 	  if ((abfd->flags & D_PAGED) != 0)
-	    off += (m->sections[0]->vma - off) % bed->maxpagesize;
+	    off += offset_vma_page_adjustment (m->sections[0]->vma, off,
+					       bed->maxpagesize);
 	  else
 	    {
 	      bfd_size_type align;
@@ -3713,7 +3742,8 @@
 		    align = secalign;
 		}
 
-	      off += (m->sections[0]->vma - off) % (1 << align);
+	      off += offset_vma_page_adjustment (m->sections[0]->vma, off,
+						 1 << align);
 	    }
 	}
 
@@ -3875,9 +3905,11 @@
 		     not have the SEC_LOAD case just above, and then
 		     this was necessary, but now I'm not sure.  */
 		  if ((abfd->flags & D_PAGED) != 0)
-		    adjust = (sec->vma - voff) % bed->maxpagesize;
+		    adjust = offset_vma_page_adjustment (sec->vma, voff,
+							 bed->maxpagesize);
 		  else
-		    adjust = (sec->vma - voff) % align;
+		    adjust = offset_vma_page_adjustment (sec->vma, voff,
+							 align);
 		}
 	      else
 		adjust = 0;
@@ -4211,9 +4243,11 @@
 		 ? "*unknown*"
 		 : hdr->bfd_section->name)));
 	      if ((abfd->flags & D_PAGED) != 0)
-		off += (hdr->sh_addr - off) % bed->maxpagesize;
+		off += offset_vma_page_adjustment (hdr->sh_addr, off,
+						   bed->maxpagesize);
 	      else
-		off += (hdr->sh_addr - off) % hdr->sh_addralign;
+		off += offset_vma_page_adjustment (hdr->sh_addr, off,
+						   hdr->sh_addralign);
 	      off = _bfd_elf_assign_file_position_for_section (hdr, off,
 							       FALSE);
 	    }
Index: bfd/libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.30
diff -u -r1.30 libbfd-in.h
--- bfd/libbfd-in.h	4 Nov 2003 10:41:51 -0000	1.30
+++ bfd/libbfd-in.h	22 Jan 2004 16:42:51 -0000
@@ -1,8 +1,9 @@
 /* libbfd.h -- Declarations used by bfd library *implementation*.
    (This include file is not for users of the library.)
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003
-   Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -593,6 +594,11 @@
 
 #undef abort
 #define abort() _bfd_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+/* Manipulate a system FILE but using BFD's "file_ptr", rather than
+   the system "off_t" or "off64_t", as the offset.  */
+extern file_ptr real_ftell (FILE *file);
+extern int real_fseek (FILE *file, file_ptr offset, int whence);
 
 FILE *	bfd_cache_lookup_worker
   (bfd *);
Index: gdb/testsuite/gdb.base/bigcore.c
===================================================================
RCS file: gdb/testsuite/gdb.base/bigcore.c
diff -N gdb/testsuite/gdb.base/bigcore.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.base/bigcore.c	22 Jan 2004 16:43:04 -0000
@@ -0,0 +1,192 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2004 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+ 
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   Please email any bugs, comments, and/or additions to this file to:
+   bug-gdb@prep.ai.mit.edu  */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/resource.h>
+
+/* Print routines:
+
+   The following are so that printf et.al. can be avoided.  Those
+   might try to use malloc() and that, for this code, would be a
+   disaster.  */
+
+#define printf do not use
+
+const char digit[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+
+static void
+print_char (char c)
+{
+  write (1, &c, sizeof (c));
+}
+
+static void
+print_unsigned (unsigned long u)
+{
+  if (u >= 10)
+    print_unsigned (u / 10);
+  print_char (digit[u % 10]);
+}
+
+static void
+print_hex (unsigned long u)
+{
+  if (u >= 16)
+    print_hex (u / 16);
+  print_char (digit[u % 16]);
+}
+
+static void
+print_string (const char *s)
+{
+  for (; (*s) != '\0'; s++)
+    print_char ((*s));
+}
+
+static void
+print_address (const void *a)
+{
+  print_string ("0x");
+  print_hex ((unsigned long) a);
+}
+
+/* Print the current values of RESOURCE.  */
+
+static void
+print_rlimit (int resource)
+{
+  struct rlimit rl;
+  getrlimit (resource, &rl);
+  print_string ("cur=0x");
+  print_hex (rl.rlim_cur);
+  print_string (" max=0x");
+  print_hex (rl.rlim_max);
+}
+
+static void
+maximize_rlimit (int resource, const char *prefix)
+{
+  struct rlimit rl;
+  print_string ("  ");
+  print_string (prefix);
+  print_string (": ");
+  print_rlimit (resource);
+  getrlimit (resource, &rl);
+  rl.rlim_cur = rl.rlim_max;
+  setrlimit (resource, &rl);
+  print_string (" -> ");
+  print_rlimit (resource);
+  print_string ("\n");
+}
+
+struct list
+{
+  struct list *next;
+  size_t size;
+};
+
+/* Put the "heap" pointer in the BSS section.  That way it is more
+   likely that the variable will occur early in the core file (an
+   address before the heap) and hence more likely that GDB will at
+   least get its value right.  */
+
+static struct list *heap;
+static struct list *stack;
+
+int
+main ()
+{
+  size_t max_chunk_size;
+
+  /* Try to expand all the resource limits beyond the point of sanity
+     - we're after the biggest possible core file.  */
+
+  print_string ("Maximize resource limits ...\n");
+#ifdef RLIMIT_CORE
+  maximize_rlimit (RLIMIT_CORE, "core");
+#endif
+#ifdef RLIMIT_DATA
+  maximize_rlimit (RLIMIT_DATA, "data");
+#endif
+#ifdef RLIMIT_STACK
+  maximize_rlimit (RLIMIT_STACK, "stack");
+#endif
+#ifdef RLIMIT_AS
+  maximize_rlimit (RLIMIT_AS, "stack");
+#endif
+
+  /* Compute an initial chunk size.  The math is dodgy but it works
+     for the moment.  Perhaphs there's a constant around somewhere.  */
+  {
+    size_t tmp;
+    for (tmp = 1; tmp > 0; tmp <<= 1)
+      max_chunk_size = tmp;
+  }
+
+  /* Allocate as much memory as possible creating a linked list of
+     each section.  The linking ensures that some, but not all, the
+     memory is allocated.  NB: Some kernels handle this efficiently -
+     only allocating and writing out referenced pages leaving holes in
+     the file for unreferend pages - while others handle this poorly -
+     writing out all pages including those that wern't referenced.  */
+
+  print_string ("Alocating the entire heap ...\n");
+  {
+    /* Create a linked list of memory chunks.  Start with
+       MAX_CHUNK_SIZE blocks of memory and then try allocating smaller
+       and smaller amounts until all (well at least most) memory has
+       been allocated.  */
+    size_t chunk_size = max_chunk_size;
+    heap = NULL;
+    while (chunk_size >= sizeof (struct list))
+      {
+	while (1)
+	  {
+	    struct list *chunk = malloc (chunk_size);
+	    if (chunk == NULL)
+	      {
+		if (heap != NULL && heap->size == chunk_size)
+		  print_string ("\n");
+		break;
+	      }
+	    if (heap == NULL || heap->size != chunk_size)
+	      {
+		print_string ("  ");
+		print_unsigned (chunk_size);
+		print_string (" bytes @ ");
+	      }
+	    else
+	      print_string (", ");
+	    chunk->size = chunk_size;
+	    chunk->next = heap;
+	    print_address (chunk);
+	    heap = chunk;
+	  }
+	chunk_size >>= 1;
+      }
+  }
+
+  /* Push everything out to disk.  */
+
+  print_string ("Dump core ....\n");
+  *(char*)0 = 0;
+}
Index: gdb/testsuite/gdb.base/bigcore.exp
===================================================================
RCS file: gdb/testsuite/gdb.base/bigcore.exp
diff -N gdb/testsuite/gdb.base/bigcore.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.base/bigcore.exp	22 Jan 2004 16:43:04 -0000
@@ -0,0 +1,172 @@
+# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004
+# Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+# This file is based on corefile.exp which was written by Fred
+# Fish. (fnf@cygnus.com)
+
+if $tracelevel then {
+	strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+# are we on a target board
+if ![isnative] then {
+    return
+}
+
+set testfile "bigcore"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+set corefile ${objdir}/${subdir}/${testfile}.corefile
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+# Create a core file named "TESTFILE.corefile" rather than just
+# "core", to avoid problems with sys admin types that like to
+# regularly prune all files named "core" from the system.
+
+# Some systems append "core" to the name of the program; others append
+# the name of the program to "core"; still others (like Linux, as of
+# May 2003) create cores named "core.PID".  In the latter case, we
+# could have many core files lying around, and it may be difficult to
+# tell which one is ours, so let's run the program in a subdirectory.
+
+set found 0
+set coredir "${objdir}/${subdir}/coredir.[getpid]"
+file mkdir $coredir
+catch "system \"(cd ${coredir}; ${binfile}; true) >/dev/null 2>&1\""
+set names [glob -nocomplain -directory $coredir *core*]
+if {[llength $names] == 1} {
+    set file [file join $coredir [lindex $names 0]]
+    remote_exec build "mv $file $corefile"
+    set found 1
+}
+
+# Try to clean up after ourselves. 
+remote_file build delete [file join $coredir coremmap.data]
+remote_exec build "rmdir $coredir"
+    
+if { $found == 0  } {
+    warning "can't generate a core file - core tests suppressed - check ulimit -c"
+    return 0
+}
+
+# Run GDB on the bigcore program up-to where it will dump core.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+gdb_test "set print sevenbit-strings" "" \
+	"set print sevenbit-strings; ${testfile}"
+gdb_test "set width 0" "" \
+	"set width 0; ${testfile}"
+if { ![runto_main] } then {
+    gdb_suppress_tests;
+}
+set print_core_line [gdb_get_line_number "Dump core"]
+gdb_test "tbreak $print_core_line"
+gdb_test continue ".*print_string.*"
+gdb_test next ".*0 = 0.*"
+
+# Traverse bigcore's linked list, saving each chunk's address.  I
+# don't know why but expect_out didn't work with gdb_test_multiple.
+
+set heap ""
+set test "extract heap"
+set lim 0
+send_gdb "print heap\n"
+gdb_expect {
+    -re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
+	pass "$test"
+    }
+    -re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" {
+	set heap [concat $heap $expect_out(1,string)]
+	if { $lim > 100 } {
+	    fail "$test (limit $lim exceeded)"
+	} else {
+	    incr lim
+	    send_gdb "print $.next\n"
+	    exp_continue
+	}
+    }
+    -re ".*$gdb_prompt $" {
+	fail "$test (entry $lim)"
+    }
+    timeout {
+	fail "$test (timeout)"
+    }
+}
+
+# Now load up that core file
+
+set test "load corefile"
+gdb_test_multiple "core $corefile" "$test" {
+    -re "A program is being debugged already.  Kill it. .y or n. " {
+	send_gdb "y\n"
+	exp_continue
+    }
+    -re "Core was generated by.*$gdb_prompt $" {
+	pass "$test"
+    }
+}
+
+# Finally, re-traverse bigcore's linked list, checking each chunk's
+# address against the executable.  Don't use gdb_test_multiple as want
+# only one pass/fail.
+
+set test "check heap"
+set lim 0
+set ok 1
+send_gdb "print heap\n"
+while { $ok } {
+    gdb_expect {
+	-re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
+	    set ok 0
+	    if { $lim == [llength $heap] } {
+		pass "$test"
+	    } else {
+		fail "$test (short list)"
+	    }
+	}
+	-re " = \\(struct list \\*\\) [lindex $heap $lim].*$gdb_prompt $" {
+	    incr lim
+	    if { $lim > 100 } {
+		set ok 0
+		fail "$test (limit $lim exceeded)"
+	    } else {
+		send_gdb "print \$.next\n"
+	    }
+	}
+	-re ".*$gdb_prompt $" {
+	    set ok 0
+	    setup_kfail i*86-*-linux* gdb/1509
+	    fail "$test (address [lindex $heap $lim])"
+	}
+	timeout {
+	    set ok 0
+	    fail "$test (timeout)"
+	}
+    }
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]