When running a program on GDB, usually, the arguments for the program are given at the run
command. Is there a way to run the program using GDB and as well as g
You can run gdb with --args parameter,
gdb --args executablename arg1 arg2 arg3
If you want it to run automatically, place some commands in a file (e.g. 'run') and give it as argument: -x /tmp/cmds. Optionally you can run with -batch mode.
gdb -batch -x /tmp/cmds --args executablename arg1 arg2 arg3
Much too late, but here is a method that works during gdb
session.
gdb <executable>
then
(gdb) apropos argument
This will return lots of matches, the useful one is set args
.
set args -- Set argument list to give program being debugged when it is started.
set args arg1 arg2 ...
then
r
This will run the program, passing to main(argc, argv) the arguments and the argument count.