2017-08-08 04:33:53 +02:00
|
|
|
""" debug utilities """
|
|
|
|
|
|
|
|
import os
|
|
|
|
import pexpect
|
2018-09-21 13:55:16 +02:00
|
|
|
import sys
|
2017-08-08 04:33:53 +02:00
|
|
|
|
2021-03-16 12:52:12 +01:00
|
|
|
from sanity_run_vpp import SanityTestCase
|
|
|
|
from shutil import rmtree
|
2021-05-31 16:08:53 +02:00
|
|
|
from config import available_cpus
|
2021-03-16 12:52:12 +01:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
gdb_path = "/usr/bin/gdb"
|
2017-08-08 04:33:53 +02:00
|
|
|
|
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
def spawn_gdb(binary_path, core_path):
|
2017-08-08 04:33:53 +02:00
|
|
|
if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
|
|
|
|
# automatically attach gdb
|
|
|
|
gdb_cmdline = "%s %s %s" % (gdb_path, binary_path, core_path)
|
|
|
|
gdb = pexpect.spawn(gdb_cmdline)
|
|
|
|
gdb.interact()
|
|
|
|
try:
|
|
|
|
gdb.terminate(True)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if gdb.isalive():
|
|
|
|
raise Exception("GDB refused to die...")
|
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
sys.stderr.write(
|
|
|
|
"Debugger '%s' does not exist or is not an executable..\n" % gdb_path
|
|
|
|
)
|
2021-03-16 12:52:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def start_vpp_in_gdb():
|
|
|
|
# here we use SanityTestCase as a dummy to inherit functionality,
|
|
|
|
# but any test case class could be used ...
|
|
|
|
SanityTestCase.set_debug_flags("attach")
|
|
|
|
SanityTestCase.tempdir = SanityTestCase.get_tempdir()
|
2022-04-26 19:02:15 +02:00
|
|
|
SanityTestCase.assign_cpus(available_cpus[: SanityTestCase.get_cpus_required()])
|
2021-03-16 12:52:12 +01:00
|
|
|
SanityTestCase.setUpConstants()
|
|
|
|
vpp_cmdline = SanityTestCase.vpp_cmdline
|
2021-05-31 16:08:53 +02:00
|
|
|
print("Hacking cmdline to make VPP interactive.")
|
|
|
|
vpp_cmdline.insert(vpp_cmdline.index("nodaemon"), "interactive")
|
2021-03-16 12:52:12 +01:00
|
|
|
print("VPP cmdline is %s" % " ".join(vpp_cmdline))
|
|
|
|
print("Running GDB.")
|
|
|
|
|
|
|
|
if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
|
|
|
|
gdb_cmdline = "%s --args %s " % (gdb_path, " ".join(vpp_cmdline))
|
|
|
|
print("GDB cmdline is %s" % gdb_cmdline)
|
|
|
|
gdb = pexpect.spawn(gdb_cmdline)
|
|
|
|
gdb.interact()
|
|
|
|
try:
|
|
|
|
gdb.terminate(True)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if gdb.isalive():
|
|
|
|
raise Exception("GDB refused to die...")
|
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
sys.stderr.write(
|
|
|
|
"Debugger '%s' does not exist or is not an executable..\n" % gdb_path
|
|
|
|
)
|