]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-symbol.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-symbol.exp
CommitLineData
8acc9f48 1# Copyright (C) 2010-2013 Free Software Foundation, Inc.
f3e9a817
PM
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
a2c09bd0
DE
19load_lib gdb-python.exp
20
b4a58790
TT
21standard_testfile
22
23if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
f3e9a817
PM
24 return -1
25}
26
f3e9a817
PM
27# Skip all tests if Python scripting is not enabled.
28if { [skip_python_tests] } { continue }
29
6e6fbe60
DE
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
9325cb04
PK
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\")"
6e6fbe60 36
9325cb04 37gdb_test "python print (gdb.lookup_global_symbol('main').value())" "$hex .main." \
f0823d2c
TT
38 "print value of main"
39
64e7d9dd 40set qq_line [gdb_get_line_number "line of qq"]
9325cb04 41gdb_test "python print (gdb.lookup_global_symbol('qq').line)" "$qq_line" \
64e7d9dd
TT
42 "print line number of qq"
43
9325cb04 44gdb_test "python print (gdb.lookup_global_symbol('qq').value())" "72" \
f0823d2c
TT
45 "print value of qq"
46
9325cb04 47gdb_test "python print (gdb.lookup_global_symbol('qq').needs_frame)" \
09fa21bd 48 "False" \
f0823d2c
TT
49 "print whether qq needs a frame"
50
51
f3e9a817
PM
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 a" 0
9325cb04
PK
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"
f3e9a817
PM
70
71# Test is_function attribute.
72gdb_py_test_silent_cmd "python func = frame.block().function" "Get block" 0
9325cb04
PK
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"
77gdb_test "python print (func.name)" "func" "Test func.name"
78gdb_test "python print (func.print_name)" "func" "Test func.print_name"
79gdb_test "python print (func.linkage_name)" "func" "Test func.linkage_name"
80gdb_test "python print (func.addr_class == gdb.SYMBOL_LOC_BLOCK)" "True" "Test func.addr_class"
f3e9a817
PM
81
82gdb_breakpoint [gdb_get_line_number "Break at end."]
83gdb_continue_to_breakpoint "Break at end."
84gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
85
86# Test is_variable attribute.
87gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0
9325cb04
PK
88gdb_test "python print (a\[0\].is_variable)" "True" "Test a.is_variable"
89gdb_test "python print (a\[0\].is_constant)" "False" "Test a.is_constant"
90gdb_test "python print (a\[0\].is_argument)" "False" "Test a.is_argument"
91gdb_test "python print (a\[0\].is_function)" "False" "Test a.is_function"
92gdb_test "python print (a\[0\].addr_class == gdb.SYMBOL_LOC_COMPUTED)" "True" "Test a.addr_class"
f3e9a817 93
9325cb04 94gdb_test "python print (a\[0\].value())" \
f0823d2c
TT
95 "symbol requires a frame to compute its value.*"\
96 "try to print value of a without a frame"
9325cb04 97gdb_test "python print (a\[0\].value(frame))" "0" \
f0823d2c 98 "print value of a"
9325cb04 99gdb_test "python print (a\[0\].needs_frame)" "True" \
f0823d2c
TT
100 "print whether a needs a frame"
101
f3e9a817
PM
102# Test is_constant attribute
103gdb_py_test_silent_cmd "python t = gdb.lookup_symbol(\"one\")" "Get variable a" 0
9325cb04
PK
104gdb_test "python print (t\[0\].is_variable)" "False" "Test t.is_variable"
105gdb_test "python print (t\[0\].is_constant)" "True" "Test t.is_constant"
106gdb_test "python print (t\[0\].is_argument)" "False" "Test t.is_argument"
107gdb_test "python print (t\[0\].is_function)" "False" "Test t.is_function"
108gdb_test "python print (t\[0\].addr_class == gdb.SYMBOL_LOC_CONST)" "True" "Test t.addr_class"
457e09f0
DE
109
110# Test type attribute.
9325cb04 111gdb_test "python print (t\[0\].type)" "enum tag" "Get type"
457e09f0
DE
112
113# Test symtab attribute.
9325cb04 114gdb_test "python print (t\[0\].symtab)" "gdb.python/py-symbol.c.*" "Get symtab"
f3e9a817
PM
115
116# C++ tests
117# Recompile binary.
db8e4570 118 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" executable "debug c++"] != "" } {
f3e9a817
PM
119 untested "Couldn't compile ${srcfile} in c++ mode"
120 return -1
121 }
122
123# Start with a fresh gdb.
124gdb_exit
125gdb_start
126gdb_reinitialize_dir $srcdir/$subdir
db8e4570 127gdb_load ${binfile}-cxx
f3e9a817
PM
128
129if ![runto_main] then {
130 fail "Can't run to main"
131 return 0
132}
133
134gdb_breakpoint [gdb_get_line_number "Break in class."]
135gdb_continue_to_breakpoint "Break in class."
136
137gdb_py_test_silent_cmd "python cplusframe = gdb.selected_frame()" "Get Frame" 0
138gdb_py_test_silent_cmd "python cplusfunc = cplusframe.block().function" "Get block" 0
9325cb04
PK
139gdb_test "python print (cplusfunc.is_variable)" "False" "Test func.is_variable"
140gdb_test "python print (cplusfunc.is_constant)" "False" "Test func.is_constant"
141gdb_test "python print (cplusfunc.is_argument)" "False" "Test func.is_argument"
142gdb_test "python print (cplusfunc.is_function)" "True" "Test func.is_function"
143gdb_test "python print (cplusfunc.name)" "SimpleClass::valueofi().*" "Test func.name"
144gdb_test "python print (cplusfunc.print_name)" "SimpleClass::valueofi().*" "Test func.print_name"
145gdb_test "python print (cplusfunc.linkage_name)" "SimpleClass::valueofi().*" "Test func.linkage_name"
146gdb_test "python print (cplusfunc.addr_class == gdb.SYMBOL_LOC_BLOCK)" "True" "Test func.addr_class"
29703da4
PM
147
148# Test is_valid when the objfile is unloaded. This must be the last
149# test as it unloads the object file in GDB.
150# Start with a fresh gdb.
151clean_restart ${testfile}
152if ![runto_main] then {
153 fail "Cannot run to main."
154 return 0
155}
156gdb_breakpoint [gdb_get_line_number "Break at end."]
157gdb_continue_to_breakpoint "Break at end."
158gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0
9325cb04 159gdb_test "python print (a\[0\].is_valid())" "True" "Test symbol validity"
29703da4
PM
160delete_breakpoints
161gdb_unload
9325cb04 162gdb_test "python print (a\[0\].is_valid())" "False" "Test symbol validity"
74f910c8 163gdb_test_no_output "python a = None" "Test symbol destructor"