1 """ debug utilities """
7 from sanity_run_vpp import SanityTestCase
8 from shutil import rmtree
10 gdb_path = '/usr/bin/gdb'
13 def spawn_gdb(binary_path, core_path):
14 if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
15 # automatically attach gdb
16 gdb_cmdline = "%s %s %s" % (gdb_path, binary_path, core_path)
17 gdb = pexpect.spawn(gdb_cmdline)
24 raise Exception("GDB refused to die...")
26 sys.stderr.write("Debugger '%s' does not exist or is not "
27 "an executable..\n" % gdb_path)
30 def start_vpp_in_gdb():
31 # here we use SanityTestCase as a dummy to inherit functionality,
32 # but any test case class could be used ...
33 SanityTestCase.set_debug_flags("attach")
34 SanityTestCase.tempdir = SanityTestCase.get_tempdir()
35 if os.path.exists(SanityTestCase.tempdir):
36 if os.getenv("VPP_IN_GDB_NO_RMDIR", "0") in ["1", "y", "yes"]:
37 raise FileExistsError(
38 "Temporary directory exists and removal denied.")
39 print("Removing existing temp dir '%s'." % SanityTestCase.tempdir)
40 rmtree(SanityTestCase.tempdir)
41 print("Creating temp dir '%s'." % SanityTestCase.tempdir)
42 os.mkdir(SanityTestCase.tempdir)
43 SanityTestCase.setUpConstants()
44 vpp_cmdline = SanityTestCase.vpp_cmdline
45 if os.getenv("VPP_IN_GDB_CMDLINE", "y").lower() in ["1", "y", "yes"]:
46 print("Hacking cmdline to make VPP interactive.")
47 vpp_cmdline.insert(vpp_cmdline.index("nodaemon"), "interactive")
48 print("VPP cmdline is %s" % " ".join(vpp_cmdline))
51 if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
52 gdb_cmdline = "%s --args %s " % (gdb_path, " ".join(vpp_cmdline))
53 print("GDB cmdline is %s" % gdb_cmdline)
54 gdb = pexpect.spawn(gdb_cmdline)
61 raise Exception("GDB refused to die...")
63 sys.stderr.write("Debugger '%s' does not exist or is not "
64 "an executable..\n" % gdb_path)