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

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