1 """ debug utilities """
7 from sanity_run_vpp import SanityTestCase
8 from shutil import rmtree
9 from cpu_config import available_cpus
11 gdb_path = '/usr/bin/gdb'
14 def spawn_gdb(binary_path, core_path):
15 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)
25 raise Exception("GDB refused to die...")
27 sys.stderr.write("Debugger '%s' does not exist or is not "
28 "an executable..\n" % gdb_path)
31 def 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()
36 if os.path.exists(SanityTestCase.tempdir):
37 if os.getenv("VPP_IN_GDB_NO_RMDIR", "0") in ["1", "y", "yes"]:
38 raise FileExistsError(
39 "Temporary directory exists and removal denied.")
40 print("Removing existing temp dir '%s'." % SanityTestCase.tempdir)
41 rmtree(SanityTestCase.tempdir)
42 print("Creating temp dir '%s'." % SanityTestCase.tempdir)
43 os.mkdir(SanityTestCase.tempdir)
44 SanityTestCase.assign_cpus(
45 available_cpus[:SanityTestCase.get_cpus_required()])
46 SanityTestCase.setUpConstants()
47 vpp_cmdline = SanityTestCase.vpp_cmdline
48 if os.getenv("VPP_IN_GDB_CMDLINE", "y").lower() in ["1", "y", "yes"]:
49 print("Hacking cmdline to make VPP interactive.")
50 vpp_cmdline.insert(vpp_cmdline.index("nodaemon"), "interactive")
51 print("VPP cmdline is %s" % " ".join(vpp_cmdline))
54 if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
55 gdb_cmdline = "%s --args %s " % (gdb_path, " ".join(vpp_cmdline))
56 print("GDB cmdline is %s" % gdb_cmdline)
57 gdb = pexpect.spawn(gdb_cmdline)
64 raise Exception("GDB refused to die...")
66 sys.stderr.write("Debugger '%s' does not exist or is not "
67 "an executable..\n" % gdb_path)