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