1"""Test single-stepping SVC. 2 3This runs as a sourced script (via -x, via run-test.py).""" 4from __future__ import print_function 5import gdb 6import sys 7 8 9n_failures = 0 10 11 12def report(cond, msg): 13 """Report success/fail of a test""" 14 if cond: 15 print("PASS: {}".format(msg)) 16 else: 17 print("FAIL: {}".format(msg)) 18 global n_failures 19 n_failures += 1 20 21 22def run_test(): 23 """Run through the tests one by one""" 24 report("lghi\t" in gdb.execute("x/i $pc", False, True), "insn #1") 25 gdb.execute("si") 26 report("larl\t" in gdb.execute("x/i $pc", False, True), "insn #2") 27 gdb.execute("si") 28 report("lghi\t" in gdb.execute("x/i $pc", False, True), "insn #3") 29 gdb.execute("si") 30 report("svc\t" in gdb.execute("x/i $pc", False, True), "insn #4") 31 gdb.execute("si") 32 report("xgr\t" in gdb.execute("x/i $pc", False, True), "insn #5") 33 gdb.execute("si") 34 report("svc\t" in gdb.execute("x/i $pc", False, True), "insn #6") 35 gdb.execute("si") 36 37 38def main(): 39 """Prepare the environment and run through the tests""" 40 try: 41 inferior = gdb.selected_inferior() 42 print("ATTACHED: {}".format(inferior.architecture().name())) 43 except (gdb.error, AttributeError): 44 print("SKIPPING (not connected)") 45 exit(0) 46 47 if gdb.parse_and_eval('$pc') == 0: 48 print("SKIP: PC not set") 49 exit(0) 50 51 try: 52 # These are not very useful in scripts 53 gdb.execute("set pagination off") 54 gdb.execute("set confirm off") 55 56 # Run the actual tests 57 run_test() 58 except gdb.error: 59 report(False, "GDB Exception: {}".format(sys.exc_info()[0])) 60 print("All tests complete: %d failures" % n_failures) 61 exit(n_failures) 62 63 64main() 65