| OLD | NEW |
| 1 # Copyright (C) 2010-2012 Free Software Foundation, Inc. | 1 # Copyright (C) 2010-2012 Free Software Foundation, Inc. |
| 2 | 2 |
| 3 # This program is free software; you can redistribute it and/or modify | 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 | 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 | 5 # the Free Software Foundation; either version 3 of the License, or |
| 6 # (at your option) any later version. | 6 # (at your option) any later version. |
| 7 # | 7 # |
| 8 # This program is distributed in the hope that it will be useful, | 8 # This program is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
| 12 # | 12 # |
| 13 # You should have received a copy of the GNU General Public License | 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/>. | 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | 15 |
| 16 # This file is part of the GDB testsuite. It tests the mechanism | 16 # This file is part of the GDB testsuite. It tests the mechanism |
| 17 # exposing values to Python. | 17 # exposing values to Python. |
| 18 | 18 |
| 19 if $tracelevel then { | |
| 20 strace $tracelevel | |
| 21 } | |
| 22 | |
| 23 load_lib gdb-python.exp | 19 load_lib gdb-python.exp |
| 24 | 20 |
| 25 set testfile "py-symbol" | 21 standard_testfile |
| 26 set srcfile ${testfile}.c | 22 |
| 27 set binfile ${objdir}/${subdir}/${testfile} | 23 if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} { |
| 28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debu
g}] != "" } { | |
| 29 untested "Couldn't compile ${srcfile}" | |
| 30 return -1 | 24 return -1 |
| 31 } | 25 } |
| 32 | 26 |
| 33 # Start with a fresh gdb. | |
| 34 gdb_exit | |
| 35 gdb_start | |
| 36 gdb_reinitialize_dir $srcdir/$subdir | |
| 37 gdb_load ${binfile} | |
| 38 | |
| 39 # Skip all tests if Python scripting is not enabled. | 27 # Skip all tests if Python scripting is not enabled. |
| 40 if { [skip_python_tests] } { continue } | 28 if { [skip_python_tests] } { continue } |
| 41 | 29 |
| 42 # Test looking up a global symbol before we runto_main as this is the | 30 # Test looking up a global symbol before we runto_main as this is the |
| 43 # point where we don't have a current frame, and we don't want to | 31 # point where we don't have a current frame, and we don't want to |
| 44 # require one. | 32 # require one. |
| 45 gdb_py_test_silent_cmd "python main_func = gdb.lookup_global_symbol(\"main\")" "
Lookup main" 1 | 33 gdb_py_test_silent_cmd "python main_func = gdb.lookup_global_symbol(\"main\")" "
Lookup main" 1 |
| 46 gdb_test "python print main_func.is_function" "True" "Test main_func.is_function
" | 34 gdb_test "python print main_func.is_function" "True" "Test main_func.is_function
" |
| 47 gdb_test "python print gdb.lookup_global_symbol(\"junk\")" "None" "Test lookup_g
lobal_symbol(\"junk\")" | 35 gdb_test "python print gdb.lookup_global_symbol(\"junk\")" "None" "Test lookup_g
lobal_symbol(\"junk\")" |
| 48 | 36 |
| 37 gdb_test "python print gdb.lookup_global_symbol('main').value()" "$hex .main." \ |
| 38 "print value of main" |
| 39 |
| 40 set qq_line [gdb_get_line_number "line of qq"] |
| 41 gdb_test "python print gdb.lookup_global_symbol('qq').line" "$qq_line" \ |
| 42 "print line number of qq" |
| 43 |
| 44 gdb_test "python print gdb.lookup_global_symbol('qq').value()" "72" \ |
| 45 "print value of qq" |
| 46 |
| 47 gdb_test "python print gdb.lookup_global_symbol('qq').needs_frame" \ |
| 48 "False" \ |
| 49 "print whether qq needs a frame" |
| 50 |
| 51 |
| 49 if ![runto_main] then { | 52 if ![runto_main] then { |
| 50 fail "Can't run to main" | 53 fail "Can't run to main" |
| 51 return 0 | 54 return 0 |
| 52 } | 55 } |
| 53 | 56 |
| 54 global hex decimal | 57 global hex decimal |
| 55 | 58 |
| 56 gdb_breakpoint [gdb_get_line_number "Block break here."] | 59 gdb_breakpoint [gdb_get_line_number "Block break here."] |
| 57 gdb_continue_to_breakpoint "Block break here." | 60 gdb_continue_to_breakpoint "Block break here." |
| 58 gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 | 61 gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 81 gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 | 84 gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 |
| 82 | 85 |
| 83 # Test is_variable attribute. | 86 # Test is_variable attribute. |
| 84 gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0 | 87 gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0 |
| 85 gdb_test "python print a\[0\].is_variable" "True" "Test a.is_variable" | 88 gdb_test "python print a\[0\].is_variable" "True" "Test a.is_variable" |
| 86 gdb_test "python print a\[0\].is_constant" "False" "Test a.is_constant" | 89 gdb_test "python print a\[0\].is_constant" "False" "Test a.is_constant" |
| 87 gdb_test "python print a\[0\].is_argument" "False" "Test a.is_argument" | 90 gdb_test "python print a\[0\].is_argument" "False" "Test a.is_argument" |
| 88 gdb_test "python print a\[0\].is_function" "False" "Test a.is_function" | 91 gdb_test "python print a\[0\].is_function" "False" "Test a.is_function" |
| 89 gdb_test "python print a\[0\].addr_class == gdb.SYMBOL_LOC_COMPUTED" "True" "Tes
t a.addr_class" | 92 gdb_test "python print a\[0\].addr_class == gdb.SYMBOL_LOC_COMPUTED" "True" "Tes
t a.addr_class" |
| 90 | 93 |
| 94 gdb_test "python print a\[0\].value()" \ |
| 95 "symbol requires a frame to compute its value.*"\ |
| 96 "try to print value of a without a frame" |
| 97 gdb_test "python print a\[0\].value(frame)" "0" \ |
| 98 "print value of a" |
| 99 gdb_test "python print a\[0\].needs_frame" "True" \ |
| 100 "print whether a needs a frame" |
| 101 |
| 91 # Test is_constant attribute | 102 # Test is_constant attribute |
| 92 gdb_py_test_silent_cmd "python t = gdb.lookup_symbol(\"one\")" "Get variable a"
0 | 103 gdb_py_test_silent_cmd "python t = gdb.lookup_symbol(\"one\")" "Get variable a"
0 |
| 93 gdb_test "python print t\[0\].is_variable" "False" "Test t.is_variable" | 104 gdb_test "python print t\[0\].is_variable" "False" "Test t.is_variable" |
| 94 gdb_test "python print t\[0\].is_constant" "True" "Test t.is_constant" | 105 gdb_test "python print t\[0\].is_constant" "True" "Test t.is_constant" |
| 95 gdb_test "python print t\[0\].is_argument" "False" "Test t.is_argument" | 106 gdb_test "python print t\[0\].is_argument" "False" "Test t.is_argument" |
| 96 gdb_test "python print t\[0\].is_function" "False" "Test t.is_function" | 107 gdb_test "python print t\[0\].is_function" "False" "Test t.is_function" |
| 97 gdb_test "python print t\[0\].addr_class == gdb.SYMBOL_LOC_CONST" "True" "Test t
.addr_class" | 108 gdb_test "python print t\[0\].addr_class == gdb.SYMBOL_LOC_CONST" "True" "Test t
.addr_class" |
| 98 | 109 |
| 99 # Test type attribute. | 110 # Test type attribute. |
| 100 gdb_test "python print t\[0\].type" "enum tag" "Get type" | 111 gdb_test "python print t\[0\].type" "enum tag" "Get type" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 fail "Cannot run to main." | 153 fail "Cannot run to main." |
| 143 return 0 | 154 return 0 |
| 144 } | 155 } |
| 145 gdb_breakpoint [gdb_get_line_number "Break at end."] | 156 gdb_breakpoint [gdb_get_line_number "Break at end."] |
| 146 gdb_continue_to_breakpoint "Break at end." | 157 gdb_continue_to_breakpoint "Break at end." |
| 147 gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0 | 158 gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0 |
| 148 gdb_test "python print a\[0\].is_valid()" "True" "Test symbol validity" | 159 gdb_test "python print a\[0\].is_valid()" "True" "Test symbol validity" |
| 149 delete_breakpoints | 160 delete_breakpoints |
| 150 gdb_unload | 161 gdb_unload |
| 151 gdb_test "python print a\[0\].is_valid()" "False" "Test symbol validity" | 162 gdb_test "python print a\[0\].is_valid()" "False" "Test symbol validity" |
| OLD | NEW |