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

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