|
|
93189d |
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
|
|
93189d |
From: Fedora GDB patches <invalid@email.com>
|
|
|
93189d |
Date: Fri, 27 Oct 2017 21:07:50 +0200
|
|
|
93189d |
Subject: gdb-rhbz1007614-memleak-infpy_read_memory-test.patch
|
|
|
93189d |
|
|
|
93189d |
;; Fix 'memory leak in infpy_read_memory()' (RH BZ 1007614)
|
|
|
93189d |
;;=fedoratest
|
|
|
93189d |
|
|
|
93189d |
Original message by Tom Tromey:
|
|
|
93189d |
|
|
|
93189d |
<https://sourceware.org/ml/gdb-patches/2012-03/msg00955.html>
|
|
|
93189d |
Message-ID: <871uoc1va3.fsf@fleche.redhat.com>
|
|
|
93189d |
|
|
|
93189d |
Comment from Sergio Durigan Junior:
|
|
|
93189d |
|
|
|
93189d |
In order to correctly test this patch, I wrote a testcase based on Jan
|
|
|
93189d |
Kratochvil's <gdb/testsuite/gdb.base/gcore-excessive-memory.exp>. The
|
|
|
93189d |
testcase, which can be seen below, tests GDB in order to see if the
|
|
|
93189d |
amount of memory being leaked is minimal, as requested in the bugzilla.
|
|
|
93189d |
It is hard to define what "minimum" is, so I ran the testcase on all
|
|
|
93189d |
supported RHEL architectures and came up with an average.
|
|
|
93189d |
|
|
|
93189d |
commit cc0265cdda9dc7e8665e8bfcf5b4477489daf27c
|
|
|
93189d |
Author: Tom Tromey <tromey@redhat.com>
|
|
|
93189d |
Date: Wed Mar 28 17:38:08 2012 +0000
|
|
|
93189d |
|
|
|
93189d |
* python/py-inferior.c (infpy_read_memory): Remove cleanups and
|
|
|
93189d |
explicitly free 'buffer' on exit paths. Decref 'membuf_object'
|
|
|
93189d |
before returning.
|
|
|
93189d |
|
|
|
93189d |
diff --git a/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.c b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.c
|
|
|
93189d |
new file mode 100644
|
|
|
93189d |
--- /dev/null
|
|
|
93189d |
+++ b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.c
|
|
|
93189d |
@@ -0,0 +1,27 @@
|
|
|
93189d |
+/* This testcase is part of GDB, the GNU debugger.
|
|
|
93189d |
+
|
|
|
93189d |
+ Copyright 2014 Free Software Foundation, Inc.
|
|
|
93189d |
+
|
|
|
93189d |
+ This program is free software; you can redistribute it and/or modify
|
|
|
93189d |
+ it under the terms of the GNU General Public License as published by
|
|
|
93189d |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
93189d |
+ (at your option) any later version.
|
|
|
93189d |
+
|
|
|
93189d |
+ This program is distributed in the hope that it will be useful,
|
|
|
93189d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
93189d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
93189d |
+ GNU General Public License for more details.
|
|
|
93189d |
+
|
|
|
93189d |
+ You should have received a copy of the GNU General Public License
|
|
|
93189d |
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
93189d |
+
|
|
|
93189d |
+static struct x
|
|
|
93189d |
+ {
|
|
|
93189d |
+ char unsigned u[4096];
|
|
|
93189d |
+ } x, *px = &x;
|
|
|
93189d |
+
|
|
|
93189d |
+int
|
|
|
93189d |
+main (int argc, char *argv[])
|
|
|
93189d |
+{
|
|
|
93189d |
+ return 0;
|
|
|
93189d |
+}
|
|
|
93189d |
diff --git a/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.exp b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.exp
|
|
|
93189d |
new file mode 100644
|
|
|
93189d |
--- /dev/null
|
|
|
93189d |
+++ b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.exp
|
|
|
93189d |
@@ -0,0 +1,68 @@
|
|
|
93189d |
+# Copyright 2014 Free Software Foundation, Inc.
|
|
|
93189d |
+
|
|
|
93189d |
+# This program is free software; you can redistribute it and/or modify
|
|
|
93189d |
+# it under the terms of the GNU General Public License as published by
|
|
|
93189d |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
93189d |
+# (at your option) any later version.
|
|
|
93189d |
+#
|
|
|
93189d |
+# This program is distributed in the hope that it will be useful,
|
|
|
93189d |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
93189d |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
93189d |
+# GNU General Public License for more details.
|
|
|
93189d |
+#
|
|
|
93189d |
+# You should have received a copy of the GNU General Public License
|
|
|
93189d |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
93189d |
+
|
|
|
93189d |
+set testfile py-gdb-rhbz1007614-memleak-infpy_read_memory
|
|
|
93189d |
+set srcfile ${testfile}.c
|
|
|
93189d |
+set binfile [standard_output_file ${testfile}]
|
|
|
93189d |
+
|
|
|
93189d |
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
|
|
|
93189d |
+ return -1
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+if { [skip_python_tests] } { continue }
|
|
|
93189d |
+
|
|
|
93189d |
+set pid_of_gdb [exp_pid -i [board_info host fileid]]
|
|
|
93189d |
+
|
|
|
93189d |
+proc memory_v_pages_get {} {
|
|
|
93189d |
+ global pid_of_gdb
|
|
|
93189d |
+ set fd [open "/proc/$pid_of_gdb/statm"]
|
|
|
93189d |
+ gets $fd line
|
|
|
93189d |
+ close $fd
|
|
|
93189d |
+ # number of pages of virtual memory
|
|
|
93189d |
+ scan $line "%d" drs
|
|
|
93189d |
+ return $drs
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+if { ![runto_main] } {
|
|
|
93189d |
+ untested $testfile.exp
|
|
|
93189d |
+ return -1
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
|
|
|
93189d |
+
|
|
|
93189d |
+gdb_test "source ${remote_python_file}" ""
|
|
|
93189d |
+
|
|
|
93189d |
+gdb_test "hello-world" ""
|
|
|
93189d |
+
|
|
|
93189d |
+set kbytes_before [memory_v_pages_get]
|
|
|
93189d |
+verbose -log "kbytes_before = $kbytes_before"
|
|
|
93189d |
+
|
|
|
93189d |
+gdb_test "hello-world" ""
|
|
|
93189d |
+
|
|
|
93189d |
+set kbytes_after [memory_v_pages_get]
|
|
|
93189d |
+verbose -log "kbytes_after = $kbytes_after"
|
|
|
93189d |
+
|
|
|
93189d |
+set kbytes_diff [expr $kbytes_after - $kbytes_before]
|
|
|
93189d |
+verbose -log "kbytes_diff = $kbytes_diff"
|
|
|
93189d |
+
|
|
|
93189d |
+# The value "1000" was calculated by running a few GDB sessions with this
|
|
|
93189d |
+# testcase, and seeing how much (in average) the memory consumption
|
|
|
93189d |
+# increased after the "hello-world" command issued above. The average
|
|
|
93189d |
+# was around 500 bytes, so I chose 1000 as a high estimate.
|
|
|
93189d |
+if { $kbytes_diff > 1000 } {
|
|
|
93189d |
+ fail "there is a memory leak on GDB (RHBZ 1007614)"
|
|
|
93189d |
+} else {
|
|
|
93189d |
+ pass "there is not a memory leak on GDB (RHBZ 1007614)"
|
|
|
93189d |
+}
|
|
|
93189d |
diff --git a/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.py b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.py
|
|
|
93189d |
new file mode 100644
|
|
|
93189d |
--- /dev/null
|
|
|
93189d |
+++ b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.py
|
|
|
93189d |
@@ -0,0 +1,30 @@
|
|
|
93189d |
+# Copyright (C) 2014 Free Software Foundation, Inc.
|
|
|
93189d |
+
|
|
|
93189d |
+# This program is free software; you can redistribute it and/or modify
|
|
|
93189d |
+# it under the terms of the GNU General Public License as published by
|
|
|
93189d |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
93189d |
+# (at your option) any later version.
|
|
|
93189d |
+#
|
|
|
93189d |
+# This program is distributed in the hope that it will be useful,
|
|
|
93189d |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
93189d |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
93189d |
+# GNU General Public License for more details.
|
|
|
93189d |
+#
|
|
|
93189d |
+# You should have received a copy of the GNU General Public License
|
|
|
93189d |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
93189d |
+
|
|
|
93189d |
+class HelloWorld (gdb.Command):
|
|
|
93189d |
+ """Greet the whole world."""
|
|
|
93189d |
+
|
|
|
93189d |
+ def __init__ (self):
|
|
|
93189d |
+ super (HelloWorld, self).__init__ ("hello-world",
|
|
|
93189d |
+ gdb.COMMAND_OBSCURE)
|
|
|
93189d |
+
|
|
|
93189d |
+ def invoke (self, arg, from_tty):
|
|
|
93189d |
+ px = gdb.parse_and_eval("px")
|
|
|
93189d |
+ core = gdb.inferiors()[0]
|
|
|
93189d |
+ for i in range(256 * 1024):
|
|
|
93189d |
+ chunk = core.read_memory(px, 4096)
|
|
|
93189d |
+ print "Hello, World!"
|
|
|
93189d |
+
|
|
|
93189d |
+HelloWorld ()
|