Files
binutils-gdb/gdb/testsuite/gdb.python/py-compunit.exp
Jan Vrany 79c9dc182d gdb/python: allow instantiation of gdb.Compunit from Python
This commit adds code to allow user extension to instantiate
gdb.Compunit. This is a step towards a Python support for dynamically
generated code (JIT) in GDB.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-11-21 13:52:21 +00:00

102 lines
3.5 KiB
Plaintext

# Copyright (C) 2024-2024 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/>.
# This file is part of the GDB testsuite. It tests the compunit
# support in Python.
load_lib gdb-python.exp
require allow_python_tests
standard_testfile py-objfile.c
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
return -1
}
if {![runto_main]} {
return 0
}
set python_error_text "Error occurred in Python.*"
gdb_py_test_silent_cmd "python sym = gdb.lookup_symbol(\"some_var\")" \
"Find a symbol in objfile" 1
gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \
"Get backing object file" 1
gdb_test "python print (len(objfile.compunits()) > 0)" \
"True" \
"Get objfile compunits"
gdb_test "python print (objfile.compunits())" \
"\\\[<gdb\.Compunit object at .*>\\\]" \
"Objfile compunits return a sequence of gdb.Compunit"
gdb_test "python print (objfile.compunits()\[0\] == objfile.compunits()\[0\])" \
"True" \
"Compunits are comparable"
gdb_test "python print (len(objfile.compunits()\[0\].symtabs) > 0)" \
"True" \
"Get compunit symtabs"
gdb_test "python print (objfile.compunits()\[0\].symtabs)" \
"\\\[<gdb\.Symtab.*>\\\]" \
"Compunit symtabs return a sequence of gdb.Symtab"
# Test creation of compunits
gdb_py_test_silent_cmd "python cu = gdb.Compunit(\"compunit1\", objfile, 200, 300)" \
"Create compunit1" 1
gdb_test "python print(cu)" \
"<gdb\.Compunit object at .*>" \
"Print created compunit1"
gdb_test "python print(cu in objfile.compunits())" \
"True" \
"Test compunit1 is in objfile.compunits()"
gdb_test "python print(cu.global_block().start)" \
"0" \
"Test compunit1.global_block().start is 0"
gdb_test "python print(cu.global_block().end)" \
"0" \
"Test compunit1.global_block().end is 0"
gdb_test "python print(cu.static_block().start)" \
"0" \
"Test compunit1.static_block().start is 0"
gdb_test "python print(cu.static_block().end)" \
"0" \
"Test compunit1.static_block().end is 0"
gdb_py_test_silent_cmd "python cu2 = gdb.Compunit(\"dynamic2\", objfile, 400, 500, 24)" \
"Create compunit2 with capacity fo 24 blocks" 1
gdb_test "python cu3 = gdb.Compunit(\"dynamic3\", gdb, 600, 700)" \
"TypeError.*:.*" \
"Create compunit3 passing non-objfile"
gdb_test "python cu4 = gdb.Compunit(\"dynamic4\", objfile, 900, 800)" \
"ValueError.*:.*" \
"Create compunit4 passing invalid global block range"
gdb_test "python cu5 = gdb.Compunit(\"dynamic5\", objfile, 225, 325)" \
"ValueError.*:.*" \
"Create compunit4 passing overlapping global block range"
gdb_unload "unload 1"
gdb_test "python print (objfile.is_valid())" "False" \
"Get objfile validity after unload"
gdb_test "python print (objfile.compunits())" "RuntimeError.*: Objfile no longer exists.*" \
"Get objfile compunits after unload"
gdb_py_test_silent_cmd "python cu6 = gdb.Compunit(\"dynamic6\", objfile)" \
"Create compunit4 passing invalid objfile" 1