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

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