blob: 0ab143201c8b017de8b78af1bce945998c9ecd65 [file] [log] [blame]
Klement Sekera909a6a12017-08-08 04:33:53 +02001""" debug utilities """
2
3import os
4import pexpect
juraj.linkes40dd73b2018-09-21 13:55:16 +02005import sys
Klement Sekera909a6a12017-08-08 04:33:53 +02006
Klement Sekerae2636852021-03-16 12:52:12 +01007from sanity_run_vpp import SanityTestCase
8from shutil import rmtree
Klement Sekerab23ffd72021-05-31 16:08:53 +02009from config import available_cpus
Klement Sekerae2636852021-03-16 12:52:12 +010010
Klement Sekera909a6a12017-08-08 04:33:53 +020011gdb_path = '/usr/bin/gdb'
12
13
juraj.linkes40dd73b2018-09-21 13:55:16 +020014def spawn_gdb(binary_path, core_path):
Klement Sekera909a6a12017-08-08 04:33:53 +020015 if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
16 # automatically attach gdb
17 gdb_cmdline = "%s %s %s" % (gdb_path, binary_path, core_path)
18 gdb = pexpect.spawn(gdb_cmdline)
19 gdb.interact()
20 try:
21 gdb.terminate(True)
22 except:
23 pass
24 if gdb.isalive():
25 raise Exception("GDB refused to die...")
26 else:
juraj.linkes40dd73b2018-09-21 13:55:16 +020027 sys.stderr.write("Debugger '%s' does not exist or is not "
28 "an executable..\n" % gdb_path)
Klement Sekerae2636852021-03-16 12:52:12 +010029
30
31def start_vpp_in_gdb():
32 # here we use SanityTestCase as a dummy to inherit functionality,
33 # but any test case class could be used ...
34 SanityTestCase.set_debug_flags("attach")
35 SanityTestCase.tempdir = SanityTestCase.get_tempdir()
Klement Sekera1dc146e2021-07-01 14:55:46 +020036 SanityTestCase.assign_cpus(
37 available_cpus[:SanityTestCase.get_cpus_required()])
Klement Sekerae2636852021-03-16 12:52:12 +010038 SanityTestCase.setUpConstants()
39 vpp_cmdline = SanityTestCase.vpp_cmdline
Klement Sekerab23ffd72021-05-31 16:08:53 +020040 print("Hacking cmdline to make VPP interactive.")
41 vpp_cmdline.insert(vpp_cmdline.index("nodaemon"), "interactive")
Klement Sekerae2636852021-03-16 12:52:12 +010042 print("VPP cmdline is %s" % " ".join(vpp_cmdline))
43 print("Running GDB.")
44
45 if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
46 gdb_cmdline = "%s --args %s " % (gdb_path, " ".join(vpp_cmdline))
47 print("GDB cmdline is %s" % gdb_cmdline)
48 gdb = pexpect.spawn(gdb_cmdline)
49 gdb.interact()
50 try:
51 gdb.terminate(True)
52 except:
53 pass
54 if gdb.isalive():
55 raise Exception("GDB refused to die...")
56 else:
57 sys.stderr.write("Debugger '%s' does not exist or is not "
58 "an executable..\n" % gdb_path)