]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - 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
1 # Copyright 2013-2024 Free Software Foundation, Inc.
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 load_lib gdb-python.exp
17 require allow_python_tests
18 set opts {}
19 standard_testfile .S
20
21 if [info exists COMPILE] {
22 # make check RUNTESTFLAGS="gdb.python/py-linetable.exp COMPILE=1"
23 standard_testfile
24 lappend opts debug optimize=-O2
25 } else {
26 require is_x86_64_m64_target
27 }
28
29 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $opts] } {
30 return -1
31 }
32
33 if ![runto_main] {
34 return -1
35 }
36
37 gdb_py_test_silent_cmd "python lt = gdb.selected_frame().find_sal().symtab.linetable()" \
38 "get instruction" 0
39
40 gdb_test_multiline "input simple command" \
41 "python" "" \
42 "def list_lines():" "" \
43 " for l in lt:" "" \
44 " print ('L' + str(l.line) + ' A ' + hex(l.pc))" "" \
45 "end" ""
46
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"
56
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"
63
64 # Test gdb.Linetable.has_line ()
65 gdb_test "python print(lt.has_line(20))" \
66 "True.*" \
67 "Test has_pcs at line 20"
68 gdb_test "python print(lt.has_line(44))" \
69 "True.*" \
70 "Test has_pcs at line 40"
71 gdb_test "python print(lt.has_line(10))" \
72 "False.*" \
73 "test has_pcs at line 10"