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

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