Add --gdb option to run any program or test under gdb

This commit is contained in:
Alexander Krotov
2019-03-20 18:42:38 +03:00
parent aa3b2c88cd
commit 269d982c7b
2 changed files with 15 additions and 2 deletions

View File

@@ -200,6 +200,10 @@ def options(opt):
' argument is the path to the python program, optionally followed'
' by command-line options that are passed to the program.'),
type="string", default='', dest='pyrun_no_build')
opt.add_option('--gdb',
help=('Change the default command template to run programs and unit tests with gdb'),
action="store_true", default=False,
dest='gdb')
opt.add_option('--valgrind',
help=('Change the default command template to run programs and unit tests with valgrind'),
action="store_true", default=False,

View File

@@ -113,8 +113,17 @@ def run_argv(argv, env, os_env=None, cwd=None, force_no_valgrind=False):
if Options.options.valgrind and Options.options.command_template:
raise WafError("Options --command-template and --valgrind are conflicting")
if Options.options.gdb and Options.options.command_template:
raise WafError("Options --command-template and --gdb are conflicting")
if Options.options.gdb and Options.options.valgrind:
raise WafError("Options --valgrind and --gdb are conflicting")
if Options.options.valgrind and not force_no_valgrind:
if Options.options.gdb:
argv = ["gdb", "--args"] + argv
proc = subprocess.Popen(argv, env=proc_env, cwd=cwd)
retval = proc.wait()
return retval
elif Options.options.valgrind and not force_no_valgrind:
if not env['VALGRIND']:
raise WafError("valgrind is not installed")
# Use the first program found in the env['VALGRIND'] list
@@ -152,7 +161,7 @@ def run_argv(argv, env, os_env=None, cwd=None, force_no_valgrind=False):
if signame:
raise WafError("Command %s terminated with signal %s."
" Run it under a debugger to get more information "
"(./waf --run <program> --command-template=\"gdb --args %%s <args>\")." % (argv, signame))
"(./waf --run <program> --gdb\")." % (argv, signame))
else:
raise WafError("Command %s exited with code %i" % (argv, retval))
return retval