test: cover subranges with present DW_AT_count attribute
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-symbol.exp
... / ...
CommitLineData
1# Copyright (C) 2010-2014 Free Software Foundation, Inc.
2
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.
7#
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.
12#
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/>.
15
16# This file is part of the GDB testsuite. It tests the mechanism
17# exposing values to Python.
18
19load_lib gdb-python.exp
20
21standard_testfile
22
23if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
24 return -1
25}
26
27# Skip all tests if Python scripting is not enabled.
28if { [skip_python_tests] } { continue }
29
30# Test looking up a global symbol before we runto_main as this is the
31# point where we don't have a current frame, and we don't want to
32# require one.
33gdb_py_test_silent_cmd "python main_func = gdb.lookup_global_symbol(\"main\")" "Lookup main" 1
34gdb_test "python print (main_func.is_function)" "True" "Test main_func.is_function"
35gdb_test "python print (gdb.lookup_global_symbol(\"junk\"))" "None" "Test lookup_global_symbol(\"junk\")"
36
37gdb_test "python print (gdb.lookup_global_symbol('main').value())" "$hex .main." \
38 "print value of main"
39
40set qq_line [gdb_get_line_number "line of qq"]
41gdb_test "python print (gdb.lookup_global_symbol('qq').line)" "$qq_line" \
42 "print line number of qq"
43
44gdb_test "python print (gdb.lookup_global_symbol('qq').value())" "72" \
45 "print value of qq"
46
47gdb_test "python print (gdb.lookup_global_symbol('qq').needs_frame)" \
48 "False" \
49 "print whether qq needs a frame"
50
51
52if ![runto_main] then {
53 fail "Can't run to main"
54 return 0
55}
56
57global hex decimal
58
59gdb_breakpoint [gdb_get_line_number "Block break here."]
60gdb_continue_to_breakpoint "Block break here."
61gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
62gdb_py_test_silent_cmd "python block = frame.block()" "Get block" 0
63
64# Test is_argument attribute.
65gdb_py_test_silent_cmd "python arg = gdb.lookup_symbol(\"arg\")" "Get variable arg" 0
66gdb_test "python print (arg\[0\].is_variable)" "False" "Test arg.is_variable"
67gdb_test "python print (arg\[0\].is_constant)" "False" "Test arg.is_constant"
68gdb_test "python print (arg\[0\].is_argument)" "True" "Test arg.is_argument"
69gdb_test "python print (arg\[0\].is_function)" "False" "Test arg.is_function"
70
71# Test is_function attribute.
72gdb_py_test_silent_cmd "python func = block.function" "Get block function" 0
73gdb_test "python print (func.is_variable)" "False" "Test func.is_variable"
74gdb_test "python print (func.is_constant)" "False" "Test func.is_constant"
75gdb_test "python print (func.is_argument)" "False" "Test func.is_argument"
76gdb_test "python print (func.is_function)" "True" "Test func.is_function"
77
78# Test attributes of func.
79gdb_test "python print (func.name)" "func" "Test func.name"
80gdb_test "python print (func.print_name)" "func" "Test func.print_name"
81gdb_test "python print (func.linkage_name)" "func" "Test func.linkage_name"
82gdb_test "python print (func.addr_class == gdb.SYMBOL_LOC_BLOCK)" "True" "Test func.addr_class"
83
84gdb_breakpoint [gdb_get_line_number "Break at end."]
85gdb_continue_to_breakpoint "Break at end for variable a" ".*Break at end.*"
86gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
87
88# Test is_variable attribute.
89gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0
90gdb_test "python print (a\[0\].is_variable)" "True" "Test a.is_variable"
91gdb_test "python print (a\[0\].is_constant)" "False" "Test a.is_constant"
92gdb_test "python print (a\[0\].is_argument)" "False" "Test a.is_argument"
93gdb_test "python print (a\[0\].is_function)" "False" "Test a.is_function"
94
95# Test attributes of a.
96gdb_test "python print (a\[0\].addr_class == gdb.SYMBOL_LOC_COMPUTED)" "True" "Test a.addr_class"
97
98gdb_test "python print (a\[0\].value())" \
99 "symbol requires a frame to compute its value.*"\
100 "try to print value of a without a frame"
101gdb_test "python print (a\[0\].value(frame))" "0" \
102 "print value of a"
103gdb_test "python print (a\[0\].needs_frame)" "True" \
104 "print whether a needs a frame"
105
106# Test is_constant attribute
107gdb_py_test_silent_cmd "python t = gdb.lookup_symbol(\"one\")" "Get constant t" 0
108gdb_test "python print (t\[0\].is_variable)" "False" "Test t.is_variable"
109gdb_test "python print (t\[0\].is_constant)" "True" "Test t.is_constant"
110gdb_test "python print (t\[0\].is_argument)" "False" "Test t.is_argument"
111gdb_test "python print (t\[0\].is_function)" "False" "Test t.is_function"
112
113# Test attributes of t.
114gdb_test "python print (t\[0\].addr_class == gdb.SYMBOL_LOC_CONST)" "True" "Test t.addr_class"
115
116# Test type attribute.
117gdb_test "python print (t\[0\].type)" "enum tag" "Get type"
118
119# Test symtab attribute.
120gdb_test "python print (t\[0\].symtab)" "gdb.python/py-symbol.c.*" "Get symtab"
121
122# C++ tests
123# Recompile binary.
124if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" executable "debug c++"] != "" } {
125 untested "Couldn't compile ${srcfile} in c++ mode"
126 return -1
127}
128
129# Start with a fresh gdb.
130gdb_exit
131gdb_start
132gdb_reinitialize_dir $srcdir/$subdir
133gdb_load ${binfile}-cxx
134
135if ![runto_main] then {
136 fail "Can't run to main"
137 return 0
138}
139
140gdb_breakpoint [gdb_get_line_number "Break in class."]
141gdb_continue_to_breakpoint "Break in class."
142
143gdb_py_test_silent_cmd "python cplusframe = gdb.selected_frame()" "Get Frame at class" 0
144gdb_py_test_silent_cmd "python cplusfunc = cplusframe.block().function" "Get function at class" 0
145
146gdb_test "python print (cplusfunc.is_variable)" \
147 "False" "Test cplusfunc.is_variable"
148gdb_test "python print (cplusfunc.is_constant)" \
149 "False" "Test cplusfunc.is_constant"
150gdb_test "python print (cplusfunc.is_argument)" \
151 "False" "Test cplusfunc.is_argument"
152gdb_test "python print (cplusfunc.is_function)" \
153 "True" "Test cplusfunc.is_function"
154
155gdb_test "python print (cplusfunc.name)" "SimpleClass::valueofi().*" "Test method.name"
156gdb_test "python print (cplusfunc.print_name)" "SimpleClass::valueofi().*" "Test method.print_name"
157gdb_test "python print (cplusfunc.linkage_name)" "SimpleClass::valueofi().*" "Test method.linkage_name"
158gdb_test "python print (cplusfunc.addr_class == gdb.SYMBOL_LOC_BLOCK)" "True" "Test method.addr_class"
159
160# Test is_valid when the objfile is unloaded. This must be the last
161# test as it unloads the object file in GDB.
162# Start with a fresh gdb.
163clean_restart ${testfile}
164if ![runto_main] then {
165 fail "Cannot run to main."
166 return 0
167}
168
169gdb_breakpoint [gdb_get_line_number "Break at end."]
170gdb_continue_to_breakpoint "Break at end for symbol validity" ".*Break at end.*"
171gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0
172gdb_test "python print (a\[0\].is_valid())" "True" "Test symbol validity"
173delete_breakpoints
174gdb_unload
175gdb_test "python print (a\[0\].is_valid())" "False" "Test symbol non-validity"
176gdb_test_no_output "python a = None" "Test symbol destructor"
This page took 0.024444 seconds and 4 git commands to generate.