aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-symtab.exp
blob: 18d77a0296fc1fd85afd8843f256059c5925017d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright (C) 2010-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 mechanism
# exposing values to Python.

load_lib gdb-python.exp

require allow_python_tests

standard_testfile py-symbol.c

if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
    return -1
}

if {![runto_main]} {
    return 0
}

set debug_types [debug_types]

global hex decimal

# Setup and get the symbol table.
set line_no [gdb_get_line_number "Block break here."]
gdb_breakpoint $line_no
gdb_continue_to_breakpoint "Block break here."
gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
gdb_py_test_silent_cmd "python sal = frame.find_sal()" "Get block" 0
gdb_py_test_silent_cmd "python symtab = sal.symtab" "Get block" 0
gdb_py_test_silent_cmd "python global_block = symtab.global_block()" "Get global block" 0
gdb_py_test_silent_cmd "python static_block = symtab.static_block()" "Get static block" 0
gdb_py_test_silent_cmd "python global_symbols = \[\]; static_symbols = \[\]" "Set up symbol name lists" 0
gdb_py_test_silent_cmd "python for sym in global_block: global_symbols.append(sym.name)" "Get global symbol names" 0
gdb_py_test_silent_cmd "python for sym in static_block: static_symbols.append(sym.name)" "Get static symbol names" 0
gdb_py_test_silent_cmd "step" "Step to the next line" 0
gdb_py_test_silent_cmd "python new_pc = gdb.selected_frame().find_sal().pc" "Get new PC" 0

# Test sal.
if { [is_remote host] } {
    set py_symbol_c [string_to_regexp $srcfile]
    set full_py_symbol_c $py_symbol_c
} else {
    set py_symbol_c [string_to_regexp ${srcdir}/${subdir}/${srcfile}]
    set full_py_symbol_c [string_to_regexp testsuite/${subdir}/${srcfile}]
}

gdb_test "python print (sal.symtab)" ".*${py_symbol_c}" "test symtab"
gdb_test "python print (sal.pc)" "${decimal}" "test sal.pc"
gdb_test "python print (sal.last == (new_pc - 1))" "True" "test sal.last"
gdb_test "python print (sal.line)" "$line_no" "test sal.line"
gdb_test "python print (sal.is_valid())" "True" "test sal.is_valid"

# Test symbol table.
gdb_test "python print (symtab.filename)" ".*${py_symbol_c}" "test symtab.filename"
gdb_test "python print (symtab.objfile)" \
    "<gdb.Objfile filename=.*${testfile}.*>" "test symtab.objfile"
gdb_test "python print (symtab.fullname())" ".*${full_py_symbol_c}" "test symtab.fullname"
gdb_test "python print (symtab.is_valid())" "True" "test symtab.is_valid()"
gdb_test "python print (\"qq\" in global_symbols)" "True" "test qq in global symbols"
gdb_test "python print (\"func\" in global_symbols)" "True" "test func in global symbols"
gdb_test "python print (\"main\" in global_symbols)" "True" "test main in global symbols"
gdb_test "python print (\"int\" in static_symbols)" "True" "test int in static symbols"
gdb_test "python print (\"char\" in static_symbols)" "True" "test char in static symbols"
gdb_test_multiple "python print (\"simple_struct\" in static_symbols)" \
    "test simple_struct in static symbols" {
	-re -wrap "True" {
	    pass $gdb_test_name
	}
	-re -wrap "False" {
	    if { $debug_types } {
		# Xfail for PR gcc/90232.
		xfail $gdb_test_name
	    } else {
		fail $gdb_test_name
	    }
	}
    }

# Test symtab identity
gdb_test "python print (symtab is symtab)"\
    "True" \
    "test symtab identity 1"
gdb_test "python print (symtab is gdb.selected_frame().find_sal().symtab)"\
    "True" \
    "test symtab identity 2"
gdb_test "python print (sal.symtab is gdb.selected_frame().find_sal().symtab)"\
    "True" \
    "test symtab identity 3"
gdb_test "python print (symtab is not \"xxx\")"\
    "True" \
    "test symtab non-identity with non-symtab"

# Test symtab equality
gdb_test "python print (symtab == symtab)"\
    "True" \
    "test symtab equality 1"
gdb_test "python print (symtab == gdb.selected_frame().find_sal().symtab)"\
    "True" \
    "test symtab equality 2"
gdb_test "python print (sal.symtab == gdb.selected_frame().find_sal().symtab)"\
    "True" \
    "test symtab equality 3"
gdb_test "python print (symtab != \"xxx\")"\
    "True" \
    "test symtab non-equality with non-symtab"

# Test is_valid when the objfile is unloaded.  This must be the last
# test as it unloads the object file in GDB.
gdb_unload
gdb_test "python print (sal.is_valid())" "False" \
    "test sal.is_valid after unload"
gdb_test "python print (symtab.is_valid())" "False" \
    "test symtab.is_valid() after unload"

gdb_test_no_output "python sal = None" "test sal destructor"
gdb_test_no_output "python symtab = None" "test symtab destructor"