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

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