]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-linetable.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-linetable.exp
CommitLineData
1d506c26 1# Copyright 2013-2024 Free Software Foundation, Inc.
bc79de95
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
16load_lib gdb-python.exp
d82e5429 17require allow_python_tests
bc79de95
PM
18set opts {}
19standard_testfile .S
20
21if [info exists COMPILE] {
22 # make check RUNTESTFLAGS="gdb.python/py-linetable.exp COMPILE=1"
23 standard_testfile
24 lappend opts debug optimize=-O2
4fe960e8
TV
25} else {
26 require is_x86_64_m64_target
bc79de95
PM
27}
28
5b362f04 29if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $opts] } {
bc79de95
PM
30 return -1
31}
32
33if ![runto_main] {
34 return -1
35}
36
bc79de95
PM
37gdb_py_test_silent_cmd "python lt = gdb.selected_frame().find_sal().symtab.linetable()" \
38 "get instruction" 0
39
2a17c803 40gdb_test_multiline "input simple command" \
bc79de95
PM
41 "python" "" \
42 "def list_lines():" "" \
43 " for l in lt:" "" \
d7fc3181 44 " print ('L' + str(l.line) + ' A ' + hex(l.pc))" "" \
bc79de95
PM
45 "end" ""
46
47gdb_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"
d7fc3181 50gdb_test "python print(len(lt.line(42)))" "2" \
bc79de95 51 "Test length of a multiple pc line"
d7fc3181 52gdb_test "python print(len(lt.line(20)))" "1" \
bc79de95 53 "Test length of a single pc line"
d7fc3181 54gdb_test "python print(lt.line(1))" "None" \
bc79de95
PM
55 "Test None returned for line with no pc"
56
57# Test gdb.Linetable.sourcelines ()
58gdb_py_test_silent_cmd "python fset = lt.source_lines()" \
59 "Get all source lines into a frozen set" 0
f28a0564
SM
60gdb_test "python print (sorted(fset))" \
61 "\\\[20, 21, 22, 24, 25, 28, 29, 30, 32, 33, 37, 39, 40, 42, 44, 45, 46\\\].*" \
bb95117e 62 "test frozen set contains line numbers"
bc79de95
PM
63
64# Test gdb.Linetable.has_line ()
d7fc3181 65gdb_test "python print(lt.has_line(20))" \
bc79de95
PM
66 "True.*" \
67 "Test has_pcs at line 20"
d7fc3181 68gdb_test "python print(lt.has_line(44))" \
bc79de95
PM
69 "True.*" \
70 "Test has_pcs at line 40"
d7fc3181 71gdb_test "python print(lt.has_line(10))" \
bc79de95 72 "False.*" \
bb95117e 73 "test has_pcs at line 10"