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

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