Blame SOURCES/gdb-6.5-gcore-buffer-limit-test.patch

7a6771
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.base/gcore-excessive-memory.c
7a6771
===================================================================
7a6771
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
7a6771
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.base/gcore-excessive-memory.c	2016-02-15 23:28:15.943731340 +0100
7a6771
@@ -0,0 +1,37 @@
7a6771
+/* This testcase is part of GDB, the GNU debugger.
7a6771
+
7a6771
+   Copyright 2008 Free Software Foundation, Inc.
7a6771
+
7a6771
+   This program is free software; you can redistribute it and/or modify
7a6771
+   it under the terms of the GNU General Public License as published by
7a6771
+   the Free Software Foundation; either version 2 of the License, or
7a6771
+   (at your option) any later version.
7a6771
+
7a6771
+   This program is distributed in the hope that it will be useful,
7a6771
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
7a6771
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7a6771
+   GNU General Public License for more details.
7a6771
+ 
7a6771
+   You should have received a copy of the GNU General Public License
7a6771
+   along with this program; if not, write to the Free Software
7a6771
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7a6771
+
7a6771
+   Please email any bugs, comments, and/or additions to this file to:
7a6771
+   bug-gdb@prep.ai.mit.edu  */
7a6771
+
7a6771
+#include <unistd.h>
7a6771
+#include <stdlib.h>
7a6771
+
7a6771
+#define MEGS 64
7a6771
+
7a6771
+int main()
7a6771
+{
7a6771
+  void *mem;
7a6771
+  
7a6771
+  mem = malloc (MEGS * 1024ULL * 1024ULL);
7a6771
+
7a6771
+  for (;;)
7a6771
+    sleep (1);
7a6771
+
7a6771
+  return 0;
7a6771
+}
7a6771
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.base/gcore-excessive-memory.exp
7a6771
===================================================================
7a6771
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
7a6771
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.base/gcore-excessive-memory.exp	2016-02-15 23:28:22.720779458 +0100
7a6771
@@ -0,0 +1,94 @@
7a6771
+# Copyright 2008 Free Software Foundation, Inc.
7a6771
+
7a6771
+# This program is free software; you can redistribute it and/or modify
7a6771
+# it under the terms of the GNU General Public License as published by
7a6771
+# the Free Software Foundation; either version 2 of the License, or
7a6771
+# (at your option) any later version.
7a6771
+# 
7a6771
+# This program is distributed in the hope that it will be useful,
7a6771
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
7a6771
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7a6771
+# GNU General Public License for more details.
7a6771
+# 
7a6771
+# You should have received a copy of the GNU General Public License
7a6771
+# along with this program; if not, write to the Free Software
7a6771
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
7a6771
+
7a6771
+set testfile gcore-excessive-memory
7a6771
+set srcfile ${testfile}.c
7a6771
+set shfile [standard_output_file ${testfile}-gdb.sh]
7a6771
+set corefile [standard_output_file ${testfile}.core]
7a6771
+set binfile [standard_output_file ${testfile}]
7a6771
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
7a6771
+    untested "Couldn't compile test program"
7a6771
+    return -1
7a6771
+}
7a6771
+
7a6771
+set f [open "|getconf PAGESIZE" "r"]
7a6771
+gets $f pagesize
7a6771
+close $f
7a6771
+
7a6771
+set pid_of_bin [eval exec $binfile &]
7a6771
+sleep 2
7a6771
+
7a6771
+# Get things started.
7a6771
+
7a6771
+gdb_exit
7a6771
+gdb_start
7a6771
+gdb_reinitialize_dir $srcdir/$subdir
7a6771
+gdb_load ${binfile}
7a6771
+
7a6771
+set pid_of_gdb [exp_pid -i [board_info host fileid]]
7a6771
+
7a6771
+gdb_test "attach $pid_of_bin" "Attaching to .*" "attach"
7a6771
+gdb_test "up 99" "in main .*" "verify we can get to main"
7a6771
+
7a6771
+proc memory_v_pages_get {} {
7a6771
+    global pid_of_gdb pagesize
7a6771
+    set fd [open "/proc/$pid_of_gdb/statm"]
7a6771
+    gets $fd line
7a6771
+    close $fd
7a6771
+    # number of pages of virtual memory
7a6771
+    scan $line "%d" drs
7a6771
+    return $drs
7a6771
+}
7a6771
+
7a6771
+set pages_found [memory_v_pages_get]
7a6771
+
7a6771
+# It must be definitely less than `MEGS' of `gcore-excessive-memory.c'.
7a6771
+set mb_gcore_reserve 4
7a6771
+verbose -log "pages_found = $pages_found, mb_gcore_reserve = $mb_gcore_reserve"
7a6771
+set kb_found [expr $pages_found * $pagesize / 1024]
7a6771
+set kb_permit [expr $kb_found + 1 * 1024 + $mb_gcore_reserve * 1024]
7a6771
+verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
7a6771
+
7a6771
+# Create the ulimit wrapper.
7a6771
+set f [open $shfile "w"]
7a6771
+puts $f "#! /bin/sh"
7a6771
+puts $f "ulimit -v $kb_permit"
7a6771
+puts $f "exec $GDB \"\$@\""
7a6771
+close $f
7a6771
+remote_exec host "chmod +x $shfile"
7a6771
+
7a6771
+gdb_exit
7a6771
+set GDBold $GDB
7a6771
+set GDB "$shfile"
7a6771
+gdb_start
7a6771
+set GDB $GDBold
7a6771
+
7a6771
+gdb_reinitialize_dir $srcdir/$subdir
7a6771
+gdb_load ${binfile}
7a6771
+
7a6771
+set pid_of_gdb [exp_pid -i [board_info host fileid]]
7a6771
+
7a6771
+gdb_test "attach $pid_of_bin" "Attaching to .*" "attach"
7a6771
+gdb_test "up 99" "in main .*" "verify we can get to main"
7a6771
+
7a6771
+verbose -log "kb_found before gcore = [expr [memory_v_pages_get] * $pagesize / 1024]"
7a6771
+
7a6771
+gdb_test "gcore $corefile" "Saved corefile \[^\n\r\]*" "Save the core file"
7a6771
+
7a6771
+verbose -log "kb_found after gcore = [expr [memory_v_pages_get] * $pagesize / 1024]"
7a6771
+
7a6771
+# Cleanup.
7a6771
+exec kill -9 $pid_of_bin