xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.python/py-linetable.exp (revision 528ce0b18ee40383f14928382d06afd754b01561)
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
16load_lib gdb-python.exp
17set opts {}
18standard_testfile .S
19
20if [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
29if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $opts] } {
30    return -1
31}
32
33if ![runto_main] {
34    return -1
35}
36
37# Skip all tests if Python scripting is not enabled.
38if { [skip_python_tests] } { continue }
39
40gdb_py_test_silent_cmd "python lt = gdb.selected_frame().find_sal().symtab.linetable()" \
41    "get instruction" 0
42
43gdb_test_multiline "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
50gdb_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"
53gdb_test "python print(len(lt.line(42)))" "2" \
54    "Test length of a multiple pc line"
55gdb_test "python print(len(lt.line(20)))" "1" \
56    "Test length of a single pc line"
57gdb_test "python print(lt.line(1))" "None" \
58    "Test None returned for line with no pc"
59
60# Test gdb.Linetable.sourcelines ()
61gdb_py_test_silent_cmd "python fset = lt.source_lines()" \
62    "Get all source lines into a frozen set" 0
63gdb_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 ()
68gdb_test "python print(lt.has_line(20))" \
69    "True.*" \
70    "Test has_pcs at line 20"
71gdb_test "python print(lt.has_line(44))" \
72    "True.*" \
73    "Test has_pcs at line 40"
74gdb_test "python print(lt.has_line(10))" \
75    "False.*" \
76    "test has_pcs at line 10"
77