Files
binutils-gdb/gdb/testsuite/gdb.python/py-read-memory-leak.py
Andrew Burgess 93c145c2aa gdb/python: restructure the existing memory leak tests
We currently have two memory leak tests in gdb.python/ and there's a
lot of duplication between these two.

In the next commit I'd like to add yet another memory leak test, which
would mean a third set of scripts which duplicate the existing two.
And three is where I draw the line.

This commit factors out the core of the memory leak tests into a new
module gdb_leak_detector.py, which can then be imported by each
tests's Python file in order to make writing the memory leak tests
easier.

I've also added a helper function to lib/gdb-python.exp which captures
some of the common steps needed in the TCL file in order to run a
memory leak test.

Finally, I use this new infrastructure to rewrite the two existing
memory leak tests.

What I considered, but ultimately didn't do, is merge the two memory
leak tests into a single TCL script.  I did consider this, and for the
existing tests this would be possible, but future tests might require
different enough setup that this might not be possible for all future
tests, and now that we have helper functions in a central location,
the each individual test is actually pretty small now, so leaving them
separate seemed OK.

There should be no change in what is actually being tested after this
commit.

Approved-By: Tom Tromey <tom@tromey.com>
2025-04-22 17:21:58 +01:00

34 lines
1.1 KiB
Python

# Copyright (C) 2024-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import gdb_leak_detector
class read_leak_detector(gdb_leak_detector.gdb_leak_detector):
def __init__(self):
super().__init__(__file__)
self.mem_buf = None
self.addr = gdb.parse_and_eval("px")
self.inf = gdb.inferiors()[0]
def allocate(self):
self.mem_buf = self.inf.read_memory(self.addr, 4096)
def deallocate(self):
self.mem_buf = None
read_leak_detector().run()