Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.python / py-lookup-type.exp
blob596ab9a9af8522ceb0b567a06a682bf803b0748c
1 # Copyright (C) 2015-2022 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file is part of the GDB testsuite. It tests the mechanism
17 # of exposing types to Python.
19 load_lib gdb-python.exp
21 # Note that the purpose of this testcase is to test the behavior
22 # of gdb.lookup_type searching for the primitive types internally
23 # created by each language since GDB. So, we must start GDB without
24 # loading any symbol in.
26 gdb_exit
27 gdb_start
28 gdb_reinitialize_dir $srcdir/$subdir
30 # Skip all tests if Python scripting is not enabled.
31 if { [skip_python_tests] } { continue }
33 proc test_lookup_type { lang type_name } {
34 gdb_test_no_output "set language ${lang}"
35 gdb_test "python print(gdb.lookup_type('${type_name}').name)" \
36 "${type_name}" \
37 "lookup type ${type_name} using language ${lang}"
40 test_lookup_type "ada" "character"
42 test_lookup_type "c" "char"
44 test_lookup_type "d" "ucent"
46 test_lookup_type "fortran" "character"
48 test_lookup_type "go" "int32"
50 test_lookup_type "modula-2" "CARDINAL"
52 test_lookup_type "opencl" "ushort"
54 test_lookup_type "objective-c" "char"
56 test_lookup_type "pascal" "char"
58 gdb_test "show language" \
59 "The current source language is .pascal.." \
60 "show language before 'with'"
61 gdb_test_multiline "look up type using set_parameter" \
62 "python" "" \
63 "with gdb.with_parameter('language', 'ada'):" "" \
64 " print(gdb.lookup_type('character'))" "" \
65 "end" "character"
66 gdb_test "show language" \
67 "The current source language is .pascal.." \
68 "show language after 'with'"
71 # Ensure that the language can be changed from within Python and still
72 # affect the results.
73 gdb_test_multiline "look up ada type from another language" \
74 "python" "" \
75 "gdb.execute('set language ada')" "" \
76 "print(gdb.lookup_type('character'))" "" \
77 "end" "character"
79 gdb_test_no_output "python gdb.set_parameter('language', 'rust')"
80 gdb_test "show language" \
81 "The current source language is .rust.." \
82 "show language after 'set_parameter'"