diff --git a/wscript b/wscript index 85d70b667..a58858c4c 100644 --- a/wscript +++ b/wscript @@ -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, diff --git a/wutils.py b/wutils.py index 3dded5430..d07f79427 100644 --- a/wutils.py +++ b/wutils.py @@ -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 --command-template=\"gdb --args %%s \")." % (argv, signame)) + "(./waf --run --gdb\")." % (argv, signame)) else: raise WafError("Command %s exited with code %i" % (argv, retval)) return retval