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

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