1 # Copyright 2013-2024 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
17 require allow_python_tests
21 if [info exists COMPILE] {
22 # make check RUNTESTFLAGS="gdb.python/py-linetable.exp COMPILE=1"
24 lappend opts debug optimize=-O2
26 require is_x86_64_m64_target
29 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $opts] } {
37 gdb_py_test_silent_cmd "python lt = gdb.selected_frame().find_sal().symtab.linetable()" \
40 gdb_test_multiline "input simple command" \
42 "def list_lines():" "" \
44 " print ('L' + str(l.line) + ' A ' + hex(l.pc))" "" \
47 gdb_test "python list_lines()" \
48 "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.*" \
49 "test linetable iterator addr"
50 gdb_test "python print(len(lt.line(42)))" "2" \
51 "Test length of a multiple pc line"
52 gdb_test "python print(len(lt.line(20)))" "1" \
53 "Test length of a single pc line"
54 gdb_test "python print(lt.line(1))" "None" \
55 "Test None returned for line with no pc"
57 # Test gdb.Linetable.sourcelines ()
58 gdb_py_test_silent_cmd "python fset = lt.source_lines()" \
59 "Get all source lines into a frozen set" 0
60 gdb_test "python print (sorted(fset))" \
61 "\\\[20, 21, 22, 24, 25, 28, 29, 30, 32, 33, 37, 39, 40, 42, 44, 45, 46\\\].*" \
62 "test frozen set contains line numbers"
64 # Test gdb.Linetable.has_line ()
65 gdb_test "python print(lt.has_line(20))" \
67 "Test has_pcs at line 20"
68 gdb_test "python print(lt.has_line(44))" \
70 "Test has_pcs at line 40"
71 gdb_test "python print(lt.has_line(10))" \
73 "test has_pcs at line 10"