a4ae050dd3a1b34d7c7c41d841c5e10ea5a479d5
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-linetable.exp
1 # Copyright 2013-2020 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 set opts {}
18 standard_testfile .S
19
20 if [info exists COMPILE] {
21 # make check RUNTESTFLAGS="gdb.python/py-linetable.exp COMPILE=1"
22 standard_testfile
23 lappend opts debug optimize=-O2
24 } elseif { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
25 verbose "Skipping ${testfile}."
26 return
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 # Skip all tests if Python scripting is not enabled.
38 if { [skip_python_tests] } { continue }
39
40 gdb_py_test_silent_cmd "python lt = gdb.selected_frame().find_sal().symtab.linetable()" \
41 "get instruction" 0
42
43 gdb_py_test_multiple "input simple command" \
44 "python" "" \
45 "def list_lines():" "" \
46 " for l in lt:" "" \
47 " print ('L' + str(l.line) + ' A ' + hex(l.pc))" "" \
48 "end" ""
49
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"
59
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"
66
67 # Test gdb.Linetable.has_line ()
68 gdb_test "python print(lt.has_line(20))" \
69 "True.*" \
70 "Test has_pcs at line 20"
71 gdb_test "python print(lt.has_line(44))" \
72 "True.*" \
73 "Test has_pcs at line 40"
74 gdb_test "python print(lt.has_line(10))" \
75 "False.*" \
76 "test has_pcs at line 10"
This page took 0.030186 seconds and 3 git commands to generate.