[gdb/python] Throw MemoryError in inferior.read_memory if malloc fails
commit06e967dbc9b75a4a3c1b15b54360cf1abbf9c2bd
authorTom de Vries <tdevries@suse.de>
Tue, 16 Apr 2024 13:53:47 +0000 (16 15:53 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 16 Apr 2024 13:53:47 +0000 (16 15:53 +0200)
tree6e4a4137a7b51c19937e94038188b55abf29ccc3
parent2d4c39a885d4d12325d0a9be9e014e75a295fb25
[gdb/python] Throw MemoryError in inferior.read_memory if malloc fails

PR python/31631 reports a gdb internal error when doing:
...
(gdb) python gdb.selected_inferior().read_memory (0, 0xffffffffffffffff)
utils.c:709: internal-error: virtual memory exhausted.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
...

Fix this by throwing a python MemoryError, such that we have instead:
...
(gdb) python gdb.selected_inferior().read_memory (0, 0xffffffffffffffff)
Python Exception <class 'MemoryError'>:
Error occurred in Python.
(gdb)
...

Likewise for DAP.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31631
gdb/python/lib/gdb/dap/memory.py
gdb/python/py-inferior.c
gdb/testsuite/gdb.dap/memory.exp
gdb/testsuite/gdb.python/py-inferior.exp