Home | History | Annotate | Line # | Download | only in gdb.python
py-arch-reg-names.exp revision 1.1.1.1
      1  1.1  christos # Copyright 2020 Free Software Foundation, Inc.
      2  1.1  christos 
      3  1.1  christos # This program is free software; you can redistribute it and/or modify
      4  1.1  christos # it under the terms of the GNU General Public License as published by
      5  1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6  1.1  christos # (at your option) any later version.
      7  1.1  christos #
      8  1.1  christos # This program is distributed in the hope that it will be useful,
      9  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  1.1  christos # GNU General Public License for more details.
     12  1.1  christos #
     13  1.1  christos # You should have received a copy of the GNU General Public License
     14  1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  1.1  christos 
     16  1.1  christos # Check the gdb.Architecture.registers functionality.
     17  1.1  christos 
     18  1.1  christos load_lib gdb-python.exp
     19  1.1  christos standard_testfile py-arch.c
     20  1.1  christos 
     21  1.1  christos if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
     22  1.1  christos     return -1
     23  1.1  christos }
     24  1.1  christos 
     25  1.1  christos # Skip all tests if Python scripting is not enabled.
     26  1.1  christos if { [skip_python_tests] } { continue }
     27  1.1  christos 
     28  1.1  christos if ![runto_main] {
     29  1.1  christos    return -1
     30  1.1  christos }
     31  1.1  christos 
     32  1.1  christos # First, use 'info registers' to get a list of register names.
     33  1.1  christos set regs {}
     34  1.1  christos gdb_test_multiple "info registers general" "info registers general" {
     35  1.1  christos     -re "^info registers general\r\n" {
     36  1.1  christos 	exp_continue
     37  1.1  christos     }
     38  1.1  christos     -re "^(\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
     39  1.1  christos 	set reg $expect_out(1,string)
     40  1.1  christos 	lappend regs $reg
     41  1.1  christos 	exp_continue
     42  1.1  christos     }
     43  1.1  christos     -re "^$gdb_prompt " {
     44  1.1  christos     }
     45  1.1  christos }
     46  1.1  christos gdb_assert {[llength $regs] > 0} \
     47  1.1  christos     "Found at least one register"
     48  1.1  christos 
     49  1.1  christos # Now get the same register names using Python API.
     50  1.1  christos gdb_py_test_silent_cmd \
     51  1.1  christos     "python frame = gdb.selected_frame()" "get frame" 0
     52  1.1  christos gdb_py_test_silent_cmd \
     53  1.1  christos     "python arch = frame.architecture()" "get arch" 0
     54  1.1  christos gdb_py_test_silent_cmd \
     55  1.1  christos     "python regs = list (arch.registers (\"general\"))" \
     56  1.1  christos     "get general registers" 0
     57  1.1  christos gdb_py_test_silent_cmd \
     58  1.1  christos     "python regs = map (lambda r : r.name, regs)" \
     59  1.1  christos     "get names of general registers" 0
     60  1.1  christos 
     61  1.1  christos set py_regs {}
     62  1.1  christos gdb_test_multiple "python print (\"\\n\".join (regs))" \
     63  1.1  christos     "general register from python" {
     64  1.1  christos 	-re "^python print \[^\r\n\]+\r\n" {
     65  1.1  christos 	    exp_continue
     66  1.1  christos 	}
     67  1.1  christos 	-re "^(\[^\r\n\]+)\r\n" {
     68  1.1  christos 	    set reg $expect_out(1,string)
     69  1.1  christos 	    lappend py_regs $reg
     70  1.1  christos 	    exp_continue
     71  1.1  christos 	}
     72  1.1  christos 	-re "^$gdb_prompt " {
     73  1.1  christos 	}
     74  1.1  christos     }
     75  1.1  christos 
     76  1.1  christos gdb_assert {[llength $py_regs] > 0} \
     77  1.1  christos     "Found at least one register from python"
     78  1.1  christos gdb_assert {[llength $py_regs] == [llength $regs]} \
     79  1.1  christos     "Same numnber of registers found"
     80  1.1  christos 
     81  1.1  christos set found_non_match 0
     82  1.1  christos for { set i 0 } { $i < [llength $regs] } { incr i } {
     83  1.1  christos     if {[lindex $regs $i] != [lindex $py_regs $i]} {
     84  1.1  christos 	set found_non_match 1
     85  1.1  christos     }
     86  1.1  christos }
     87  1.1  christos gdb_assert { $found_non_match == 0 } "all registers match"
     88  1.1  christos 
     89  1.1  christos # Check that we get the same register descriptors from two different
     90  1.1  christos # iterators.
     91  1.1  christos gdb_py_test_silent_cmd \
     92  1.1  christos     "python iter1 = arch.registers ()" \
     93  1.1  christos     "get first all register iterator" 0
     94  1.1  christos gdb_py_test_silent_cmd \
     95  1.1  christos     "python iter2 = arch.registers ()" \
     96  1.1  christos     "get second all register iterator" 0
     97  1.1  christos gdb_py_test_silent_cmd \
     98  1.1  christos     [multi_line_input \
     99  1.1  christos 	 "python" \
    100  1.1  christos 	 "for r1, r2 in zip(iter1, iter2):" \
    101  1.1  christos 	 "  if (r1.name != r2.name):"\
    102  1.1  christos 	 "    raise gdb.GdbError (\"miss-matched names\")" \
    103  1.1  christos 	 "  if (r1 != r2):" \
    104  1.1  christos 	 "    raise gdb.GdbError (\"miss-matched objects\")" \
    105  1.1  christos 	 "\004" ] \
    106  1.1  christos     "check names and objects match" 1
    107  1.1  christos 
    108  1.1  christos # Ensure that the '.find' method on the iterator returns the same
    109  1.1  christos # Python object as we got from the iterator's list of descriptors.
    110  1.1  christos gdb_py_test_silent_cmd \
    111  1.1  christos     [multi_line \
    112  1.1  christos 	 "python" \
    113  1.1  christos 	 "def check_regs (arch, regs):" \
    114  1.1  christos 	 "   for r in (regs):" \
    115  1.1  christos 	 "     if (arch.registers ().find (r.name) != r):" \
    116  1.1  christos 	 "       raise gdb.GdbError (\"object miss-match\")" \
    117  1.1  christos 	 "end" ] \
    118  1.1  christos     "build check_obj function" 0
    119  1.1  christos gdb_py_test_silent_cmd \
    120  1.1  christos     "python check_regs (arch, arch.registers (\"general\"))" \
    121  1.1  christos     "ensure find gets expected descriptors" 1
    122