Index: gdb-6.1/gdb/testsuite/gdb.base/bigcore.exp
===================================================================
--- gdb-6.1.orig/gdb/testsuite/gdb.base/bigcore.exp	2004-02-27 11:48:03.000000000 -0500
+++ gdb-6.1/gdb/testsuite/gdb.base/bigcore.exp	2004-04-19 10:45:28.000000000 -0400
@@ -103,9 +103,72 @@ gdb_test "tbreak $print_core_line"
 gdb_test continue ".*print_string.*"
 gdb_test next ".*0 = 0.*"
 
+# Traverse part of bigcore's linked list of memory chunks, finding the total
+# size.  Note that we use GDB to do the math; TCL is not reliable with
+# extremely large integers.
+
+proc heap_size { } {
+    global gdb_prompt
+    global expect_out
+    set test "find heap size"
+    set lim 0
+    gdb_test "set \$size = 0" ""
+    gdb_test_multiple "print heap.next" "$test" {
+	-re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
+	    pass "$test"
+	}
+	-re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" {
+	    if { $lim >= 50 } {
+		pass "$test (stop at $lim)"
+	    } else {
+		incr lim
+		gdb_test "set \$size = \$size + \$.size" ""
+		send_gdb "print \$.next\n"
+		exp_continue
+	    }
+	}
+	-re ".*$gdb_prompt $" {
+	    fail "$test (entry $lim)"
+	}
+	timeout {
+	    fail "$test (timeout)"
+	}
+    }
+    gdb_test_multiple "print \$size" "print \$size" {
+	-re " = (\[0-9\]*)\r\n$gdb_prompt $" {
+	    set size $expect_out(1,string)
+	    pass "print \$size"
+	}
+    }
+    return $size;
+}
+
+set total_size [heap_size]
+
+# Check that the corefile is plausibly large enough.  We're trying to
+# detect the case where the operating system has truncated the file
+# just before signed wraparound.  TCL, unfortunately, has a similar
+# problem - so use catch.  It can handle the "bad" size but not necessarily
+# the "good" one.  And we must use GDB for the comparison, similarly.
+
+if {[catch {file size $corefile} core_size] == 0} {
+    set core_ok 0
+    gdb_test_multiple "print $total_size < $core_size" "check core size" {
+	-re " = 1\r\n$gdb_prompt $" {
+	    pass "check core size"
+	    set core_ok 1
+	}
+	-re " = 0\r\n$gdb_prompt $" {
+	    xfail "check core size (system does not support large corefiles)"
+	}
+    }
+    if {$core_ok == 0} {
+	return 0
+    }
+}
+
 # Traverse part of bigcore's linked list of memory chunks (forward or
-# backward), saving each chunk's address.  I don't know why but
-# expect_out didn't work with gdb_test_multiple.
+# backward), saving each chunk's address.
 
 proc extract_heap { dir } {
     global gdb_prompt
@@ -113,8 +176,7 @@ proc extract_heap { dir } {
     set heap ""
     set test "extract ${dir} heap"
     set lim 0
-    send_gdb "print heap.${dir}\n"
-    gdb_expect {
+    gdb_test_multiple "print heap.${dir}" "$test" {
 	-re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
 	    pass "$test"
 	}
