1 # Copyright 2013-2023 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 load_lib gdb-python.exp
20 if [info exists COMPILE] {
21 # make check RUNTESTFLAGS="gdb.python/py-linetable.exp COMPILE=1"
23 lappend opts debug optimize=-O2
24 } elseif { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
25 verbose "Skipping ${testfile}."
29 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $opts] } {
37 # Skip all tests if Python scripting is not enabled.
38 if { [skip_python_tests] } { continue }
40 gdb_py_test_silent_cmd "python lt = gdb.selected_frame().find_sal().symtab.linetable()" \
43 gdb_test_multiline "input simple command" \
45 "def list_lines():" "" \
47 " print ('L' + str(l.line) + ' A ' + hex(l.pc))" "" \
50 gdb_test "python list_lines()" \
51 "L20 A $hex.*L21 A $hex.*L22 A $hex.*L24 A $hex.*L25 A $hex.*L40 A $hex.*L42 A $hex.*L44 A $hex.*L42 A $hex.*L46 A $hex.*" \
52 "test linetable iterator addr"
53 gdb_test "python print(len(lt.line(42)))" "2" \
54 "Test length of a multiple pc line"
55 gdb_test "python print(len(lt.line(20)))" "1" \
56 "Test length of a single pc line"
57 gdb_test "python print(lt.line(1))" "None" \
58 "Test None returned for line with no pc"
60 # Test gdb.Linetable.sourcelines ()
61 gdb_py_test_silent_cmd "python fset = lt.source_lines()" \
62 "Get all source lines into a frozen set" 0
63 gdb_test "python print (sorted(fset))" \
64 "\\\[20, 21, 22, 24, 25, 28, 29, 30, 32, 33, 37, 39, 40, 42, 44, 45, 46\\\].*" \
65 "test frozen set contains line numbers"
67 # Test gdb.Linetable.has_line ()
68 gdb_test "python print(lt.has_line(20))" \
70 "Test has_pcs at line 20"
71 gdb_test "python print(lt.has_line(44))" \
73 "Test has_pcs at line 40"
74 gdb_test "python print(lt.has_line(10))" \
76 "test has_pcs at line 10"