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