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

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