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